Skip to main content

Col

Struct Col 

Source
pub struct Col<M = ()>(/* private fields */);
Expand description

col: a vertical stack.

Implementations§

Source§

impl<M> Col<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/dashboard.rs (line 808)
783	fn body(&self, plain: bool) -> Node<Msg> {
784		let page = self.page;
785		let selected = self.selected[page.index()];
786		let (list, detail) = match page {
787			Page::Services => (
788				nodes![self.services_table()],
789				selected
790					.and_then(|id| self.services.iter().find(|s| s.id == id))
791					.map(service_card),
792			),
793			Page::Deploys => (
794				nodes![self.deploys_bar(), self.deploys_table()],
795				selected
796					.and_then(|id| self.deploys.iter().find(|d| d.id == id))
797					.map(deploy_card),
798			),
799			Page::Incidents => (
800				nodes![self.incidents_table()],
801				selected
802					.and_then(|id| self.incidents.iter().find(|i| i.id == id))
803					.map(incident_card),
804			),
805		};
806		let mut parts: Vec<Node<Msg>> = nodes![
807			ui::col()
808				.key("list")
809				.gap("sm")
810				.grow(1.0)
811				.basis(0.0)
812				.children(list)
813		];
814		if let Some(card) = detail {
815			parts.push(
816				card
817					.key("detail")
818					.min(Bound::w(Extent::Ch(44.0)))
819					.max(Bound::w(Extent::Ch(56.0)))
820					.into(),
821			);
822		}
823		if plain {
824			ui::col().key(page.id()).gap("md").children(parts).into()
825		} else {
826			ui::row()
827				.key(page.id())
828				.align("stretch")
829				.gap("lg")
830				.children(parts)
831				.into()
832		}
833	}
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 hovercard<N>(self, card: impl Into<Node<N>>) -> Self

A floating card of card’s tree shown while the pointer rests on the node, in place of title. Sent id-less (ids, keys and handlers inside are ignored); an older Tern ignores it.

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.

Examples found in repository?
examples/dashboard.rs (line 810)
783	fn body(&self, plain: bool) -> Node<Msg> {
784		let page = self.page;
785		let selected = self.selected[page.index()];
786		let (list, detail) = match page {
787			Page::Services => (
788				nodes![self.services_table()],
789				selected
790					.and_then(|id| self.services.iter().find(|s| s.id == id))
791					.map(service_card),
792			),
793			Page::Deploys => (
794				nodes![self.deploys_bar(), self.deploys_table()],
795				selected
796					.and_then(|id| self.deploys.iter().find(|d| d.id == id))
797					.map(deploy_card),
798			),
799			Page::Incidents => (
800				nodes![self.incidents_table()],
801				selected
802					.and_then(|id| self.incidents.iter().find(|i| i.id == id))
803					.map(incident_card),
804			),
805		};
806		let mut parts: Vec<Node<Msg>> = nodes![
807			ui::col()
808				.key("list")
809				.gap("sm")
810				.grow(1.0)
811				.basis(0.0)
812				.children(list)
813		];
814		if let Some(card) = detail {
815			parts.push(
816				card
817					.key("detail")
818					.min(Bound::w(Extent::Ch(44.0)))
819					.max(Bound::w(Extent::Ch(56.0)))
820					.into(),
821			);
822		}
823		if plain {
824			ui::col().key(page.id()).gap("md").children(parts).into()
825		} else {
826			ui::row()
827				.key(page.id())
828				.align("stretch")
829				.gap("lg")
830				.children(parts)
831				.into()
832		}
833	}
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.

Examples found in repository?
examples/dashboard.rs (line 811)
783	fn body(&self, plain: bool) -> Node<Msg> {
784		let page = self.page;
785		let selected = self.selected[page.index()];
786		let (list, detail) = match page {
787			Page::Services => (
788				nodes![self.services_table()],
789				selected
790					.and_then(|id| self.services.iter().find(|s| s.id == id))
791					.map(service_card),
792			),
793			Page::Deploys => (
794				nodes![self.deploys_bar(), self.deploys_table()],
795				selected
796					.and_then(|id| self.deploys.iter().find(|d| d.id == id))
797					.map(deploy_card),
798			),
799			Page::Incidents => (
800				nodes![self.incidents_table()],
801				selected
802					.and_then(|id| self.incidents.iter().find(|i| i.id == id))
803					.map(incident_card),
804			),
805		};
806		let mut parts: Vec<Node<Msg>> = nodes![
807			ui::col()
808				.key("list")
809				.gap("sm")
810				.grow(1.0)
811				.basis(0.0)
812				.children(list)
813		];
814		if let Some(card) = detail {
815			parts.push(
816				card
817					.key("detail")
818					.min(Bound::w(Extent::Ch(44.0)))
819					.max(Bound::w(Extent::Ch(56.0)))
820					.into(),
821			);
822		}
823		if plain {
824			ui::col().key(page.id()).gap("md").children(parts).into()
825		} else {
826			ui::row()
827				.key(page.id())
828				.align("stretch")
829				.gap("lg")
830				.children(parts)
831				.into()
832		}
833	}
Source

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

Sets any prop untyped; null removes it.

Source

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

Lower size bounds.

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; a menu, select or trace line that opened is not 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§

impl<M> Col<M>

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.

