Skip to main content

Style

Struct Style 

Source
pub struct Style {
    pub background: Option<Color>,
    pub color: Option<Color>,
    pub font: Option<Font>,
    pub padding: Option<Padding>,
    pub radius: Option<f32>,
    pub border: Option<Border>,
    pub opacity: Option<f32>,
}
Expand description

How a widget looks. Every field is optional, and an unset field falls back to the widget’s default: no background, black text in Font::DEFAULT, no padding, square corners, no border, fully opaque.

Text takes color and font from the nearest widget that sets them, starting with itself and going up. Nothing else inherits.

font and padding change the layout; the other fields only change how the widget is painted.

use crabshell_ui::{Color, Font, Style};

const BAR: Style = Style::new()
    .background(Color::rgb(0x1e, 0x1e, 0x2e))
    .color(Color::hex("#cdd6f4"))
    .font(Font::new("Inter", 13.0));
const WS: Style = Style::new().padding(2, 8).radius(4.0);
const WS_FOCUSED: Style = WS.background(Color::rgb(0x45, 0x47, 0x5a));

Fields§

§background: Option<Color>

Fills the widget’s rectangle.

§color: Option<Color>

The text color, inherited by Text.

§font: Option<Font>

The text font, inherited by Text.

§padding: Option<Padding>

Space between the edge and the content.

§radius: Option<f32>

The corner radius in logical pixels.

§border: Option<Border>

A border inside the edge.

§opacity: Option<f32>

From 0.0 (invisible) to 1.0 (opaque), applied to the widget and everything inside it.

Implementations§

Source§

impl Style

Source

pub const fn new() -> Style

A style that sets nothing.

Source

pub const fn background(self, color: Color) -> Style

Sets the background color.

Source

pub const fn color(self, color: Color) -> Style

Sets the text color.

Source

pub const fn font(self, font: Font) -> Style

Sets the text font.

Source

pub const fn padding(self, vertical: u32, horizontal: u32) -> Style

Sets the padding: vertical above and below, horizontal left and right, in logical pixels.

Source

pub const fn radius(self, radius: f32) -> Style

Sets the corner radius in logical pixels.

Source

pub const fn border(self, width: f32, color: Color) -> Style

Sets a border of width logical pixels.

Source

pub const fn opacity(self, opacity: f32) -> Style

Sets the opacity, from 0.0 to 1.0.

Source

pub const fn merge(self, over: Style) -> Style

This style with every field that over sets replaced by its value. Buttons use it to lay their hover and pressed styles over the normal one.

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

Source§

fn into_prop(self) -> Prop<Style>

Wraps the value or closure.
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 Forget for Style

§

impl Freeze for Style

§

impl Move 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> 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> 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