mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
ui-widgets choice: ChoiceLook, a root style value; under ChoiceLook::Strong a check box, radio button or switch track that is on fills with accent.strong (pressed accent.strong_pressed, disabled unchanged) under a text.on_strong mark; ChoiceLook::Accent, the default, keeps accent.solid with text.on_accent. Check box and radio stories under Strong
This commit is contained in:
1 parent
09650e1d3d
commit
68cde01dc5
3 files changed
+76
-9
No files matched your search
@@ -1,8 +1,10 @@
|
||||
//! Stories of `Checkbox`.
|
||||
|
||||
use super::Checkbox;
|
||||
use crate::contract::{Props as _, Show as _, Validity};
|
||||
use crate::runtime::env::Message;
|
||||
use crate::choice::ChoiceLook;
|
||||
use crate::contract::{Props as _, Show as _, ShowContainer as _, Validity};
|
||||
use crate::layout_components::Stack;
|
||||
use crate::runtime::env::{Message, with_env};
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use craft_behavior::Mixed;
|
||||
use craft_theme::ControlSize;
|
||||
@@ -59,3 +61,25 @@ fn checkbox_disabled_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn checkbox_long_label(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
Checkbox::new(data.bind("checked", true)).label(LONG_LABEL).show(ui).into()
|
||||
}
|
||||
|
||||
/// The check boxes of an app that sets `ChoiceLook::Strong` at its root: a checked or mixed box fills with the strong
|
||||
/// accent under a white mark; an unchecked box and a disabled one look as they do by default.
|
||||
#[story(Checkbox<'static>, covers = [], drive = Drive::Never, group = "Looks", title = "Strong")]
|
||||
fn checkbox_strong(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut output = StoryOutput::default();
|
||||
with_env(
|
||||
ui,
|
||||
|overrides| {
|
||||
overrides.values.set(ChoiceLook::Strong);
|
||||
},
|
||||
|ui| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
output = Checkbox::new(data.bind("checked", true)).label("Checked").show(ui).into();
|
||||
Checkbox::new(data.bind("unchecked", false)).label("Unchecked").show(ui);
|
||||
Checkbox::new(data.bind_mixed("mixed", Mixed::Mixed)).label("Mixed").show(ui);
|
||||
Checkbox::new(data.bind("disabled", true)).label("Disabled (checked)").enabled(false).show(ui);
|
||||
})
|
||||
},
|
||||
);
|
||||
output
|
||||
}
|
||||
@@ -22,6 +22,19 @@ pub use swatch::{
|
||||
};
|
||||
pub use swatch_table::{RowMarks, SwatchArrangement, SwatchRows, SwatchSpacing, SwatchTable, SwatchTableOutput, SwatchTableStyle};
|
||||
|
||||
/// How a check box, radio button or switch track that is on fills. An app sets it once at its root
|
||||
/// (`RootEnv::values`); the default is the accent.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)]
|
||||
#[env(style)]
|
||||
#[non_exhaustive]
|
||||
pub enum ChoiceLook {
|
||||
/// `accent.solid` with a `text.on_accent` mark.
|
||||
#[default]
|
||||
Accent,
|
||||
/// `accent.strong` with a white `text.on_strong` mark: VectorCraft's.
|
||||
Strong,
|
||||
}
|
||||
|
||||
/// The well of a check box, radio button or switch track with `radius` corners: the sunken surface, so a bevelled theme
|
||||
/// draws its bevel, filled with the off fill or the on accent. A flat theme draws the outline as its edge, in the failure
|
||||
/// colour while the value is invalid.
|
||||
@@ -61,21 +74,29 @@ fn well(cx: &crate::style::StyleCx<'_>) -> craft_theme::Stateful<crate::style::S
|
||||
Stateful::new(well).off(States::new(well, well, pressed, disabled))
|
||||
}
|
||||
|
||||
/// The fill of a check box, radio button or switch track while on: the accent, its pressed shade while pressed, and
|
||||
/// `text.disabled` while disabled.
|
||||
/// The fill of a check box, radio button or switch track while on: the accent of the [`ChoiceLook`], its pressed shade
|
||||
/// while pressed, and `text.disabled` while disabled.
|
||||
fn on_fill(cx: &crate::style::StyleCx<'_>) -> craft_theme::Stateful<crate::style::StyleColor> {
|
||||
use craft_theme::{Stateful, States};
|
||||
let accent = &cx.tokens.color.accent;
|
||||
let (solid, pressed, disabled) = (cx.color(accent.solid), cx.color(accent.pressed), cx.color(cx.tokens.color.text.disabled));
|
||||
let (solid, pressed) = match cx.env::<ChoiceLook>() {
|
||||
ChoiceLook::Accent => (accent.solid, accent.pressed),
|
||||
ChoiceLook::Strong => (accent.strong, accent.strong_pressed),
|
||||
};
|
||||
let (solid, pressed, disabled) = (cx.color(solid), cx.color(pressed), cx.color(cx.tokens.color.text.disabled));
|
||||
Stateful::new(solid).off(States::new(solid, solid, pressed, disabled))
|
||||
}
|
||||
|
||||
/// The mark on an on-accent fill (check, dash, dot): `text.on_accent`, and the panel while disabled, cut into the
|
||||
/// disabled box.
|
||||
/// The mark on the on fill (check, dash, dot): the text colour paired with the [`ChoiceLook`]'s accent, and the panel
|
||||
/// while disabled, cut into the disabled box.
|
||||
fn mark(cx: &crate::style::StyleCx<'_>) -> craft_theme::Stateful<crate::style::StyleColor> {
|
||||
use craft_theme::{Stateful, States};
|
||||
let colors = &cx.tokens.color;
|
||||
let (mark, disabled) = (cx.color(colors.text.on_accent), cx.color(colors.state.disabled_fill));
|
||||
let mark = match cx.env::<ChoiceLook>() {
|
||||
ChoiceLook::Accent => colors.text.on_accent,
|
||||
ChoiceLook::Strong => colors.text.on_strong,
|
||||
};
|
||||
let (mark, disabled) = (cx.color(mark), cx.color(colors.state.disabled_fill));
|
||||
Stateful::new(mark).off(States::new(mark, mark, mark, disabled))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
//! Stories of `RadioGroup` and `Radio`.
|
||||
|
||||
use super::{Radio, RadioGroup};
|
||||
use crate::choice::ChoiceLook;
|
||||
use crate::contract::{FieldLayout, Props as _, Show as _, ShowContainer as _, SideLabel, Validity};
|
||||
use crate::display::{Shade, Text};
|
||||
use crate::layout_components::{Row, Stack};
|
||||
use crate::runtime::env::Message;
|
||||
use crate::runtime::env::{Message, with_env};
|
||||
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story};
|
||||
use craft_behavior::{IconId, Mixed};
|
||||
use egui::{Response, Ui};
|
||||
@@ -153,3 +154,24 @@ fn radio(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
});
|
||||
selected.map(StoryOutput::from).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The radio buttons of an app that sets `ChoiceLook::Strong` at its root: the selected one fills with the strong
|
||||
/// accent under a white dot. Beside it a mixed group, which selects none, and a disabled group.
|
||||
#[story(RadioGroup<'static, u8>, covers = [], drive = Drive::Never, group = "Looks", title = "Strong")]
|
||||
fn radio_group_strong(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut output = StoryOutput::default();
|
||||
with_env(
|
||||
ui,
|
||||
|overrides| {
|
||||
overrides.values.set(ChoiceLook::Strong);
|
||||
},
|
||||
|ui| {
|
||||
Row::new().show(ui, |ui, _| {
|
||||
output = column(ui, RadioGroup::new("Size", data.bind("size", 2u8)));
|
||||
column(ui, RadioGroup::new("Mixed", data.bind_mixed("mixed", Mixed::Mixed)));
|
||||
column(ui, RadioGroup::new("Disabled", data.bind("disabled", 2u8)).enabled(false));
|
||||
})
|
||||
},
|
||||
);
|
||||
output
|
||||
}
|
||||
Reference in new issue
Block a user