Examples found in repository?
examples/chat.rs (line 77)
62	fn view(&self) -> View<Msg> {
63		let messages = self.transcript.iter().enumerate().map(|(i, (who, text))| {
64			let node = ui::md(text.clone()).key(i);
65			if *who == "you" {
66				ui::card().key(i).tone("user").child(node.key("t"))
67			} else {
68				ui::card().key(i).variant("bare").child(node.key("t"))
69			}
70		});
71		let cursor: usize = self
72			.draft
73			.chars()
74			.take(self.cursor)
75			.map(char::len_utf16)
76			.sum();
77		View::new().main(ui::col().children(messages)).dock(nodes![
78			ui::editor()
79				.key("ed")
80				.text(self.draft.clone())
81				.cursor(cursor)
82				.placeholder("Message (Enter sends, Escape quits)")
83				.sendable(true)
84				.on_send(|text| Msg::Send(text.to_owned()))
85				.on_focus(Msg::Focus),
86			ui::status()
87				.key("bar")
88				.child(ui::seg("chat").icon("message"))
89				.child(
90					ui::seg(format!("{} messages", self.transcript.len()))
91						.side(Side::Right)
92						.tone(if self.transcript.is_empty() {
93							Tone::Muted
94						} else {
95							Tone::Success
96						}),
97				),
98		])
99	}
More examples
Hide additional examples
examples/dashboard.rs (line 812)
783	fn body(&self, plain: bool) -> Node<Msg> {
784		let page = self.page;
785		let selected = self.selected[page.index()];
786		let (list, detail) = match page {
787			Page::Services => (
788				nodes![self.services_table()],
789				selected
790					.and_then(|id| self.services.iter().find(|s| s.id == id))
791					.map(service_card),
792			),
793			Page::Deploys => (
794				nodes![self.deploys_bar(), self.deploys_table()],
795				selected
796					.and_then(|id| self.deploys.iter().find(|d| d.id == id))
797					.map(deploy_card),
798			),
799			Page::Incidents => (
800				nodes![self.incidents_table()],
801				selected
802					.and_then(|id| self.incidents.iter().find(|i| i.id == id))
803					.map(incident_card),
804			),
805		};
806		let mut parts: Vec<Node<Msg>> = nodes![
807			ui::col()
808				.key("list")
809				.gap("sm")
810				.grow(1.0)
811				.basis(0.0)
812				.children(list)
813		];
814		if let Some(card) = detail {
815			parts.push(
816				card
817					.key("detail")
818					.min(Bound::w(Extent::Ch(44.0)))
819					.max(Bound::w(Extent::Ch(56.0)))
820					.into(),
821			);
822		}
823		if plain {
824			ui::col().key(page.id()).gap("md").children(parts).into()
825		} else {
826			ui::row()
827				.key(page.id())
828				.align("stretch")
829				.gap("lg")
830				.children(parts)
831				.into()
832		}
833	}
Source§

impl<M> Col<M>

Source

pub fn gap(self, value: impl Into<Gap>) -> Self

Space between children.

Examples found in repository?
examples/dashboard.rs (line 809)
783	fn body(&self, plain: bool) -> Node<Msg> {
784		let page = self.page;
785		let selected = self.selected[page.index()];
786		let (list, detail) = match page {
787			Page::Services => (
788				nodes![self.services_table()],
789				selected
790					.and_then(|id| self.services.iter().find(|s| s.id == id))
791					.map(service_card),
792			),
793			Page::Deploys => (
794				nodes![self.deploys_bar(), self.deploys_table()],
795				selected
796					.and_then(|id| self.deploys.iter().find(|d| d.id == id))
797					.map(deploy_card),
798			),
799			Page::Incidents => (
800				nodes![self.incidents_table()],
801				selected
802					.and_then(|id| self.incidents.iter().find(|i| i.id == id))
803					.map(incident_card),
804			),
805		};
806		let mut parts: Vec<Node<Msg>> = nodes![
807			ui::col()
808				.key("list")
809				.gap("sm")
810				.grow(1.0)
811				.basis(0.0)
812				.children(list)
813		];
814		if let Some(card) = detail {
815			parts.push(
816				card
817					.key("detail")
818					.min(Bound::w(Extent::Ch(44.0)))
819					.max(Bound::w(Extent::Ch(56.0)))
820					.into(),
821			);
822		}
823		if plain {
824			ui::col().key(page.id()).gap("md").children(parts).into()
825		} else {
826			ui::row()
827				.key(page.id())
828				.align("stretch")
829				.gap("lg")
830				.children(parts)
831				.into()
832		}
833	}
Source

pub fn align(self, value: impl Into<Align>) -> Self

Cross-axis alignment.

Source

pub fn justify(self, value: impl Into<Justify>) -> Self

Main-axis distribution.

Source

pub fn wrap(self, value: impl Into<bool>) -> Self

Adds class wrap.

Trait Implementations§

Source§

impl<M> Clone for Col<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 Col<M>

Source§

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

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

impl<M> From<Col<M>> for Slot<M>

Source§

fn from(n: Col<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<Col<M>> for View<M>

A bare node is main’s one child.

Source§

fn from(n: Col<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.

Auto Trait Implementations§

§

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

§

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

§

impl<M> Freeze for Col<M>
where Node<M>: Freeze,

§

impl<M> Send for Col<M>
where Node<M>: Send,

§

impl<M> Sync for Col<M>
where Node<M>: Sync,

§

impl<M> Unpin for Col<M>
where Node<M>: Unpin,

§

impl<M> UnsafeUnpin for Col<M>
where Node<M>: 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