Skip to main content

Table

Struct Table 

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

table: a table with priority-hidden columns and meter cells.

Implementations§

Source§

impl<M> Table<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 838)
836	fn table(&self, page: Page, empty: &str) -> ui::Table<Msg> {
837		let mut table = ui::table()
838			.key("table")
839			.selectable(true)
840			.empty(empty)
841			.on_select(move |id| Msg::Select(page, id.to_owned()))
842			.on_activate(move |id| Msg::Open(page, id.to_owned()));
843		if let Some(id) = self.selected[page.index()] {
844			table = table.selected(id);
845		}
846		table
847	}
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.

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 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.

Examples found in repository?
examples/dashboard.rs (line 841)
836	fn table(&self, page: Page, empty: &str) -> ui::Table<Msg> {
837		let mut table = ui::table()
838			.key("table")
839			.selectable(true)
840			.empty(empty)
841			.on_select(move |id| Msg::Select(page, id.to_owned()))
842			.on_activate(move |id| Msg::Open(page, id.to_owned()));
843		if let Some(id) = self.selected[page.index()] {
844			table = table.selected(id);
845		}
846		table
847	}
Source

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

Maps activate events (the item) to a message.

Examples found in repository?
examples/dashboard.rs (line 842)
836	fn table(&self, page: Page, empty: &str) -> ui::Table<Msg> {
837		let mut table = ui::table()
838			.key("table")
839			.selectable(true)
840			.empty(empty)
841			.on_select(move |id| Msg::Select(page, id.to_owned()))
842			.on_activate(move |id| Msg::Open(page, id.to_owned()));
843		if let Some(id) = self.selected[page.index()] {
844			table = table.selected(id);
845		}
846		table
847	}
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> Table<M>

Source

pub fn cols(self, value: impl Into<Vec<Column>>) -> Self

All columns.

Source

pub fn rows(self, value: impl Into<Vec<TableRow>>) -> Self

All rows.

Examples found in repository?
examples/table.rs (line 58)
43fn view(entries: &[Entry]) -> View {
44	let rows = entries.iter().map(|e| {
45		let (name, icon) = if e.dir {
46			(format!("{}/", e.name), "folder")
47		} else {
48			(e.name.clone(), "file")
49		};
50		let size = if e.dir { "-".to_owned() } else { human(e.size) };
51		TableRow::new(e.name.clone())
52			.cell("name", TextCell::new(name).icon(icon))
53			.cell("size", size)
54	});
55	View::new().main([ui::table()
56		.col(Column::new("name", "Name").grow(1.0))
57		.col(Column::new("size", "Size").align(TextAlign::End).mono(true))
58		.rows(rows.collect::<Vec<_>>())])
59}
Source

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

Rows take clicks: select on click, activate on double click, with the row id as item.

Examples found in repository?
examples/dashboard.rs (line 839)
836	fn table(&self, page: Page, empty: &str) -> ui::Table<Msg> {
837		let mut table = ui::table()
838			.key("table")
839			.selectable(true)
840			.empty(empty)
841			.on_select(move |id| Msg::Select(page, id.to_owned()))
842			.on_activate(move |id| Msg::Open(page, id.to_owned()));
843		if let Some(id) = self.selected[page.index()] {
844			table = table.selected(id);
845		}
846		table
847	}
Source

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

The row drawn selected, kept in view.

Examples found in repository?
examples/dashboard.rs (line 844)
836	fn table(&self, page: Page, empty: &str) -> ui::Table<Msg> {
837		let mut table = ui::table()
838			.key("table")
839			.selectable(true)
840			.empty(empty)
841			.on_select(move |id| Msg::Select(page, id.to_owned()))
842			.on_activate(move |id| Msg::Open(page, id.to_owned()));
843		if let Some(id) = self.selected[page.index()] {
844			table = table.selected(id);
845		}
846		table
847	}
Source

pub fn empty(self, value: impl Into<Text>) -> Self

Shown muted when there are no rows.

