Skip to content

Commit

Permalink
Write documentation for iced_style
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Nov 10, 2022
1 parent bec1f5b commit 4b3d0fb
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 56 deletions.
10 changes: 10 additions & 0 deletions style/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
//! Change the appearance of an application.
use iced_core::Color;

/// A set of rules that dictate the style of an application.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;

/// Returns the [`Appearance`] of the application for the provided [`Style`].
///
/// [`Style`]: Self::Style
fn appearance(&self, style: &Self::Style) -> Appearance;
}

/// The appearance of an application.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Appearance {
/// The background [`Color`] of the application.
pub background_color: Color,

/// The default text [`Color`] of the application.
pub text_color: Color,
}
13 changes: 12 additions & 1 deletion style/src/button.rs
Original file line number Diff line number Diff line change
@@ -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,
}

Expand All @@ -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);

Expand All @@ -40,13 +49,15 @@ pub trait StyleSheet {
}
}

/// Produces the pressed [`Appearance`] of a button.
fn pressed(&self, style: &Self::Style) -> Appearance {
Appearance {
shadow_offset: Vector::default(),
..self.active(style)
}
}

/// Produces the disabled [`Appearance`] of a button.
fn disabled(&self, style: &Self::Style) -> Appearance {
let active = self.active(style);

Expand Down
11 changes: 10 additions & 1 deletion style/src/checkbox.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
//! Show toggle controls using checkboxes.
//! Change the appearance of a checkbox.
use iced_core::{Background, Color};

/// The appearance of a checkbox.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The [`Background`] of the checkbox.
pub background: Background,
/// The checkmark [`Color`] of the checkbox.
pub checkmark_color: Color,
/// The border radius of the checkbox.
pub border_radius: f32,
/// The border width of the checkbox.
pub border_width: f32,
/// The border [`Color`] of the checkbox.
pub border_color: Color,
/// The text [`Color`] of the checkbox.
pub text_color: Option<Color>,
}

/// A set of rules that dictate the style of a checkbox.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;

/// Produces the active [`Appearance`] of a checkbox.
fn active(&self, style: &Self::Style, is_checked: bool) -> Appearance;

/// Produces the hovered [`Appearance`] of a checkbox.
fn hovered(&self, style: &Self::Style, is_checked: bool) -> Appearance;
}
8 changes: 7 additions & 1 deletion style/src/container.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
//! Decorate content and apply alignment.
//! Change the appearance of a container.
use iced_core::{Background, Color};

/// The appearance of a container.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The text [`Color`] of the container.
pub text_color: Option<Color>,
/// The [`Background`] of the container.
pub background: Option<Background>,
/// The border radius of the container.
pub border_radius: f32,
/// The border width of the container.
pub border_width: f32,
/// The border [`Color`] of the container.
pub border_color: Color,
}

Expand All @@ -25,6 +30,7 @@ impl std::default::Default for Appearance {

/// A set of rules that dictate the [`Appearance`] of a container.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;

/// Produces the [`Appearance`] of a container.
Expand Down
1 change: 1 addition & 0 deletions style/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
clippy::new_without_default,
clippy::useless_conversion
)]
#![deny(missing_docs, unused_results)]
#![forbid(unsafe_code, rust_2018_idioms)]
#![allow(clippy::inherent_to_string, clippy::type_complexity)]
pub use iced_core::{Background, Color};
Expand Down
11 changes: 11 additions & 0 deletions style/src/menu.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
//! Change the appearance of menus.
use iced_core::{Background, Color};

/// The appearance of a menu.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The text [`Color`] of the menu.
pub text_color: Color,
/// The [`Background`] of the menu.
pub background: Background,
/// The border width of the menu.
pub border_width: f32,
/// The border radius of the menu.
pub border_radius: f32,
/// The border [`Color`] of the menu.
pub border_color: Color,
/// The text [`Color`] of a selected option in the menu.
pub selected_text_color: Color,
/// The background [`Color`] of a selected option in the menu.
pub selected_background: Background,
}

/// The style sheet of a menu.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default + Clone;

/// Produces the [`Appearance`] of a menu.
fn appearance(&self, style: &Self::Style) -> Appearance;
}
4 changes: 2 additions & 2 deletions style/src/pane_grid.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Let your users split regions of your application and organize layout
//! dynamically.
//! Change the appearance of a pane grid.
use iced_core::Color;

/// A set of rules that dictate the style of a container.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;

/// The [`Line`] to draw when a split is picked.
Expand Down
11 changes: 11 additions & 0 deletions style/src/pick_list.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
//! Change the appearance of a pick list.
use iced_core::{Background, Color};

/// The appearance of a pick list.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The text [`Color`] of the pick list.
pub text_color: Color,
/// The placeholder [`Color`] of the pick list.
pub placeholder_color: Color,
/// The [`Background`] of the pick list.
pub background: Background,
/// The border radius of the pick list.
pub border_radius: f32,
/// The border width of the pick list.
pub border_width: f32,
/// The border color of the pick list.
pub border_color: Color,
/// The size of the arrow icon of the pick list.
pub icon_size: f32,
}

