Skip to main content

Node

Struct Node 

Source
pub struct Node<M = ()> { /* private fields */ }
Expand description

A node: a kind, props, children and handlers. It has no id until it is reconciled. Every kind’s builder converts into it.

Implementations§

Source§

impl<M> Node<M>

Source

pub fn new(kind: impl Into<String>) -> Self

A node of any kind, without props.

Source

pub fn kind(&self) -> &str

The kind.

Source

pub const fn props(&self) -> &Map<String, Value>

The props.

Source

pub fn child_nodes(&self) -> &[Self]

The children.

Source

pub fn from_json(value: &Value) -> Result<Self, Error>

Builds a node from its wire form {k, p?, c?} (no handlers).

§Errors

Error::InvalidView when it isn’t an object with a string k, or p/c have the wrong shape.

Source§

impl<M> Node<M>

Source

pub fn key(self, key: impl Into<NodeKey>) -> Self

Identity among siblings: keeps the node’s id (and Tern’s view state) across reorders. A string, or an integer.

Examples found in repository?
examples/progress.rs (line 73)
40fn view(build: &Build) -> View {
41	let fraction = build.done as f64 / STEPS.len() as f64;
42	let running = build.took.is_none();
43	let activity: ui::Node = if running {
44		ui::spinner()
45			.style("dots")
46			.label(STEPS[build.done.min(STEPS.len() - 1)])
47			.into()
48	} else {
49		ui::icon(if build.status == Status::Done {
50			"check"
51		} else {
52			"x"
53		})
54		.tone(if build.status == Status::Done {
55			"success"
56		} else {
57			"error"
58		})
59		.into()
60	};
61	let mut timer = ui::elapsed().age(0);
62	if let Some(took) = build.took {
63		timer = timer.stopped(took);
64	}
65	View::new().main([ui::card()
66		.key("build")
67		.head("Building demo")
68		.status(build.status.clone())
69		.child(
70			ui::row()
71				.key("head")
72				.gap("sm")
73				.children(nodes![activity.key("a"), timer.key("t")]),
74		)
75		.child(
76			ui::ansi(&build.log)
77				.key("log")
78				.follow(true)
79				.max(Bound::h(Extent::Lines(8.0))),
80		)
81		.child(ui::progress().key("bar").value(fraction).label(format!(
82			"{}/{}",
83			build.done,
84			STEPS.len()
85		)))])
86}
Source

pub fn role(self, role: impl Into<String>) -> Self

A name of yours, exposed to CSS as data-role.

Source

pub fn tone(self, tone: impl Into<Tone>) -> Self

The semantic color of the node’s chrome.

Source

pub fn hidden(self, hidden: bool) -> Self

Keeps the node mounted but not laid out.

Source

pub fn mark(self, mark: impl Into<Mark>) -> Self

A transient selection mark drawn over the node.

Source

pub fn aria(self, aria: impl Into<String>) -> Self

The accessible name of a node that shows no text.

Source

pub fn href(self, href: impl Into<String>) -> Self

A link: ⌘-click opens it; copy and open use it.

Source

pub fn grow(self, grow: f64) -> Self

Flex grow inside a row or col.

Source

pub fn shrink(self, shrink: f64) -> Self

Flex shrink inside a row or col.

Source

pub fn basis(self, basis: impl Into<Basis>) -> Self

Flex basis: a fraction of the parent, or the content’s size.

Source

pub fn min(self, min: Bound) -> Self

Lower size bounds.

Source

pub fn prop(self, name: &str, value: impl Serialize) -> Self

Sets any prop untyped; null removes it.

Source

pub fn title(self, title: impl Into<String>) -> Self

A tooltip.

Source

pub fn max(self, max: Bound) -> Self

Upper size bounds (a max.h also clips the node).

Source

pub fn actions(self, actions: Actions) -> Self

What a pointer does, by action name.

Source

pub fn on_click(self, msg: M) -> Self
where M: Clone + Send + Sync + 'static,