Examples found in repository?
examples/dashboard.rs (line 840)
836	fn table(&self, page: Page, empty: &str) -> ui::Table<Msg> {
837		let mut table = ui::table()
838			.key("table")
839			.selectable(true)
840			.empty(empty)
841			.on_select(move |id| Msg::Select(page, id.to_owned()))
842			.on_activate(move |id| Msg::Open(page, id.to_owned()));
843		if let Some(id) = self.selected[page.index()] {
844			table = table.selected(id);
845		}
846		table
847	}
Source

pub fn sort(self, value: impl Into<Sort>) -> Self

The column the rows are sorted by (its header draws the arrow). A header click sends action sort with {col, dir}.

Source

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

Rows are picked several at a time; each change sends change with the picked ids.

Source

pub fn picked(self, value: impl Into<Vec<String>>) -> Self

The ids of the picked rows.

Source

pub fn variant(self, value: impl Into<TableVariant>) -> Self

How picks and the sort look.

Source

pub fn bar(self, value: impl Into<Vec<ActButton>>) -> Self

Buttons in the selection bar, sent with the picked ids.

Source

pub fn hint(self, value: impl Into<Text>) -> Self

Muted text after the count in the selection bar.

Source

pub fn col(self, col: Column) -> Self

Adds a column.

Examples found in repository?
examples/table.rs (line 56)
43fn view(entries: &[Entry]) -> View {
44	let rows = entries.iter().map(|e| {
45		let (name, icon) = if e.dir {
46			(format!("{}/", e.name), "folder")
47		} else {
48			(e.name.clone(), "file")
49		};
50		let size = if e.dir { "-".to_owned() } else { human(e.size) };
51		TableRow::new(e.name.clone())
52			.cell("name", TextCell::new(name).icon(icon))
53			.cell("size", size)
54	});
55	View::new().main([ui::table()
56		.col(Column::new("name", "Name").grow(1.0))
57		.col(Column::new("size", "Size").align(TextAlign::End).mono(true))
58		.rows(rows.collect::<Vec<_>>())])
59}
More examples
Hide additional examples
examples/dashboard.rs (line 853)
850	fn services_table(&self) -> ui::Table<Msg> {
851		let mut table = self
852			.table(Page::Services, "No services yet")
853			.col(Column::new("name", "Service").grow(1.0).priority(6.0))
854			.col(Column::new("region", "Region").priority(3.0))
855			.col(Column::new("version", "Version").mono(true).priority(2.0))
856			.col(Column::new("traffic", "Traffic").priority(1.0))
857			.col(
858				Column::new("rps", "req/s")
859					.align(TextAlign::End)
860					.mono(true)
861					.priority(4.0),
862			)
863			.col(
864				Column::new("p95", "p95")
865					.align(TextAlign::End)
866					.mono(true)
867					.priority(4.0),
868			)
869			.col(
870				Column::new("errors", "Errors")
871					.align(TextAlign::End)
872					.mono(true)
873					.priority(4.0),
874			)
875			.col(Column::new("health", "Health").priority(5.0));
876		for s in &self.services {
877			let (label, tone) = s.health.look();
878			let mut errors = TextCell::new(format!("{:.1}%", s.errors));
879			if s.errors >= 1.0 {
880				errors = errors.tone(Tone::Error);
881			}
882			table = table.row(
883				TableRow::new(s.id)
884					.cell("name", TextCell::new(s.id).dot(tone.clone()))
885					.cell("region", s.region)
886					.cell("version", s.version)
887					.cell("traffic", SparkCell::new(s.rps.clone()))
888					.cell("rps", format!("{:.0}", s.rps.last().copied().unwrap_or_default()))
889					.cell("p95", format!("{:.0} ms", s.p95))
890					.cell("errors", errors)
891					.cell("health", BadgeSpec::new(label).tone(tone)),
892			);
893		}
894		table
895	}
896
897	/// The deploys toolbar: a muted description and the filter.
898	fn deploys_bar(&self) -> ui::Row<Msg> {
899		let attention = self
900			.deploys
901			.iter()
902			.filter(|d| matches!(d.state, State::Waiting | State::Failed))
903			.count();
904		ui::row()
905			.key("bar")
906			.justify("between")
907			.align("center")
908			.child(
909				ui::text(ui::span("Rollouts to production, newest first").style("muted")).key("about"),
910			)
911			.child(
912				ui::tabs()
913					.key("filter")
914					.variant("segmented")
915					.active(self.filter.clone())
916					.tab("all", "All")
917					.tab("attention", spans![
918						"Needs you ",
919						ui::span(attention.to_string()).style("muted")
920					])
921					.on_select(|id| Msg::Filter(id.to_owned())),
922			)
923	}
924
925	/// The deploys table.
926	fn deploys_table(&self) -> ui::Table<Msg> {
927		let mut table = self
928			.table(Page::Deploys, "Nothing needs you right now")
929			.col(Column::new("service", "Service").grow(1.0).priority(6.0))
930			.col(Column::new("commit", "Commit").mono(true).priority(3.0))
931			.col(Column::new("region", "Region").priority(2.0))
932			.col(Column::new("traffic", "Traffic").priority(1.0))
933			.col(Column::new("rollout", "Rollout").priority(1.0))
934			.col(Column::new("state", "State").priority(5.0));
935		for d in self.shown_deploys() {
936			let (label, tone) = d.state.look();
937			table = table.row(
938				TableRow::new(d.id)
939					.cell("service", TextCell::new(d.service).dot(tone.clone()))
940					.cell("commit", d.commit)
941					.cell("region", d.region)
942					.cell("traffic", SparkCell::new(d.rps.clone()))
943					.cell("rollout", MeterCell {
944						value: Some(d.done),
945						title: Some(format!("{:.0}%", d.done * 100.0)),
946						..MeterCell::default()
947					})
948					.cell("state", BadgeSpec::new(label).tone(tone)),
949			);
950		}
951		table
952	}
953
954	/// The incidents table.
955	fn incidents_table(&self) -> ui::Table<Msg> {
956		let mut table = self
957			.table(Page::Incidents, "No incidents. All quiet.")
958			.col(Column::new("title", "Incident").grow(1.0).priority(6.0))
959			.col(Column::new("id", "Id").mono(true).priority(2.0))
960			.col(Column::new("service", "Service").priority(3.0))
961			.col(Column::new("severity", "Severity").priority(4.0))
962			.col(
963				Column::new("age", "Open for")
964					.align(TextAlign::End)
965					.mono(true)
966					.priority(4.0),
967			)
968			.col(Column::new("phase", "State").priority(5.0));
969		for i in &self.incidents {
970			let (sev, sev_tone) = i.severity.look();
971			let (phase, phase_tone) = i.phase.look();
972			table = table.row(
973				TableRow::new(i.id)
974					.cell("title", TextCell::new(i.title).dot(sev_tone.clone()))
975					.cell("id", i.id)
976					.cell("service", i.service)
977					.cell("severity", BadgeSpec::new(sev).tone(sev_tone))
978					.cell("age", ago(i.age))
979					.cell("phase", BadgeSpec::new(phase).tone(phase_tone)),
980			);
981		}
982		table
983	}
Source

