Skip to content

Commit

Permalink
Remove Widget::_replay's msg; pass via stack instead
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy committed Dec 18, 2023
1 parent 5bb1281 commit f2030b8
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 33 deletions.
13 changes: 3 additions & 10 deletions crates/kas-core/src/core/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::event::{ConfigCx, Event, EventCx, FocusSource, IsUsed, Scroll, Unused, Used};
#[cfg(debug_assertions)] use crate::util::IdentifyWidget;
use crate::{messages::Erased, Events, Id, Layout, NavAdvance, Node, Widget};
use crate::{Events, Id, Layout, NavAdvance, Node, Widget};

/// Generic implementation of [`Widget::_send`]
pub fn _send<W: Events>(
Expand Down Expand Up @@ -84,17 +84,11 @@ pub fn _send<W: Events>(
}

/// Generic implementation of [`Widget::_replay`]
pub fn _replay<W: Events>(
widget: &mut W,
cx: &mut EventCx,
data: &<W as Widget>::Data,
id: Id,
msg: Erased,
) {
pub fn _replay<W: Events>(widget: &mut W, cx: &mut EventCx, data: &<W as Widget>::Data, id: Id) {
if let Some(index) = widget.find_child_index(&id) {
let mut _found = false;
widget.as_node(data).for_child(index, |mut node| {
node._replay(cx, id.clone(), msg);
node._replay(cx, id.clone());
_found = true;
});

Expand All @@ -116,7 +110,6 @@ pub fn _replay<W: Events>(
widget.handle_messages(cx, data);
}
} else if id == widget.id_ref() {
cx.push_erased(msg);
widget.handle_messages(cx, data);
} else {
// This implies use of push_async / push_spawn from a widget which was
Expand Down
14 changes: 7 additions & 7 deletions crates/kas-core/src/core/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::event::{ConfigCx, Event, EventCx, IsUsed};
use crate::geom::{Coord, Rect};
use crate::layout::{AxisInfo, SizeRules};
use crate::theme::{DrawCx, SizeCx};
use crate::{messages::Erased, Id, Layout, NavAdvance};
use crate::{Id, Layout, NavAdvance};

#[cfg(not(feature = "unsafe_node"))]
trait NodeT {
Expand All @@ -35,7 +35,7 @@ trait NodeT {
fn _update(&mut self, cx: &mut ConfigCx);

fn _send(&mut self, cx: &mut EventCx, id: Id, event: Event) -> IsUsed;
fn _replay(&mut self, cx: &mut EventCx, id: Id, msg: Erased);
fn _replay(&mut self, cx: &mut EventCx, id: Id);
fn _nav_next(
&mut self,
cx: &mut ConfigCx,
Expand Down Expand Up @@ -97,8 +97,8 @@ impl<'a, T> NodeT for (&'a mut dyn Widget<Data = T>, &'a T) {
fn _send(&mut self, cx: &mut EventCx, id: Id, event: Event) -> IsUsed {
self.0._send(cx, self.1, id, event)
}
fn _replay(&mut self, cx: &mut EventCx, id: Id, msg: Erased) {
self.0._replay(cx, self.1, id, msg);
fn _replay(&mut self, cx: &mut EventCx, id: Id) {
self.0._replay(cx, self.1, id);
}
fn _nav_next(
&mut self,
Expand Down Expand Up @@ -355,12 +355,12 @@ impl<'a> Node<'a> {
}

/// Internal method: replay recursively
pub(crate) fn _replay(&mut self, cx: &mut EventCx, id: Id, msg: Erased) {
pub(crate) fn _replay(&mut self, cx: &mut EventCx, id: Id) {
cfg_if::cfg_if! {
if #[cfg(feature = "unsafe_node")] {
self.0._replay(cx, self.1, id, msg);
self.0._replay(cx, self.1, id);
} else {
self.0._replay(cx, id, msg);
self.0._replay(cx, id);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/kas-core/src/core/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use super::{Layout, Node};
#[allow(unused)] use crate::event::Used;
use crate::event::{ConfigCx, Event, EventCx, IsUsed, Scroll, Unused};
use crate::{messages::Erased, Id};
use crate::Id;
use kas_macros::autoimpl;

#[allow(unused)] use kas_macros as macros;
Expand Down Expand Up @@ -402,13 +402,13 @@ pub trait Widget: Layout {

/// Internal method: replay recursively
///
/// Behaves as if an event had been sent to `id`, then the widget had pushed
/// `msg` to the message stack. Widget `id` or any ancestor may handle.
/// Traverses the widget tree to `id`, then unwinds.
/// It is expected that some message is available on the stack.
///
/// Do not implement this method directly!
#[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
#[cfg_attr(doc_cfg, doc(cfg(internal_doc)))]
fn _replay(&mut self, cx: &mut EventCx, data: &Self::Data, id: Id, msg: Erased);
fn _replay(&mut self, cx: &mut EventCx, data: &Self::Data, id: Id);

/// Internal method: search for the previous/next navigation target
///
Expand Down
3 changes: 2 additions & 1 deletion crates/kas-core/src/event/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@ impl<'a> EventCx<'a> {
log::trace!(target: "kas_core::event", "replay: id={id}: {msg:?}");

self.target_is_disabled = false;
widget._replay(self, id, msg);
self.push_erased(msg);
widget._replay(self, id);
self.last_child = None;
self.scroll = Scroll::None;
}
Expand Down
6 changes: 3 additions & 3 deletions crates/kas-core/src/hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::geom::{Coord, Offset, Rect};
use crate::layout::{Align, AxisInfo, SizeRules};
use crate::text::{Text, TextApi};
use crate::theme::{DrawCx, SizeCx, TextClass};
use crate::{messages::Erased, Id, Layout, NavAdvance, Node, Widget};
use crate::{Id, Layout, NavAdvance, Node, Widget};
use kas_macros::{autoimpl, impl_scope};

impl_scope! {
Expand Down Expand Up @@ -185,8 +185,8 @@ impl_scope! {
self.inner._send(cx, &(), id, event)
}

fn _replay(&mut self, cx: &mut EventCx, _: &A, id: Id, msg: Erased) {
self.inner._replay(cx, &(), id, msg);
fn _replay(&mut self, cx: &mut EventCx, _: &A, id: Id) {
self.inner._replay(cx, &(), id);
}

fn _nav_next(
Expand Down
6 changes: 2 additions & 4 deletions crates/kas-macros/src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,8 @@ pub fn widget(attr_span: Span, mut args: WidgetArgs, scope: &mut Scope) -> Resul
cx: &mut ::kas::event::EventCx,
data: &Self::Data,
id: ::kas::Id,
msg: ::kas::messages::Erased,
) {
self.#inner._replay(cx, data, id, msg);
self.#inner._replay(cx, data, id);
}

fn _nav_next(
Expand Down Expand Up @@ -1129,9 +1128,8 @@ fn widget_recursive_methods(core_path: &Toks) -> Toks {
cx: &mut ::kas::event::EventCx,
data: &Self::Data,
id: ::kas::Id,
msg: ::kas::messages::Erased,
) {
::kas::impls::_replay(self, cx, data, id, msg);
::kas::impls::_replay(self, cx, data, id);
}

fn _nav_next(
Expand Down
4 changes: 2 additions & 2 deletions crates/kas-view/src/list_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,8 @@ impl_scope! {
kas::impls::_send(self, cx, data, id, event)
}

fn _replay(&mut self, cx: &mut EventCx, data: &A, id: Id, msg: kas::messages::Erased) {
kas::impls::_replay(self, cx, data, id, msg);
fn _replay(&mut self, cx: &mut EventCx, data: &A, id: Id) {
kas::impls::_replay(self, cx, data, id);
}

// Non-standard implementation to allow mapping new children
Expand Down
4 changes: 2 additions & 2 deletions crates/kas-view/src/matrix_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ impl_scope! {
kas::impls::_send(self, cx, data, id, event)
}

fn _replay(&mut self, cx: &mut EventCx, data: &A, id: Id, msg: kas::messages::Erased) {
kas::impls::_replay(self, cx, data, id, msg);
fn _replay(&mut self, cx: &mut EventCx, data: &A, id: Id) {
kas::impls::_replay(self, cx, data, id);
}

// Non-standard implementation to allow mapping new children
Expand Down

0 comments on commit f2030b8

Please sign in to comment.