Merge StatusChange with Update (#697)

This commit is contained in:
Olivier FAURE 2024-10-20 19:15:18 +02:00 committed by GitHub
parent f403337219
commit 4d20e0dd19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 64 additions and 155 deletions

View File

@ -13,8 +13,7 @@ use masonry::dpi::LogicalSize;
use masonry::widget::{Align, CrossAxisAlignment, Flex, Label, RootWidget, SizedBox};
use masonry::{
AccessCtx, AccessEvent, Action, BoxConstraints, Color, EventCtx, LayoutCtx, PaintCtx, Point,
PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId,
WidgetPod,
PointerEvent, RegisterCtx, Size, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetPod,
};
use smallvec::{smallvec, SmallVec};
use tracing::{trace, trace_span, Span};
@ -182,14 +181,14 @@ impl Widget for CalcButton {
}
}
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange) {
fn update(&mut self, ctx: &mut UpdateCtx, 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
// "hovered" visual effect, but it's somewhat non-idiomatic compared to
// implementing the effect inside the "paint" method.
match event {
StatusChange::HoveredChanged(true) => {
Update::HoveredChanged(true) => {
ctx.mutate_later(&mut self.inner, move |mut inner| {
inner.set_border(Color::WHITE, 3.0);
});
@ -197,7 +196,7 @@ impl Widget for CalcButton {
// Should be fixed once the pass spec RFC is implemented.
ctx.request_anim_frame();
}
StatusChange::HoveredChanged(false) => {
Update::HoveredChanged(false) => {
ctx.mutate_later(&mut self.inner, move |mut inner| {
inner.set_border(Color::TRANSPARENT, 3.0);
});

View File

@ -13,8 +13,7 @@ use masonry::kurbo::{BezPath, Stroke};
use masonry::widget::{ObjectFit, RootWidget};
use masonry::{
AccessCtx, AccessEvent, Action, Affine, BoxConstraints, Color, EventCtx, LayoutCtx, PaintCtx,
Point, PointerEvent, Rect, RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget,
WidgetId,
Point, PointerEvent, Rect, RegisterCtx, Size, TextEvent, Widget, WidgetId,
};
use parley::layout::Alignment;
use parley::style::{FontFamily, FontStack, StyleProperty};
@ -41,8 +40,6 @@ impl Widget for CustomWidget {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn layout(&mut self, _layout_ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
// BoxConstraints are passed by the parent widget.
// This method can return any Size within those constraints:

View File

@ -302,14 +302,14 @@ impl_context_method!(
/// A widget can request focus using the [`request_focus`] method.
/// It's also possible to register for automatic focus via [`register_for_focus`].
///
/// If a widget gains or loses focus it will get a [`StatusChange::FocusChanged`] event.
/// If a widget gains or loses focus it will get a [`Update::FocusChanged`] event.
///
/// Only one widget at a time is focused. However due to the way events are routed,
/// all ancestors of that widget will also receive keyboard events.
///
/// [`request_focus`]: EventCtx::request_focus
/// [`register_for_focus`]: UpdateCtx::register_for_focus
/// [`StatusChange::FocusChanged`]: crate::StatusChange::FocusChanged
/// [`Update::FocusChanged`]: crate::Update::FocusChanged
/// [`has_focus`]: Self::has_focus
pub fn is_focused(&self) -> bool {
self.global_state.focused_widget == Some(self.widget_id())

View File

@ -286,17 +286,12 @@ pub enum Update {
/// Called when a child widgets uses
/// [`EventCtx::request_pan_to_this`](crate::EventCtx::request_pan_to_this).
RequestPanToChild(Rect),
}
/// Event indicating status changes within the widget hierarchy.
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum StatusChange {
/// Called when the "hovered" status changes.
///
/// This will always be called _before_ the event that triggered it; that is,
/// when the mouse moves over a widget, that widget will receive
/// `StatusChange::HoveredChanged` before it receives `Event::MouseMove`.
/// `Update::HoveredChanged` before it receives `Event::MouseMove`.
///
/// See [`is_hovered`](crate::EventCtx::is_hovered) for
/// discussion about the hovered status.
@ -477,6 +472,9 @@ impl Update {
Update::DisabledChanged(_) => "DisabledChanged",
Update::StashedChanged(_) => "StashedChanged",
Update::RequestPanToChild(_) => "RequestPanToChild",
Update::HoveredChanged(_) => "HoveredChanged",
Update::FocusChanged(_) => "FocusChanged",
Update::ChildFocusChanged(_) => "ChildFocusChanged",
}
}
}

View File

@ -139,8 +139,8 @@ pub use contexts::{
};
pub use cursor_icon::{CursorIcon, ParseError as CursorIconParseError};
pub use event::{
AccessEvent, PointerButton, PointerEvent, PointerState, StatusChange, TextEvent, Update,
WindowEvent, WindowTheme,
AccessEvent, PointerButton, PointerEvent, PointerState, TextEvent, Update, WindowEvent,
WindowTheme,
};
pub use kurbo::{Affine, Insets, Point, Rect, Size, Vec2};
pub use parley::fontique::Weight as TextWeight;

View File

@ -10,9 +10,7 @@ use crate::passes::event::run_on_pointer_event_pass;
use crate::passes::{merge_state_up, recurse_on_children};
use crate::render_root::{RenderRoot, RenderRootSignal, RenderRootState};
use crate::tree_arena::ArenaMut;
use crate::{
PointerEvent, RegisterCtx, StatusChange, Update, UpdateCtx, Widget, WidgetId, WidgetState,
};
use crate::{PointerEvent, RegisterCtx, Update, UpdateCtx, Widget, WidgetId, WidgetState};
// --- MARK: HELPERS ---
fn get_id_path(root: &RenderRoot, widget_id: Option<WidgetId>) -> Vec<WidgetId> {
@ -422,7 +420,7 @@ pub(crate) fn run_update_focus_pass(root: &mut RenderRoot) {
let has_focus = focused_set.contains(&ctx.widget_id());
if ctx.widget_state.has_focus != has_focus {
widget.on_status_change(ctx, &StatusChange::ChildFocusChanged(has_focus));
widget.update(ctx, &Update::ChildFocusChanged(has_focus));
}
ctx.widget_state.has_focus = has_focus;
});
@ -459,12 +457,12 @@ pub(crate) fn run_update_focus_pass(root: &mut RenderRoot) {
// 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.on_status_change(ctx, &StatusChange::FocusChanged(false));
widget.update(ctx, &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.on_status_change(ctx, &StatusChange::FocusChanged(true));
widget.update(ctx, &Update::FocusChanged(true));
ctx.widget_state.request_accessibility = true;
ctx.widget_state.needs_accessibility = true;
});
@ -579,7 +577,7 @@ pub(crate) fn run_update_pointer_pass(root: &mut RenderRoot) {
let is_hovered = hovered_set.contains(&ctx.widget_id());
if ctx.widget_state.is_hovered != is_hovered {
widget.on_status_change(ctx, &StatusChange::HoveredChanged(is_hovered));
widget.update(ctx, &Update::HoveredChanged(is_hovered));
ctx.widget_state.request_accessibility = true;
ctx.widget_state.needs_accessibility = true;
}

View File

@ -32,7 +32,6 @@ pub type TextEventFn<S> = dyn FnMut(&mut S, &mut EventCtx, &TextEvent);
pub type AccessEventFn<S> = dyn FnMut(&mut S, &mut EventCtx, &AccessEvent);
pub type AnimFrameFn<S> = dyn FnMut(&mut S, &mut UpdateCtx, u64);
pub type RegisterChildrenFn<S> = dyn FnMut(&mut S, &mut RegisterCtx);
pub type StatusChangeFn<S> = dyn FnMut(&mut S, &mut UpdateCtx, &StatusChange);
pub type UpdateFn<S> = dyn FnMut(&mut S, &mut UpdateCtx, &Update);
pub type LayoutFn<S> = dyn FnMut(&mut S, &mut LayoutCtx, &BoxConstraints) -> Size;
pub type ComposeFn<S> = dyn FnMut(&mut S, &mut ComposeCtx);
@ -57,7 +56,6 @@ pub struct ModularWidget<S> {
on_access_event: Option<Box<AccessEventFn<S>>>,
on_anim_frame: Option<Box<AnimFrameFn<S>>>,
register_children: Option<Box<RegisterChildrenFn<S>>>,
on_status_change: Option<Box<StatusChangeFn<S>>>,
update: Option<Box<UpdateFn<S>>>,
layout: Option<Box<LayoutFn<S>>>,
compose: Option<Box<ComposeFn<S>>>,
@ -109,7 +107,6 @@ pub enum Record {
AE(AccessEvent),
AF(u64),
RC,
SC(StatusChange),
U(Update),
Layout(Size),
Compose,
@ -145,7 +142,6 @@ impl<S> ModularWidget<S> {
on_access_event: None,
on_anim_frame: None,
register_children: None,
on_status_change: None,
update: None,
layout: None,
compose: None,
@ -208,14 +204,6 @@ impl<S> ModularWidget<S> {
self
}
pub fn status_change_fn(
mut self,
f: impl FnMut(&mut S, &mut UpdateCtx, &StatusChange) + 'static,
) -> Self {
self.on_status_change = Some(Box::new(f));
self
}
pub fn update_fn(mut self, f: impl FnMut(&mut S, &mut UpdateCtx, &Update) + 'static) -> Self {
self.update = Some(Box::new(f));
self
@ -293,12 +281,6 @@ impl<S: 'static> Widget for ModularWidget<S> {
}
}
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange) {
if let Some(f) = self.on_status_change.as_mut() {
f(&mut self.state, ctx, event);
}
}
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
if let Some(f) = self.update.as_mut() {
f(&mut self.state, ctx, event);
@ -428,10 +410,6 @@ impl Widget for ReplaceChild {
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, ctx: &mut UpdateCtx, _event: &StatusChange) {
ctx.request_layout();
}
fn register_children(&mut self, ctx: &mut RegisterCtx) {
ctx.register_child(&mut self.child);
}
@ -509,11 +487,6 @@ impl<W: Widget> Widget for Recorder<W> {
self.child.on_anim_frame(ctx, interval);
}
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange) {
self.recording.push(Record::SC(event.clone()));
self.child.on_status_change(ctx, event);
}
fn register_children(&mut self, ctx: &mut RegisterCtx) {
self.recording.push(Record::RC);
self.child.register_children(ctx);

View File

@ -18,7 +18,7 @@ use crate::paint_scene_helpers::UnitPoint;
use crate::widget::WidgetPod;
use crate::{
AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, Rect, RegisterCtx,
Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId,
Size, TextEvent, Widget, WidgetId,
};
// TODO - Have child widget type as generic argument
@ -95,8 +95,6 @@ impl Widget for Align {
ctx.register_child(&mut self.child);
}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
let size = ctx.run_layout(&mut self.child, &bc.loosen());

View File

@ -14,7 +14,7 @@ use crate::paint_scene_helpers::{fill_lin_gradient, stroke, UnitPoint};
use crate::widget::{Label, WidgetMut, WidgetPod};
use crate::{
theme, AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, Insets, LayoutCtx, PaintCtx,
PointerEvent, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId,
PointerEvent, Size, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
// the minimum padding added to a button.
@ -111,9 +111,13 @@ impl Widget for Button {
}
}
fn on_status_change(&mut self, ctx: &mut UpdateCtx, _event: &StatusChange) {
// Changes in hovered/focused status impact appearance, but not accessibility node
ctx.request_paint_only();
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
Update::HoveredChanged(_) | Update::FocusChanged(_) | Update::DisabledChanged(_) => {
ctx.request_paint_only();
}
_ => {}
}
}
fn register_children(&mut self, ctx: &mut crate::RegisterCtx) {

View File

@ -14,7 +14,7 @@ use crate::paint_scene_helpers::{fill_lin_gradient, stroke, UnitPoint};
use crate::widget::{Label, WidgetMut};
use crate::{
theme, AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, RegisterCtx, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId, WidgetPod,
PointerEvent, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetPod,
};
/// A checkbox that can be toggled.
@ -102,9 +102,14 @@ impl Widget for Checkbox {
}
}
fn on_status_change(&mut self, ctx: &mut UpdateCtx, _event: &StatusChange) {
// Hovered/focused status impacts appearance, but not accessibility node
ctx.request_paint_only();
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
Update::HoveredChanged(_) | Update::FocusChanged(_) | Update::DisabledChanged(_) => {
ctx.request_paint_only();
}
_ => {}
}
}
fn register_children(&mut self, ctx: &mut RegisterCtx) {

View File

@ -14,7 +14,7 @@ use crate::theme::get_debug_color;
use crate::widget::WidgetMut;
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent,
Rect, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId, WidgetPod,
Rect, Size, TextEvent, Widget, WidgetId, WidgetPod,
};
/// A container with either horizontal or vertical layout.
@ -901,8 +901,6 @@ impl Widget for Flex {
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn register_children(&mut self, ctx: &mut crate::RegisterCtx) {
for child in self.children.iter_mut().filter_map(|x| x.widget_mut()) {
ctx.register_child(child);

View File

@ -11,7 +11,7 @@ use crate::theme::get_debug_color;
use crate::widget::WidgetMut;
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent,
Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId, WidgetPod,
Size, TextEvent, Widget, WidgetId, WidgetPod,
};
pub struct Grid {
@ -238,8 +238,6 @@ impl Widget for Grid {
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn register_children(&mut self, ctx: &mut crate::RegisterCtx) {
for child in self.children.iter_mut().filter_map(|x| x.widget_mut()) {
ctx.register_child(child);

View File

@ -14,7 +14,7 @@ use vello::Scene;
use crate::widget::{ObjectFit, WidgetMut};
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
RegisterCtx, Size, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
RegisterCtx, Size, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
// TODO - Resolve name collision between masonry::Image and peniko::Image
@ -79,8 +79,6 @@ impl Widget for Image {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {}
fn layout(&mut self, _ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {

View File

@ -17,7 +17,7 @@ use crate::text::{TextBrush, TextLayout};
use crate::widget::WidgetMut;
use crate::{
AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
// added padding between the edges of the widget and the text.
@ -167,8 +167,6 @@ impl Widget for Label {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
Update::DisabledChanged(disabled) => {

View File

@ -14,8 +14,7 @@ use vello::Scene;
use crate::widget::{Axis, ScrollBar, WidgetMut};
use crate::{
AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
WidgetPod,
PointerEvent, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId, WidgetPod,
};
// TODO - refactor - see https://github.com/linebender/xilem/issues/366
@ -320,8 +319,6 @@ impl<W: Widget> Widget for Portal<W> {
// TODO - Handle scroll-related events?
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn register_children(&mut self, ctx: &mut RegisterCtx) {
ctx.register_child(&mut self.child);
ctx.register_child(&mut self.scrollbar_horizontal);

View File

@ -14,7 +14,7 @@ use crate::text::TextLayout;
use crate::widget::WidgetMut;
use crate::{
theme, AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point,
PointerEvent, RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
PointerEvent, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
/// A progress bar
@ -105,8 +105,6 @@ impl Widget for ProgressBar {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {}
fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {

View File

@ -15,7 +15,7 @@ use crate::widget::label::LABEL_X_PADDING;
use crate::widget::{LineBreaking, WidgetMut};
use crate::{
AccessCtx, AccessEvent, ArcStr, BoxConstraints, CursorIcon, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
PointerEvent, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
/// The prose widget is a widget which displays text which can be
@ -198,23 +198,16 @@ impl Widget for Prose {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
#[allow(missing_docs)]
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange) {
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
StatusChange::FocusChanged(false) => {
Update::FocusChanged(false) => {
self.text_layout.focus_lost();
ctx.request_layout();
// TODO: Stop focusing on any links
}
StatusChange::FocusChanged(true) => {
Update::FocusChanged(true) => {
// TODO: Focus on first link
}
_ => {}
}
}
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
Update::DisabledChanged(disabled) => {
if self.show_disabled {
if *disabled {

View File

@ -10,7 +10,7 @@ use vello::Scene;
use crate::widget::{WidgetMut, WidgetPod};
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId,
RegisterCtx, Size, TextEvent, Widget, WidgetId,
};
// TODO: This is a hack to provide an accessibility node with a Window type.
@ -43,8 +43,6 @@ impl<W: Widget> Widget for RootWidget<W> {
fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {}
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, _: &mut UpdateCtx, _: &StatusChange) {}
fn register_children(&mut self, ctx: &mut RegisterCtx) {
ctx.register_child(&mut self.pod);
}

View File

@ -13,8 +13,7 @@ use crate::paint_scene_helpers::{fill_color, stroke};
use crate::widget::{Axis, WidgetMut};
use crate::{
theme, AccessCtx, AccessEvent, AllowRawMut, BoxConstraints, EventCtx, LayoutCtx, PaintCtx,
Point, PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, Update, UpdateCtx, Widget,
WidgetId,
Point, PointerEvent, RegisterCtx, Size, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
// RULES
@ -175,8 +174,6 @@ impl Widget for ScrollBar {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {}
fn layout(&mut self, _ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {

View File

@ -14,7 +14,7 @@ use crate::paint_scene_helpers::stroke;
use crate::widget::{WidgetMut, WidgetPod};
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent,
RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId,
RegisterCtx, Size, TextEvent, Widget, WidgetId,
};
// FIXME - Improve all doc in this module ASAP.
@ -310,8 +310,6 @@ impl Widget for SizedBox {
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn register_children(&mut self, ctx: &mut RegisterCtx) {
if let Some(ref mut child) = self.child {
ctx.register_child(child);

View File

@ -14,8 +14,7 @@ use vello::Scene;
use crate::widget::WidgetMut;
use crate::{
theme, AccessCtx, AccessEvent, BoxConstraints, Color, EventCtx, LayoutCtx, PaintCtx, Point,
PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, Update, UpdateCtx, Vec2, Widget,
WidgetId,
PointerEvent, RegisterCtx, Size, TextEvent, Update, UpdateCtx, Vec2, Widget, WidgetId,
};
// TODO - Set color
@ -88,8 +87,6 @@ impl Widget for Spinner {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
Update::WidgetAdded => {

View File

@ -16,8 +16,7 @@ use crate::widget::flex::Axis;
use crate::widget::{WidgetMut, WidgetPod};
use crate::{
theme, AccessCtx, AccessEvent, BoxConstraints, Color, CursorIcon, EventCtx, LayoutCtx,
PaintCtx, Point, PointerEvent, Rect, RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx,
Widget, WidgetId,
PaintCtx, Point, PointerEvent, Rect, RegisterCtx, Size, TextEvent, Widget, WidgetId,
};
// TODO - Have child widget type as generic argument
@ -445,8 +444,6 @@ impl Widget for Split {
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn register_children(&mut self, ctx: &mut RegisterCtx) {
ctx.register_child(&mut self.child1);
ctx.register_child(&mut self.child2);

View File

@ -33,7 +33,7 @@ impl FocusTaker {
}
})
.status_change_fn(|is_focused, _ctx, event| {
if let StatusChange::FocusChanged(focus) = event {
if let Update::FocusChanged(focus) = event {
is_focused.set(*focus);
}
})

View File

@ -27,7 +27,7 @@ fn is_hovered(harness: &TestHarness, id: WidgetId) -> bool {
fn next_hovered_changed(recording: &Recording) -> Option<bool> {
while let Some(event) = recording.next() {
match event {
Record::SC(StatusChange::HoveredChanged(hovered)) => return Some(hovered),
Record::U(Update::HoveredChanged(hovered)) => return Some(hovered),
_ => {}
}
}

View File

@ -15,7 +15,7 @@ use crate::text::{TextBrush, TextEditor, TextWithSelection};
use crate::widget::{LineBreaking, WidgetMut};
use crate::{
AccessCtx, AccessEvent, BoxConstraints, CursorIcon, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
PointerEvent, RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
const TEXTBOX_PADDING: f64 = 3.0;
@ -226,23 +226,16 @@ impl Widget for Textbox {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
#[allow(missing_docs)]
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange) {
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
StatusChange::FocusChanged(false) => {
Update::FocusChanged(false) => {
self.editor.focus_lost();
ctx.request_layout();
}
StatusChange::FocusChanged(true) => {
Update::FocusChanged(true) => {
self.editor.focus_gained();
ctx.request_layout();
}
_ => {}
}
}
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
Update::DisabledChanged(disabled) => {
if self.show_disabled {
if *disabled {

View File

@ -19,7 +19,7 @@ use crate::text::{Hinting, TextBrush, TextLayout};
use crate::widget::{LineBreaking, WidgetMut};
use crate::{
AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
RegisterCtx, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
// added padding between the edges of the widget and the text.
@ -319,18 +319,11 @@ impl Widget for VariableLabel {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
#[allow(missing_docs)]
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, event: &StatusChange) {
match event {
StatusChange::FocusChanged(_) => {
// TODO: Focus on first link
}
_ => {}
}
}
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
Update::FocusChanged(_) => {
// TODO: Focus on first link
}
Update::DisabledChanged(disabled) => {
if self.show_disabled {
if *disabled {

View File

@ -14,7 +14,7 @@ use tracing::{trace_span, Span};
use vello::Scene;
use crate::contexts::ComposeCtx;
use crate::event::{AccessEvent, PointerEvent, StatusChange, TextEvent};
use crate::event::{AccessEvent, PointerEvent, TextEvent};
use crate::widget::WidgetRef;
use crate::{
AccessCtx, AsAny, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, QueryCtx, RegisterCtx,
@ -91,9 +91,6 @@ pub trait Widget: AsAny {
/// the monitor's refresh, causing lag or jerky animations.
fn on_anim_frame(&mut self, ctx: &mut UpdateCtx, interval: u64) {}
#[allow(missing_docs)]
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange);
/// Register child widgets with Masonry.
///
/// Leaf widgets can implement this with an empty body.
@ -402,10 +399,6 @@ impl Widget for Box<dyn Widget> {
self.deref_mut().register_children(ctx);
}
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange) {
self.deref_mut().on_status_change(ctx, event);
}
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
self.deref_mut().update(ctx, event);
}

View File

@ -5,7 +5,7 @@ use accesskit::{NodeBuilder, Role};
use masonry::widget::WidgetMut;
use masonry::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent,
RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId, WidgetPod,
RegisterCtx, Size, TextEvent, Widget, WidgetId, WidgetPod,
};
use smallvec::{smallvec, SmallVec};
use tracing::{trace_span, Span};
@ -78,10 +78,6 @@ impl Widget for DynWidget {
fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {}
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, _: &mut UpdateCtx, _: &StatusChange) {
// Intentionally do nothing
}
fn register_children(&mut self, ctx: &mut RegisterCtx) {
ctx.register_child(&mut self.inner);
}

View File

@ -6,7 +6,7 @@
use accesskit::{NodeBuilder, Role};
use masonry::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent,
RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId, WidgetPod,
RegisterCtx, Size, TextEvent, Widget, WidgetId, WidgetPod,
};
use smallvec::{smallvec, SmallVec};
use vello::Scene;
@ -175,11 +175,6 @@ impl<
fn on_text_event(&mut self, _ctx: &mut EventCtx, _event: &TextEvent) {}
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
#[allow(missing_docs)] // reason: Doesn't do anything and is not available publicly
fn on_status_change(&mut self, _: &mut UpdateCtx, _: &StatusChange) {
// Intentionally do nothing
}
fn register_children(&mut self, ctx: &mut RegisterCtx) {
match self {
OneOfWidget::A(w) => ctx.register_child(w),