Skip to main content

Style

Struct Style 

Source
pub struct Style {
Show 34 fields pub background: Option<Color>, pub gradient: Option<Gradient>, pub shadow: Option<Shadow>, pub color: Option<Color>, pub font: Option<Font>, pub padding: Option<Padding>, pub radius: Option<Radii>, pub border: Option<Border>, pub border_dash: Option<(f32, f32)>, pub opacity: Option<f32>, pub mask: Option<Mask>, pub clip: Option<bool>, pub width: Option<f32>, pub height: Option<f32>, pub min_width: Option<f32>, pub min_height: Option<f32>, pub max_width: Option<f32>, pub max_height: Option<f32>, pub grow: Option<f32>, pub shrink: Option<f32>, pub basis: Option<f32>, pub align_self: Option<Align>, pub justify_self: Option<Align>, pub left: Option<f32>, pub top: Option<f32>, pub right: Option<f32>, pub bottom: Option<f32>, pub z: Option<i32>, pub span: Option<(u32, u32)>, pub translate: Option<Point>, pub scale: Option<f32>, pub rotate: Option<f32>, pub origin: Option<Point>, pub transition: Option<Transition>,
}
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, padding, clip, the sizes, the flex fields, the alignment, the absolute position and span change the layout, at once; the other fields only change how the widget is painted. A number that isn’t finite counts as unset.

translate, scale, rotate and origin move the widget and everything inside it where it is drawn and where the pointer finds it, without moving anything else: the layout, and popups anchored to the widget, keep its box where it was laid out.

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.

§gradient: Option<Gradient>

Colors blending across the widget’s rectangle, over the background.

§shadow: Option<Shadow>

A shadow under the widget’s box.

§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<Radii>

How round each corner is, in logical pixels.

§border: Option<Border>

A border inside the edge.

§border_dash: Option<(f32, f32)>

Dashes for the border, on and off logical pixels along its middle line, or a solid border when unset. See border_dash.

§opacity: Option<f32>

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

§mask: Option<Mask>

Where the widget and everything inside it show.

§clip: Option<bool>

Whether the children are cut to the inside of the border, following the rounded corners, like CSS’s overflow: hidden.

§width: Option<f32>

The width in logical pixels, instead of what the content needs.

§height: Option<f32>

The height in logical pixels, instead of what the content needs.

§min_width: Option<f32>

The least width in logical pixels.

§min_height: Option<f32>

The least height in logical pixels.

§max_width: Option<f32>

The most width in logical pixels.

§max_height: Option<f32>

The most height in logical pixels.

§grow: Option<f32>

How much of a row’s or column’s free space it takes, against its siblings’, as CSS’s flex-grow. 0 by default.

§shrink: Option<f32>

How much it gives up when a row or column is too small, against its siblings’, as CSS’s flex-shrink. 1 by default.

§basis: Option<f32>

Its size along a row or column before growing or shrinking, in logical pixels, as CSS’s flex-basis.

§align_self: Option<Align>

How it is placed across its row’s or column’s direction, or vertically in a stack’s or grid’s cell, instead of the parent’s align.

§justify_self: Option<Align>

How it is placed horizontally in a stack’s or grid’s cell. Rows and columns ignore it, as CSS’s flexbox does.

§left: Option<f32>

Logical pixels from its parent’s left edge, inside the border. Any of left, top, right and bottom takes the widget out of its parent’s flow, as CSS’s position: absolute: it is placed from those edges and no longer sizes its parent.

§top: Option<f32>

Logical pixels from its parent’s top edge, as left.

§right: Option<f32>

Logical pixels from its parent’s right edge, as left.

§bottom: Option<f32>

Logical pixels from its parent’s bottom edge, as left.

§z: Option<i32>

The order it is drawn and found by the pointer among its siblings, lowest first; siblings of equal z keep their order, later on top. 0 by default. It changes no layout.

§span: Option<(u32, u32)>

The columns and rows of a Grid it takes, each at least 1.

§translate: Option<Point>

How far the widget is moved, right and down, in logical pixels, after it is scaled and turned.

§scale: Option<f32>

How many times its size it is drawn, around origin. 0 draws nothing, and a negative scale also turns it upside down.

§rotate: Option<f32>

How many degrees it is turned clockwise, around origin.

§origin: Option<Point>

The point it is scaled and turned around, as fractions of its box: (0, 0) is the top-left corner, and the default (0.5, 0.5) the middle.

§transition: Option<Transition>

How a change to the paint fields fades in: background, gradient, shadow, color, border, radius, opacity and the transform. Other fields change at once.

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 gradient(self, gradient: Gradient) -> Style

Sets a gradient, drawn over the background.

Source

pub const fn shadow(self, shadow: Shadow) -> Style

Sets a shadow under the box.

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 padding_top(self, top: u32) -> Style

Sets the padding above the content, in logical pixels, keeping the other sides this style sets, or 0 where it sets none. As with every field, merge takes the whole padding of the style on top, so a hover style built from Style::new() sets the rest to 0.

use crabshell_ui::Style;

const PILL: Style = Style::new().padding(2, 8).padding_left(12);
Source

pub const fn padding_right(self, right: u32) -> Style

Sets the padding right of the content, keeping the other sides, as padding_top does.

Source

pub const fn padding_bottom(self, bottom: u32) -> Style

Sets the padding below the content, keeping the other sides, as padding_top does.

Source

