From 0a8a301607152fe4aa19c0599b61064cbc75d538 Mon Sep 17 00:00:00 2001 From: Olivier FAURE Date: Tue, 18 Feb 2025 16:58:32 +0100 Subject: [PATCH] Add Properties argument to widget methods --- masonry/examples/calc_masonry.rs | 39 +++- masonry/examples/custom_widget.rs | 37 +++- masonry/src/core/widget.rs | 48 ++++- masonry/src/doc/02_implementing_widget.md | 36 ++-- .../doc/03_implementing_container_widget.md | 16 +- masonry/src/passes/accessibility.rs | 7 +- masonry/src/passes/anim.rs | 7 +- masonry/src/passes/event.rs | 23 ++- masonry/src/passes/layout.rs | 7 +- masonry/src/passes/paint.rs | 7 +- masonry/src/passes/update.rs | 63 +++--- masonry/src/testing/helper_widgets.rs | 193 ++++++++++++------ masonry/src/widgets/align.rs | 39 +++- masonry/src/widgets/button.rs | 39 +++- masonry/src/widgets/checkbox.rs | 16 +- masonry/src/widgets/flex.rs | 14 +- masonry/src/widgets/grid.rs | 14 +- masonry/src/widgets/image.rs | 16 +- masonry/src/widgets/label.rs | 16 +- masonry/src/widgets/portal.rs | 40 +++- masonry/src/widgets/progress_bar.rs | 40 +++- masonry/src/widgets/prose.rs | 16 +- masonry/src/widgets/root_widget.rs | 38 +++- masonry/src/widgets/scroll_bar.rs | 16 +- masonry/src/widgets/sized_box.rs | 14 +- masonry/src/widgets/spinner.rs | 18 +- masonry/src/widgets/split.rs | 37 +++- masonry/src/widgets/tests/layout.rs | 2 +- masonry/src/widgets/tests/safety_rails.rs | 34 +-- masonry/src/widgets/text_area.rs | 38 +++- masonry/src/widgets/textbox.rs | 16 +- masonry/src/widgets/variable_label.rs | 18 +- masonry/src/widgets/zstack.rs | 15 +- xilem/src/any_view.rs | 38 +++- xilem/src/one_of.rs | 37 +++- 35 files changed, 724 insertions(+), 330 deletions(-) diff --git a/masonry/examples/calc_masonry.rs b/masonry/examples/calc_masonry.rs index 7cbd8b706..9ea0a3ffd 100644 --- a/masonry/examples/calc_masonry.rs +++ b/masonry/examples/calc_masonry.rs @@ -16,8 +16,8 @@ use accesskit::{Node, Role}; use masonry::app::{AppDriver, DriverCtx}; use masonry::core::{ AccessCtx, AccessEvent, Action, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, - QueryCtx, RegisterCtx, StyleProperty, TextEvent, Update, UpdateCtx, Widget, WidgetId, - WidgetPod, + Properties, PropertiesMut, QueryCtx, RegisterCtx, StyleProperty, TextEvent, Update, UpdateCtx, + Widget, WidgetId, WidgetPod, }; use masonry::dpi::LogicalSize; use masonry::kurbo::{Point, Size}; @@ -148,7 +148,12 @@ impl CalcButton { } impl Widget for CalcButton { - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) { + fn on_pointer_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &PointerEvent, + ) { match event { PointerEvent::PointerDown(_, _) => { if !ctx.is_disabled() { @@ -176,9 +181,20 @@ impl Widget for CalcButton { } } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &TextEvent, + ) { + } - fn on_access_event(&mut self, ctx: &mut EventCtx, event: &AccessEvent) { + fn on_access_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &AccessEvent, + ) { if ctx.target() == ctx.widget_id() { match event.action { accesskit::Action::Click => { @@ -189,7 +205,7 @@ impl Widget for CalcButton { } } - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) { + fn update(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, event: &Update) { // Masonry doesn't let us change a widget's attributes directly. // We use `mutate_later` to get a mutable reference to the inner widget // and change its border color. This is a simple way to implement a @@ -214,20 +230,25 @@ impl Widget for CalcButton { ctx.register_child(&mut self.inner); } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { let size = ctx.run_layout(&mut self.inner, bc); ctx.place_child(&mut self.inner, Point::ORIGIN); size } - fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {} + fn paint(&mut self, _ctx: &mut PaintCtx, _props: &Properties<'_>, _scene: &mut Scene) {} fn accessibility_role(&self) -> Role { Role::Button } - fn accessibility(&mut self, _ctx: &mut AccessCtx, node: &mut Node) { + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, node: &mut Node) { let _name = match self.action { CalcAction::Digit(digit) => digit.to_string(), CalcAction::Op(op) => op.to_string(), diff --git a/masonry/examples/custom_widget.rs b/masonry/examples/custom_widget.rs index 8a85be248..ba0cbdc99 100644 --- a/masonry/examples/custom_widget.rs +++ b/masonry/examples/custom_widget.rs @@ -14,7 +14,7 @@ use accesskit::{Node, Role}; use masonry::app::{AppDriver, DriverCtx}; use masonry::core::{ AccessCtx, AccessEvent, Action, BoxConstraints, EventCtx, LayoutCtx, ObjectFit, PaintCtx, - PointerEvent, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, + PointerEvent, Properties, PropertiesMut, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, }; use masonry::kurbo::{Affine, BezPath, Point, Rect, Size, Stroke}; use masonry::palette; @@ -37,15 +37,38 @@ impl AppDriver for Driver { struct CustomWidget(String); impl Widget for CustomWidget { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} + fn on_pointer_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &PointerEvent, + ) { + } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &TextEvent, + ) { + } - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &AccessEvent, + ) { + } fn register_children(&mut self, _ctx: &mut RegisterCtx) {} - fn layout(&mut self, _layout_ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + _layout_ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { // BoxConstraints are passed by the parent widget. // This method can return any Size within those constraints: // bc.constrain(my_size) @@ -68,7 +91,7 @@ impl Widget for CustomWidget { // The paint method gets called last, after an event flow. // It goes event -> update -> layout -> paint, and each method can influence the next. // Basically, anything that changes the appearance of a widget causes a paint. - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { // Clear the whole widget with the color of your choice // (ctx.size() returns the size of the layout rect we're painting in) // Note: ctx also has a `clear` method, but that clears the whole context, @@ -137,7 +160,7 @@ impl Widget for CustomWidget { Role::Window } - fn accessibility(&mut self, _ctx: &mut AccessCtx, node: &mut Node) { + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, node: &mut Node) { let text = &self.0; node.set_label( format!("This is a demo of the Masonry Widget trait. Masonry has accessibility tree support. The demo shows colored shapes with the text '{text}'."), diff --git a/masonry/src/core/widget.rs b/masonry/src/core/widget.rs index 46a99dcf4..9a089e95d 100644 --- a/masonry/src/core/widget.rs +++ b/masonry/src/core/widget.rs @@ -15,7 +15,8 @@ use vello::Scene; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, PaintCtx, - PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, WidgetRef, + PointerEvent, Properties, PropertiesMut, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, + WidgetRef, }; use crate::kurbo::{Point, Size}; use crate::AsAny; @@ -128,19 +129,37 @@ pub trait Widget: AsAny + AsDynWidget { /// /// Pointer events will target the widget under the pointer, and then the /// event will bubble to each of its parents. - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) {} + fn on_pointer_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &PointerEvent, + ) { + } /// Handle a text event. /// /// Text events will target the [focused widget], then bubble to each parent. /// /// [focused widget]: crate::doc::doc_06_masonry_concepts#text-focus - fn on_text_event(&mut self, ctx: &mut EventCtx, event: &TextEvent) {} + fn on_text_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &TextEvent, + ) { + } /// Handle an event from the platform's accessibility API. /// /// Accessibility events target a specific widget id, then bubble to each parent. - fn on_access_event(&mut self, ctx: &mut EventCtx, event: &AccessEvent) {} + fn on_access_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &AccessEvent, + ) { + } /// Called at the beginning of a new animation frame. /// @@ -161,7 +180,13 @@ pub trait Widget: AsAny + AsDynWidget { /// For that reason, you should try to avoid doing anything computationally /// intensive in response to an `AnimFrame` event: it might make the app miss /// the monitor's refresh, causing lag or jerky animations. - fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, interval: u64) {} + fn on_anim_frame( + &mut self, + ctx: &mut UpdateCtx, + _props: &mut PropertiesMut<'_>, + interval: u64, + ) { + } // TODO - Reorder methods to match 02_implementing_widget.md @@ -179,7 +204,7 @@ pub trait Widget: AsAny + AsDynWidget { /// This method is called to notify your widget of certain special events, /// (available in the [`Update`] enum) that are generally related to /// changes in the widget graph or in the state of your specific widget. - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {} + fn update(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, event: &Update) {} /// Compute layout and return the widget's size. /// @@ -206,7 +231,12 @@ pub trait Widget: AsAny + AsDynWidget { /// While each widget should try to return a size that fits the input constraints, /// **any widget may return a size that doesn't fit its constraints**, and container /// widgets should handle those cases gracefully. - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size; + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size; fn compose(&mut self, ctx: &mut ComposeCtx) {} @@ -216,11 +246,11 @@ pub trait Widget: AsAny + AsDynWidget { /// children, or annotations (for example, scrollbars) by painting /// afterwards. In addition, they can apply masks and transforms on /// the render context, which is especially useful for scrolling. - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene); + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene); fn accessibility_role(&self) -> Role; - fn accessibility(&mut self, ctx: &mut AccessCtx, node: &mut Node); + fn accessibility(&mut self, ctx: &mut AccessCtx, _props: &Properties<'_>, node: &mut Node); /// Return ids of this widget's children. /// diff --git a/masonry/src/doc/02_implementing_widget.md b/masonry/src/doc/02_implementing_widget.md index 75ebf9534..88d34f2e8 100644 --- a/masonry/src/doc/02_implementing_widget.md +++ b/masonry/src/doc/02_implementing_widget.md @@ -25,18 +25,18 @@ Widgets are types which implement the [`Widget`] trait: ```rust,ignore trait Widget { - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent); - fn on_text_event(&mut self, ctx: &mut EventCtx, event: &TextEvent); - fn on_access_event(&mut self, ctx: &mut EventCtx, event: &AccessEvent); + fn on_pointer_event(&mut self, ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, event: &PointerEvent); + fn on_text_event(&mut self, ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, event: &TextEvent); + fn on_access_event(&mut self, ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, event: &AccessEvent); - fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, interval: u64); - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update); + fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, interval: u64); + fn update(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, event: &Update); - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size; + fn layout(&mut self, ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size; - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene); + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene); fn accessibility_role(&self) -> Role; - fn accessibility(&mut self, ctx: &mut AccessCtx, node: &mut Node); + fn accessibility(&mut self, ctx: &mut AccessCtx, _props: &Properties<'_>, node: &mut Node); // ... } @@ -90,7 +90,7 @@ use masonry::core::{ }; impl Widget for ColorRectangle { - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) { + fn on_pointer_event(&mut self, ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, event: &PointerEvent) { match event { PointerEvent::PointerDown(PointerButton::Primary, _) => { ctx.submit_action(Action::ButtonPressed(PointerButton::Primary)); @@ -99,9 +99,9 @@ impl Widget for ColorRectangle { } } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, ctx: &mut EventCtx, event: &AccessEvent) { + fn on_access_event(&mut self, ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, event: &AccessEvent) { match event.action { accesskit::Action::Default => { ctx.submit_action(Action::ButtonPressed(PointerButton::Primary)); @@ -136,8 +136,8 @@ use masonry::core::{ impl Widget for ColorRectangle { // ... - fn on_anim_frame(&mut self, _ctx: &mut UpdateCtx, _interval: u64) {} - fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {} + fn on_anim_frame(&mut self, _ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, _interval: u64) {} + fn update(&mut self, _ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, _event: &Update) {} // ... } @@ -155,7 +155,7 @@ use masonry::core::{ impl Widget for ColorRectangle { // ... - fn layout(&mut self, _ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, _ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { bc.constrain(self.size) } @@ -182,7 +182,7 @@ use accesskit::{Node, Role}; impl Widget for ColorRectangle { // ... - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { let rect = ctx.size().to_rect(); scene.fill( Fill::NonZero, @@ -197,7 +197,7 @@ impl Widget for ColorRectangle { Role::Button } - fn accessibility(&mut self, ctx: &mut AccessCtx, node: &mut Node) { + fn accessibility(&mut self, ctx: &mut AccessCtx, _props: &Properties<'_>, node: &mut Node) { node.set_default_action_verb(DefaultActionVerb::Click); } @@ -302,7 +302,7 @@ First, we update our paint method: impl Widget for ColorRectangle { // ... - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { let rect = ctx.size().to_rect(); let color = if ctx.is_hovered() { Color::WHITE @@ -330,7 +330,7 @@ Let's re-implement the `update` method: impl Widget for ColorRectangle { // ... - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) { + fn update(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, event: &Update) { match event { Update::HoveredChanged(_) => { ctx.request_render(); diff --git a/masonry/src/doc/03_implementing_container_widget.md b/masonry/src/doc/03_implementing_container_widget.md index 21be30bd3..ec86bb896 100644 --- a/masonry/src/doc/03_implementing_container_widget.md +++ b/masonry/src/doc/03_implementing_container_widget.md @@ -85,7 +85,7 @@ use masonry::core::{ impl Widget for VerticalStack { // ... - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { let total_width = bc.max().width; let total_height = bc.max().height; let total_child_height = total_height - self.gap * (self.children.len() - 1) as f64; @@ -228,22 +228,22 @@ In the case of our `VerticalStack`, all of them can be left empty: ```rust,ignore impl Widget for VerticalStack { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &PointerEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} + fn on_access_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &AccessEvent) {} - fn on_anim_frame(&mut self, _ctx: &mut UpdateCtx, _interval: u64) {} - fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {} + fn on_anim_frame(&mut self, _ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, _interval: u64) {} + fn update(&mut self, _ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, _event: &Update) {} // ... - fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {} + fn paint(&mut self, _ctx: &mut PaintCtx, _props: &Properties<'_>, _scene: &mut Scene) {} fn accessibility_role(&self) -> Role { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} // ... } diff --git a/masonry/src/passes/accessibility.rs b/masonry/src/passes/accessibility.rs index 0922c11a0..75a71cf2b 100644 --- a/masonry/src/passes/accessibility.rs +++ b/masonry/src/passes/accessibility.rs @@ -7,7 +7,7 @@ use tree_arena::ArenaMut; use vello::kurbo::Rect; use crate::app::{RenderRoot, RenderRootState}; -use crate::core::{AccessCtx, Widget, WidgetState}; +use crate::core::{AccessCtx, Properties, Widget, WidgetState}; use crate::passes::{enter_span_if, recurse_on_children}; // --- MARK: BUILD TREE --- @@ -52,7 +52,10 @@ fn build_accessibility_tree( rebuild_all, }; let mut node = build_access_node(&mut **widget.item, &mut ctx, scale_factor); - widget.item.accessibility(&mut ctx, &mut node); + let props = Properties { + map: properties.item, + }; + widget.item.accessibility(&mut ctx, &props, &mut node); let id: NodeId = ctx.widget_state.id.into(); if ctx.global_state.trace.access { diff --git a/masonry/src/passes/anim.rs b/masonry/src/passes/anim.rs index bbeb7b55e..04f0ab48f 100644 --- a/masonry/src/passes/anim.rs +++ b/masonry/src/passes/anim.rs @@ -5,7 +5,7 @@ use tracing::info_span; use tree_arena::ArenaMut; use crate::app::{RenderRoot, RenderRootState}; -use crate::core::{UpdateCtx, Widget, WidgetState}; +use crate::core::{PropertiesMut, UpdateCtx, Widget, WidgetState}; use crate::passes::{enter_span_if, recurse_on_children}; // --- MARK: UPDATE ANIM --- @@ -40,7 +40,10 @@ fn update_anim_for_widget( widget_children: widget.children.reborrow_mut(), properties_children: properties.children.reborrow_mut(), }; - widget.item.on_anim_frame(&mut ctx, elapsed_ns); + let mut props = PropertiesMut { + map: properties.item, + }; + widget.item.on_anim_frame(&mut ctx, &mut props, elapsed_ns); } let id = state.item.id; diff --git a/masonry/src/passes/event.rs b/masonry/src/passes/event.rs index 1b8cfdb89..8add7e570 100644 --- a/masonry/src/passes/event.rs +++ b/masonry/src/passes/event.rs @@ -7,7 +7,9 @@ use winit::event::ElementState; use winit::keyboard::{KeyCode, PhysicalKey}; use crate::app::{RenderRoot, RenderRootSignal}; -use crate::core::{AccessEvent, EventCtx, PointerEvent, TextEvent, Widget, WidgetId}; +use crate::core::{ + AccessEvent, EventCtx, PointerEvent, PropertiesMut, TextEvent, Widget, WidgetId, +}; use crate::passes::{enter_span, merge_state_up}; use crate::Handled; @@ -38,7 +40,7 @@ fn run_event_pass( target: Option, event: &E, allow_pointer_capture: bool, - pass_fn: impl FnMut(&mut dyn Widget, &mut EventCtx, &E), + pass_fn: impl FnMut(&mut dyn Widget, &mut EventCtx, &mut PropertiesMut<'_>, &E), trace: bool, ) -> Handled { let mut pass_fn = pass_fn; @@ -77,7 +79,10 @@ fn run_event_pass( ); } - pass_fn(&mut **widget, &mut ctx, event); + let mut props = PropertiesMut { + map: properties_mut.item, + }; + pass_fn(&mut **widget, &mut ctx, &mut props, event); is_handled = ctx.is_handled; } @@ -160,8 +165,8 @@ pub(crate) fn run_on_pointer_event_pass(root: &mut RenderRoot, event: &PointerEv target_widget_id, event, matches!(event, PointerEvent::PointerDown(..)), - |widget, ctx, event| { - widget.on_pointer_event(ctx, event); + |widget, ctx, props, event| { + widget.on_pointer_event(ctx, props, event); }, !event.is_high_density(), ); @@ -216,8 +221,8 @@ pub(crate) fn run_on_text_event_pass(root: &mut RenderRoot, event: &TextEvent) - target, event, false, - |widget, ctx, event| { - widget.on_text_event(ctx, event); + |widget, ctx, props, event| { + widget.on_text_event(ctx, props, event); }, !event.is_high_density(), ); @@ -282,8 +287,8 @@ pub(crate) fn run_on_access_event_pass( Some(target), event, false, - |widget, ctx, event| { - widget.on_access_event(ctx, event); + |widget, ctx, props, event| { + widget.on_access_event(ctx, props, event); }, true, ); diff --git a/masonry/src/passes/layout.rs b/masonry/src/passes/layout.rs index 6a0bc0f0d..a6d2f90ac 100644 --- a/masonry/src/passes/layout.rs +++ b/masonry/src/passes/layout.rs @@ -11,7 +11,7 @@ use tracing::{info_span, trace}; use vello::kurbo::{Point, Rect, Size}; use crate::app::{RenderRoot, RenderRootSignal, WindowSizePolicy}; -use crate::core::{BoxConstraints, LayoutCtx, Widget, WidgetPod, WidgetState}; +use crate::core::{BoxConstraints, LayoutCtx, PropertiesMut, Widget, WidgetPod, WidgetState}; use crate::passes::{enter_span_if, recurse_on_children}; // --- MARK: RUN LAYOUT --- @@ -109,7 +109,10 @@ pub(crate) fn run_layout_on( // TODO - If constraints are the same and request_layout isn't set, // skip calling layout inner_ctx.widget_state.request_layout = false; - widget.item.layout(&mut inner_ctx, bc) + let mut props = PropertiesMut { + map: properties.item, + }; + widget.item.layout(&mut inner_ctx, &mut props, bc) }; if state.item.request_layout { debug_panic!( diff --git a/masonry/src/passes/paint.rs b/masonry/src/passes/paint.rs index 00bf6981a..0c8ba08be 100644 --- a/masonry/src/passes/paint.rs +++ b/masonry/src/passes/paint.rs @@ -10,7 +10,7 @@ use vello::peniko::{Color, Fill, Mix}; use vello::Scene; use crate::app::{RenderRoot, RenderRootState}; -use crate::core::{PaintCtx, Widget, WidgetId, WidgetState}; +use crate::core::{PaintCtx, Properties, Widget, WidgetId, WidgetState}; use crate::kurbo::Rect; use crate::passes::{enter_span_if, recurse_on_children}; use crate::theme::get_debug_color; @@ -55,7 +55,10 @@ fn paint_widget( // https://github.com/linebender/xilem/issues/524 let scene = scenes.entry(id).or_default(); scene.reset(); - widget.item.paint(&mut ctx, scene); + let props = Properties { + map: properties.item, + }; + widget.item.paint(&mut ctx, &props, scene); } state.item.request_paint = false; diff --git a/masonry/src/passes/update.rs b/masonry/src/passes/update.rs index b898d51e0..b3ff112ed 100644 --- a/masonry/src/passes/update.rs +++ b/masonry/src/passes/update.rs @@ -9,8 +9,8 @@ use tree_arena::ArenaMut; use crate::app::{RenderRoot, RenderRootSignal, RenderRootState}; use crate::core::{ - PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, - WidgetState, + PointerEvent, PropertiesMut, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, + WidgetId, WidgetState, }; use crate::passes::event::{run_on_pointer_event_pass, run_on_text_event_pass}; use crate::passes::{enter_span, enter_span_if, merge_state_up, recurse_on_children}; @@ -35,7 +35,7 @@ fn get_id_path(root: &RenderRoot, widget_id: Option) -> Vec fn run_targeted_update_pass( root: &mut RenderRoot, target: Option, - mut pass_fn: impl FnMut(&mut dyn Widget, &mut UpdateCtx), + mut pass_fn: impl FnMut(&mut dyn Widget, &mut UpdateCtx, &mut PropertiesMut<'_>), ) { let mut current_id = target; while let Some(widget_id) = current_id { @@ -49,7 +49,10 @@ fn run_targeted_update_pass( widget_children: widget_mut.children, properties_children: properties_mut.children, }; - pass_fn(&mut **widget_mut.item, &mut ctx); + let mut props = PropertiesMut { + map: properties_mut.item, + }; + pass_fn(&mut **widget_mut.item, &mut ctx, &mut props); merge_state_up(&mut root.widget_arena, widget_id); current_id = parent_id; @@ -59,7 +62,7 @@ fn run_targeted_update_pass( fn run_single_update_pass( root: &mut RenderRoot, target: Option, - mut pass_fn: impl FnMut(&mut dyn Widget, &mut UpdateCtx), + mut pass_fn: impl FnMut(&mut dyn Widget, &mut UpdateCtx, &mut PropertiesMut<'_>), ) { let Some(target) = target else { return; @@ -77,7 +80,10 @@ fn run_single_update_pass( widget_children: widget_mut.children, properties_children: properties_mut.children, }; - pass_fn(&mut **widget_mut.item, &mut ctx); + let mut props = PropertiesMut { + map: properties_mut.item, + }; + pass_fn(&mut **widget_mut.item, &mut ctx, &mut props); let mut current_id = Some(target); while let Some(widget_id) = current_id { @@ -158,7 +164,12 @@ fn update_widget_tree( widget_children: widget.children.reborrow_mut(), properties_children: properties.children.reborrow_mut(), }; - widget.item.update(&mut ctx, &Update::WidgetAdded); + let mut props = PropertiesMut { + map: properties.item, + }; + widget + .item + .update(&mut ctx, &mut props, &Update::WidgetAdded); if trace { trace!( "{} received Update::WidgetAdded", @@ -243,9 +254,12 @@ fn update_disabled_for_widget( widget_children: widget.children.reborrow_mut(), properties_children: properties.children.reborrow_mut(), }; + let mut props = PropertiesMut { + map: properties.item, + }; widget .item - .update(&mut ctx, &Update::DisabledChanged(disabled)); + .update(&mut ctx, &mut props, &Update::DisabledChanged(disabled)); state.item.is_disabled = disabled; state.item.needs_update_focus_chain = true; state.item.request_accessibility = true; @@ -327,9 +341,12 @@ fn update_stashed_for_widget( widget_children: widget.children.reborrow_mut(), properties_children: properties.children.reborrow_mut(), }; + let mut props = PropertiesMut { + map: properties.item, + }; widget .item - .update(&mut ctx, &Update::StashedChanged(stashed)); + .update(&mut ctx, &mut props, &Update::StashedChanged(stashed)); state.item.is_stashed = stashed; state.item.needs_update_focus_chain = true; // Note: We don't need request_repaint because stashing doesn't actually change @@ -545,11 +562,11 @@ pub(crate) fn run_update_focus_pass(root: &mut RenderRoot) { widget_id: WidgetId, focused_set: &HashSet, ) { - run_targeted_update_pass(root, Some(widget_id), |widget, ctx| { + run_targeted_update_pass(root, Some(widget_id), |widget, ctx, props| { let has_focused = focused_set.contains(&ctx.widget_id()); if ctx.widget_state.has_focus_target != has_focused { - widget.update(ctx, &Update::ChildFocusChanged(has_focused)); + widget.update(ctx, props, &Update::ChildFocusChanged(has_focused)); } ctx.widget_state.has_focus_target = has_focused; }); @@ -586,13 +603,13 @@ pub(crate) fn run_update_focus_pass(root: &mut RenderRoot) { if prev_focused != next_focused { // We send FocusChange event to widget that lost and the widget that gained focus. // We also request accessibility, because build_access_node() depends on the focus state. - run_single_update_pass(root, prev_focused, |widget, ctx| { - widget.update(ctx, &Update::FocusChanged(false)); + run_single_update_pass(root, prev_focused, |widget, ctx, props| { + widget.update(ctx, props, &Update::FocusChanged(false)); ctx.widget_state.request_accessibility = true; ctx.widget_state.needs_accessibility = true; }); - run_single_update_pass(root, next_focused, |widget, ctx| { - widget.update(ctx, &Update::FocusChanged(true)); + run_single_update_pass(root, next_focused, |widget, ctx, props| { + widget.update(ctx, props, &Update::FocusChanged(true)); ctx.widget_state.request_accessibility = true; ctx.widget_state.needs_accessibility = true; }); @@ -630,9 +647,9 @@ pub(crate) fn run_update_scroll_pass(root: &mut RenderRoot) { let mut target_rect = rect; // TODO - Run top-down instead of bottom-up. - run_targeted_update_pass(root, Some(target), |widget, ctx| { + run_targeted_update_pass(root, Some(target), |widget, ctx, props| { let event = Update::RequestPanToChild(rect); - widget.update(ctx, &event); + widget.update(ctx, props, &event); // TODO - We should run the compose method after this, so // translations are updated and the rect passed to parents @@ -722,11 +739,11 @@ pub(crate) fn run_update_pointer_pass(root: &mut RenderRoot) { widget_id: WidgetId, hovered_set: &HashSet, ) { - run_targeted_update_pass(root, Some(widget_id), |widget, ctx| { + run_targeted_update_pass(root, Some(widget_id), |widget, ctx, props| { let has_hovered = hovered_set.contains(&ctx.widget_id()); if ctx.widget_state.has_hovered != has_hovered { - widget.update(ctx, &Update::ChildHoveredChanged(has_hovered)); + widget.update(ctx, props, &Update::ChildHoveredChanged(has_hovered)); } ctx.widget_state.has_hovered = has_hovered; }); @@ -752,13 +769,13 @@ pub(crate) fn run_update_pointer_pass(root: &mut RenderRoot) { } if prev_hovered_widget != next_hovered_widget { - run_single_update_pass(root, prev_hovered_widget, |widget, ctx| { + run_single_update_pass(root, prev_hovered_widget, |widget, ctx, props| { ctx.widget_state.is_hovered = false; - widget.update(ctx, &Update::HoveredChanged(false)); + widget.update(ctx, props, &Update::HoveredChanged(false)); }); - run_single_update_pass(root, next_hovered_widget, |widget, ctx| { + run_single_update_pass(root, next_hovered_widget, |widget, ctx, props| { ctx.widget_state.is_hovered = true; - widget.update(ctx, &Update::HoveredChanged(true)); + widget.update(ctx, props, &Update::HoveredChanged(true)); }); } diff --git a/masonry/src/testing/helper_widgets.rs b/masonry/src/testing/helper_widgets.rs index 9c5465820..dfd381731 100644 --- a/masonry/src/testing/helper_widgets.rs +++ b/masonry/src/testing/helper_widgets.rs @@ -19,25 +19,27 @@ use vello::Scene; use crate::core::{ find_widget_at_pos, AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, - PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, - WidgetPod, WidgetRef, + PaintCtx, PointerEvent, Properties, PropertiesMut, QueryCtx, RegisterCtx, TextEvent, Update, + UpdateCtx, Widget, WidgetId, WidgetPod, WidgetRef, }; use crate::kurbo::{Point, Size}; use crate::widgets::SizedBox; use crate::AsAny; use cursor_icon::CursorIcon; -pub type PointerEventFn = dyn FnMut(&mut S, &mut EventCtx, &PointerEvent); -pub type TextEventFn = dyn FnMut(&mut S, &mut EventCtx, &TextEvent); -pub type AccessEventFn = dyn FnMut(&mut S, &mut EventCtx, &AccessEvent); -pub type AnimFrameFn = dyn FnMut(&mut S, &mut UpdateCtx, u64); +pub type PointerEventFn = + dyn FnMut(&mut S, &mut EventCtx, &mut PropertiesMut<'_>, &PointerEvent); +pub type TextEventFn = dyn FnMut(&mut S, &mut EventCtx, &mut PropertiesMut<'_>, &TextEvent); +pub type AccessEventFn = dyn FnMut(&mut S, &mut EventCtx, &mut PropertiesMut<'_>, &AccessEvent); +pub type AnimFrameFn = dyn FnMut(&mut S, &mut UpdateCtx, &mut PropertiesMut<'_>, u64); pub type RegisterChildrenFn = dyn FnMut(&mut S, &mut RegisterCtx); -pub type UpdateFn = dyn FnMut(&mut S, &mut UpdateCtx, &Update); -pub type LayoutFn = dyn FnMut(&mut S, &mut LayoutCtx, &BoxConstraints) -> Size; +pub type UpdateFn = dyn FnMut(&mut S, &mut UpdateCtx, &mut PropertiesMut<'_>, &Update); +pub type LayoutFn = + dyn FnMut(&mut S, &mut LayoutCtx, &mut PropertiesMut<'_>, &BoxConstraints) -> Size; pub type ComposeFn = dyn FnMut(&mut S, &mut ComposeCtx); -pub type PaintFn = dyn FnMut(&mut S, &mut PaintCtx, &mut Scene); +pub type PaintFn = dyn FnMut(&mut S, &mut PaintCtx, &Properties<'_>, &mut Scene); pub type RoleFn = dyn Fn(&S) -> Role; -pub type AccessFn = dyn FnMut(&mut S, &mut AccessCtx, &mut Node); +pub type AccessFn = dyn FnMut(&mut S, &mut AccessCtx, &Properties<'_>, &mut Node); pub type ChildrenFn = dyn Fn(&S) -> SmallVec<[WidgetId; 16]>; #[cfg(FALSE)] @@ -207,7 +209,7 @@ impl ModularWidget { /// See [`Widget::on_pointer_event`] pub fn pointer_event_fn( mut self, - f: impl FnMut(&mut S, &mut EventCtx, &PointerEvent) + 'static, + f: impl FnMut(&mut S, &mut EventCtx, &mut PropertiesMut<'_>, &PointerEvent) + 'static, ) -> Self { self.on_pointer_event = Some(Box::new(f)); self @@ -216,7 +218,7 @@ impl ModularWidget { /// See [`Widget::on_text_event`] pub fn text_event_fn( mut self, - f: impl FnMut(&mut S, &mut EventCtx, &TextEvent) + 'static, + f: impl FnMut(&mut S, &mut EventCtx, &mut PropertiesMut<'_>, &TextEvent) + 'static, ) -> Self { self.on_text_event = Some(Box::new(f)); self @@ -225,14 +227,17 @@ impl ModularWidget { /// See [`Widget::on_access_event`] pub fn access_event_fn( mut self, - f: impl FnMut(&mut S, &mut EventCtx, &AccessEvent) + 'static, + f: impl FnMut(&mut S, &mut EventCtx, &mut PropertiesMut<'_>, &AccessEvent) + 'static, ) -> Self { self.on_access_event = Some(Box::new(f)); self } /// See [`Widget::on_anim_frame`] - pub fn anim_frame_fn(mut self, f: impl FnMut(&mut S, &mut UpdateCtx, u64) + 'static) -> Self { + pub fn anim_frame_fn( + mut self, + f: impl FnMut(&mut S, &mut UpdateCtx, &mut PropertiesMut<'_>, u64) + 'static, + ) -> Self { self.on_anim_frame = Some(Box::new(f)); self } @@ -247,7 +252,10 @@ impl ModularWidget { } /// See [`Widget::update`] - pub fn update_fn(mut self, f: impl FnMut(&mut S, &mut UpdateCtx, &Update) + 'static) -> Self { + pub fn update_fn( + mut self, + f: impl FnMut(&mut S, &mut UpdateCtx, &mut PropertiesMut<'_>, &Update) + 'static, + ) -> Self { self.update = Some(Box::new(f)); self } @@ -255,7 +263,7 @@ impl ModularWidget { /// See [`Widget::layout`] pub fn layout_fn( mut self, - f: impl FnMut(&mut S, &mut LayoutCtx, &BoxConstraints) -> Size + 'static, + f: impl FnMut(&mut S, &mut LayoutCtx, &mut PropertiesMut<'_>, &BoxConstraints) -> Size + 'static, ) -> Self { self.layout = Some(Box::new(f)); self @@ -268,7 +276,10 @@ impl ModularWidget { } /// See [`Widget::paint`] - pub fn paint_fn(mut self, f: impl FnMut(&mut S, &mut PaintCtx, &mut Scene) + 'static) -> Self { + pub fn paint_fn( + mut self, + f: impl FnMut(&mut S, &mut PaintCtx, &Properties<'_>, &mut Scene) + 'static, + ) -> Self { self.paint = Some(Box::new(f)); self } @@ -280,7 +291,10 @@ impl ModularWidget { } /// See [`Widget::accessibility`] - pub fn access_fn(mut self, f: impl FnMut(&mut S, &mut AccessCtx, &mut Node) + 'static) -> Self { + pub fn access_fn( + mut self, + f: impl FnMut(&mut S, &mut AccessCtx, &Properties<'_>, &mut Node) + 'static, + ) -> Self { self.access = Some(Box::new(f)); self } @@ -297,27 +311,42 @@ impl ModularWidget { #[warn(clippy::missing_trait_methods)] impl Widget for ModularWidget { - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) { + fn on_pointer_event( + &mut self, + ctx: &mut EventCtx, + props: &mut PropertiesMut<'_>, + event: &PointerEvent, + ) { if let Some(f) = self.on_pointer_event.as_mut() { - f(&mut self.state, ctx, event); + f(&mut self.state, ctx, props, event); } } - fn on_text_event(&mut self, ctx: &mut EventCtx, event: &TextEvent) { + fn on_text_event( + &mut self, + ctx: &mut EventCtx, + props: &mut PropertiesMut<'_>, + event: &TextEvent, + ) { if let Some(f) = self.on_text_event.as_mut() { - f(&mut self.state, ctx, event); + f(&mut self.state, ctx, props, event); } } - fn on_access_event(&mut self, ctx: &mut EventCtx, event: &AccessEvent) { + fn on_access_event( + &mut self, + ctx: &mut EventCtx, + props: &mut PropertiesMut<'_>, + event: &AccessEvent, + ) { if let Some(f) = self.on_access_event.as_mut() { - f(&mut self.state, ctx, event); + f(&mut self.state, ctx, props, event); } } - fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, interval: u64) { + fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, props: &mut PropertiesMut<'_>, interval: u64) { if let Some(f) = self.on_anim_frame.as_mut() { - f(&mut self.state, ctx, interval); + f(&mut self.state, ctx, props, interval); } } @@ -327,13 +356,18 @@ impl Widget for ModularWidget { } } - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) { + fn update(&mut self, ctx: &mut UpdateCtx, props: &mut PropertiesMut<'_>, event: &Update) { if let Some(f) = self.update.as_mut() { - f(&mut self.state, ctx, event); + f(&mut self.state, ctx, props, event); } } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { let Self { ref mut state, ref mut layout, @@ -341,7 +375,7 @@ impl Widget for ModularWidget { } = self; layout .as_mut() - .map(|f| f(state, ctx, bc)) + .map(|f| f(state, ctx, props, bc)) .unwrap_or_else(|| Size::new(100., 100.)) } @@ -359,15 +393,15 @@ impl Widget for ModularWidget { } } - fn accessibility(&mut self, ctx: &mut AccessCtx, node: &mut Node) { + fn accessibility(&mut self, ctx: &mut AccessCtx, props: &Properties<'_>, node: &mut Node) { if let Some(f) = self.access.as_mut() { - f(&mut self.state, ctx, node); + f(&mut self.state, ctx, props, node); } } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, props: &Properties<'_>, scene: &mut Scene) { if let Some(f) = self.paint.as_mut() { - f(&mut self.state, ctx, scene); + f(&mut self.state, ctx, props, scene); } } @@ -442,7 +476,7 @@ impl ReplaceChild { impl Widget for ReplaceChild { #[cfg(FALSE)] - fn on_event(&mut self, ctx: &mut EventCtx, event: &Event) { + fn on_event(&mut self, ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, event: &Event) { #[cfg(FALSE)] if let Event::Command(cmd) = event { if cmd.is(REPLACE_CHILD) { @@ -454,31 +488,54 @@ impl Widget for ReplaceChild { self.child.on_event(ctx, event) } - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} + fn on_pointer_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &PointerEvent, + ) { + } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &TextEvent, + ) { + } - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &AccessEvent, + ) { + } fn register_children(&mut self, ctx: &mut RegisterCtx) { ctx.register_child(&mut self.child); } - fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {} + fn update(&mut self, _ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, _event: &Update) {} - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { ctx.run_layout(&mut self.child, bc) } fn compose(&mut self, _ctx: &mut ComposeCtx) {} - fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {} + fn paint(&mut self, _ctx: &mut PaintCtx, _props: &Properties<'_>, _scene: &mut Scene) {} fn accessibility_role(&self) -> Role { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { todo!() @@ -520,24 +577,39 @@ impl Recording { #[warn(clippy::missing_trait_methods)] impl Widget for Recorder { - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) { + fn on_pointer_event( + &mut self, + ctx: &mut EventCtx, + props: &mut PropertiesMut<'_>, + event: &PointerEvent, + ) { self.recording.push(Record::PE(event.clone())); - self.child.on_pointer_event(ctx, event); + self.child.on_pointer_event(ctx, props, event); } - fn on_text_event(&mut self, ctx: &mut EventCtx, event: &TextEvent) { + fn on_text_event( + &mut self, + ctx: &mut EventCtx, + props: &mut PropertiesMut<'_>, + event: &TextEvent, + ) { self.recording.push(Record::TE(event.clone())); - self.child.on_text_event(ctx, event); + self.child.on_text_event(ctx, props, event); } - fn on_access_event(&mut self, ctx: &mut EventCtx, event: &AccessEvent) { + fn on_access_event( + &mut self, + ctx: &mut EventCtx, + props: &mut PropertiesMut<'_>, + event: &AccessEvent, + ) { self.recording.push(Record::AE(event.clone())); - self.child.on_access_event(ctx, event); + self.child.on_access_event(ctx, props, event); } - fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, interval: u64) { + fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, props: &mut PropertiesMut<'_>, interval: u64) { self.recording.push(Record::AF(interval)); - self.child.on_anim_frame(ctx, interval); + self.child.on_anim_frame(ctx, props, interval); } fn register_children(&mut self, ctx: &mut RegisterCtx) { @@ -545,13 +617,18 @@ impl Widget for Recorder { self.child.register_children(ctx); } - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) { + fn update(&mut self, ctx: &mut UpdateCtx, props: &mut PropertiesMut<'_>, event: &Update) { self.recording.push(Record::U(event.clone())); - self.child.update(ctx, event); + self.child.update(ctx, props, event); } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { - let size = self.child.layout(ctx, bc); + fn layout( + &mut self, + ctx: &mut LayoutCtx, + props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { + let size = self.child.layout(ctx, props, bc); self.recording.push(Record::Layout(size)); size } @@ -561,18 +638,18 @@ impl Widget for Recorder { self.child.compose(ctx); } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, props: &Properties<'_>, scene: &mut Scene) { self.recording.push(Record::Paint); - self.child.paint(ctx, scene); + self.child.paint(ctx, props, scene); } fn accessibility_role(&self) -> Role { self.child.accessibility_role() } - fn accessibility(&mut self, ctx: &mut AccessCtx, node: &mut Node) { + fn accessibility(&mut self, ctx: &mut AccessCtx, props: &Properties<'_>, node: &mut Node) { self.recording.push(Record::Access); - self.child.accessibility(ctx, node); + self.child.accessibility(ctx, props, node); } fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { diff --git a/masonry/src/widgets/align.rs b/masonry/src/widgets/align.rs index a85cdb0b7..e6e6c5077 100644 --- a/masonry/src/widgets/align.rs +++ b/masonry/src/widgets/align.rs @@ -14,8 +14,8 @@ use tracing::{trace_span, Span}; use vello::Scene; use crate::core::{ - AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, - RegisterCtx, TextEvent, Widget, WidgetId, WidgetPod, + AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, + Properties, PropertiesMut, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, WidgetPod, }; use crate::kurbo::{Rect, Size}; use crate::util::UnitPoint; @@ -86,17 +86,40 @@ impl Align { // --- MARK: IMPL WIDGET --- impl Widget for Align { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} + fn on_pointer_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &PointerEvent, + ) { + } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &TextEvent, + ) { + } - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &AccessEvent, + ) { + } fn register_children(&mut self, ctx: &mut RegisterCtx) { ctx.register_child(&mut self.child); } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { let size = ctx.run_layout(&mut self.child, &bc.loosen()); log_size_warnings(size); @@ -137,13 +160,13 @@ impl Widget for Align { my_size } - fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {} + fn paint(&mut self, _ctx: &mut PaintCtx, _props: &Properties<'_>, _scene: &mut Scene) {} fn accessibility_role(&self) -> Role { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { smallvec![self.child.id()] diff --git a/masonry/src/widgets/button.rs b/masonry/src/widgets/button.rs index 12cd97770..ee1786d4b 100644 --- a/masonry/src/widgets/button.rs +++ b/masonry/src/widgets/button.rs @@ -10,8 +10,8 @@ use vello::Scene; use crate::core::{ AccessCtx, AccessEvent, Action, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, - PointerButton, PointerEvent, QueryCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, - WidgetMut, WidgetPod, + PointerButton, PointerEvent, Properties, PropertiesMut, QueryCtx, TextEvent, Update, UpdateCtx, + Widget, WidgetId, WidgetMut, WidgetPod, }; use crate::kurbo::{Insets, Size}; use crate::theme; @@ -86,7 +86,12 @@ impl Button { // --- MARK: IMPL WIDGET --- impl Widget for Button { - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) { + fn on_pointer_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &PointerEvent, + ) { match event { PointerEvent::PointerDown(_, _) => { if !ctx.is_disabled() { @@ -108,9 +113,20 @@ impl Widget for Button { } } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &TextEvent, + ) { + } - fn on_access_event(&mut self, ctx: &mut EventCtx, event: &AccessEvent) { + fn on_access_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &AccessEvent, + ) { if ctx.target() == ctx.widget_id() { match event.action { accesskit::Action::Click => { @@ -121,7 +137,7 @@ impl Widget for Button { } } - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) { + fn update(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, event: &Update) { match event { Update::HoveredChanged(_) | Update::FocusChanged(_) | Update::DisabledChanged(_) => { ctx.request_paint_only(); @@ -134,7 +150,12 @@ impl Widget for Button { ctx.register_child(&mut self.label); } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { let padding = Size::new(LABEL_INSETS.x_value(), LABEL_INSETS.y_value()); let label_bc = bc.shrink(padding).loosen(); @@ -158,7 +179,7 @@ impl Widget for Button { button_size } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { let is_active = ctx.is_pointer_capture_target() && !ctx.is_disabled(); let is_hovered = ctx.is_hovered(); let size = ctx.size(); @@ -197,7 +218,7 @@ impl Widget for Button { Role::Button } - fn accessibility(&mut self, ctx: &mut AccessCtx, node: &mut Node) { + fn accessibility(&mut self, ctx: &mut AccessCtx, _props: &Properties<'_>, node: &mut Node) { // IMPORTANT: We don't want to merge this code in practice, because // the child label already has a 'name' property. // This is more of a proof of concept of `get_raw_ref()`. diff --git a/masonry/src/widgets/checkbox.rs b/masonry/src/widgets/checkbox.rs index b96d311bf..cf7b2d7cc 100644 --- a/masonry/src/widgets/checkbox.rs +++ b/masonry/src/widgets/checkbox.rs @@ -10,7 +10,7 @@ use vello::kurbo::{Affine, BezPath, Cap, Join, Size, Stroke}; use vello::Scene; use crate::core::{ - AccessCtx, AccessEvent, Action, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, + AccessCtx, AccessEvent, Action, ArcStr, BoxConstraints, Properties, PropertiesMut, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod, }; @@ -66,7 +66,7 @@ impl Checkbox { // --- MARK: IMPL WIDGET --- impl Widget for Checkbox { - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) { + fn on_pointer_event(&mut self, ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, event: &PointerEvent) { match event { PointerEvent::PointerDown(_, _) => { if !ctx.is_disabled() { @@ -89,9 +89,9 @@ impl Widget for Checkbox { } } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, ctx: &mut EventCtx, event: &AccessEvent) { + fn on_access_event(&mut self, ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, event: &AccessEvent) { if ctx.target() == ctx.widget_id() { match event.action { accesskit::Action::Click => { @@ -105,7 +105,7 @@ impl Widget for Checkbox { } } - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) { + fn update(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, event: &Update) { match event { Update::HoveredChanged(_) | Update::FocusChanged(_) | Update::DisabledChanged(_) => { ctx.request_paint_only(); @@ -119,7 +119,7 @@ impl Widget for Checkbox { ctx.register_child(&mut self.label); } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { let x_padding = theme::WIDGET_CONTROL_COMPONENT_PADDING; let check_size = theme::BASIC_WIDGET_HEIGHT; @@ -137,7 +137,7 @@ impl Widget for Checkbox { our_size } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { let check_size = theme::BASIC_WIDGET_HEIGHT; let border_width = 1.; @@ -193,7 +193,7 @@ impl Widget for Checkbox { Role::CheckBox } - fn accessibility(&mut self, ctx: &mut AccessCtx, node: &mut Node) { + fn accessibility(&mut self, ctx: &mut AccessCtx, _props: &Properties<'_>, node: &mut Node) { // IMPORTANT: We don't want to merge this code in practice, because // the child label already has a 'name' property. // This is more of a proof of concept of `get_raw_ref()`. diff --git a/masonry/src/widgets/flex.rs b/masonry/src/widgets/flex.rs index 047c6fcfd..751282abc 100644 --- a/masonry/src/widgets/flex.rs +++ b/masonry/src/widgets/flex.rs @@ -11,7 +11,7 @@ use vello::kurbo::{Affine, Line, Stroke, Vec2}; use vello::Scene; use crate::core::{ - AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, + AccessCtx, AccessEvent, BoxConstraints, Properties, PropertiesMut, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, TextEvent, Widget, WidgetId, WidgetMut, WidgetPod, }; use crate::kurbo::{Point, Rect, Size}; @@ -909,11 +909,11 @@ fn new_flex_child(params: FlexParams, widget: WidgetPod) -> Child { // --- MARK: IMPL WIDGET--- impl Widget for Flex { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} + fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &PointerEvent) {} - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &AccessEvent) {} fn register_children(&mut self, ctx: &mut crate::core::RegisterCtx) { for child in self.children.iter_mut().filter_map(|x| x.widget_mut()) { @@ -921,7 +921,7 @@ impl Widget for Flex { } } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { // we loosen our constraints when passing to children. let loosened_bc = bc.loosen(); @@ -1175,7 +1175,7 @@ impl Widget for Flex { my_size } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { // paint the baseline if we're debugging layout if ctx.debug_paint_enabled() && ctx.baseline_offset() != 0.0 { let color = ctx.debug_color(); @@ -1191,7 +1191,7 @@ impl Widget for Flex { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { self.children diff --git a/masonry/src/widgets/grid.rs b/masonry/src/widgets/grid.rs index 2c44d647b..7ff1a5585 100644 --- a/masonry/src/widgets/grid.rs +++ b/masonry/src/widgets/grid.rs @@ -8,7 +8,7 @@ use vello::kurbo::{Affine, Line, Stroke}; use vello::Scene; use crate::core::{ - AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, + AccessCtx, AccessEvent, BoxConstraints, Properties, PropertiesMut, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, TextEvent, Widget, WidgetId, WidgetMut, WidgetPod, }; use crate::kurbo::{Point, Size}; @@ -242,11 +242,11 @@ impl Grid { // --- MARK: IMPL WIDGET--- impl Widget for Grid { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} + fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &PointerEvent) {} - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &AccessEvent) {} fn register_children(&mut self, ctx: &mut crate::core::RegisterCtx) { for child in self.children.iter_mut().filter_map(|x| x.widget_mut()) { @@ -254,7 +254,7 @@ impl Widget for Grid { } } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { let total_size = bc.max(); if !total_size.is_finite() { debug_panic!( @@ -279,7 +279,7 @@ impl Widget for Grid { total_size } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { // paint the baseline if we're debugging layout if ctx.debug_paint_enabled() && ctx.baseline_offset() != 0.0 { let color = ctx.debug_color(); @@ -295,7 +295,7 @@ impl Widget for Grid { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { self.children diff --git a/masonry/src/widgets/image.rs b/masonry/src/widgets/image.rs index 05a31f45a..0291ef2d4 100644 --- a/masonry/src/widgets/image.rs +++ b/masonry/src/widgets/image.rs @@ -12,7 +12,7 @@ use vello::peniko::{BlendMode, Image as ImageBuf}; use vello::Scene; use crate::core::{ - AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, ObjectFit, PaintCtx, PointerEvent, + AccessCtx, AccessEvent, BoxConstraints, Properties, PropertiesMut, EventCtx, LayoutCtx, ObjectFit, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, }; use crate::kurbo::Size; @@ -71,17 +71,17 @@ impl Image { // --- MARK: IMPL WIDGET --- impl Widget for Image { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} + fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &PointerEvent) {} - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &AccessEvent) {} fn register_children(&mut self, _ctx: &mut RegisterCtx) {} - fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {} + fn update(&mut self, _ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, _event: &Update) {} - fn layout(&mut self, _ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, _ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { // If either the width or height is constrained calculate a value so that the image fits // in the size exactly. If it is unconstrained by both width and height take the size of // the image. @@ -112,7 +112,7 @@ impl Widget for Image { } } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { let image_size = Size::new(self.image_data.width as f64, self.image_data.height as f64); let transform = self.object_fit.affine_to_fill(ctx.size(), image_size); @@ -126,7 +126,7 @@ impl Widget for Image { Role::Image } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) { + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) { // TODO - Handle alt text and such. } diff --git a/masonry/src/widgets/label.rs b/masonry/src/widgets/label.rs index 1ac9f2ebe..f08bab726 100644 --- a/masonry/src/widgets/label.rs +++ b/masonry/src/widgets/label.rs @@ -18,7 +18,7 @@ use vello::Scene; use crate::core::{ default_styles, render_text, AccessCtx, AccessEvent, ArcStr, BoxConstraints, BrushIndex, - EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, StyleProperty, StyleSet, + Properties, PropertiesMut, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, StyleProperty, StyleSet, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, }; use crate::theme; @@ -311,19 +311,19 @@ impl Label { // --- MARK: IMPL WIDGET --- impl Widget for Label { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} + fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &PointerEvent) {} fn accepts_pointer_interaction(&self) -> bool { false } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &AccessEvent) {} fn register_children(&mut self, _ctx: &mut RegisterCtx) {} - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) { + fn update(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, event: &Update) { match event { Update::DisabledChanged(_) => { if self.disabled_brush.is_some() { @@ -334,7 +334,7 @@ impl Widget for Label { } } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { let available_width = if bc.max().width.is_finite() { Some(bc.max().width as f32 - 2. * LABEL_X_PADDING as f32) } else { @@ -397,7 +397,7 @@ impl Widget for Label { bc.constrain(label_size) } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { if self.line_break_mode == LineBreaking::Clip { let clip_rect = ctx.size().to_rect(); scene.push_layer(BlendMode::default(), 1., Affine::IDENTITY, &clip_rect); @@ -422,7 +422,7 @@ impl Widget for Label { Role::Label } - fn accessibility(&mut self, ctx: &mut AccessCtx, node: &mut Node) { + fn accessibility(&mut self, ctx: &mut AccessCtx, _props: &Properties<'_>, node: &mut Node) { let window_origin = ctx.window_origin(); self.accessibility.build_nodes( self.text.as_ref(), diff --git a/masonry/src/widgets/portal.rs b/masonry/src/widgets/portal.rs index 5d5b4f127..135c0224e 100644 --- a/masonry/src/widgets/portal.rs +++ b/masonry/src/widgets/portal.rs @@ -13,8 +13,8 @@ use vello::Scene; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, FromDynWidget, LayoutCtx, - PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, - WidgetMut, WidgetPod, + PaintCtx, PointerEvent, Properties, PropertiesMut, QueryCtx, RegisterCtx, TextEvent, Update, + UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod, }; use crate::widgets::{Axis, ScrollBar}; @@ -260,7 +260,12 @@ impl Portal { // --- MARK: IMPL WIDGET --- impl Widget for Portal { - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) { + fn on_pointer_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &PointerEvent, + ) { const SCROLLING_SPEED: f64 = 10.0; let portal_size = ctx.size(); @@ -321,10 +326,22 @@ impl Widget for Portal { } // TODO - handle Home/End keys, etc - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &TextEvent, + ) { + } // TODO - Handle scroll-related events? - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &AccessEvent, + ) { + } fn register_children(&mut self, ctx: &mut RegisterCtx) { ctx.register_child(&mut self.child); @@ -332,7 +349,7 @@ impl Widget for Portal { ctx.register_child(&mut self.scrollbar_vertical); } - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) { + fn update(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, event: &Update) { match event { Update::RequestPanToChild(target) => { let portal_size = ctx.size(); @@ -361,7 +378,12 @@ impl Widget for Portal { } } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { // TODO - How Portal handles BoxConstraints is due for a rework let min_child_size = if self.must_fill { bc.min() } else { Size::ZERO }; let max_child_size = bc.max(); @@ -432,13 +454,13 @@ impl Widget for Portal { ctx.set_child_scroll_translation(&mut self.child, Vec2::new(0.0, -self.viewport_pos.y)); } - fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {} + fn paint(&mut self, _ctx: &mut PaintCtx, _props: &Properties<'_>, _scene: &mut Scene) {} fn accessibility_role(&self) -> Role { Role::GenericContainer } - fn accessibility(&mut self, ctx: &mut AccessCtx, node: &mut Node) { + fn accessibility(&mut self, ctx: &mut AccessCtx, _props: &Properties<'_>, node: &mut Node) { // TODO - Double check this code // Not sure about these values if false { diff --git a/masonry/src/widgets/progress_bar.rs b/masonry/src/widgets/progress_bar.rs index 7d548c02a..e5cdfe425 100644 --- a/masonry/src/widgets/progress_bar.rs +++ b/masonry/src/widgets/progress_bar.rs @@ -10,7 +10,8 @@ use vello::Scene; use crate::core::{ AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, - QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod, + Properties, PropertiesMut, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, + WidgetId, WidgetMut, WidgetPod, }; use crate::kurbo::{Point, Size}; use crate::theme; @@ -90,19 +91,42 @@ fn clamp_progress(progress: &mut Option) { // --- MARK: IMPL WIDGET --- impl Widget for ProgressBar { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} + fn on_pointer_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &PointerEvent, + ) { + } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &TextEvent, + ) { + } - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &AccessEvent, + ) { + } fn register_children(&mut self, ctx: &mut RegisterCtx) { ctx.register_child(&mut self.label); } - fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {} + fn update(&mut self, _ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, _event: &Update) {} - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { const DEFAULT_WIDTH: f64 = 400.; // TODO: Clearer constraints here let label_size = ctx.run_layout(&mut self.label, &bc.loosen()); @@ -121,7 +145,7 @@ impl Widget for ProgressBar { final_size } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { let border_width = 1.; let rect = ctx @@ -163,7 +187,7 @@ impl Widget for ProgressBar { Role::ProgressIndicator } - fn accessibility(&mut self, _ctx: &mut AccessCtx, node: &mut Node) { + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, node: &mut Node) { node.set_value(self.value_accessibility()); if let Some(value) = self.progress { node.set_numeric_value(value * 100.0); diff --git a/masonry/src/widgets/prose.rs b/masonry/src/widgets/prose.rs index 62a5f3fa6..162ddd470 100644 --- a/masonry/src/widgets/prose.rs +++ b/masonry/src/widgets/prose.rs @@ -10,7 +10,7 @@ use vello::kurbo::{Point, Rect, Size}; use vello::Scene; use crate::core::{ - AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, + AccessCtx, AccessEvent, BoxConstraints, Properties, PropertiesMut, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod, }; use crate::widgets::{Padding, TextArea}; @@ -111,19 +111,19 @@ impl Prose { // --- MARK: IMPL WIDGET --- impl Widget for Prose { - fn on_pointer_event(&mut self, _: &mut EventCtx, _: &PointerEvent) {} + fn on_pointer_event(&mut self, _: &mut EventCtx, _props: &mut PropertiesMut<'_>, _: &PointerEvent) {} - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &AccessEvent) {} fn register_children(&mut self, ctx: &mut RegisterCtx) { ctx.register_child(&mut self.text); } - fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {} + fn update(&mut self, _ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, _event: &Update) {} - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { // TODO: Set minimum to deal with alignment let size = ctx.run_layout(&mut self.text, bc); ctx.place_child(&mut self.text, Point::ORIGIN); @@ -135,7 +135,7 @@ impl Widget for Prose { size } - fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) { + fn paint(&mut self, _ctx: &mut PaintCtx, _props: &Properties<'_>, _scene: &mut Scene) { // All painting is handled by the child } @@ -143,7 +143,7 @@ impl Widget for Prose { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { smallvec![self.text.id()] diff --git a/masonry/src/widgets/root_widget.rs b/masonry/src/widgets/root_widget.rs index 1f53d77e4..e2ab361f7 100644 --- a/masonry/src/widgets/root_widget.rs +++ b/masonry/src/widgets/root_widget.rs @@ -9,7 +9,8 @@ use vello::Scene; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, FromDynWidget, LayoutCtx, PaintCtx, - PointerEvent, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, WidgetMut, WidgetPod, + PointerEvent, Properties, PropertiesMut, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, + WidgetMut, WidgetPod, }; use crate::kurbo::Size; @@ -40,27 +41,50 @@ impl RootWidget { } impl Widget for RootWidget { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_pointer_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &PointerEvent, + ) { + } + fn on_text_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &TextEvent, + ) { + } + fn on_access_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &AccessEvent, + ) { + } fn register_children(&mut self, ctx: &mut RegisterCtx) { ctx.register_child(&mut self.pod); } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { let size = ctx.run_layout(&mut self.pod, bc); ctx.place_child(&mut self.pod, Point::ORIGIN); size } - fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {} + fn paint(&mut self, _ctx: &mut PaintCtx, _props: &Properties<'_>, _scene: &mut Scene) {} fn accessibility_role(&self) -> Role { Role::Window } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { smallvec![self.pod.id()] diff --git a/masonry/src/widgets/scroll_bar.rs b/masonry/src/widgets/scroll_bar.rs index b1a349126..be34f540f 100644 --- a/masonry/src/widgets/scroll_bar.rs +++ b/masonry/src/widgets/scroll_bar.rs @@ -10,7 +10,7 @@ use vello::kurbo::Rect; use vello::Scene; use crate::core::{ - AccessCtx, AccessEvent, AllowRawMut, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, + AccessCtx, AccessEvent, AllowRawMut, BoxConstraints, Properties, PropertiesMut, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, }; use crate::kurbo::{Point, Size}; @@ -121,7 +121,7 @@ impl ScrollBar { // --- MARK: IMPL WIDGET --- impl Widget for ScrollBar { - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) { + fn on_pointer_event(&mut self, ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, event: &PointerEvent) { match event { PointerEvent::PointerDown(_, _) => { ctx.capture_pointer(); @@ -162,17 +162,17 @@ impl Widget for ScrollBar { } } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) { + fn on_access_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &AccessEvent) { // TODO - Handle scroll-related events? } fn register_children(&mut self, _ctx: &mut RegisterCtx) {} - fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {} + fn update(&mut self, _ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, _event: &Update) {} - fn layout(&mut self, _ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, _ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { // TODO - handle resize let scrollbar_width = theme::SCROLLBAR_WIDTH; @@ -185,7 +185,7 @@ impl Widget for ScrollBar { .into() } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { let radius = theme::SCROLLBAR_RADIUS; let edge_width = theme::SCROLLBAR_EDGE_WIDTH; let cursor_padding = theme::SCROLLBAR_PAD; @@ -210,7 +210,7 @@ impl Widget for ScrollBar { Role::ScrollBar } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) { + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) { // TODO // Use set_scroll_x/y_min/max? } diff --git a/masonry/src/widgets/sized_box.rs b/masonry/src/widgets/sized_box.rs index 98b088d93..6e26a33c4 100644 --- a/masonry/src/widgets/sized_box.rs +++ b/masonry/src/widgets/sized_box.rs @@ -11,7 +11,7 @@ use vello::peniko::{Brush, Fill}; use vello::Scene; use crate::core::{ - AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, + AccessCtx, AccessEvent, BoxConstraints, Properties, PropertiesMut, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, WidgetMut, WidgetPod, }; use crate::kurbo::{Point, Size}; @@ -461,11 +461,11 @@ impl SizedBox { // --- MARK: IMPL WIDGET --- impl Widget for SizedBox { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} + fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &PointerEvent) {} - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &AccessEvent) {} fn register_children(&mut self, ctx: &mut RegisterCtx) { if let Some(ref mut child) = self.child { @@ -473,7 +473,7 @@ impl Widget for SizedBox { } } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { // Shrink constraints by border offset let border_width = match &self.border { Some(border) => border.width, @@ -518,7 +518,7 @@ impl Widget for SizedBox { size } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { let corner_radius = self.corner_radius; if let Some(background) = self.background.as_mut() { @@ -550,7 +550,7 @@ impl Widget for SizedBox { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { if let Some(child) = &self.child { diff --git a/masonry/src/widgets/spinner.rs b/masonry/src/widgets/spinner.rs index 2199cf555..caed27f1b 100644 --- a/masonry/src/widgets/spinner.rs +++ b/masonry/src/widgets/spinner.rs @@ -12,7 +12,7 @@ use vello::kurbo::{Affine, Cap, Line, Stroke}; use vello::Scene; use crate::core::{ - AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, + AccessCtx, AccessEvent, BoxConstraints, Properties, PropertiesMut, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, }; use crate::kurbo::{Point, Size, Vec2}; @@ -73,13 +73,13 @@ impl Spinner { // --- MARK: IMPL WIDGET --- impl Widget for Spinner { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} + fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &PointerEvent) {} - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &AccessEvent) {} - fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, interval: u64) { + fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, interval: u64) { self.t += (interval as f64) * 1e-9; if self.t >= 1.0 { self.t = self.t.rem_euclid(1.0); @@ -90,7 +90,7 @@ impl Widget for Spinner { fn register_children(&mut self, _ctx: &mut RegisterCtx) {} - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) { + fn update(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, event: &Update) { match event { Update::WidgetAdded => { ctx.request_anim_frame(); @@ -99,7 +99,7 @@ impl Widget for Spinner { } } - fn layout(&mut self, _ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, _ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { if bc.is_width_bounded() && bc.is_height_bounded() { bc.max() } else { @@ -110,7 +110,7 @@ impl Widget for Spinner { } } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { let t = self.t; let (width, height) = (ctx.size().width, ctx.size().height); let center = Point::new(width / 2.0, height / 2.0); @@ -141,7 +141,7 @@ impl Widget for Spinner { Role::Unknown } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { SmallVec::new() diff --git a/masonry/src/widgets/split.rs b/masonry/src/widgets/split.rs index 29e30eeb4..6718b9bf6 100644 --- a/masonry/src/widgets/split.rs +++ b/masonry/src/widgets/split.rs @@ -10,7 +10,8 @@ use vello::Scene; use crate::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerButton, - PointerEvent, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, WidgetMut, WidgetPod, + PointerEvent, Properties, PropertiesMut, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, + WidgetMut, WidgetPod, }; use crate::kurbo::{Line, Point, Rect, Size}; use crate::peniko::Color; @@ -367,7 +368,12 @@ impl Split { // --- MARK: IMPL WIDGET --- impl Widget for Split { - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) { + fn on_pointer_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &PointerEvent, + ) { if self.draggable { match event { PointerEvent::PointerDown(PointerButton::Primary, state) => { @@ -403,16 +409,33 @@ impl Widget for Split { } } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &TextEvent, + ) { + } - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &AccessEvent, + ) { + } fn register_children(&mut self, ctx: &mut RegisterCtx) { ctx.register_child(&mut self.child1); ctx.register_child(&mut self.child2); } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { match self.split_axis { Axis::Horizontal => { if !bc.is_width_bounded() { @@ -510,7 +533,7 @@ impl Widget for Split { my_size } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { // TODO - Paint differently if the bar is draggable and hovered. if self.solid { self.paint_solid_bar(ctx, scene); @@ -537,7 +560,7 @@ impl Widget for Split { Role::Splitter } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { smallvec![self.child1.id(), self.child2.id()] diff --git a/masonry/src/widgets/tests/layout.rs b/masonry/src/widgets/tests/layout.rs index 1a3a2c633..c310e1df6 100644 --- a/masonry/src/widgets/tests/layout.rs +++ b/masonry/src/widgets/tests/layout.rs @@ -45,7 +45,7 @@ fn layout_insets() { let [child_id, parent_id] = widget_ids(); - let child_widget = ModularWidget::new(()).layout_fn(|_, ctx, _| { + let child_widget = ModularWidget::new(()).layout_fn(|_, ctx, _, _| { // this widget paints twenty points above below its layout bounds ctx.set_paint_insets(Insets::uniform_xy(0., 20.)); Size::new(BOX_WIDTH, BOX_WIDTH) diff --git a/masonry/src/widgets/tests/safety_rails.rs b/masonry/src/widgets/tests/safety_rails.rs index bfa8cdc89..26395fe74 100644 --- a/masonry/src/widgets/tests/safety_rails.rs +++ b/masonry/src/widgets/tests/safety_rails.rs @@ -14,7 +14,7 @@ fn make_parent_widget(child: W) -> ModularWidget> { .register_children_fn(move |child, ctx| { ctx.register_child(child); }) - .layout_fn(move |child, ctx, bc| { + .layout_fn(move |child, ctx, _, bc| { let size = ctx.run_layout(child, bc); ctx.place_child(child, Point::ZERO); size @@ -26,7 +26,7 @@ fn make_parent_widget(child: W) -> ModularWidget> { #[should_panic(expected = "not visited in method on_text_event")] #[test] fn check_forget_to_recurse_text_event() { - let widget = make_parent_widget(Flex::row()).text_event_fn(|_child, _ctx, _event| { + let widget = make_parent_widget(Flex::row()).text_event_fn(|_child, _ctx, _, _event| { // We forget to call child.on_text_event(); }); @@ -101,7 +101,7 @@ fn check_register_invalid_child() { ignore = "This test doesn't work without debug assertions (i.e. in release mode). See https://github.com/linebender/xilem/issues/477" )] fn check_pointer_capture_outside_pointer_down() { - let widget = ModularWidget::new(()).pointer_event_fn(|_, ctx, _event| { + let widget = ModularWidget::new(()).pointer_event_fn(|_, ctx, _, _event| { ctx.capture_pointer(); }); @@ -120,7 +120,7 @@ fn check_pointer_capture_text_event() { let id = WidgetId::next(); let widget = ModularWidget::new(()) .accepts_focus(true) - .text_event_fn(|_, ctx, _event| { + .text_event_fn(|_, ctx, _, _event| { ctx.capture_pointer(); }) .with_id(id); @@ -137,7 +137,7 @@ fn check_pointer_capture_text_event() { ignore = "This test doesn't work without debug assertions (i.e. in release mode). See https://github.com/linebender/xilem/issues/477" )] fn check_forget_to_recurse_layout() { - let widget = make_parent_widget(Flex::row()).layout_fn(|_child, _ctx, _| { + let widget = make_parent_widget(Flex::row()).layout_fn(|_child, _ctx, _, _| { // We forget to call ctx.run_layout(); Size::ZERO }); @@ -152,7 +152,7 @@ fn check_forget_to_recurse_layout() { ignore = "This test doesn't work without debug assertions (i.e. in release mode). See https://github.com/linebender/xilem/issues/477" )] fn check_forget_to_call_place_child() { - let widget = make_parent_widget(Flex::row()).layout_fn(|child, ctx, bc| { + let widget = make_parent_widget(Flex::row()).layout_fn(|child, ctx, _, bc| { // We call ctx.run_layout(), but forget place_child ctx.run_layout(child, bc) }); @@ -168,11 +168,11 @@ fn check_forget_to_call_place_child() { #[test] fn allow_non_recurse_event_handled() { let widget = make_parent_widget(Flex::row()) - .pointer_event_fn(|_child, ctx, _event| { + .pointer_event_fn(|_child, ctx, _, _event| { // Event handled, we don't need to recurse ctx.set_handled(); }) - .text_event_fn(|_child, ctx, _event| { + .text_event_fn(|_child, ctx, _, _event| { // Event handled, we don't need to recurse ctx.set_handled(); }); @@ -185,12 +185,12 @@ fn allow_non_recurse_event_handled() { #[test] fn allow_non_recurse_cursor_oob() { let widget = make_parent_widget(Flex::row()) - .pointer_event_fn(|child, ctx, event| { + .pointer_event_fn(|child, ctx, _, event| { if !matches!(event, PointerEvent::PointerMove(_)) { child.on_pointer_event(ctx, event); } }) - .layout_fn(|child, ctx, bc| { + .layout_fn(|child, ctx, _, bc| { let _size = ctx.run_layout(child, bc); ctx.place_child(child, Point::ZERO); Size::new(6000.0, 6000.0) @@ -207,7 +207,7 @@ fn allow_non_recurse_oob_paint() { .paint_fn(|_child, _ctx, _| { // We forget to call child.paint(); }) - .layout_fn(|child, ctx, bc| { + .layout_fn(|child, ctx, _, bc| { let _size = ctx.run_layout(child, bc); ctx.place_child(child, Point::new(500.0, 500.0)); Size::new(600.0, 600.0) @@ -242,7 +242,7 @@ fn check_forget_children_changed() { child.lifecycle(ctx, event); } }) - .layout_fn(|child, ctx, bc| { + .layout_fn(|child, ctx, _, bc| { if let Some(child) = child { let size = ctx.run_layout(child, bc); ctx.place_child(child, Point::ZERO); @@ -274,7 +274,7 @@ fn check_forget_children_changed() { #[should_panic] #[test] fn check_recurse_event_twice() { - let widget = make_parent_widget(Flex::row()).pointer_event_fn(|child, ctx, event| { + let widget = make_parent_widget(Flex::row()).pointer_event_fn(|child, ctx, _, event| { child.on_pointer_event(ctx, event); child.on_pointer_event(ctx, event); }); @@ -299,7 +299,7 @@ fn check_recurse_lifecycle_twice() { #[should_panic] #[test] fn check_recurse_layout_twice() { - let widget = make_parent_widget(Flex::row()).layout_fn(|child, ctx, bc| { + let widget = make_parent_widget(Flex::row()).layout_fn(|child, ctx, _, bc| { let size = ctx.run_layout(child, bc); let _ = ctx.run_layout(child, bc); ctx.place_child(child, Point::ZERO); @@ -328,12 +328,12 @@ fn check_recurse_paint_twice() { #[test] fn check_layout_stashed() { let widget = make_parent_widget(Flex::row()) - .update_fn(|child, ctx, event| { + .update_fn(|child, ctx, _, event| { if matches!(event, Update::WidgetAdded) { ctx.set_stashed(child, true); } }) - .layout_fn(|child, ctx, bc| { + .layout_fn(|child, ctx, _, bc| { let size = ctx.run_layout(child, bc); ctx.place_child(child, Point::ZERO); size @@ -351,7 +351,7 @@ fn check_layout_stashed() { #[test] fn check_paint_rect_includes_children() { use crate::widgets::Label; - let widget = make_parent_widget(Label::new("Hello world")).layout_fn(|child, ctx, bc| { + let widget = make_parent_widget(Label::new("Hello world")).layout_fn(|child, ctx, _, bc| { let _size = ctx.run_layout(child, bc); ctx.place_child(child, Point::ZERO); Size::ZERO diff --git a/masonry/src/widgets/text_area.rs b/masonry/src/widgets/text_area.rs index 41037c773..2d265ed4d 100644 --- a/masonry/src/widgets/text_area.rs +++ b/masonry/src/widgets/text_area.rs @@ -19,8 +19,8 @@ use winit::keyboard::{Key, NamedKey}; use crate::core::{ default_styles, render_text, AccessCtx, AccessEvent, BoxConstraints, BrushIndex, EventCtx, - LayoutCtx, PaintCtx, PointerButton, PointerEvent, QueryCtx, RegisterCtx, StyleProperty, - TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, + LayoutCtx, PaintCtx, PointerButton, PointerEvent, Properties, PropertiesMut, QueryCtx, + RegisterCtx, StyleProperty, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, }; use crate::widgets::Padding; use crate::{palette, theme}; @@ -507,7 +507,12 @@ impl TextArea { // --- MARK: IMPL WIDGET --- impl Widget for TextArea { - fn on_pointer_event(&mut self, ctx: &mut EventCtx, event: &PointerEvent) { + fn on_pointer_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &PointerEvent, + ) { if self.editor.is_composing() { return; } @@ -567,7 +572,12 @@ impl Widget for TextArea { } } - fn on_text_event(&mut self, ctx: &mut EventCtx, event: &TextEvent) { + fn on_text_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &TextEvent, + ) { match event { TextEvent::KeyboardKey(key_event, modifiers_state) => { if !key_event.state.is_pressed() || self.editor.is_composing() { @@ -836,7 +846,12 @@ impl Widget for TextArea { EDITABLE } - fn on_access_event(&mut self, ctx: &mut EventCtx, event: &AccessEvent) { + fn on_access_event( + &mut self, + ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + event: &AccessEvent, + ) { if event.action == accesskit::Action::SetTextSelection { if self.editor.is_composing() { return; @@ -853,7 +868,7 @@ impl Widget for TextArea { fn register_children(&mut self, _ctx: &mut RegisterCtx) {} - fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) { + fn update(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, event: &Update) { match event { Update::FocusChanged(_) => { ctx.request_render(); @@ -866,7 +881,12 @@ impl Widget for TextArea { } } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { // Shrink constraints by padding inset let padding_size = Size::new( self.padding.leading + self.padding.trailing, @@ -908,7 +928,7 @@ impl Widget for TextArea { bc.constrain(area_size) } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { let layout = if let Some(layout) = self.editor.try_layout() { layout } else { @@ -962,7 +982,7 @@ impl Widget for TextArea { } } - fn accessibility(&mut self, ctx: &mut AccessCtx, node: &mut Node) { + fn accessibility(&mut self, ctx: &mut AccessCtx, _props: &Properties<'_>, node: &mut Node) { if !EDITABLE { node.set_read_only(); } diff --git a/masonry/src/widgets/textbox.rs b/masonry/src/widgets/textbox.rs index 45fdeb8c8..7848e4a74 100644 --- a/masonry/src/widgets/textbox.rs +++ b/masonry/src/widgets/textbox.rs @@ -10,7 +10,7 @@ use vello::kurbo::{Affine, Insets, Point, Rect, Size, Stroke}; use vello::Scene; use crate::core::{ - AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, + AccessCtx, AccessEvent, BoxConstraints, Properties, PropertiesMut, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod, }; use crate::peniko::Color; @@ -110,19 +110,19 @@ impl Textbox { // --- MARK: IMPL WIDGET --- impl Widget for Textbox { - fn on_pointer_event(&mut self, _: &mut EventCtx, _: &PointerEvent) {} + fn on_pointer_event(&mut self, _: &mut EventCtx, _props: &mut PropertiesMut<'_>, _: &PointerEvent) {} - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &AccessEvent) {} fn register_children(&mut self, ctx: &mut RegisterCtx) { ctx.register_child(&mut self.text); } - fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {} + fn update(&mut self, _ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, _event: &Update) {} - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { let margin = TEXTBOX_MARGIN; // Shrink constraints by padding inset let margin_size = Size::new(margin.leading + margin.trailing, margin.top + margin.bottom); @@ -137,7 +137,7 @@ impl Widget for Textbox { size + margin_size } - fn paint(&mut self, ctx: &mut PaintCtx, scene: &mut Scene) { + fn paint(&mut self, ctx: &mut PaintCtx, _props: &Properties<'_>, scene: &mut Scene) { let size = ctx.size(); let outline_rect = size.to_rect().inset(Insets::new( -TEXTBOX_MARGIN.leading, @@ -158,7 +158,7 @@ impl Widget for Textbox { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { smallvec![self.text.id()] diff --git a/masonry/src/widgets/variable_label.rs b/masonry/src/widgets/variable_label.rs index 5e9d847d9..4604e05fd 100644 --- a/masonry/src/widgets/variable_label.rs +++ b/masonry/src/widgets/variable_label.rs @@ -12,7 +12,7 @@ use vello::kurbo::{Point, Size}; use vello::Scene; use crate::core::{ - AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, + AccessCtx, AccessEvent, ArcStr, BoxConstraints, Properties, PropertiesMut, EventCtx, LayoutCtx, PaintCtx, PointerEvent, QueryCtx, RegisterCtx, StyleProperty, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetMut, WidgetPod, }; @@ -173,23 +173,23 @@ impl VariableLabel { // --- MARK: IMPL WIDGET --- impl Widget for VariableLabel { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} + fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &PointerEvent) {} fn accepts_pointer_interaction(&self) -> bool { false } - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} + fn on_text_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_access_event(&mut self, _ctx: &mut EventCtx, _props: &mut PropertiesMut<'_>, _event: &AccessEvent) {} - fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {} + fn update(&mut self, _ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, _event: &Update) {} fn register_children(&mut self, ctx: &mut RegisterCtx) { ctx.register_child(&mut self.label); } - fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, interval: u64) { + fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, _props: &mut PropertiesMut<'_>, interval: u64) { let millis = (interval as f64 / 1_000_000.) as f32; let result = self.weight.advance(millis); let new_weight = self.weight.value; @@ -212,19 +212,19 @@ impl Widget for VariableLabel { } } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout(&mut self, ctx: &mut LayoutCtx, _props: &mut PropertiesMut<'_>, bc: &BoxConstraints) -> Size { let size = ctx.run_layout(&mut self.label, bc); ctx.place_child(&mut self.label, Point::ORIGIN); size } - fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {} + fn paint(&mut self, _ctx: &mut PaintCtx, _props: &Properties<'_>, _scene: &mut Scene) {} fn accessibility_role(&self) -> Role { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { smallvec![self.label.id()] diff --git a/masonry/src/widgets/zstack.rs b/masonry/src/widgets/zstack.rs index 0d3c63fef..6b425f3b5 100644 --- a/masonry/src/widgets/zstack.rs +++ b/masonry/src/widgets/zstack.rs @@ -8,8 +8,8 @@ use smallvec::SmallVec; use tracing::trace_span; use crate::core::{ - AccessCtx, BoxConstraints, LayoutCtx, PaintCtx, QueryCtx, RegisterCtx, Widget, WidgetId, - WidgetMut, WidgetPod, + AccessCtx, BoxConstraints, LayoutCtx, PaintCtx, Properties, PropertiesMut, QueryCtx, + RegisterCtx, Widget, WidgetId, WidgetMut, WidgetPod, }; use crate::kurbo::{Point, Size}; use crate::vello::Scene; @@ -298,7 +298,12 @@ impl ZStack { // --- MARK: IMPL WIDGET--- impl Widget for ZStack { - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { // First pass: calculate the smallest bounds needed to layout the children. let mut max_size = bc.min(); let loosened_bc = bc.loosen(); @@ -341,7 +346,7 @@ impl Widget for ZStack { max_size } - fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {} + fn paint(&mut self, _ctx: &mut PaintCtx, _props: &Properties<'_>, _scene: &mut Scene) {} fn register_children(&mut self, ctx: &mut RegisterCtx) { for child in self.children.iter_mut().map(|x| &mut x.widget) { @@ -361,7 +366,7 @@ impl Widget for ZStack { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn make_trace_span(&self, ctx: &QueryCtx<'_>) -> tracing::Span { trace_span!("ZStack", id = ctx.widget_id().trace()) diff --git a/xilem/src/any_view.rs b/xilem/src/any_view.rs index 4a15d30e8..ed5be0585 100644 --- a/xilem/src/any_view.rs +++ b/xilem/src/any_view.rs @@ -4,7 +4,8 @@ use accesskit::{Node, Role}; use masonry::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, FromDynWidget, LayoutCtx, PaintCtx, - PointerEvent, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, WidgetMut, WidgetPod, + PointerEvent, Properties, PropertiesMut, QueryCtx, RegisterCtx, TextEvent, Widget, WidgetId, + WidgetMut, WidgetPod, }; use masonry::kurbo::{Point, Size}; use smallvec::{smallvec, SmallVec}; @@ -68,27 +69,50 @@ impl DynWidget { /// Forward all events to the child widget. impl Widget for DynWidget { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_pointer_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &PointerEvent, + ) { + } + fn on_text_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &TextEvent, + ) { + } + fn on_access_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &AccessEvent, + ) { + } fn register_children(&mut self, ctx: &mut RegisterCtx) { ctx.register_child(&mut self.inner); } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { let size = ctx.run_layout(&mut self.inner, bc); ctx.place_child(&mut self.inner, Point::ORIGIN); size } - fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {} + fn paint(&mut self, _ctx: &mut PaintCtx, _props: &Properties<'_>, _scene: &mut Scene) {} fn accessibility_role(&self) -> Role { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { smallvec![self.inner.id()] diff --git a/xilem/src/one_of.rs b/xilem/src/one_of.rs index 1574b0b14..3446e1959 100644 --- a/xilem/src/one_of.rs +++ b/xilem/src/one_of.rs @@ -6,7 +6,7 @@ use accesskit::{Node, Role}; use masonry::core::{ AccessCtx, AccessEvent, BoxConstraints, EventCtx, FromDynWidget, LayoutCtx, PaintCtx, - PointerEvent, RegisterCtx, TextEvent, Widget, WidgetId, WidgetPod, + PointerEvent, Properties, PropertiesMut, RegisterCtx, TextEvent, Widget, WidgetId, WidgetPod, }; use masonry::kurbo::{Point, Size}; use smallvec::{smallvec, SmallVec}; @@ -182,9 +182,27 @@ impl< I: Widget + FromDynWidget + ?Sized, > Widget for OneOfWidget { - fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {} - fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {} - fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {} + fn on_pointer_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &PointerEvent, + ) { + } + fn on_text_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &TextEvent, + ) { + } + fn on_access_event( + &mut self, + _ctx: &mut EventCtx, + _props: &mut PropertiesMut<'_>, + _event: &AccessEvent, + ) { + } fn register_children(&mut self, ctx: &mut RegisterCtx) { match self { @@ -200,7 +218,12 @@ impl< } } - fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size { + fn layout( + &mut self, + ctx: &mut LayoutCtx, + _props: &mut PropertiesMut<'_>, + bc: &BoxConstraints, + ) -> Size { match self { Self::A(w) => { let size = ctx.run_layout(w, bc); @@ -250,13 +273,13 @@ impl< } } - fn paint(&mut self, _ctx: &mut PaintCtx, _scene: &mut Scene) {} + fn paint(&mut self, _ctx: &mut PaintCtx, _props: &Properties<'_>, _scene: &mut Scene) {} fn accessibility_role(&self) -> Role { Role::GenericContainer } - fn accessibility(&mut self, _ctx: &mut AccessCtx, _node: &mut Node) {} + fn accessibility(&mut self, _ctx: &mut AccessCtx, _props: &Properties<'_>, _node: &mut Node) {} fn children_ids(&self) -> SmallVec<[WidgetId; 16]> { match self {