Rename lifecycle to update (#677)

This commit is contained in:
Olivier FAURE 2024-10-17 14:09:14 +02:00 committed by GitHub
parent cdda9b542d
commit dc9a2e2a97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
33 changed files with 173 additions and 184 deletions

View File

@ -12,8 +12,8 @@ use masonry::app_driver::{AppDriver, DriverCtx};
use masonry::dpi::LogicalSize;
use masonry::widget::{Align, CrossAxisAlignment, Flex, Label, RootWidget, SizedBox};
use masonry::{
AccessCtx, AccessEvent, Action, BoxConstraints, Color, EventCtx, LayoutCtx, LifeCycleCtx,
PaintCtx, Point, PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, Widget, WidgetId,
AccessCtx, AccessEvent, Action, BoxConstraints, Color, EventCtx, LayoutCtx, PaintCtx, Point,
PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId,
WidgetPod,
};
use smallvec::{smallvec, SmallVec};
@ -182,7 +182,7 @@ impl Widget for CalcButton {
}
}
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, event: &StatusChange) {
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange) {
// 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

View File

@ -12,9 +12,9 @@ use masonry::app_driver::{AppDriver, DriverCtx};
use masonry::kurbo::{BezPath, Stroke};
use masonry::widget::{ObjectFit, RootWidget};
use masonry::{
AccessCtx, AccessEvent, Action, Affine, BoxConstraints, Color, EventCtx, LayoutCtx,
LifeCycleCtx, PaintCtx, Point, PointerEvent, Rect, RegisterCtx, Size, StatusChange, TextEvent,
Widget, WidgetId,
AccessCtx, AccessEvent, Action, Affine, BoxConstraints, Color, EventCtx, LayoutCtx, PaintCtx,
Point, PointerEvent, Rect, RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget,
WidgetId,
};
use parley::layout::Alignment;
use parley::style::{FontFamily, FontStack, StyleProperty};
@ -32,9 +32,6 @@ impl AppDriver for Driver {
struct CustomWidget(String);
// If this widget has any child widgets it should call its event, update and layout
// (and lifecycle) methods as well to make sure it works. Some things can be filtered,
// but a general rule is to just pass it through unless you really know you don't want it.
impl Widget for CustomWidget {
fn on_pointer_event(&mut self, _ctx: &mut EventCtx, _event: &PointerEvent) {}
@ -44,7 +41,7 @@ impl Widget for CustomWidget {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}
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.

View File

@ -81,10 +81,10 @@ pub struct RegisterCtx<'a> {
pub(crate) registered_ids: Vec<WidgetId>,
}
/// A context provided to the [`lifecycle`] method on widgets.
/// A context provided to the [`update`] method on widgets.
///
/// [`lifecycle`]: Widget::lifecycle
pub struct LifeCycleCtx<'a> {
/// [`update`]: Widget::update
pub struct UpdateCtx<'a> {
pub(crate) global_state: &'a mut RenderRootState,
pub(crate) widget_state: &'a mut WidgetState,
pub(crate) widget_state_children: ArenaMutChildren<'a, WidgetState>,
@ -135,7 +135,7 @@ impl_context_method!(
MutateCtx<'_>,
QueryCtx<'_>,
EventCtx<'_>,
LifeCycleCtx<'_>,
UpdateCtx<'_>,
LayoutCtx<'_>,
ComposeCtx<'_>,
PaintCtx<'_>,
@ -172,7 +172,7 @@ impl_context_method!(
impl_context_method!(
MutateCtx<'_>,
EventCtx<'_>,
LifeCycleCtx<'_>,
UpdateCtx<'_>,
LayoutCtx<'_>,
ComposeCtx<'_>,
{
@ -200,7 +200,7 @@ impl_context_method!(
MutateCtx<'_>,
QueryCtx<'_>,
EventCtx<'_>,
LifeCycleCtx<'_>,
UpdateCtx<'_>,
ComposeCtx<'_>,
PaintCtx<'_>,
AccessCtx<'_>,
@ -260,7 +260,7 @@ impl_context_method!(
MutateCtx<'_>,
QueryCtx<'_>,
EventCtx<'_>,
LifeCycleCtx<'_>,
UpdateCtx<'_>,
ComposeCtx<'_>,
PaintCtx<'_>,
AccessCtx<'_>,
@ -308,7 +308,7 @@ impl_context_method!(
/// all ancestors of that widget will also receive keyboard events.
///
/// [`request_focus`]: EventCtx::request_focus
/// [`register_for_focus`]: LifeCycleCtx::register_for_focus
/// [`register_for_focus`]: UpdateCtx::register_for_focus
/// [`StatusChange::FocusChanged`]: crate::StatusChange::FocusChanged
/// [`has_focus`]: Self::has_focus
pub fn is_focused(&self) -> bool {
@ -468,8 +468,8 @@ impl<'w> QueryCtx<'w> {
}
// --- MARK: UPDATE FLAGS ---
// Methods on MutateCtx, EventCtx, and LifeCycleCtx
impl_context_method!(MutateCtx<'_>, EventCtx<'_>, LifeCycleCtx<'_>, {
// Methods on MutateCtx, EventCtx, and UpdateCtx
impl_context_method!(MutateCtx<'_>, EventCtx<'_>, UpdateCtx<'_>, {
/// Request a [`paint`](crate::Widget::paint) and an [`accessibility`](crate::Widget::accessibility) pass.
pub fn request_render(&mut self) {
trace!("request_render");
@ -580,7 +580,7 @@ impl_context_method!(MutateCtx<'_>, EventCtx<'_>, LifeCycleCtx<'_>, {
impl_context_method!(
MutateCtx<'_>,
EventCtx<'_>,
LifeCycleCtx<'_>,
UpdateCtx<'_>,
LayoutCtx<'_>,
ComposeCtx<'_>,
{
@ -1161,7 +1161,7 @@ macro_rules! impl_get_raw {
}
impl_get_raw!(EventCtx);
impl_get_raw!(LifeCycleCtx);
impl_get_raw!(UpdateCtx);
impl_get_raw!(LayoutCtx);
impl<'s> AccessCtx<'s> {
@ -1262,5 +1262,5 @@ macro_rules! impl_context_trait {
}
impl_context_trait!(EventCtx);
impl_context_trait!(LifeCycleCtx);
impl_context_trait!(UpdateCtx);
impl_context_trait!(LayoutCtx);

View File

@ -15,7 +15,7 @@ use winit::keyboard::ModifiersState;
// TODO - winit ActivationTokenDone thing
// TODO - Suspended/Resume/NewEvents/MemoryWarning
// TODO - wtf is InnerSizeWriter?
// TODO - Move AnimFrame to Lifecycle
// TODO - Move AnimFrame to Update
// TODO - switch anim frames to being about age / an absolute timestamp
// instead of time elapsed.
// (this will help in cases where we want to skip anim frames)
@ -203,7 +203,7 @@ pub enum TextEvent {
KeyboardKey(KeyEvent, ModifiersState),
Ime(Ime),
ModifierChange(ModifiersState),
// TODO - Document difference with Lifecycle focus change
// TODO - Document difference with Update focus change
FocusChange(bool),
}
@ -232,17 +232,18 @@ pub enum WindowTheme {
Dark,
}
// TODO - Rewrite that doc.
/// Application life cycle events.
///
/// Unlike [`Event`]s, [`LifeCycle`] events are generated by Masonry, and
/// Unlike [`Event`]s, [`Update`] events are generated by Masonry, and
/// may occur at different times during a given pass of the event loop. The
/// [`LifeCycle::WidgetAdded`] event, for instance, may occur when the app
/// [`Update::WidgetAdded`] event, for instance, may occur when the app
/// first launches (during the handling of [`Event::WindowConnected`]) or it
/// may occur during an [`on_event`](crate::Widget::on_event) pass, if some
/// widget has been added then.
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum LifeCycle {
pub enum Update {
/// Sent to a `Widget` when it is added to the widget tree. This should be
/// the first message that each widget receives.
///
@ -477,17 +478,17 @@ impl PointerState {
}
}
impl LifeCycle {
impl Update {
/// Short name, for debug logging.
///
/// Essentially returns the enum variant name.
pub fn short_name(&self) -> &str {
match self {
LifeCycle::WidgetAdded => "WidgetAdded",
LifeCycle::AnimFrame(_) => "AnimFrame",
LifeCycle::DisabledChanged(_) => "DisabledChanged",
LifeCycle::StashedChanged(_) => "StashedChanged",
LifeCycle::RequestPanToChild(_) => "RequestPanToChild",
Update::WidgetAdded => "WidgetAdded",
Update::AnimFrame(_) => "AnimFrame",
Update::DisabledChanged(_) => "DisabledChanged",
Update::StashedChanged(_) => "StashedChanged",
Update::RequestPanToChild(_) => "RequestPanToChild",
}
}
}

View File

@ -135,11 +135,11 @@ mod tree_arena;
pub use action::Action;
pub use box_constraints::BoxConstraints;
pub use contexts::{
AccessCtx, ComposeCtx, EventCtx, IsContext, LayoutCtx, LifeCycleCtx, MutateCtx, PaintCtx,
QueryCtx, RawWrapper, RawWrapperMut, RegisterCtx,
AccessCtx, ComposeCtx, EventCtx, IsContext, LayoutCtx, MutateCtx, PaintCtx, QueryCtx,
RawWrapper, RawWrapperMut, RegisterCtx, UpdateCtx,
};
pub use event::{
AccessEvent, LifeCycle, PointerButton, PointerEvent, PointerState, StatusChange, TextEvent,
AccessEvent, PointerButton, PointerEvent, PointerState, StatusChange, TextEvent, Update,
WindowEvent, WindowTheme,
};
pub use kurbo::{Affine, Insets, Point, Rect, Size, Vec2};

View File

@ -6,7 +6,7 @@ use tracing::info_span;
use crate::passes::recurse_on_children;
use crate::render_root::{RenderRoot, RenderRootState};
use crate::tree_arena::ArenaMut;
use crate::{LifeCycle, LifeCycleCtx, Widget, WidgetState};
use crate::{Update, UpdateCtx, Widget, WidgetState};
// --- MARK: UPDATE ANIM ---
fn update_anim_for_widget(
@ -27,15 +27,13 @@ fn update_anim_for_widget(
// set in response to `AnimFrame`.
if state.item.request_anim {
state.item.request_anim = false;
let mut ctx = LifeCycleCtx {
let mut ctx = UpdateCtx {
global_state,
widget_state: state.item,
widget_state_children: state.children.reborrow_mut(),
widget_children: widget.children.reborrow_mut(),
};
widget
.item
.lifecycle(&mut ctx, &LifeCycle::AnimFrame(elapsed_ns));
widget.item.update(&mut ctx, &Update::AnimFrame(elapsed_ns));
}
let id = state.item.id;

View File

@ -11,7 +11,7 @@ use crate::passes::{merge_state_up, recurse_on_children};
use crate::render_root::{RenderRoot, RenderRootSignal, RenderRootState};
use crate::tree_arena::ArenaMut;
use crate::{
LifeCycle, LifeCycleCtx, PointerEvent, RegisterCtx, StatusChange, Widget, WidgetId, WidgetState,
PointerEvent, RegisterCtx, StatusChange, Update, UpdateCtx, Widget, WidgetId, WidgetState,
};
// --- MARK: HELPERS ---
@ -28,18 +28,17 @@ fn get_id_path(root: &RenderRoot, widget_id: Option<WidgetId>) -> Vec<WidgetId>
.collect()
}
// TODO - Replace LifecycleCtx with UpdateCtx
fn run_targeted_update_pass(
root: &mut RenderRoot,
target: Option<WidgetId>,
mut pass_fn: impl FnMut(&mut dyn Widget, &mut LifeCycleCtx),
mut pass_fn: impl FnMut(&mut dyn Widget, &mut UpdateCtx),
) {
let mut current_id = target;
while let Some(widget_id) = current_id {
let parent_id = root.widget_arena.parent_of(widget_id);
let (widget_mut, state_mut) = root.widget_arena.get_pair_mut(widget_id);
let mut ctx = LifeCycleCtx {
let mut ctx = UpdateCtx {
global_state: &mut root.state,
widget_state: state_mut.item,
widget_state_children: state_mut.children,
@ -52,16 +51,15 @@ fn run_targeted_update_pass(
}
}
// TODO - Replace LifecycleCtx with UpdateCtx
fn run_single_update_pass(
root: &mut RenderRoot,
target: Option<WidgetId>,
mut pass_fn: impl FnMut(&mut dyn Widget, &mut LifeCycleCtx),
mut pass_fn: impl FnMut(&mut dyn Widget, &mut UpdateCtx),
) {
if let Some(widget_id) = target {
let (widget_mut, state_mut) = root.widget_arena.get_pair_mut(widget_id);
let mut ctx = LifeCycleCtx {
let mut ctx = UpdateCtx {
global_state: &mut root.state,
widget_state: state_mut.item,
widget_state_children: state_mut.children,
@ -134,15 +132,15 @@ fn update_widget_tree(
}
if state.item.is_new {
let mut ctx = LifeCycleCtx {
let mut ctx = UpdateCtx {
global_state,
widget_state: state.item,
widget_state_children: state.children.reborrow_mut(),
widget_children: widget.children.reborrow_mut(),
};
widget.item.lifecycle(&mut ctx, &LifeCycle::WidgetAdded);
widget.item.update(&mut ctx, &Update::WidgetAdded);
trace!(
"{} received LifeCycle::WidgetAdded",
"{} received Update::WidgetAdded",
widget.item.short_type_name()
);
state.item.accepts_pointer_interaction = widget.item.accepts_pointer_interaction();
@ -200,7 +198,7 @@ fn update_disabled_for_widget(
}
if disabled != state.item.is_disabled {
let mut ctx = LifeCycleCtx {
let mut ctx = UpdateCtx {
global_state,
widget_state: state.item,
widget_state_children: state.children.reborrow_mut(),
@ -208,7 +206,7 @@ fn update_disabled_for_widget(
};
widget
.item
.lifecycle(&mut ctx, &LifeCycle::DisabledChanged(disabled));
.update(&mut ctx, &Update::DisabledChanged(disabled));
state.item.is_disabled = disabled;
state.item.update_focus_chain = true;
}
@ -257,7 +255,7 @@ fn update_stashed_for_widget(
}
if stashed != state.item.is_stashed {
let mut ctx = LifeCycleCtx {
let mut ctx = UpdateCtx {
global_state,
widget_state: state.item,
widget_state_children: state.children.reborrow_mut(),
@ -265,7 +263,7 @@ fn update_stashed_for_widget(
};
widget
.item
.lifecycle(&mut ctx, &LifeCycle::StashedChanged(stashed));
.update(&mut ctx, &Update::StashedChanged(stashed));
state.item.is_stashed = stashed;
state.item.update_focus_chain = true;
// Note: We don't need request_repaint because stashing doesn't actually change
@ -357,9 +355,7 @@ fn update_focus_chain_for_widget(
// had_focus is the old focus value. state.has_focus was replaced with parent_ctx.is_focused().
// Therefore if had_focus is true but state.has_focus is false then the widget which is
// currently focused is not part of the functional tree anymore
// (Lifecycle::BuildFocusChain.should_propagate_to_hidden() is false!) and should
// resign the focus.
// currently focused is not part of the functional tree anymore and should resign the focus.
if had_focus && !state.item.has_focus {
// Not sure about this logic, might remove
global_state.next_focused_widget = None;
@ -495,8 +491,8 @@ pub(crate) fn run_update_scroll_pass(root: &mut RenderRoot) {
let mut target_rect = rect;
run_targeted_update_pass(root, Some(target), |widget, ctx| {
let event = LifeCycle::RequestPanToChild(rect);
widget.lifecycle(ctx, &event);
let event = Update::RequestPanToChild(rect);
widget.update(ctx, &event);
// TODO - We should run the compose method after this, so
// translations are updated and the rect passed to parents

View File

@ -49,7 +49,7 @@ pub const HARNESS_DEFAULT_BACKGROUND_COLOR: Color = Color::rgb8(0x29, 0x29, 0x29
///
/// - Create a harness with some widget.
/// - Send events to the widget as if you were a user interacting with a window.
/// (Lifecycle and layout passes are handled automatically.)
/// (rewrite passes are handled automatically.)
/// - Check that the state of the widget graph matches what you expect.
///
/// You can do that last part in a few different ways. You can get a [`WidgetRef`] to
@ -63,7 +63,7 @@ pub const HARNESS_DEFAULT_BACKGROUND_COLOR: Color = Color::rgb8(0x29, 0x29, 0x29
///
/// ## Fidelity
///
/// `TestHarness` tries to act like the normal masonry environment. For instance, it will dispatch every `Command` sent during event handling, handle lifecycle methods, etc.
/// `TestHarness` tries to act like the normal masonry environment. It will run the same passes as the normal app after every user event and animation.
///
/// The passage of time is simulated with the [`move_timers_forward`](Self::move_timers_forward) methods. **(TODO -
/// Doesn't move animations forward.)**
@ -215,7 +215,7 @@ impl TestHarness {
/// Send an event to the widget.
///
/// If this event triggers lifecycle events, they will also be dispatched,
/// If this event triggers update events, they will also be dispatched,
/// as will any resulting commands. Commands created as a result of this event
/// will also be dispatched.
pub fn process_window_event(&mut self, event: WindowEvent) -> Handled {
@ -226,7 +226,7 @@ impl TestHarness {
/// Send an event to the widget.
///
/// If this event triggers lifecycle events, they will also be dispatched,
/// If this event triggers update events, they will also be dispatched,
/// as will any resulting commands. Commands created as a result of this event
/// will also be dispatched.
pub fn process_pointer_event(&mut self, event: PointerEvent) -> Handled {
@ -237,7 +237,7 @@ impl TestHarness {
/// Send an event to the widget.
///
/// If this event triggers lifecycle events, they will also be dispatched,
/// If this event triggers update events, they will also be dispatched,
/// as will any resulting commands. Commands created as a result of this event
/// will also be dispatched.
pub fn process_text_event(&mut self, event: TextEvent) -> Handled {

View File

@ -31,8 +31,8 @@ pub type PointerEventFn<S> = dyn FnMut(&mut S, &mut EventCtx, &PointerEvent);
pub type TextEventFn<S> = dyn FnMut(&mut S, &mut EventCtx, &TextEvent);
pub type AccessEventFn<S> = dyn FnMut(&mut S, &mut EventCtx, &AccessEvent);
pub type RegisterChildrenFn<S> = dyn FnMut(&mut S, &mut RegisterCtx);
pub type StatusChangeFn<S> = dyn FnMut(&mut S, &mut LifeCycleCtx, &StatusChange);
pub type LifeCycleFn<S> = dyn FnMut(&mut S, &mut LifeCycleCtx, &LifeCycle);
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);
pub type PaintFn<S> = dyn FnMut(&mut S, &mut PaintCtx, &mut Scene);
@ -56,7 +56,7 @@ pub struct ModularWidget<S> {
on_access_event: Option<Box<AccessEventFn<S>>>,
register_children: Option<Box<RegisterChildrenFn<S>>>,
on_status_change: Option<Box<StatusChangeFn<S>>>,
lifecycle: Option<Box<LifeCycleFn<S>>>,
update: Option<Box<UpdateFn<S>>>,
layout: Option<Box<LayoutFn<S>>>,
compose: Option<Box<ComposeFn<S>>>,
paint: Option<Box<PaintFn<S>>>,
@ -77,7 +77,7 @@ pub struct ReplaceChild {
///
/// ```
/// # use masonry::widget::Label;
/// # use masonry::{LifeCycle};
/// # use masonry::{Update};
/// use masonry::testing::{Recording, Record, TestWidgetExt};
/// use masonry::testing::TestHarness;
/// use assert_matches::assert_matches;
@ -86,7 +86,7 @@ pub struct ReplaceChild {
///
/// TestHarness::create(widget);
/// assert_matches!(recording.next().unwrap(), Record::RegisterChildren);
/// assert_matches!(recording.next().unwrap(), Record::L(LifeCycle::WidgetAdded));
/// assert_matches!(recording.next().unwrap(), Record::L(Update::WidgetAdded));
/// ```
pub struct Recorder<W> {
recording: Recording,
@ -107,7 +107,7 @@ pub enum Record {
AE(AccessEvent),
RegisterChildren,
SC(StatusChange),
L(LifeCycle),
L(Update),
Layout(Size),
Compose,
Paint,
@ -142,7 +142,7 @@ impl<S> ModularWidget<S> {
on_access_event: None,
register_children: None,
on_status_change: None,
lifecycle: None,
update: None,
layout: None,
compose: None,
paint: None,
@ -201,17 +201,14 @@ impl<S> ModularWidget<S> {
pub fn status_change_fn(
mut self,
f: impl FnMut(&mut S, &mut LifeCycleCtx, &StatusChange) + 'static,
f: impl FnMut(&mut S, &mut UpdateCtx, &StatusChange) + 'static,
) -> Self {
self.on_status_change = Some(Box::new(f));
self
}
pub fn lifecycle_fn(
mut self,
f: impl FnMut(&mut S, &mut LifeCycleCtx, &LifeCycle) + 'static,
) -> Self {
self.lifecycle = Some(Box::new(f));
pub fn update_fn(mut self, f: impl FnMut(&mut S, &mut UpdateCtx, &Update) + 'static) -> Self {
self.update = Some(Box::new(f));
self
}
@ -281,14 +278,14 @@ impl<S: 'static> Widget for ModularWidget<S> {
}
}
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, event: &StatusChange) {
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 lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
if let Some(f) = self.lifecycle.as_mut() {
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
if let Some(f) = self.update.as_mut() {
f(&mut self.state, ctx, event);
}
}
@ -416,7 +413,7 @@ impl Widget for ReplaceChild {
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, _event: &StatusChange) {
fn on_status_change(&mut self, ctx: &mut UpdateCtx, _event: &StatusChange) {
ctx.request_layout();
}
@ -424,7 +421,7 @@ impl Widget for ReplaceChild {
ctx.register_child(&mut self.child);
}
fn lifecycle(&mut self, _ctx: &mut LifeCycleCtx, _event: &LifeCycle) {}
fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {}
fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
ctx.run_layout(&mut self.child, bc)
@ -497,14 +494,14 @@ impl<W: Widget> Widget for Recorder<W> {
self.child.register_children(ctx);
}
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, event: &StatusChange) {
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 lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
self.recording.push(Record::L(event.clone()));
self.child.lifecycle(ctx, event);
self.child.update(ctx, event);
}
fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {

View File

@ -17,8 +17,8 @@ use crate::contexts::AccessCtx;
use crate::paint_scene_helpers::UnitPoint;
use crate::widget::WidgetPod;
use crate::{
AccessEvent, BoxConstraints, EventCtx, LayoutCtx, LifeCycleCtx, PaintCtx, PointerEvent, Rect,
RegisterCtx, Size, StatusChange, TextEvent, Widget, WidgetId,
AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent, Rect, RegisterCtx,
Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId,
};
// TODO - Have child widget type as generic argument
@ -95,7 +95,7 @@ impl Widget for Align {
ctx.register_child(&mut self.child);
}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}
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,8 +14,8 @@ 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,
LifeCycleCtx, PaintCtx, PointerEvent, Size, StatusChange, TextEvent, Widget, WidgetId,
theme, AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, Insets, LayoutCtx, PaintCtx,
PointerEvent, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId,
};
// the minimum padding added to a button.
@ -112,7 +112,7 @@ impl Widget for Button {
}
}
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, _event: &StatusChange) {
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();
}

View File

@ -14,8 +14,8 @@ use crate::paint_scene_helpers::{fill_lin_gradient, stroke, UnitPoint};
use crate::widget::{Label, WidgetMut};
use crate::{
theme, AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, LifeCycleCtx,
PaintCtx, PointerEvent, RegisterCtx, StatusChange, TextEvent, Widget, WidgetId, WidgetPod,
theme, AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, RegisterCtx, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId, WidgetPod,
};
/// A checkbox that can be toggled.
@ -103,7 +103,7 @@ impl Widget for Checkbox {
}
}
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, _event: &StatusChange) {
fn on_status_change(&mut self, ctx: &mut UpdateCtx, _event: &StatusChange) {
// Hovered/focused status impacts appearance, but not accessibility node
ctx.request_paint_only();
}

View File

@ -13,8 +13,8 @@ use crate::theme::get_debug_color;
use crate::widget::WidgetMut;
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, LifeCycleCtx, PaintCtx, Point,
PointerEvent, Rect, Size, StatusChange, TextEvent, Widget, WidgetId, WidgetPod,
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent,
Rect, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId, WidgetPod,
};
/// A container with either horizontal or vertical layout.
@ -901,7 +901,7 @@ impl Widget for Flex {
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}
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()) {

View File

@ -10,8 +10,8 @@ use vello::Scene;
use crate::theme::get_debug_color;
use crate::widget::WidgetMut;
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, LifeCycleCtx, PaintCtx, Point,
PointerEvent, Size, StatusChange, TextEvent, Widget, WidgetId, WidgetPod,
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent,
Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId, WidgetPod,
};
pub struct Grid {
@ -238,7 +238,7 @@ impl Widget for Grid {
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}
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()) {

View File

@ -13,8 +13,8 @@ use vello::Scene;
use crate::widget::{ObjectFit, WidgetMut};
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, LifeCycle, LifeCycleCtx, PaintCtx,
PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, Widget, WidgetId,
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
RegisterCtx, Size, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
// TODO - Resolve name collision between masonry::Image and peniko::Image
@ -79,9 +79,9 @@ impl Widget for Image {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn lifecycle(&mut self, _ctx: &mut LifeCycleCtx, _event: &LifeCycle) {}
fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {}
fn layout(&mut self, _ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
// If either the width or height is constrained calculate a value so that the image fits

View File

@ -16,8 +16,8 @@ use vello::Scene;
use crate::text::{TextBrush, TextLayout};
use crate::widget::WidgetMut;
use crate::{
AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, LifeCycle, LifeCycleCtx,
PaintCtx, PointerEvent, RegisterCtx, StatusChange, TextEvent, Widget, WidgetId,
AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
// added padding between the edges of the widget and the text.
@ -193,7 +193,7 @@ impl Widget for Label {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
#[allow(missing_docs)]
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, event: &StatusChange) {
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, event: &StatusChange) {
match event {
StatusChange::FocusChanged(_) => {
// TODO: Focus on first link
@ -202,9 +202,9 @@ impl Widget for Label {
}
}
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
LifeCycle::DisabledChanged(disabled) => {
Update::DisabledChanged(disabled) => {
if self.show_disabled {
if *disabled {
self.text_layout

View File

@ -13,8 +13,8 @@ use vello::Scene;
use crate::widget::{Axis, ScrollBar, WidgetMut};
use crate::{
AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, LifeCycle,
LifeCycleCtx, PaintCtx, PointerEvent, RegisterCtx, StatusChange, TextEvent, Widget, WidgetId,
AccessCtx, AccessEvent, BoxConstraints, ComposeCtx, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
WidgetPod,
};
@ -320,7 +320,7 @@ 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 LifeCycleCtx, _event: &StatusChange) {}
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);
@ -328,9 +328,9 @@ impl<W: Widget> Widget for Portal<W> {
ctx.register_child(&mut self.scrollbar_vertical);
}
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
LifeCycle::RequestPanToChild(target) => {
Update::RequestPanToChild(target) => {
let portal_size = ctx.size();
let content_size = ctx.get_raw_ref(&mut self.child).ctx().layout_rect().size();

View File

@ -14,8 +14,8 @@ use crate::paint_scene_helpers::{fill_lin_gradient, stroke, UnitPoint};
use crate::text::TextLayout;
use crate::widget::WidgetMut;
use crate::{
theme, AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, LifeCycle,
LifeCycleCtx, PaintCtx, PointerEvent, RegisterCtx, StatusChange, TextEvent, Widget, WidgetId,
theme, AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
/// A progress bar
@ -106,9 +106,9 @@ impl Widget for ProgressBar {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn lifecycle(&mut self, _ctx: &mut LifeCycleCtx, _event: &LifeCycle) {}
fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {}
fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
const DEFAULT_WIDTH: f64 = 400.;

View File

@ -18,8 +18,8 @@ use crate::widget::{LineBreaking, WidgetMut};
use crate::{
text::{TextBrush, TextWithSelection},
widget::label::LABEL_X_PADDING,
AccessCtx, AccessEvent, ArcStr, BoxConstraints, CursorIcon, EventCtx, LayoutCtx, LifeCycle,
LifeCycleCtx, PaintCtx, PointerEvent, RegisterCtx, StatusChange, TextEvent, Widget, WidgetId,
AccessCtx, AccessEvent, ArcStr, BoxConstraints, CursorIcon, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
/// The prose widget is a widget which displays text which can be
@ -203,7 +203,7 @@ impl Widget for Prose {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
#[allow(missing_docs)]
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, event: &StatusChange) {
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange) {
match event {
StatusChange::FocusChanged(false) => {
self.text_layout.focus_lost();
@ -217,9 +217,9 @@ impl Widget for Prose {
}
}
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
LifeCycle::DisabledChanged(disabled) => {
Update::DisabledChanged(disabled) => {
if self.show_disabled {
if *disabled {
self.text_layout

View File

@ -9,8 +9,8 @@ use vello::Scene;
use crate::widget::{WidgetMut, WidgetPod};
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, LifeCycleCtx, PaintCtx,
PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, Widget, WidgetId,
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId,
};
// TODO: This is a hack to provide an accessibility node with a Window type.
@ -43,7 +43,7 @@ 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 LifeCycleCtx, _: &StatusChange) {}
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

@ -12,9 +12,9 @@ use vello::Scene;
use crate::paint_scene_helpers::{fill_color, stroke};
use crate::widget::{Axis, WidgetMut};
use crate::{
theme, AccessCtx, AccessEvent, AllowRawMut, BoxConstraints, EventCtx, LayoutCtx, LifeCycle,
LifeCycleCtx, PaintCtx, Point, PointerEvent, RegisterCtx, Size, StatusChange, TextEvent,
Widget, WidgetId,
theme, AccessCtx, AccessEvent, AllowRawMut, BoxConstraints, EventCtx, LayoutCtx, PaintCtx,
Point, PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, Update, UpdateCtx, Widget,
WidgetId,
};
// RULES
@ -175,9 +175,9 @@ impl Widget for ScrollBar {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn lifecycle(&mut self, _ctx: &mut LifeCycleCtx, _event: &LifeCycle) {}
fn update(&mut self, _ctx: &mut UpdateCtx, _event: &Update) {}
fn layout(&mut self, _ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {
// TODO - handle resize

View File

@ -13,8 +13,8 @@ use vello::Scene;
use crate::paint_scene_helpers::stroke;
use crate::widget::{WidgetMut, WidgetPod};
use crate::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, LifeCycleCtx, PaintCtx, Point,
PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, Widget, WidgetId,
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent,
RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId,
};
// FIXME - Improve all doc in this module ASAP.
@ -310,7 +310,7 @@ impl Widget for SizedBox {
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}
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 {

View File

@ -13,9 +13,9 @@ use vello::Scene;
use crate::widget::WidgetMut;
use crate::{
theme, AccessCtx, AccessEvent, BoxConstraints, Color, EventCtx, LayoutCtx, LifeCycle,
LifeCycleCtx, PaintCtx, Point, PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, Vec2,
Widget, WidgetId,
theme, AccessCtx, AccessEvent, BoxConstraints, Color, EventCtx, LayoutCtx, PaintCtx, Point,
PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, Update, UpdateCtx, Vec2, Widget,
WidgetId,
};
// TODO - Set color
@ -79,14 +79,14 @@ impl Widget for Spinner {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, _event: &StatusChange) {}
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
LifeCycle::WidgetAdded => {
Update::WidgetAdded => {
ctx.request_anim_frame();
}
LifeCycle::AnimFrame(interval) => {
Update::AnimFrame(interval) => {
self.t += (*interval as f64) * 1e-9;
if self.t >= 1.0 {
self.t = self.t.rem_euclid(1.0);

View File

@ -16,7 +16,7 @@ use crate::widget::flex::Axis;
use crate::widget::{WidgetMut, WidgetPod};
use crate::{
theme, AccessCtx, AccessEvent, BoxConstraints, Color, CursorIcon, EventCtx, LayoutCtx,
LifeCycleCtx, PaintCtx, Point, PointerEvent, Rect, RegisterCtx, Size, StatusChange, TextEvent,
PaintCtx, Point, PointerEvent, Rect, RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx,
Widget, WidgetId,
};
@ -445,7 +445,7 @@ impl Widget for Split {
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, _event: &StatusChange) {}
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);

View File

@ -19,10 +19,10 @@ const CHANGE_DISABLED: Selector<bool> = Selector::new("masonry-test.change-disab
fn make_focusable_widget(id: WidgetId, state: Rc<Cell<Option<bool>>>) -> impl Widget {
ModularWidget::new(state)
.lifecycle_fn(move |state, ctx, event| match event {
LifeCycle::BuildFocusChain => {
Update::BuildFocusChain => {
ctx.register_for_focus();
}
LifeCycle::DisabledChanged(disabled) => {
Update::DisabledChanged(disabled) => {
state.set(Some(*disabled));
}
_ => {}

View File

@ -38,7 +38,7 @@ impl FocusTaker {
}
})
.lifecycle_fn(|_is_focused, ctx, event| {
if let LifeCycle::BuildFocusChain = event {
if let Update::BuildFocusChain = event {
ctx.register_for_focus();
}
})

View File

@ -5,7 +5,7 @@ use smallvec::smallvec;
use crate::testing::{ModularWidget, TestHarness, TestWidgetExt};
use crate::widget::Flex;
use crate::{LifeCycle, Point, PointerButton, Size, Widget, WidgetId, WidgetPod};
use crate::{Point, PointerButton, Size, Update, Widget, WidgetId, WidgetPod};
fn make_parent_widget<W: Widget>(child: W) -> ModularWidget<WidgetPod<W>> {
let child = WidgetPod::new(child);
@ -53,7 +53,7 @@ fn check_forget_to_recurse_lifecycle() {
#[test]
fn check_forget_to_recurse_widget_added() {
let widget = make_parent_widget(Flex::row()).lifecycle_fn(|child, ctx, event| {
if let LifeCycle::WidgetAdded = event {
if let Update::WidgetAdded = event {
// We forget to call child.lifecycle();
ctx.skip_child(child);
} else {
@ -327,8 +327,8 @@ fn check_recurse_paint_twice() {
#[test]
fn check_layout_stashed() {
let widget = make_parent_widget(Flex::row())
.lifecycle_fn(|child, ctx, event| {
if matches!(event, LifeCycle::WidgetAdded) {
.update_fn(|child, ctx, event| {
if matches!(event, Update::WidgetAdded) {
ctx.set_stashed(child, true);
}
})

View File

@ -18,8 +18,8 @@ use winit::event::Ime;
use crate::text::{TextBrush, TextEditor, TextWithSelection};
use crate::widget::{LineBreaking, WidgetMut};
use crate::{
AccessCtx, AccessEvent, BoxConstraints, CursorIcon, EventCtx, LayoutCtx, LifeCycle,
LifeCycleCtx, PaintCtx, PointerEvent, RegisterCtx, StatusChange, TextEvent, Widget, WidgetId,
AccessCtx, AccessEvent, BoxConstraints, CursorIcon, EventCtx, LayoutCtx, PaintCtx,
PointerEvent, RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
const TEXTBOX_PADDING: f64 = 3.0;
@ -231,7 +231,7 @@ impl Widget for Textbox {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
#[allow(missing_docs)]
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, event: &StatusChange) {
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange) {
match event {
StatusChange::FocusChanged(false) => {
self.editor.focus_lost();
@ -245,9 +245,9 @@ impl Widget for Textbox {
}
}
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
LifeCycle::DisabledChanged(disabled) => {
Update::DisabledChanged(disabled) => {
if self.show_disabled {
if *disabled {
self.editor.set_brush(crate::theme::DISABLED_TEXT_COLOR);

View File

@ -18,8 +18,8 @@ use vello::Scene;
use crate::text::{Hinting, TextBrush, TextLayout};
use crate::widget::{LineBreaking, WidgetMut};
use crate::{
AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, LifeCycle, LifeCycleCtx,
PaintCtx, PointerEvent, RegisterCtx, StatusChange, TextEvent, Widget, WidgetId,
AccessCtx, AccessEvent, ArcStr, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, PointerEvent,
RegisterCtx, StatusChange, TextEvent, Update, UpdateCtx, Widget, WidgetId,
};
// added padding between the edges of the widget and the text.
@ -310,7 +310,7 @@ impl Widget for VariableLabel {
fn register_children(&mut self, _ctx: &mut RegisterCtx) {}
#[allow(missing_docs)]
fn on_status_change(&mut self, _ctx: &mut LifeCycleCtx, event: &StatusChange) {
fn on_status_change(&mut self, _ctx: &mut UpdateCtx, event: &StatusChange) {
match event {
StatusChange::FocusChanged(_) => {
// TODO: Focus on first link
@ -319,9 +319,9 @@ impl Widget for VariableLabel {
}
}
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
match event {
LifeCycle::DisabledChanged(disabled) => {
Update::DisabledChanged(disabled) => {
if self.show_disabled {
if *disabled {
self.text_layout
@ -333,7 +333,7 @@ impl Widget for VariableLabel {
// TODO: Parley seems to require a relayout when colours change
ctx.request_layout();
}
LifeCycle::AnimFrame(time) => {
Update::AnimFrame(time) => {
let millis = (*time as f64 / 1_000_000.) as f32;
let result = self.weight.advance(millis);
self.text_layout.invalidate();

View File

@ -17,8 +17,8 @@ use crate::contexts::ComposeCtx;
use crate::event::{AccessEvent, PointerEvent, StatusChange, TextEvent};
use crate::widget::WidgetRef;
use crate::{
AccessCtx, AsAny, BoxConstraints, EventCtx, LayoutCtx, LifeCycle, LifeCycleCtx, PaintCtx,
Point, QueryCtx, RegisterCtx, Size,
AccessCtx, AsAny, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, QueryCtx, RegisterCtx,
Size, Update, UpdateCtx,
};
/// A unique identifier for a single [`Widget`].
@ -31,7 +31,7 @@ use crate::{
/// and passing a `WidgetId` as the [`Target`](crate::Target).
///
/// A widget can retrieve its id via methods on the various contexts, such as
/// [`LifeCycleCtx::widget_id`].
/// [`UpdateCtx::widget_id`].
///
/// ## Explicit `WidgetId`s.
///
@ -51,7 +51,7 @@ pub struct WidgetId(pub(crate) NonZeroU64);
/// For details on how to implement this trait, see tutorial **(TODO)**
///
/// Whenever external events affect the given widget, methods [`on_event`],
/// [`on_status_change`](Self::on_status_change) and [`lifecycle`](Self::lifecycle)
/// [`on_status_change`](Self::on_status_change) and [`update`](Self::update)
/// are called. Later on, when the widget is laid out and displayed, methods
/// [`layout`](Self::layout) and [`paint`](Self::paint) are called.
///
@ -64,7 +64,7 @@ pub struct WidgetId(pub(crate) NonZeroU64);
///
/// Generally speaking, widgets aren't used directly. They are stored in
/// [`WidgetPod`](crate::WidgetPod)s. Widget methods are called by `WidgetPod`s, and the
/// widget is mutated either during a method call (eg `on_event` or `lifecycle`) or
/// widget is mutated either during a method call (eg `on_event` or `update`) or
/// through a [`WidgetMut`](crate::widget::WidgetMut).
#[allow(unused_variables)]
pub trait Widget: AsAny {
@ -80,7 +80,7 @@ pub trait Widget: AsAny {
fn on_access_event(&mut self, ctx: &mut EventCtx, event: &AccessEvent) {}
#[allow(missing_docs)]
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, event: &StatusChange);
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange);
/// Register child widgets with Masonry.
///
@ -91,12 +91,12 @@ pub trait Widget: AsAny {
/// All the children returned by `children_ids` should be visited.
fn register_children(&mut self, ctx: &mut RegisterCtx);
/// Handle a lifecycle notification.
/// Handle an update to the widget's state.
///
/// This method is called to notify your widget of certain special events,
/// (available in the [`LifeCycle`] enum) that are generally related to
/// (available in the [`Update`] enum) that are generally related to
/// changes in the widget graph or in the state of your specific widget.
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {}
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {}
/// Compute layout.
///
@ -302,9 +302,9 @@ pub(crate) fn get_child_at_pos<'c>(
///
/// "Raw mut" means using a mutable reference (eg `&mut MyWidget`) to the data
/// structure, instead of going through the Widget trait methods
/// (`on_text_event`, `lifecycle`, `layout`, etc) or through `WidgetMut`.
/// (`on_text_event`, `update`, `layout`, etc) or through `WidgetMut`.
///
/// A parent widget can use [`EventCtx::get_raw_mut`], [`LifeCycleCtx::get_raw_mut`],
/// A parent widget can use [`EventCtx::get_raw_mut`], [`UpdateCtx::get_raw_mut`],
/// or [`LayoutCtx::get_raw_mut`] to directly access a child widget. In that case,
/// these methods return both a mutable reference to the child widget and a new
/// context (`MutateCtx`, `EventCtx`, etc) scoped to the child. The parent is
@ -386,12 +386,12 @@ impl Widget for Box<dyn Widget> {
self.deref_mut().register_children(ctx);
}
fn on_status_change(&mut self, ctx: &mut LifeCycleCtx, event: &StatusChange) {
fn on_status_change(&mut self, ctx: &mut UpdateCtx, event: &StatusChange) {
self.deref_mut().on_status_change(ctx, event);
}
fn lifecycle(&mut self, ctx: &mut LifeCycleCtx, event: &LifeCycle) {
self.deref_mut().lifecycle(ctx, event);
fn update(&mut self, ctx: &mut UpdateCtx, event: &Update) {
self.deref_mut().update(ctx, event);
}
fn layout(&mut self, ctx: &mut LayoutCtx, bc: &BoxConstraints) -> Size {

View File

@ -14,7 +14,7 @@ use crate::Widget;
/// change.
///
/// You can create a `WidgetMut` from [`TestHarness`](crate::testing::TestHarness),
/// [`EventCtx`](crate::EventCtx), [`LifeCycleCtx`](crate::LifeCycleCtx) or from a parent
/// [`EventCtx`](crate::EventCtx), [`UpdateCtx`](crate::UpdateCtx) or from a parent
/// `WidgetMut` with [`MutateCtx`].
///
/// `WidgetMut` implements [`Deref`](std::ops::Deref) with `W::Mut` as target.

View File

@ -4,8 +4,8 @@
use accesskit::{NodeBuilder, Role};
use masonry::widget::WidgetMut;
use masonry::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, LifeCycleCtx, PaintCtx, Point,
PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, Widget, WidgetId, WidgetPod,
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent,
RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId, WidgetPod,
};
use smallvec::{smallvec, SmallVec};
use tracing::{trace_span, Span};
@ -80,7 +80,7 @@ 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 LifeCycleCtx, _: &StatusChange) {
fn on_status_change(&mut self, _: &mut UpdateCtx, _: &StatusChange) {
// Intentionally do nothing
}

View File

@ -9,8 +9,8 @@ use crate::{
};
use accesskit::{NodeBuilder, Role};
use masonry::{
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, LifeCycleCtx, PaintCtx, Point,
PointerEvent, RegisterCtx, Size, StatusChange, TextEvent, Widget, WidgetId, WidgetPod,
AccessCtx, AccessEvent, BoxConstraints, EventCtx, LayoutCtx, PaintCtx, Point, PointerEvent,
RegisterCtx, Size, StatusChange, TextEvent, UpdateCtx, Widget, WidgetId, WidgetPod,
};
use smallvec::{smallvec, SmallVec};
use vello::Scene;
@ -176,7 +176,7 @@ impl<
fn on_access_event(&mut self, _ctx: &mut EventCtx, _event: &AccessEvent) {}
#[allow(missing_docs)]
fn on_status_change(&mut self, _: &mut LifeCycleCtx, _: &StatusChange) {
fn on_status_change(&mut self, _: &mut UpdateCtx, _: &StatusChange) {
// Intentionally do nothing
}