diff --git a/crates/draw/tests/it/gradient_fill.rs b/crates/draw/tests/it/gradient_fill.rs index ae28c566e..9e415be9c 100644 --- a/crates/draw/tests/it/gradient_fill.rs +++ b/crates/draw/tests/it/gradient_fill.rs @@ -158,7 +158,9 @@ fn a_style_tile_samples_its_parameter_from_the_start_point_outward() { assert!(t(tile, 0.5, 0.5) < t(tile, 0.6, 0.5) && t(tile, 0.6, 0.5) < t(tile, 0.9, 0.5)); assert!((t(tile, 0.7, 0.5) - t(tile, 0.5, 0.3)).abs() < 1e-4); } - // A corner-ward step along the diagonal is farther in a circle than in a rectangle. - assert!(t(circle, 0.7, 0.7) > t(rect, 0.7, 0.7) + 0.05); + // Both reach 1 at the farthest corner, so a diagonal step reads the same in both; along an axis the rectangle's + // square isoline is nearer the centre than the circle's, so it rises faster there. + assert!((t(circle, 0.7, 0.7) - t(rect, 0.7, 0.7)).abs() < 1e-4, "both outlines reach the corner together"); + assert!(t(rect, 0.9, 0.5) > t(circle, 0.9, 0.5) + 0.05, "along an axis a rectangle rises faster than a circle"); assert!((t(rect, 0.7, 0.7) - t(rect, 0.7, 0.5)).abs() < 1e-4, "a rectangle's isoline is square"); } diff --git a/crates/ui-contract/src/contract/editor.rs b/crates/ui-contract/src/contract/editor.rs index 9591077a4..3c3442385 100644 --- a/crates/ui-contract/src/contract/editor.rs +++ b/crates/ui-contract/src/contract/editor.rs @@ -154,7 +154,7 @@ impl EditorHandle { .collect(); let text = state.lines.iter().map(|line| line.text).collect::>().join("\n"); let selection = state.selection.or(Some((state.caret_at, state.caret_at))); - Some(TextFacts { widget: self.widget, text, masked, editable: !self.read_only, lines, selection }) + Some(TextFacts { widget: self.widget, text, masked, editable: !self.read_only, disabled: false, lines, selection }) } } diff --git a/crates/ui-contract/src/contract/text.rs b/crates/ui-contract/src/contract/text.rs index dd8701a4d..1236b4d8d 100644 --- a/crates/ui-contract/src/contract/text.rs +++ b/crates/ui-contract/src/contract/text.rs @@ -316,6 +316,7 @@ fn facts( rect: Rect, masked: bool, read_only: bool, + enabled: bool, ) { if !text_access::exposed(&cx.core.ctx, widget) { state.rows = None; @@ -325,7 +326,7 @@ fn facts( let text = out.layout.full.clone(); let selection = adapter::selection(&cx.core.ctx, widget).map(|(caret, anchor)| (rows.pos(&text, anchor), rows.pos(&text, caret))); *cx.core.text_access.borrow_mut() = - Some(text_access::TextFacts { widget, text, masked, editable: !read_only, lines: rows.lines.clone(), selection }); + Some(text_access::TextFacts { widget, text, masked, editable: !read_only, disabled: !enabled, lines: rows.lines.clone(), selection }); state.rows = Some(rows); } @@ -508,7 +509,7 @@ pub(crate) fn run( if let Some(baseline) = out.baseline { cx.core.paint.borrow_mut().baseline.get_or_insert(baseline); } - facts(cx, &mut state, widget, &out, decl.rect, decl.options.mask, read_only); + facts(cx, &mut state, widget, &out, decl.rect, decl.options.mask, read_only, enabled); cx.core.text_invalid = state.invalid; cx.core.text_unparsed = decl.options.unparsed.clone().filter(|_| state.invalid); cx.core.escape_to_list = state.completions.open || list_open; diff --git a/crates/ui-contract/src/runtime/access/text.rs b/crates/ui-contract/src/runtime/access/text.rs index 87d4fe449..db1bbec91 100644 --- a/crates/ui-contract/src/runtime/access/text.rs +++ b/crates/ui-contract/src/runtime/access/text.rs @@ -43,6 +43,8 @@ pub(crate) struct TextFacts { /// A password: the node carries no value and exposes no runs. pub masked: bool, pub editable: bool, + /// The text part is disabled (its component may not be): the owner's node stands for the part and says so. + pub disabled: bool, pub lines: Vec, /// The anchor and focus as a line index and a byte offset in the line. pub selection: Option<(TextPos, TextPos)>, @@ -112,7 +114,7 @@ pub(crate) fn report_text(ctx: &Context, owner: Id, facts: &TextFacts) { Some((anchor_node, anchor_at, focus_node, focus_at)) }); let value = (!facts.masked).then_some(facts.text.as_str()); - adapter::write_text(ctx, owner, &TextNode { value, editable: facts.editable, selection }); + adapter::write_text(ctx, owner, &TextNode { value, editable: facts.editable, disabled: facts.disabled, selection }); Service::::run(ctx, |tables| tables.0.insert(owner, entries)); } diff --git a/crates/ui-contract/src/runtime/egui/access/text.rs b/crates/ui-contract/src/runtime/egui/access/text.rs index 8566d9b8d..ed3ac3b41 100644 --- a/crates/ui-contract/src/runtime/egui/access/text.rs +++ b/crates/ui-contract/src/runtime/egui/access/text.rs @@ -36,6 +36,8 @@ pub(crate) struct TextNode<'a> { /// The text; `None` for a node that exposes none (a masked field). pub value: Option<&'a str>, pub editable: bool, + /// The node is disabled. + pub disabled: bool, /// The anchor and focus of the selection, `None` while the text has no runs. pub selection: Option<(Id, usize, Id, usize)>, } @@ -113,6 +115,9 @@ pub(crate) fn write_text(ctx: &Context, id: Id, text: &TextNode<'_>) { node.set_value(value.to_owned()); } node.add_action(accesskit::Action::SetTextSelection); + if text.disabled { + node.set_disabled(); + } if text.editable { node.add_action(accesskit::Action::SetValue); node.add_action(accesskit::Action::ReplaceSelectedText);