pub fn row(self, row: TableRow) -> Self

Adds a row.

Examples found in repository?
examples/dashboard.rs (lines 882-892)
850	fn services_table(&self) -> ui::Table<Msg> {
851		let mut table = self
852			.table(Page::Services, "No services yet")
853			.col(Column::new("name", "Service").grow(1.0).priority(6.0))
854			.col(Column::new("region", "Region").priority(3.0))
855			.col(Column::new("version", "Version").mono(true).priority(2.0))
856			.col(Column::new("traffic", "Traffic").priority(1.0))
857			.col(
858				Column::new("rps", "req/s")
859					.align(TextAlign::End)
860					.mono(true)
861					.priority(4.0),
862			)
863			.col(
864				Column::new("p95", "p95")
865					.align(TextAlign::End)
866					.mono(true)
867					.priority(4.0),
868			)
869			.col(
870				Column::new("errors", "Errors")
871					.align(TextAlign::End)
872					.mono(true)
873					.priority(4.0),
874			)
875			.col(Column::new("health", "Health").priority(5.0));
876		for s in &self.services {
877			let (label, tone) = s.health.look();
878			let mut errors = TextCell::new(format!("{:.1}%", s.errors));
879			if s.errors >= 1.0 {
880				errors = errors.tone(Tone::Error);
881			}
882			table = table.row(
883				TableRow::new(s.id)
884					.cell("name", TextCell::new(s.id).dot(tone.clone()))
885					.cell("region", s.region)
886					.cell("version", s.version)
887					.cell("traffic", SparkCell::new(s.rps.clone()))
888					.cell("rps", format!("{:.0}", s.rps.last().copied().unwrap_or_default()))
889					.cell("p95", format!("{:.0} ms", s.p95))
890					.cell("errors", errors)
891					.cell("health", BadgeSpec::new(label).tone(tone)),
892			);
893		}
894		table
895	}
896
897	/// The deploys toolbar: a muted description and the filter.
898	fn deploys_bar(&self) -> ui::Row<Msg> {
899		let attention = self
900			.deploys
901			.iter()
902			.filter(|d| matches!(d.state, State::Waiting | State::Failed))
903			.count();
904		ui::row()
905			.key("bar")
906			.justify("between")
907			.align("center")
908			.child(
909				ui::text(ui::span("Rollouts to production, newest first").style("muted")).key("about"),
910			)
911			.child(
912				ui::tabs()
913					.key("filter")
914					.variant("segmented")
915					.active(self.filter.clone())
916					.tab("all", "All")
917					.tab("attention", spans![
918						"Needs you ",
919						ui::span(attention.to_string()).style("muted")
920					])
921					.on_select(|id| Msg::Filter(id.to_owned())),
922			)
923	}
924
925	/// The deploys table.
926	fn deploys_table(&self) -> ui::Table<Msg> {
927		let mut table = self
928			.table(Page::Deploys, "Nothing needs you right now")
929			.col(Column::new("service", "Service").grow(1.0).priority(6.0))
930			.col(Column::new("commit", "Commit").mono(true).priority(3.0))
931			.col(Column::new("region", "Region").priority(2.0))
932			.col(Column::new("traffic", "Traffic").priority(1.0))
933			.col(Column::new("rollout", "Rollout").priority(1.0))
934			.col(Column::new("state", "State").priority(5.0));
935		for d in self.shown_deploys() {
936			let (label, tone) = d.state.look();
937			table = table.row(
938				TableRow::new(d.id)
939					.cell("service", TextCell::new(d.service).dot(tone.clone()))
940					.cell("commit", d.commit)
941					.cell("region", d.region)
942					.cell("traffic", SparkCell::new(d.rps.clone()))
943					.cell("rollout", MeterCell {
944						value: Some(d.done),
945						title: Some(format!("{:.0}%", d.done * 100.0)),
946						..MeterCell::default()
947					})
948					.cell("state", BadgeSpec::new(label).tone(tone)),
949			);
950		}
951		table
952	}
953
954	/// The incidents table.
955	fn incidents_table(&self) -> ui::Table<Msg> {
956		let mut table = self
957			.table(Page::Incidents, "No incidents. All quiet.")
958			.col(Column::new("title", "Incident").grow(1.0).priority(6.0))
959			.col(Column::new("id", "Id").mono(true).priority(2.0))
960			.col(Column::new("service", "Service").priority(3.0))
961			.col(Column::new("severity", "Severity").priority(4.0))
962			.col(
963				Column::new("age", "Open for")
964					.align(TextAlign::End)
965					.mono(true)
966					.priority(4.0),
967			)
968			.col(Column::new("phase", "State").priority(5.0));
969		for i in &self.incidents {
970			let (sev, sev_tone) = i.severity.look();
971			let (phase, phase_tone) = i.phase.look();
972			table = table.row(
973				TableRow::new(i.id)
974					.cell("title", TextCell::new(i.title).dot(sev_tone.clone()))
975					.cell("id", i.id)
976					.cell("service", i.service)
977					.cell("severity", BadgeSpec::new(sev).tone(sev_tone))
978					.cell("age", ago(i.age))
979					.cell("phase", BadgeSpec::new(phase).tone(phase_tone)),
980			);
981		}
982		table
983	}
Source

pub fn bar_button(self, button: ActButton) -> Self

Adds a selection bar button.

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more
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<Table<M>> for Slot<M>

Source§

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

A bare node is main’s one child.

Source§

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

Converts to this type from the input type.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<M> UnsafeUnpin for Table<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