mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Preferences: one label column per page across its groups; AppearancePage rows join it
This commit is contained in:
@@ -8,8 +8,8 @@ use craft_theme::{ContrastChoice, ModeChoice, MotionChoice, Size, TextSize, Them
|
||||
use craft_ui::choice::RadioGroup;
|
||||
use craft_ui::contract::{Bind, Entry, Held, NoValue, Outcome, Props as _, Show as _, ShowContainer as _};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::form::{Field, FieldGroup};
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::menu::Menu;
|
||||
use craft_ui::pickers::Select;
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
@@ -110,7 +110,7 @@ impl<'a> AppearancePage<'a> {
|
||||
let mut held = Held::new(draft);
|
||||
let mut toggled = None;
|
||||
let mut changed = false;
|
||||
let mut shown = FieldGroup::new(words.appearance.clone()).show(ui, |ui, cx| {
|
||||
let mut shown = Stack::new().label(words.appearance.clone()).show(ui, |ui, cx| {
|
||||
let before = held.read(cx).unwrap_or_default();
|
||||
let mut now = before.clone();
|
||||
let shown = now.applied_to(&suite.shown);
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::{SelectionChange, SuiteClient};
|
||||
use craft_theme::{ThemeId, builtins};
|
||||
use craft_ui::choice::RadioGroup;
|
||||
use craft_ui::contract::{Props as _, Show as _, ShowContainer as _};
|
||||
use craft_ui::form::FieldGroup;
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -18,13 +19,18 @@ fn favorites() -> Vec<ThemeId> {
|
||||
fn appearance_page(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let client = SuiteClient::memory().view();
|
||||
let favorites = favorites();
|
||||
AppearancePage::new(&client, data.bind("draft", SelectionChange::default())).favorites(&favorites).show(ui).into()
|
||||
let mut draft = data.bind("draft", SelectionChange::default());
|
||||
FieldGroup::new("Appearance").show(ui, |ui, _| AppearancePage::new(&client, draft.reborrowed()).favorites(&favorites).show(ui)).output.into()
|
||||
}
|
||||
|
||||
#[story(AppearancePage<'static>, covers = [], drive = Drive::Never)]
|
||||
fn appearance_page_without_text_size(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let client = SuiteClient::memory().view();
|
||||
AppearancePage::new(&client, data.bind("plain", SelectionChange::default())).text_size(false).system_dark(true).show(ui).into()
|
||||
let mut draft = data.bind("plain", SelectionChange::default());
|
||||
FieldGroup::new("Appearance")
|
||||
.show(ui, |ui, _| AppearancePage::new(&client, draft.reborrowed()).text_size(false).system_dark(true).show(ui))
|
||||
.output
|
||||
.into()
|
||||
}
|
||||
|
||||
/// One theme's chips in a group: plain, chosen, favourite, and both. A click on a star toggles the chip's favourite.
|
||||
|
||||
@@ -284,21 +284,24 @@ fn show_page<H: PreferencesModel + ?Sized>(
|
||||
} else if page.groups.is_empty() && !searching {
|
||||
Notice::new(Tone::Info, words.empty_page.clone()).layout(NoticeLayout::Centred).show(ui);
|
||||
}
|
||||
for (at, group) in page.groups.iter().enumerate() {
|
||||
let mut rows = |ui: &mut Ui| {
|
||||
let name = group.title.clone().unwrap_or_else(|| page.title.clone());
|
||||
FieldGroup::new(name).show(ui, |ui, _| {
|
||||
for row in &group.rows {
|
||||
show_row(ui, host, row, units, &mut out.rows);
|
||||
if !page.groups.is_empty() {
|
||||
FieldGroup::new(page.title.clone()).show(ui, |ui, _| {
|
||||
for (at, group) in page.groups.iter().enumerate() {
|
||||
let mut rows = |ui: &mut Ui| {
|
||||
Stack::new().id_salt(at).show(ui, |ui, _| {
|
||||
for row in &group.rows {
|
||||
show_row(ui, host, row, units, &mut out.rows);
|
||||
}
|
||||
});
|
||||
};
|
||||
match &group.title {
|
||||
Some(title) => {
|
||||
Section::fixed(title.clone()).id_salt(at).show(ui, |ui, _| rows(ui));
|
||||
}
|
||||
None => rows(ui),
|
||||
}
|
||||
});
|
||||
};
|
||||
match &group.title {
|
||||
Some(title) => {
|
||||
Section::fixed(title.clone()).id_salt(at).show(ui, |ui, _| rows(ui));
|
||||
}
|
||||
None => rows(ui),
|
||||
}
|
||||
});
|
||||
}
|
||||
if let Some(note) = &page.footnote {
|
||||
Text::new(note.clone()).role(TypeRole::Caption).shade(Shade::Muted).show(ui);
|
||||
|
||||
@@ -124,6 +124,16 @@ fn grouped_page() -> Fixture {
|
||||
fixture
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn the_rows_of_every_group_of_a_page_share_one_label_column() {
|
||||
let fixture = grouped_page();
|
||||
let end = |label: &str| {
|
||||
let run = fixture.texts().iter().find(|run| run.text.trim_end_matches(':') == label).unwrap_or_else(|| panic!("no label {label}"));
|
||||
run.rect.right()
|
||||
};
|
||||
assert_eq!(end("Aa"), end("A much longer label"), "the labels of both groups end at one x");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_host_labelled_custom_row_shows_its_label_once() {
|
||||
let fixture = grouped_page();
|
||||
|
||||
Reference in New Issue
Block a user