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
impl ButtonStyleSpec
Sourcepub fn on_tint(fill: Color) -> Color
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
impl Clone for ButtonStyleSpec
Source§fn clone(&self) -> ButtonStyleSpec
fn clone(&self) -> ButtonStyleSpec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more