Skip to content

Identified nodes return a NodeHandle: .on_click / .on_response / .draw replace the positional draw closure (#66) - #67

Merged
samitbasu merged 3 commits into
mainfrom
node-handles
Nov 10, 2026
Merged

samitbasu merged 3 commits into
mainfrom
node-handles

Conversation

@samitbasu

Copy link
Copy Markdown
Owner

Closes #66. Breaking change (undeployed): every identified-node builder loses its positional draw-closure argument, and bullseye::none is removed.

Shape

pub fn div_id<K: Key>(&mut self, key: K, tw: Tw, body: impl FnOnce(&mut Scope<'_, 'f, A>)) -> NodeHandle<'_, 'f, A>;
pub fn span<K: Key>(&mut self, key: K, tw: Tw, text: impl Into<String>) -> NodeHandle<'_, 'f, A>;
pub fn icon<K: Key>(&mut self, key: K, tw: Tw, icon: Icon) -> NodeHandle<'_, 'f, A>;

pub struct NodeHandle<'b, 'f, A>;            // not #[must_use]: dropping it means "no handler"
impl<A: 'static> NodeHandle<'_, '_, A> {
    pub fn draw(self, impl FnOnce(&mut A, &mut egui::Ui) + 'static) -> Self;
    pub fn on_response(self, impl FnOnce(&mut A, &egui::Response) + 'static) -> Self;
    pub fn on_click(self, impl FnOnce(&mut A) + 'static) -> Self;
}
  • The node is still added immediately, so the common case (a node keyed only for identity) needs no call at all.
  • Handlers compose: each call wraps the previous one, and they run in call order in the node's own Ui. on_click and on_response are thin wrappers over draw, with the same names as the owned widget chains (API ergonomics: readable class syntax, symmetric widget calls, optional keys #41).
  • Sense is unchanged. It comes from Tw, never from the presence of a closure, and every interaction test passes unchanged.
  • widget() keeps its positional draw: its closure receives the stock widget, so one without a draw makes no sense. The crate-internal leaf returns the handle. custom(..) remains the public measure+ui route.

Before / after

b.div_id(key, row, bullseye::none, |b| { … });                         // before
b.div_id(key, row, |b| { … });                                         // after

b.span("up", tw, "Up", common::on_click(move |s| s.shift(key, Up)));    // before
b.span("up", tw, "Up").on_click(move |s| s.shift(key, Up));             // after

b.div_id(Part::Resize, tw, |state, ui| { let r = ui.node_response(); … }, |_| {});   // before
b.div_id(Part::Resize, tw, |_| {}).on_response(|state, r| { … });                    // after

Migration

  • Call sites: about 140 were migrated by script, then narrowed by hand. 9 became .on_click and 3 became .on_response. .draw remains only where the closure really uses the Ui (egui widgets, ui.is_enabled() for widget info, style, data, rect probes).
  • Removed: the examples' common::on_click adapter.
  • Syntax: 18 expression-bodied closures (|b| b.span(..)) needed braces, because they now return a handle.

Behaviour changes

  • A node with no handler no longer opens an empty draw-time Ui. That Ui did nothing, and no golden or interaction test changed.
  • on_click no longer calls request_repaint() (the old adapter did). A handler's state change isn't shown until the next input event (no repaint requested) #63 established that egui already repaints after every input frame.
  • layout::identified_nodes_are_found_by_id_and_path previously asserted has_draw() on a span whose draw was only none. It now attaches .draw(..) explicitly and also asserts that a span with no handler has no draw.

Tests

New, in tests/it/interaction.rs:

  • a div_id with no handler;
  • on_click fires once per click through the real pointer path;
  • on_response sees hover;
  • draw gets the content-rect Ui;
  • compose order.

All 71 goldens are unchanged. cargo xtask ci is green.

There's no UI change, so there's nothing to try. The reference shell migrates after the tag.

🤖 Generated with Claude Code

https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up

samitbasu and others added 3 commits November 10, 2026 07:59
…#66)

div_id, span and icon (and the crate-internal leaf, div_id_with and
leaf_with) no longer take a positional draw closure; most call sites
passed `none`. The node is still added immediately and the call returns a
NodeHandle that borrows the builder for the statement. `.draw`,
`.on_click` and `.on_response` attach behaviour to the node; dropping the
handle attaches nothing, so it is not must_use.

Handlers compose: each call wraps the node's existing draw closure, so
`.on_click(..).on_response(..)` runs both in call order in the node's own
Ui, instead of a debug panic on the second call.

A node's Sense comes from its Tw (sensing, grouping, variants), never from
the presence of a draw closure, so the build-error rules are unchanged.
A node without a handler now has no draw slot at all, so it no longer
opens a draw-time Ui.

`leaf` keeps its positional measure and returns the same handle; the
owned widgets use `.draw(..)` on it. `widget` keeps its positional draw
because the draw is its point and receives the widget back.

Breaking API change: `bullseye::none` is removed, div_id/span/icon lose
their draw argument and return NodeHandle, and closures that were
`|b| b.span(..)` now need a block. NodeHandle<A> needs A: 'static.

Call sites outside src follow in the next commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
Mechanical migration of examples, tests, doc tests and docs/design.md to
the NodeHandle API: `none` arguments dropped, draw closures moved to
`.draw(..)`, `common::on_click(..)` adapters to `.on_click(..)`, and
expression-bodied closures given a block. examples/common::on_click is
removed. Goldens are unchanged. layout::identified_nodes_are_found_by_id_and_path
now attaches a draw explicitly, because a node without one no longer
reports has_draw. New tests in tests/it/interaction.rs cover a handlerless
div_id, on_click via the real pointer path, on_response hover, draw's
content-rect Ui, and handler composition order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
The mechanical migration turned every inline draw closure into a literal
`.draw(..)`. Where the closure is only `if node_response().clicked() { X }`
it is now `.on_click(|app| X)`; where it only reads the response (the
resize handles, the GitHub link) it is `.on_response(|app, response| ..)`
and reaches the context through `response.ctx`. `.draw` stays where the
closure really uses the Ui: adds widgets, paints, or reads its rect, id,
opacity or clip.

NodeHandle::on_click no longer calls request_repaint: egui already repaints
after every input frame (#63), so it was redundant. No behaviour change;
all goldens are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
@samitbasu
samitbasu merged commit a29da39 into main Nov 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Identified nodes: drop the positional draw closure; attach handlers with .on_click / .draw on a returned handle

1 participant