/// A set of rules that dictate the style of a container.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default + Clone;

/// Produces the active [`Appearance`] of a pick list.
fn active(&self, style: &<Self as StyleSheet>::Style) -> Appearance;

/// Produces the hovered [`Appearance`] of a pick list.
fn hovered(&self, style: &<Self as StyleSheet>::Style) -> Appearance;
}
7 changes: 6 additions & 1 deletion style/src/progress_bar.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
//! Provide progress feedback to your users.
//! Change the appearance of a progress bar.
use iced_core::Background;

/// The appearance of a progress bar.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The [`Background`] of the progress bar.
pub background: Background,
/// The [`Background`] of the bar of the progress bar.
pub bar: Background,
/// The border radius of the progress bar.
pub border_radius: f32,
}

/// A set of rules that dictate the style of a progress bar.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;

/// Produces the [`Appearance`] of the progress bar.
fn appearance(&self, style: &Self::Style) -> Appearance;
}
10 changes: 9 additions & 1 deletion style/src/radio.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
//! Create choices using radio buttons.
//! Change the appearance of radio buttons.
use iced_core::{Background, Color};

/// The appearance of a radio button.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The [`Background`] of the radio button.
pub background: Background,
/// The [`Color`] of the dot of the radio button.
pub dot_color: Color,
/// The border width of the radio button.
pub border_width: f32,
/// The border [`Color`] of the radio button.
pub border_color: Color,
/// The text [`Color`] of the radio button.
pub text_color: Option<Color>,
}

/// A set of rules that dictate the style of a radio button.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;

/// Produces the active [`Appearance`] of a radio button.
fn active(&self, style: &Self::Style, is_selected: bool) -> Appearance;

/// Produces the hovered [`Appearance`] of a radio button.
fn hovered(&self, style: &Self::Style, is_selected: bool) -> Appearance;
}
3 changes: 2 additions & 1 deletion style/src/rule.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Display a horizontal or vertical rule for dividing content.
//! Change the appearance of a rule.
use iced_core::Color;

/// The appearance of a rule.
Expand All @@ -16,6 +16,7 @@ pub struct Appearance {

/// A set of rules that dictate the style of a rule.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;

/// Produces the style of a rule.
Expand Down
12 changes: 11 additions & 1 deletion style/src/scrollable.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
//! Navigate an endless amount of content with a scrollbar.
//! Change the appearance of a scrollable.
use iced_core::{Background, Color};

/// The appearance of a scrollable.
#[derive(Debug, Clone, Copy)]
pub struct Scrollbar {
/// The [`Background`] of a scrollable.
pub background: Option<Background>,
/// The border radius of a scrollable.
pub border_radius: f32,
/// The border width of a scrollable.
pub border_width: f32,
/// The border [`Color`] of a scrollable.
pub border_color: Color,
/// The appearance of the [`Scroller`] of a scrollable.
pub scroller: Scroller,
}

/// The appearance of the scroller of a scrollable.
#[derive(Debug, Clone, Copy)]
pub struct Scroller {
/// The [`Color`] of the scroller.
pub color: Color,
/// The border radius of the scroller.
pub border_radius: f32,
/// The border width of the scroller.
pub border_width: f32,
/// The border [`Color`] of the scroller.
pub border_color: Color,
}

/// A set of rules that dictate the style of a scrollable.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;

/// Produces the style of an active scrollbar.
Expand Down
23 changes: 20 additions & 3 deletions style/src/slider.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,48 @@
//! Display an interactive selector of a single value from a range of values.
//! Change the apperance of a slider.
use iced_core::Color;

/// The appearance of a slider.
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
/// The colors of the rail of the slider.
pub rail_colors: (Color, Color),
/// The appearance of the [`Handle`] of the slider.
pub handle: Handle,
}

/// The appearance of the handle of a slider.
#[derive(Debug, Clone, Copy)]
pub struct Handle {
/// The shape of the handle.
pub shape: HandleShape,
/// The [`Color`] of the handle.
pub color: Color,
/// The border width of the handle.
pub border_width: f32,
/// The border [`Color`] of the handle.
pub border_color: Color,
}

/// The shape of the handle of a slider.
#[derive(Debug, Clone, Copy)]
pub enum HandleShape {
Circle { radius: f32 },
Rectangle { width: u16, border_radius: f32 },
/// A circular handle.
Circle {
/// The radius of the circle.
radius: f32,
},
/// A rectangular shape.
Rectangle {
/// The width of the rectangle.
width: u16,
/// The border radius of the corners of the rectangle.
border_radius: f32,
},
}

/// A set of rules that dictate the style of a slider.
pub trait StyleSheet {
/// The supported style of the [`StyleSheet`].
type Style: Default;

/// Produces the style of an active slider.
Expand Down
Loading

0 comments on commit 4b3d0fb

Please sign in to comment.