pub struct Card<M = ()>(/* private fields */);Expand description
card: a rounded card with a head and a body, optionally folding.
Implementations§
Source§impl<M> Card<M>
impl<M> Card<M>
Sourcepub fn key(self, key: impl Into<NodeKey>) -> Self
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?
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}More examples
61 fn view(&self) -> View<Msg> {
62 let messages = self.transcript.iter().enumerate().map(|(i, (who, text))| {
63 let node = ui::md(text.clone()).key(i);
64 if *who == "you" {
65 ui::card().key(i).tone("user").child(node.key("t"))
66 } else {
67 ui::card().key(i).variant("bare").child(node.key("t"))
68 }
69 });
70 let cursor: usize = self
71 .draft
72 .chars()
73 .take(self.cursor)
74 .map(char::len_utf16)
75 .sum();
76 View::new().main(ui::col().children(messages)).dock(nodes![
77 ui::editor()
78 .key("ed")
79 .text(self.draft.clone())
80 .cursor(cursor)
81 .placeholder("Message (Enter sends, Escape quits)")
82 .sendable(true)
83 .on_send(|text| Msg::Send(text.to_owned()))
84 .on_focus(Msg::Focus),
85 ui::status()
86 .key("bar")
87 .child(ui::seg("chat").icon("message"))
88 .child(
89 ui::seg(format!("{} messages", self.transcript.len()))
90 .side(Side::Right)
91 .tone(if self.transcript.is_empty() {
92 Tone::Muted
93 } else {
94 Tone::Success
95 }),
96 ),
97 ])
98 }Sourcepub fn role(self, role: impl Into<String>) -> Self
pub fn role(self, role: impl Into<String>) -> Self
A name of yours, exposed to CSS as data-role.
Sourcepub fn tone(self, tone: impl Into<Tone>) -> Self
pub fn tone(self, tone: impl Into<Tone>) -> Self
The semantic color of the node’s chrome.
Examples found in repository?
61 fn view(&self) -> View<Msg> {
62 let messages = self.transcript.iter().enumerate().map(|(i, (who, text))| {
63 let node = ui::md(text.clone()).key(i);
64 if *who == "you" {
65 ui::card().key(i).tone("user").child(node.key("t"))
66 } else {
67 ui::card().key(i).variant("bare").child(node.key("t"))
68 }
69 });
70 let cursor: usize = self
71 .draft
72 .chars()
73 .take(self.cursor)
74 .map(char::len_utf16)
75 .sum();
76 View::new().main(ui::col().children(messages)).dock(nodes![
77 ui::editor()
78 .key("ed")
79 .text(self.draft.clone())
80 .cursor(cursor)
81 .placeholder("Message (Enter sends, Escape quits)")
82 .sendable(true)
83 .on_send(|text| Msg::Send(text.to_owned()))
84 .on_focus(Msg::Focus),
85 ui::status()
86 .key("bar")
87 .child(ui::seg("chat").icon("message"))
88 .child(
89 ui::seg(format!("{} messages", self.transcript.len()))
90 .side(Side::Right)
91 .tone(if self.transcript.is_empty() {
92 Tone::Muted
93 } else {
94 Tone::Success
95 }),
96 ),
97 ])
98 }Keeps the node mounted but not laid out.
Sourcepub fn mark(self, mark: impl Into<Mark>) -> Self
pub fn mark(self, mark: impl Into<Mark>) -> Self
A transient selection mark drawn over the node.
Sourcepub fn aria(self, aria: impl Into<String>) -> Self
pub fn aria(self, aria: impl Into<String>) -> Self
The accessible name of a node that shows no text.
Sourcepub fn href(self, href: impl Into<String>) -> Self
pub fn href(self, href: impl Into<String>) -> Self
A link: ⌘-click opens it; copy and open use it.
Sourcepub fn basis(self, basis: impl Into<Basis>) -> Self
pub fn basis(self, basis: impl Into<Basis>) -> Self
Flex basis: a fraction of the parent, or the content’s size.
Sourcepub fn prop(self, name: &str, value: impl Serialize) -> Self
pub fn prop(self, name: &str, value: impl Serialize) -> Self
Sets any prop untyped; null removes it.
Sourcepub fn on_click(self, msg: M) -> Self
pub fn on_click(self, msg: M) -> Self
Sends msg on a click (sets actions.click to "click" unless
the node names its click action itself).
Sourcepub fn on_dblclick(self, msg: M) -> Self
pub fn on_dblclick(self, msg: M) -> Self
Sends msg on a double click (sets actions.dblclick to
"dblclick" unless the node names it).
Adds act to the context menu and sends msg when it is picked.
Sourcepub fn on_action(self, act: impl Into<String>, msg: M) -> Self
pub fn on_action(self, act: impl Into<String>, msg: M) -> Self
Sends msg on action events whose action is act (name or
name=value).
Sourcepub fn on_action_with(
self,
act: impl Into<String>,
f: impl Fn(&Action) -> M + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn on_toggle(self, f: impl Fn(bool) -> M + Send + Sync + 'static) -> Self
pub fn on_toggle(self, f: impl Fn(bool) -> M + Send + Sync + 'static) -> Self
Maps toggle events (the new collapsed) to a message.
Sourcepub fn on_select(self, f: impl Fn(&str) -> M + Send + Sync + 'static) -> Self
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.
Sourcepub fn on_activate(self, f: impl Fn(&str) -> M + Send + Sync + 'static) -> Self
pub fn on_activate(self, f: impl Fn(&str) -> M + Send + Sync + 'static) -> Self
Maps activate events (the item) to a message.
Sourcepub fn on_change(self, f: impl Fn(&Change) -> M + Send + Sync + 'static) -> Self
pub fn on_change(self, f: impl Fn(&Change) -> M + Send + Sync + 'static) -> Self
Maps change events to a message.
Sourcepub fn on_edit(self, f: impl Fn(&Edit) -> M + Send + Sync + 'static) -> Self
pub fn on_edit(self, f: impl Fn(&Edit) -> M + Send + Sync + 'static) -> Self
Maps edit events (native editing) to a message.
Source§impl<M> Card<M>
impl<M> Card<M>
Sourcepub fn child(self, child: impl Into<Node<M>>) -> Self
pub fn child(self, child: impl Into<Node<M>>) -> Self
Adds a child.
Examples found in repository?
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}More examples
61 fn view(&self) -> View<Msg> {
62 let messages = self.transcript.iter().enumerate().map(|(i, (who, text))| {
63 let node = ui::md(text.clone()).key(i);
64 if *who == "you" {
65 ui::card().key(i).tone("user").child(node.key("t"))
66 } else {
67 ui::card().key(i).variant("bare").child(node.key("t"))
68 }
69 });
70 let cursor: usize = self
71 .draft
72 .chars()
73 .take(self.cursor)
74 .map(char::len_utf16)
75 .sum();
76 View::new().main(ui::col().children(messages)).dock(nodes![
77 ui::editor()
78 .key("ed")
79 .text(self.draft.clone())
80 .cursor(cursor)
81 .placeholder("Message (Enter sends, Escape quits)")
82 .sendable(true)
83 .on_send(|text| Msg::Send(text.to_owned()))
84 .on_focus(Msg::Focus),
85 ui::status()
86 .key("bar")
87 .child(ui::seg("chat").icon("message"))
88 .child(
89 ui::seg(format!("{} messages", self.transcript.len()))
90 .side(Side::Right)
91 .tone(if self.transcript.is_empty() {
92 Tone::Muted
93 } else {
94 Tone::Success
95 }),
96 ),
97 ])
98 }Sourcepub fn children<C: Into<Node<M>>>(
self,
children: impl IntoIterator<Item = C>,
) -> Self
pub fn children<C: Into<Node<M>>>( self, children: impl IntoIterator<Item = C>, ) -> Self
Adds children.
Source§impl<M> Card<M>
impl<M> Card<M>
Sourcepub fn head(self, value: impl Into<Text>) -> Self
pub fn head(self, value: impl Into<Text>) -> Self
Head content: text, spans, or a child’s id.
Examples found in repository?
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}Sourcepub fn status(self, value: impl Into<Status>) -> Self
pub fn status(self, value: impl Into<Status>) -> Self
The status chip.
Examples found in repository?
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}Sourcepub fn collapsible(self, value: impl Into<bool>) -> Self
pub fn collapsible(self, value: impl Into<bool>) -> Self
The head flips the fold.
Sourcepub fn variant(self, value: impl Into<CardVariant>) -> Self
pub fn variant(self, value: impl Into<CardVariant>) -> Self
The bare variant.
Examples found in repository?
61 fn view(&self) -> View<Msg> {
62 let messages = self.transcript.iter().enumerate().map(|(i, (who, text))| {
63 let node = ui::md(text.clone()).key(i);
64 if *who == "you" {
65 ui::card().key(i).tone("user").child(node.key("t"))
66 } else {
67 ui::card().key(i).variant("bare").child(node.key("t"))
68 }
69 });
70 let cursor: usize = self
71 .draft
72 .chars()
73 .take(self.cursor)
74 .map(char::len_utf16)
75 .sum();
76 View::new().main(ui::col().children(messages)).dock(nodes![
77 ui::editor()
78 .key("ed")
79 .text(self.draft.clone())
80 .cursor(cursor)
81 .placeholder("Message (Enter sends, Escape quits)")
82 .sendable(true)
83 .on_send(|text| Msg::Send(text.to_owned()))
84 .on_focus(Msg::Focus),
85 ui::status()
86 .key("bar")
87 .child(ui::seg("chat").icon("message"))
88 .child(
89 ui::seg(format!("{} messages", self.transcript.len()))
90 .side(Side::Right)
91 .tone(if self.transcript.is_empty() {
92 Tone::Muted
93 } else {
94 Tone::Success
95 }),
96 ),
97 ])
98 }