pub const fn padding_left(self, left: u32) -> Style

Sets the padding left of the content, keeping the other sides, as padding_top does.

Source

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

Rounds every corner by radius logical pixels.

Source

pub const fn radii( self, top_left: f32, top_right: f32, bottom_right: f32, bottom_left: f32, ) -> Style

Rounds each corner on its own, in logical pixels, as CSS’s border-radius with four values. Each is clamped to half the box’s shorter side. Everything that follows the corners follows each one: the background, gradient, border, shadow, a clip and the scroll bar’s cut.

use crabshell_ui::Style;

// A tab, round on top only.
const TAB: Style = Style::new().radii(8.0, 8.0, 0.0, 0.0);
Source

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

Sets a border of width logical pixels.

Source

pub const fn border_dash(self, on: f32, off: f32) -> Style

Dashes the border: on logical pixels drawn, off left out, along the middle of the border, so the dashes follow its corners. An on of 0 draws round dots the border’s width across, off apart from middle to middle. The dashes are stretched or squeezed a little so a whole number of them goes around. A number that isn’t finite, a negative one, an off of 0 or a pattern shorter than a pixel draws the border solid. It is a field of its own, so a hover style can dash a border the style under it sets, and with no border it draws nothing. A fade takes the end style’s dash at once.

use crabshell_ui::{Color, Style};

const DROP_ZONE: Style = Style::new()
    .border(2.0, Color::hex("#89b4fa"))
    .border_dash(6.0, 4.0)
    .radius(8.0);
const DOTTED: Style = DROP_ZONE.border_dash(0.0, 5.0);
Source

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

Sets the opacity, from 0.0 to 1.0.

Source

pub const fn mask(self, mask: Mask) -> Style

Keeps the widget and everything inside it only where mask is opaque, as Qt’s OpacityMask. They are drawn into one layer, the one opacity and a transform use, so stacking them costs no extra layer, and a clip still cuts inside it. A fade takes the end style’s mask at once.

Source

pub const fn clip(self, clip: bool) -> Style

Sets whether the children are cut to the inside of the border, following the rounded corners. Nothing is cut by default.

Source

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

Sets the width in logical pixels, instead of what the content needs.

Source

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

Sets the height in logical pixels, instead of what the content needs.

Source

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

Sets the least width in logical pixels.

Source

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

Sets the least height in logical pixels.

Source

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

Sets the most width in logical pixels.

Source

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

Sets the most height in logical pixels.

Source

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

Sets how much of a row’s or column’s free space the widget takes, against its siblings’: two children with a grow of 1 and 3 take a quarter and three quarters. A Spacer grows by 1.

use crabshell_ui::Style;

const FILL: Style = Style::new().grow(1.0).basis(0.0);
Source

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

Sets how much the widget gives up, against its siblings’, when its row or column is too small for them all. 0 keeps its size.

Source

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

Sets the widget’s size along its row or column, in logical pixels, before it grows or shrinks.

Source

pub const fn align_self(self, align: Align) -> Style

Sets how the widget is placed across its row’s or column’s direction, or vertically in a stack’s or grid’s cell, instead of the parent’s align.

Source

pub const fn justify_self(self, justify: Align) -> Style

Sets how the widget is placed horizontally in a stack’s or grid’s cell. Rows and columns ignore it.

Source

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

Places the widget left logical pixels from its parent’s left edge, inside the border, out of the parent’s flow.

use crabshell_ui::Style;

// A badge in a stack's top-right corner.
const BADGE: Style = Style::new().top(2.0).right(2.0);
Source

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

Places the widget top logical pixels from its parent’s top edge, as left does.

Source

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

Places the widget right logical pixels from its parent’s right edge, as left does.

Source

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

Places the widget bottom logical pixels from its parent’s bottom edge, as left does.

Source

pub const fn z(self, z: i32) -> Style

Sets the order the widget is drawn and hit in among its siblings, lowest first. Equal ones keep their order.

Source

pub const fn span(self, columns: u32, rows: u32) -> Style

Makes the widget take columns columns and rows rows of its Grid. 0 counts as 1.

Source

pub const fn translate(self, x: f32, y: f32) -> Style

Moves the widget and everything inside it x logical pixels right and y down where it is drawn, after it is scaled and turned. The layout doesn’t move.

use crabshell_ui::Style;

const HIDDEN: Style = Style::new().translate(0.0, -40.0);
Source

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

Draws the widget and everything inside it scale times its size, around its origin, without changing the layout. 0 draws nothing and is never under the pointer; a negative scale also turns it upside down. A number that isn’t finite is ignored.

Source

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

Turns the widget and everything inside it degrees clockwise, around its origin, without changing the layout. A number that isn’t finite is ignored.

Source

pub const fn origin(self, x: f32, y: f32) -> Style

Sets the point the widget is scaled and turned around, as fractions of its box: (0.0, 0.0) is the top-left corner, (1.0, 1.0) the bottom-right. The default is the middle, (0.5, 0.5).

Source

pub const fn transition(self, transition: Transition) -> Style

Sets how a change to the paint fields fades in, as when a hover style takes over: background, gradient, shadow, color, border, radius, opacity, translate, scale, rotate and origin move over transition. The style being changed to says how.

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.

Source

pub fn clips(&self) -> bool

Whether the children are cut to the widget’s box.

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

Source§

fn into_prop(self) -> Prop<Option<Style>>

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