Skip to main content

ButtonStyleSpec

Enum ButtonStyleSpec 

Source
pub enum ButtonStyleSpec {
    Automatic,
    Bordered,
    Prominent,
    Tinted(Color),
    Compact,
    Plain,
}
Expand description

A button’s native styling tier. Automatic is the toolkit’s stock look; Bordered asks for a visually contained button where the stock look is borderless (iOS’s plain system button reads as a link); Prominent asks for the platform’s accent-filled / default-action affordance. Toolkits whose stock buttons are already contained treat Bordered as Automatic.

Variants§

§

Automatic

§

Bordered

§

Prominent

§

Tinted(Color)

A filled button in an app-chosen color, still drawn by the native control: the platform keeps its own pressed, hover, focus and disabled rendering, its button role, and its keyboard activation. The label color is not carried; each backend picks the readable one for the fill (see ButtonStyleSpec::on_tint), the same call the platform’s own tinted buttons make.

A backend with no way to recolor its button ignores this and draws its ordinary button. That is the trade: a plain button everywhere beats a colored rectangle that is no longer a button on the platforms that cannot.

§

Compact

A button no wider than its title asks for (a one-glyph “−” or “+” in a stepper, a “×” on a chip) on toolkits whose stock button carries a minimum width and wide insets (Material’s 88 dp button turns a two-button stepper into 240 dp). The native control stays: only its minimum width and horizontal padding are reduced. A toolkit whose buttons already hug their title (AppKit, UIKit’s plain button, Qt) draws its ordinary button.

§

Plain

Borderless native action button; compact horizontal insets on Material.

Implementations§

Source§

impl ButtonStyleSpec

Source

pub fn on_tint(fill: Color) -> Color

The label color to draw on a ButtonStyleSpec::Tinted fill: whichever of black or white contrasts better against it, by WCAG’s contrast ratio.

Comparing the two ratios rather than thresholding the luminance is the difference between right and nearly right. A mid amber (#F0A64C) has a relative luminance of 0.44; under a “brighter than half” test it reads as dark and takes white text, at a hopeless 2.2:1. Its contrast against black is 9.7:1. The two ratios cross at a luminance of 0.179, not 0.5, and everything between those two numbers is a button nobody can read.

Trait Implementations§

Source§

impl Clone for ButtonStyleSpec

Source§

fn clone(&self) -> ButtonStyleSpec

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 ButtonStyleSpec

Source§

impl Debug for ButtonStyleSpec

Source§

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

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

impl Default for ButtonStyleSpec

Source§

fn default() -> ButtonStyleSpec

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

impl PartialEq for ButtonStyleSpec

Source§

fn eq(&self, other: &ButtonStyleSpec) -> 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 ButtonStyleSpec

Auto Trait Implementations§

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> 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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Day API ↩ Guides· daybrite.dev