Sends msg on a click (sets actions.click to "click" unless the node names its click action itself).

Source

pub fn on_dblclick(self, msg: M) -> Self
where M: Clone + Send + Sync + 'static,

Sends msg on a double click (sets actions.dblclick to "dblclick" unless the node names it).

Source

pub fn on_menu(self, act: impl Into<String>, msg: M) -> Self
where M: Clone + Send + Sync + 'static,

Adds act to the context menu and sends msg when it is picked.

Source

pub fn on_action(self, act: impl Into<String>, msg: M) -> Self
where M: Clone + Send + Sync + 'static,

Sends msg on action events whose action is act (name or name=value).

Source

pub fn on_action_with( self, act: impl Into<String>, f: impl Fn(&Action) -> M + Send + Sync + 'static, ) -> Self

Maps action events whose action is act to a message.

Source

pub fn on_toggle(self, f: impl Fn(bool) -> M + Send + Sync + 'static) -> Self

Maps toggle events (the new collapsed) to a message.

Source

pub fn on_select(self, f: impl Fn(&str) -> M + Send + Sync + 'static) -> Self

Maps select events (the item) to a message. On a list’s item the item’s own handler runs first.

Source

pub fn on_activate(self, f: impl Fn(&str) -> M + Send + Sync + 'static) -> Self

Maps activate events (the item) to a message.

Source

pub fn on_change(self, f: impl Fn(&Change) -> M + Send + Sync + 'static) -> Self

Maps change events to a message.

Source

pub fn on_focus(self, msg: M) -> Self
where M: Clone + Send + Sync + 'static,

Sends msg on focus events (a click asked for the keys).

Source

pub fn on_edit(self, f: impl Fn(&Edit) -> M + Send + Sync + 'static) -> Self

Maps edit events (native editing) to a message.

Source

pub fn on_undo(self, msg: M) -> Self
where M: Clone + Send + Sync + 'static,

Sends msg on undo events.

Source

pub fn on_send(self, f: impl Fn(&str) -> M + Send + Sync + 'static) -> Self

Maps send events (the text to submit) to a message.

Source

pub fn child(self, child: impl Into<Node<M>>) -> Self

Adds a child.

Source

pub fn children<C: Into<Node<M>>>( self, children: impl IntoIterator<Item = C>, ) -> Self

Adds children.

Trait Implementations§

Source§

impl<M> Clone for Node<M>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M> Debug for Node<M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M> From<Agent<M>> for Node<M>

Source§

fn from(n: Agent<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Ansi<M>> for Node<M>

Source§

fn from(n: Ansi<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Badge<M>> for Node<M>

Source§

fn from(n: Badge<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Card<M>> for Node<M>

Source§

fn from(n: Card<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Chart<M>> for Node<M>

Source§

fn from(n: Chart<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Checklist<M>> for Node<M>

Source§

fn from(n: Checklist<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Code<M>> for Node<M>

Source§

fn from(n: Code<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Col<M>> for Node<M>

Source§

fn from(n: Col<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Diff<M>> for Node<M>

Source§

fn from(n: Diff<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Editor<M>> for Node<M>

Source§

fn from(n: Editor<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Effort<M>> for Node<M>

Source§

fn from(n: Effort<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<El<M>> for Node<M>

Source§

fn from(n: El<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Elapsed<M>> for Node<M>

Source§

fn from(n: Elapsed<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<IconNode<M>> for Node<M>

Source§

fn from(n: IconNode<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Image<M>> for Node<M>

Source§

fn from(n: Image<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Input<M>> for Node<M>

Source§

fn from(n: Input<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Item<M>> for Node<M>

Source§

fn from(n: Item<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Kbd<M>> for Node<M>

Source§

fn from(n: Kbd<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Kv<M>> for Node<M>

Source§

fn from(n: Kv<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<List<M>> for Node<M>

Source§

fn from(n: List<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Math<M>> for Node<M>

Source§

fn from(n: Math<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Md<M>> for Node<M>

Source§

fn from(n: Md<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Meter<M>> for Node<M>

Source§

fn from(n: Meter<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for View<M>

A bare node is main’s one child.

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Col<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Row<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Card<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Section<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Rule<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Spacer<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for TextNode<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Md<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Code<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Diff<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Ansi<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Rows<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Math<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Kv<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Table<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Tree<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Badge<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Kbd<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for IconNode<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Image<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for List<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Item<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Tabs<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Picker<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Spinner<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Shimmer<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Elapsed<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Rate<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Progress<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Meter<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Chart<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Effort<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Editor<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Input<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for StatusBar<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Seg<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Toast<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Overlay<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Tool<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Agent<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Checklist<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Node<M>> for Prefs<M>

Source§

fn from(node: Node<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Overlay<M>> for Node<M>

Source§

fn from(n: Overlay<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Picker<M>> for Node<M>

Source§

fn from(n: Picker<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Prefs<M>> for Node<M>

Source§

fn from(n: Prefs<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Progress<M>> for Node<M>

Source§

fn from(n: Progress<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Rate<M>> for Node<M>

Source§

fn from(n: Rate<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Row<M>> for Node<M>

Source§

fn from(n: Row<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Rows<M>> for Node<M>

Source§

fn from(n: Rows<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Rule<M>> for Node<M>

Source§

fn from(n: Rule<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Section<M>> for Node<M>

Source§

fn from(n: Section<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Seg<M>> for Node<M>

Source§

fn from(n: Seg<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Shimmer<M>> for Node<M>

Source§

fn from(n: Shimmer<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Spacer<M>> for Node<M>

Source§

fn from(n: Spacer<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Spinner<M>> for Node<M>

Source§

fn from(n: Spinner<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<StatusBar<M>> for Node<M>

Source§

fn from(n: StatusBar<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Table<M>> for Node<M>

Source§

fn from(n: Table<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Tabs<M>> for Node<M>

Source§

fn from(n: Tabs<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<TextNode<M>> for Node<M>

Source§

fn from(n: TextNode<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Toast<M>> for Node<M>

Source§

fn from(n: Toast<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Tool<M>> for Node<M>

Source§

fn from(n: Tool<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Tree<M>> for Node<M>

Source§

fn from(n: Tree<M>) -> Self

Converts to this type from the input type.
Source§

impl<M> From<Vec<Node<M>>> for Node<M>

A list of nodes is a col of them (how a region given as a list is wrapped).

Source§

fn from(children: Vec<Self>) -> Self

Converts to this type from the input type.
Source§

impl<M, C: Into<Self>, const N: usize> From<[C; N]> for Node<M>

An array of nodes is a col of them.

Source§

fn from(children: [C; N]) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<M = ()> !RefUnwindSafe for Node<M>

§

impl<M = ()> !UnwindSafe for Node<M>

§

impl<M> Freeze for Node<M>
where Vec<Node<M>>: Freeze, Vec<(Trigger, Arc<dyn Fn(&Event) -> Option<M> + Sync + Send>)>: Freeze,

§

impl<M> Send for Node<M>
where Vec<Node<M>>: Send, Vec<(Trigger, Arc<dyn Fn(&Event) -> Option<M> + Sync + Send>)>: Send,

§

impl<M> Sync for Node<M>
where Vec<Node<M>>: Sync, Vec<(Trigger, Arc<dyn Fn(&Event) -> Option<M> + Sync + Send>)>: Sync,

§

impl<M> Unpin for Node<M>
where Vec<Node<M>>: Unpin, Vec<(Trigger, Arc<dyn Fn(&Event) -> Option<M> + Sync + Send>)>: Unpin,

§

impl<M> UnsafeUnpin for Node<M>
where Vec<Node<M>>: UnsafeUnpin, Vec<(Trigger, Arc<dyn Fn(&Event) -> Option<M> + Sync + Send>)>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more