Skip to main content

Style

Struct Style 

Source
pub struct Style {
    pub fg: Colour,
    pub bg: Colour,
    pub attrs: Attrs,
}
Expand description

How a cell paints: foreground, background, attributes.

Fields§

§fg: Colour§bg: Colour§attrs: Attrs

Implementations§

Source§

impl Style

Source

pub const DEFAULT: Self

Theme text on a transparent background.

Source

pub const fn new() -> Self

Source

pub const fn fg(colour: Colour) -> Self

A style with this foreground.

Examples found in repository?
examples/together_ui.rs (line 57)
53    fn paint(&mut self) {
54        let (cols, _) = self.card.size();
55        self.card.clear();
56        let line = format!("{} · {} builds", self.status.state, self.status.builds);
57        self.card.text(0, 0, &line, Style::fg(Colour::FG));
58        let hint = "rebuild";
59        let x = cols.saturating_sub(hint.len() as u32);
60        self.card
61            .text(x, 0, hint, Style::fg(Colour::ACCENT).underline());
62        let _ = self.card.commit();
63    }
More examples
Hide additional examples
examples/clock_card.rs (line 43)
32    fn frame(&mut self, frame: &Frame) {
33        let second = frame.now_ms() / 1000;
34        if self.shown != Some(second) {
35            self.shown = Some(second);
36            let (cols, _) = self.card.size();
37            let time = format!(
38                "{:02}:{:02}:{:02}",
39                second / 3600 % 24,
40                second / 60 % 60,
41                second % 60
42            );
43            self.card.text(0, 0, &time, Style::fg(Colour::FG).bold());
44            let fraction = (second % 60) as f32 / 60.0;
45            let track = Style::fg(Colour::RECEDE_FG);
46            self.card.bar(
47                Area::new(0, 1, cols, 1),
48                fraction,
49                Style::fg(Colour::ACCENT),
50                track,
51            );
52            // Publishes only the cells that changed.
53            let _ = self.card.commit();
54        }
55        // The next second boundary: an idle viewer wakes once a second.
56        frame.wake_at((second + 1) * 1000);
57    }
Source

pub const fn with_fg(self, colour: Colour) -> Self

Source

pub const fn with_bg(self, colour: Colour) -> Self

Source

pub const fn with_attrs(self, attrs: Attrs) -> Self

Source

pub const fn bold(self) -> Self

Examples found in repository?
examples/clock_card.rs (line 43)
32    fn frame(&mut self, frame: &Frame) {
33        let second = frame.now_ms() / 1000;
34        if self.shown != Some(second) {
35            self.shown = Some(second);
36            let (cols, _) = self.card.size();
37            let time = format!(
38                "{:02}:{:02}:{:02}",
39                second / 3600 % 24,
40                second / 60 % 60,
41                second % 60
42            );
43            self.card.text(0, 0, &time, Style::fg(Colour::FG).bold());
44            let fraction = (second % 60) as f32 / 60.0;
45            let track = Style::fg(Colour::RECEDE_FG);
46            self.card.bar(
47                Area::new(0, 1, cols, 1),
48                fraction,
49                Style::fg(Colour::ACCENT),
50                track,
51            );
52            // Publishes only the cells that changed.
53            let _ = self.card.commit();
54        }
55        // The next second boundary: an idle viewer wakes once a second.
56        frame.wake_at((second + 1) * 1000);
57    }
Source

pub const fn dim(self) -> Self

Source

pub const fn italic(self) -> Self

Source

pub const fn underline(self) -> Self

Examples found in repository?
examples/together_ui.rs (line 61)
53    fn paint(&mut self) {
54        let (cols, _) = self.card.size();
55        self.card.clear();
56        let line = format!("{} · {} builds", self.status.state, self.status.builds);
57        self.card.text(0, 0, &line, Style::fg(Colour::FG));
58        let hint = "rebuild";
59        let x = cols.saturating_sub(hint.len() as u32);
60        self.card
61            .text(x, 0, hint, Style::fg(Colour::ACCENT).underline());
62        let _ = self.card.commit();
63    }

Trait Implementations§

Source§

impl Clone for Style

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 Copy for Style

Source§

impl Debug for Style

Source§

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

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

impl Default for Style

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Style

Source§

impl Hash for Style

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Style

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Style

Auto Trait Implementations§

§

impl Freeze for Style

§

impl RefUnwindSafe for Style

§

impl Send for Style

§

impl Sync for Style

§

impl Unpin for Style

§

impl UnsafeUnpin for Style

§

impl UnwindSafe for Style

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, 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> Resource for T
where T: 'static,

Source§

type Rep = Option<T>

The type which is actually stored in-memory for this resource. Read more
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.