Write documentation for iced_style

This commit is contained in:
Héctor Ramón Jiménez 2022-11-10 01:10:28 +01:00
parent bec1f5bbe0
commit 4b3d0fb08d
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
18 changed files with 261 additions and 56 deletions

View file

@ -1,14 +1,20 @@
//! Allow your users to perform actions by pressing a button.
//! Change the apperance of a button.
use iced_core::{Background, Color, Vector};
/// The appearance of a button.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The amount of offset to apply to the shadow of the button.
pub shadow_offset: Vector,
/// The [`Background`] of the button.
pub background: Option<Background>,
/// The border radius of the button.
pub border_radius: f32,
/// The border width of the button.
pub border_width: f32,
/// The border [`Color`] of the button.
pub border_color: Color,
/// The text [`Color`] of the button.
pub text_color: Color,
}
@ -27,10 +33,13 @@ impl std::default::Default for Appearance {
/// A set of rules that dictate the style of a button.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;
/// Produces the active [`Appearance`] of a button.
fn active(&self, style: &Self::Style) -> Appearance;
/// Produces the hovered [`Appearance`] of a button.
fn hovered(&self, style: &Self::Style) -> Appearance {
let active = self.active(style);
@ -40,6 +49,7 @@ pub trait StyleSheet {
}
}
/// Produces the pressed [`Appearance`] of a button.
fn pressed(&self, style: &Self::Style) -> Appearance {
Appearance {
shadow_offset: Vector::default(),
@ -47,6 +57,7 @@ pub trait StyleSheet {
}
}
/// Produces the disabled [`Appearance`] of a button.
fn disabled(&self, style: &Self::Style) -> Appearance {
let active = self.active(style);