mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 03:17:43 +00:00
Merge branch 'red/look-dialogs-b' into area/ribbon-fw
This commit is contained in:
@@ -45,6 +45,8 @@ craft_ui::words! {
|
||||
about_tab: "aboutDialog.tab" = "About";
|
||||
contributors_tab: "aboutDialog.contributors" = "Contributors";
|
||||
models_tab: "aboutDialog.models" = "Models";
|
||||
/// The footer button of the listed layout ([`AboutLayout::Listed`]).
|
||||
close: "aboutDialog.close" = "Close";
|
||||
version: template "aboutDialog.version" = "Version {version}";
|
||||
show: "aboutDialog.show" = "Show";
|
||||
username: "aboutDialog.username" = "Username";
|
||||
@@ -108,6 +110,18 @@ pub enum AboutTab {
|
||||
App(u8),
|
||||
}
|
||||
|
||||
/// How the About tab lays out the app's [`AboutInfo`], and the dialog's footer button.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum AboutLayout {
|
||||
/// The blurb, the version, the community button and the link row centred, the built-with line faint; OK closes.
|
||||
#[default]
|
||||
Centred,
|
||||
/// From the start edge, one item to a line: the app's name as a heading, the version, the blurb, the community
|
||||
/// link and then the other links in their order, the built-with line as a faint caption; Close closes.
|
||||
Listed,
|
||||
}
|
||||
|
||||
/// A tab the app adds after Models: a name for the hosted dialog's `tab` field, a title and a body.
|
||||
///
|
||||
/// The body is `Send` because a [`HostedAbout`] lives on the dialog stack, which needs its dialogs `Send`.
|
||||
@@ -212,7 +226,8 @@ impl Outcome for AboutOutput {
|
||||
|
||||
/// Help > About: tabs About, Contributors and Models over the app's [`AboutInfo`] and [`Credits`], with an OK button.
|
||||
///
|
||||
/// - **About.** The blurb, the version, the community button and the link row centred, the built-with line faint.
|
||||
/// - **About.** The blurb, the version, the community button and the link row centred, the built-with line faint; or,
|
||||
/// with [`AboutLayout::Listed`], the name, version, blurb and links one to a line, and Close for OK.
|
||||
/// - **Contributors.** Show (Username, Display name, Real name), Sort (the list, with a button to reverse) and View
|
||||
/// (Grab bag or Table). The grab bag flows the names as links: a click reports the contributor's profile URL as the
|
||||
/// link (nothing for one without a profile), and the link's tooltip is the summary. The table has every figure; a
|
||||
@@ -237,12 +252,20 @@ pub struct AboutDialog<'a> {
|
||||
#[prop]
|
||||
tab: Option<Bind<'a, AboutTab>>,
|
||||
app_tabs: Option<&'a mut [AboutAppTab]>,
|
||||
layout: AboutLayout,
|
||||
}
|
||||
|
||||
impl<'a> AboutDialog<'a> {
|
||||
/// The dialog over `info` and `credits`, opening on the About tab.
|
||||
pub fn new(info: &'a AboutInfo, credits: &'a Credits) -> Self {
|
||||
AboutDialog { info, credits, open: None, tab: None, app_tabs: None }
|
||||
AboutDialog { info, credits, open: None, tab: None, app_tabs: None, layout: AboutLayout::default() }
|
||||
}
|
||||
|
||||
/// How the About tab lays out the info, and the footer button that goes with it.
|
||||
#[must_use]
|
||||
pub fn layout(mut self, layout: AboutLayout) -> Self {
|
||||
self.layout = layout;
|
||||
self
|
||||
}
|
||||
|
||||
/// The app's own tabs, shown after Models.
|
||||
@@ -253,7 +276,7 @@ impl<'a> AboutDialog<'a> {
|
||||
|
||||
/// Shows the dialog.
|
||||
pub fn show(self, ui: &mut Ui) -> AboutOutput {
|
||||
let AboutDialog { info, credits, open, tab, mut app_tabs } = self;
|
||||
let AboutDialog { info, credits, open, tab, mut app_tabs, layout } = self;
|
||||
// The strip shows the titles while the body draws a tab, so it reads its own copy of them.
|
||||
let app_titles: Vec<Label> = app_tabs.as_deref().unwrap_or_default().iter().map(|app| app.title.clone()).collect();
|
||||
let env = Env::of(ui);
|
||||
@@ -262,13 +285,16 @@ impl<'a> AboutDialog<'a> {
|
||||
let dates = env.dates();
|
||||
let writer = Writer { format: env.format(), dates: &dates, words: &words };
|
||||
let title = Label::from(words.title.fill(&[("app", info.app_name.as_str())]));
|
||||
let shown = Shown { words: &words, writer: &writer, info, credits };
|
||||
let shown = Shown { words: &words, writer: &writer, info, credits, layout };
|
||||
|
||||
let mut tab = tab;
|
||||
let view = RefCell::new(View::default());
|
||||
let link = RefCell::new(None);
|
||||
let mut dialog =
|
||||
Dialog::new(title.clone()).collection_body().close_on_enter(true).buttons([FooterButton::new(common.ok.clone(), DialogRole::Accept)]);
|
||||
let button = match layout {
|
||||
AboutLayout::Centred => common.ok.clone(),
|
||||
AboutLayout::Listed => words.close.clone(),
|
||||
};
|
||||
let mut dialog = Dialog::new(title.clone()).collection_body().close_on_enter(true).buttons([FooterButton::new(button, DialogRole::Accept)]);
|
||||
if let Some(open) = open {
|
||||
dialog = dialog.opened(open);
|
||||
}
|
||||
@@ -318,6 +344,7 @@ struct Shown<'s> {
|
||||
writer: &'s Writer<'s>,
|
||||
info: &'s AboutInfo,
|
||||
credits: &'s Credits,
|
||||
layout: AboutLayout,
|
||||
}
|
||||
|
||||
impl Shown<'_> {
|
||||
@@ -346,9 +373,25 @@ impl Shown<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// The About tab.
|
||||
/// The About tab, laid out as [`AboutLayout`] says.
|
||||
fn about(&self, ui: &mut Ui, link: &RefCell<Option<String>>) {
|
||||
let (words, info) = (self.words, self.info);
|
||||
if self.layout == AboutLayout::Listed {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
Text::new(info.app_name.clone()).role(TypeRole::Heading).show(ui);
|
||||
Text::new(words.version.fill(&[("version", info.version.as_str())])).show(ui);
|
||||
Text::new(info.blurb.clone()).show(ui);
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
for (at, item) in info.community.iter().chain(info.links.iter()).enumerate() {
|
||||
if clicked(&Link::new(item.label.clone()).id_salt(("link", at)).show(ui)) {
|
||||
*link.borrow_mut() = Some(item.url.clone());
|
||||
}
|
||||
}
|
||||
});
|
||||
Text::new(info.built_with.clone()).role(TypeRole::Caption).shade(Shade::Faint).show(ui);
|
||||
});
|
||||
return;
|
||||
}
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
Text::new(info.blurb.clone()).show(ui);
|
||||
Text::new(words.version.fill(&[("version", info.version.as_str())])).show(ui);
|
||||
@@ -528,6 +571,7 @@ pub struct HostedAbout {
|
||||
link: Option<String>,
|
||||
open: bool,
|
||||
app_tabs: Vec<AboutAppTab>,
|
||||
layout: AboutLayout,
|
||||
#[cfg(feature = "testing")]
|
||||
facts: crate::testing::StoryOutput,
|
||||
}
|
||||
@@ -543,6 +587,7 @@ impl HostedAbout {
|
||||
link: None,
|
||||
open: true,
|
||||
app_tabs: Vec::new(),
|
||||
layout: AboutLayout::default(),
|
||||
#[cfg(feature = "testing")]
|
||||
facts: crate::testing::StoryOutput::default(),
|
||||
}
|
||||
@@ -562,6 +607,13 @@ impl HostedAbout {
|
||||
self
|
||||
}
|
||||
|
||||
/// How the About tab lays out the info ([`AboutDialog::layout`]).
|
||||
#[must_use]
|
||||
pub fn layout(mut self, layout: AboutLayout) -> Self {
|
||||
self.layout = layout;
|
||||
self
|
||||
}
|
||||
|
||||
/// The URL of the link the user activated since the last call, once. The app opens it.
|
||||
pub fn take_link(&mut self) -> Option<String> {
|
||||
self.link.take()
|
||||
@@ -628,6 +680,7 @@ impl StackDialog for HostedAbout {
|
||||
open: Some(Bind::bound(&mut self.open)),
|
||||
tab: Some(Bind::bound(&mut self.tab)),
|
||||
app_tabs: Some(&mut self.app_tabs[..]),
|
||||
layout: self.layout,
|
||||
}
|
||||
.show(ui);
|
||||
#[cfg(feature = "testing")]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Stories of `AboutDialog`: the About tab, the Contributors tab with a PR-only contributor, and an app tab.
|
||||
//! Stories of `AboutDialog`: the About tab (centred and listed), the Contributors tab with a PR-only contributor, and an app tab.
|
||||
|
||||
use super::{AboutAppTab, AboutDialog, AboutInfo, AboutLink, AboutTab, Contributor, Credits, HostedAbout, ModelCredit};
|
||||
use super::{AboutAppTab, AboutDialog, AboutInfo, AboutLayout, AboutLink, AboutTab, Contributor, Credits, HostedAbout, ModelCredit};
|
||||
use crate::contract::Show as _;
|
||||
use crate::dialog::stories::hosted;
|
||||
use crate::display::Text;
|
||||
@@ -41,6 +41,13 @@ fn about_dialog(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
hosted(ui, data, (tab, community), || HostedAbout::new(info(community), CREDITS.clone()).tab(tab))
|
||||
}
|
||||
|
||||
/// The About tab in the listed layout: name, version, blurb and links one to a line, and Close.
|
||||
#[story(AboutDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn about_dialog_listed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let community = *data.value("community_link", true);
|
||||
hosted(ui, data, community, || HostedAbout::new(info(community), CREDITS.clone()).layout(AboutLayout::Listed))
|
||||
}
|
||||
|
||||
/// The dialog with one app tab after Models, open on it.
|
||||
#[story(AboutDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn about_dialog_app_tab(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
@@ -61,7 +61,7 @@ pub use new_document::{
|
||||
mod about;
|
||||
|
||||
pub use about::{
|
||||
AboutAppTab, AboutDialog, AboutInfo, AboutLink, AboutOutput, AboutTab, AboutWords, CommitShare, Contributor, ContributorSort, Credits,
|
||||
AboutAppTab, AboutDialog, AboutInfo, AboutLayout, AboutLink, AboutOutput, AboutTab, AboutWords, CommitShare, Contributor, ContributorSort, Credits,
|
||||
HostedAbout, ModelCredit, NameMode,
|
||||
};
|
||||
|
||||
|
||||
@@ -467,6 +467,8 @@ pub(crate) struct RowOptions {
|
||||
eyedropper: bool,
|
||||
eyedropper_armed: bool,
|
||||
full_width: bool,
|
||||
/// A radio row's options stand in one row with no caption ([`Param::options_in_row`]).
|
||||
options_in_row: bool,
|
||||
not_remembered: bool,
|
||||
/// The lines a multi-line text row shows.
|
||||
lines: Option<usize>,
|
||||
@@ -834,6 +836,14 @@ impl Param {
|
||||
self
|
||||
}
|
||||
|
||||
/// For a [`ParamKind::Radio`] row: the options stand side by side in one row, with no caption over them; the label
|
||||
/// still names the group for assistive technology. Other kinds are unchanged.
|
||||
#[must_use]
|
||||
pub fn options_in_row(mut self) -> Self {
|
||||
self.options.get_or_insert_default().options_in_row = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// A [`ParamKind::Text`] row without a Browse button edits multi-line text in a field `lines` lines tall: Enter
|
||||
/// inserts a line break and the dialog's default button leaves it to the field. `lines` below 2 keeps a
|
||||
/// single-line field, whose Enter answers the default button. Other kinds are unchanged.
|
||||
@@ -991,6 +1001,11 @@ impl RowOptions {
|
||||
self.full_width
|
||||
}
|
||||
|
||||
/// Whether a radio row's options stand in one row with no caption.
|
||||
pub(crate) fn options_in_row(&self) -> bool {
|
||||
self.options_in_row
|
||||
}
|
||||
|
||||
/// The lines of a multi-line text row; `None` for a single line.
|
||||
pub(crate) fn lines(&self) -> Option<usize> {
|
||||
self.lines
|
||||
|
||||
@@ -669,25 +669,40 @@ impl<'p> Pass<'p> {
|
||||
};
|
||||
}
|
||||
|
||||
/// A radio row is its own section: the title shows the row's name once, and the group it names follows.
|
||||
/// A radio row is its own section: the title shows the row's name once, and the group it names follows. A row with
|
||||
/// [`options_in_row`](Param::options_in_row) has no title and stands its options side by side.
|
||||
fn radio_options(&mut self, ui: &mut Ui, line: &Line<'_>, options: &[(String, Label)]) {
|
||||
let value = self.work.text(line.key).map(str::to_owned).or_else(|| line.param.kind.default_value().and_then(text_of)).unwrap_or_default();
|
||||
if line.param.option().options_in_row() {
|
||||
self.radio_group(ui, line, options, true);
|
||||
return;
|
||||
}
|
||||
Section::fixed(line.name.clone()).strength(HeaderStrength::Caption).id_salt(line.key).show(ui, |ui, _| {
|
||||
let mut group = RadioGroup::new(line.name.clone(), Bind::given(value.clone())).enabled(line.enabled);
|
||||
if let Some(tip) = line.param.tooltip_text() {
|
||||
group = group.tooltip(tip.clone());
|
||||
self.radio_group(ui, line, options, false);
|
||||
});
|
||||
}
|
||||
|
||||
/// The radio group of `line`, its options in a column, or side by side when `in_row`.
|
||||
fn radio_group(&mut self, ui: &mut Ui, line: &Line<'_>, options: &[(String, Label)], in_row: bool) {
|
||||
let value = self.work.text(line.key).map(str::to_owned).or_else(|| line.param.kind.default_value().and_then(text_of)).unwrap_or_default();
|
||||
let mut group = RadioGroup::new(line.name.clone(), Bind::given(value)).enabled(line.enabled);
|
||||
if let Some(tip) = line.param.tooltip_text() {
|
||||
group = group.tooltip(tip.clone());
|
||||
}
|
||||
let radios = |ui: &mut Ui| {
|
||||
for (id, label) in options {
|
||||
Radio::new(id.clone()).label(label.clone()).enabled(line.param.option_enabled(id) && line.enabled).show(ui);
|
||||
}
|
||||
let group = group.show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
for (id, label) in options {
|
||||
Radio::new(id.clone()).label(label.clone()).enabled(line.param.option_enabled(id) && line.enabled).show(ui);
|
||||
}
|
||||
});
|
||||
});
|
||||
if let Some(v) = group.output.value().cloned() {
|
||||
self.work.set(line.key, FieldValue::Text(v));
|
||||
};
|
||||
let group = group.show(ui, |ui, _| {
|
||||
if in_row {
|
||||
Row::new().show(ui, |ui, _| radios(ui));
|
||||
} else {
|
||||
Stack::new().show(ui, |ui, _| radios(ui));
|
||||
}
|
||||
});
|
||||
if let Some(v) = group.output.value().cloned() {
|
||||
self.work.set(line.key, FieldValue::Text(v));
|
||||
}
|
||||
}
|
||||
|
||||
/// An angle row: the dial and the field over `range` at `decimals` digits. The field clamps a typed angle into
|
||||
|
||||
@@ -24,8 +24,8 @@ fn patterns() -> Vec<PresetRow<String>> {
|
||||
}
|
||||
|
||||
/// One row of every kind the rows show, a section, a row that waits for a check box, a row with a unit menu, a
|
||||
/// multi-line text row, a searchable choice, a radio row with a disabled option, a blend row, a pattern row, a files
|
||||
/// row in folder mode and a section of read-only rows.
|
||||
/// multi-line text row, a searchable choice, a radio row with a disabled option, a radio row with its options in a row,
|
||||
/// a blend row, a pattern row, a files row in folder mode and a section of read-only rows.
|
||||
fn params() -> Vec<Param> {
|
||||
let mut params = Param::parse_list(SPEC);
|
||||
let blend = vec![
|
||||
@@ -39,6 +39,7 @@ fn params() -> Vec<Param> {
|
||||
params.push(Param::files("files", "Files").folder_mode(true));
|
||||
params.push(Param::new("size", "Size", ParamKind::choice(sizes(), None)).searchable());
|
||||
params.push(Param::new("scale", "Scale", ParamKind::radio(sizes(), None)).disabled_options(["large"]));
|
||||
params.push(Param::new("fit", "Fit", ParamKind::radio(sizes(), Some("medium".to_owned()))).options_in_row());
|
||||
params.push(Param::new("angle", "Angle", ParamKind::angle(30.0)));
|
||||
params.push(Param::new("centre", "Centre", ParamKind::point([50.0, 50.0])));
|
||||
params.push(Param::section("Output"));
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
use craft_ui::contract::{Bind, Role};
|
||||
use craft_ui::dialog::{DialogHost, StackDialog as _};
|
||||
use craft_ui::patterns::form_dialogs::{AboutAppTab, AboutDialog, AboutInfo, AboutTab, Contributor, Credits, HostedAbout, ModelCredit};
|
||||
use craft_ui::patterns::form_dialogs::{AboutAppTab, AboutDialog, AboutInfo, AboutLayout, AboutLink, AboutTab, Contributor, Credits, HostedAbout, ModelCredit};
|
||||
use craft_ui::testing::{Fixture, access, trial};
|
||||
use egui::Vec2;
|
||||
use serde_json::json;
|
||||
@@ -42,6 +42,35 @@ fn a_click_on_a_name_in_the_grab_bag_reports_its_profile() {
|
||||
assert!(!fixture.by_role(Role::TABLE).is_empty(), "Table shows the contributors as a table");
|
||||
}
|
||||
|
||||
// The listed layout stands the name, version, blurb, links and built-with line in one column from the start edge,
|
||||
// the links in the community-then-links order, one to a line; a link click reports its URL and the button is Close.
|
||||
#[trial]
|
||||
fn the_listed_about_tab_stands_one_item_to_a_line_and_closes_with_close() {
|
||||
let info = AboutInfo::new("PhotoCraft", "An image editor.", "1.0")
|
||||
.community(AboutLink::new("Chat", "https://chat.example"))
|
||||
.links([AboutLink::new("Website", "https://example.org"), AboutLink::new("Source", "https://example.org/source")])
|
||||
.built_with("MIT");
|
||||
let links = Rc::new(RefCell::new(Vec::new()));
|
||||
let seen = Rc::clone(&links);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let shown = AboutDialog::new(&info, &CREDITS).layout(AboutLayout::Listed).show(ui);
|
||||
seen.borrow_mut().extend(shown.link);
|
||||
});
|
||||
fixture.room(Vec2::new(1400.0, 1000.0)).idle(30);
|
||||
assert!(fixture.by_label("OK").is_none(), "no OK button");
|
||||
assert!(fixture.by_label("Close").is_some(), "Close closes the listed dialog");
|
||||
let [chat, website, source] = ["Chat", "Website", "Source"].map(|name| fixture.by_label(name).expect("every link shows").rect);
|
||||
let painted = |text: &str| fixture.texts().iter().find(|painted| painted.text == text).map(|painted| painted.rect).expect("the text shows");
|
||||
let (name, version) = (painted("PhotoCraft"), painted("Version 1.0"));
|
||||
assert!(name.bottom() <= version.top() && version.bottom() <= painted("An image editor.").top(), "name, version, blurb in order");
|
||||
assert!(chat.bottom() <= website.top() && website.bottom() <= source.top(), "one link to a line, community first");
|
||||
assert!((chat.left() - website.left()).abs() < 1.0 && (website.left() - name.left()).abs() < 1.0, "every line starts at one edge");
|
||||
assert!(source.bottom() <= painted("MIT").top(), "the built-with line comes last");
|
||||
let website = fixture.by_label("Website").expect("the website link");
|
||||
fixture.click(&website).idle(4);
|
||||
assert_eq!(links.borrow().as_slice(), ["https://example.org".to_owned()]);
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn about_tab_is_a_field() {
|
||||
let host = Rc::new(RefCell::new(DialogHost::new()));
|
||||
|
||||
@@ -130,6 +130,29 @@ fn a_row_that_resets_drops_its_dependents_when_its_value_changes() {
|
||||
assert_ne!(values.borrow().int("layer"), Some(7), "a click on another option resets the dependent");
|
||||
}
|
||||
|
||||
// A radio row is captioned by its label with its options in a column; with `options_in_row` its options stand side by
|
||||
// side with no caption, and still pick the value.
|
||||
#[trial]
|
||||
fn a_radio_row_in_a_row_stands_its_options_side_by_side_without_a_caption() {
|
||||
let layouts = || ParamKind::radio(vec![("diagonal".into(), "Diagonal".into()), ("horizontal".into(), "Horizontal".into())], Some("diagonal".into()));
|
||||
let painted = |fixture: &Fixture, text: &str| fixture.texts().iter().any(|painted| painted.text == text);
|
||||
|
||||
let values = Rc::new(RefCell::new(DialogFields::new()));
|
||||
let fixture = rows(vec![Param::new("layout", "Layout", layouts())], &values);
|
||||
let (first, second) = (fixture.by_label("Diagonal").expect("the first option"), fixture.by_label("Horizontal").expect("the second option"));
|
||||
assert!(painted(&fixture, "Layout"), "a radio row is captioned by its label");
|
||||
assert!(second.rect.top() >= first.rect.bottom(), "the options stand in a column");
|
||||
|
||||
let values = Rc::new(RefCell::new(DialogFields::new()));
|
||||
let mut fixture = rows(vec![Param::new("layout", "Layout", layouts()).options_in_row()], &values);
|
||||
let (first, second) = (fixture.by_label("Diagonal").expect("the first option"), fixture.by_label("Horizontal").expect("the second option"));
|
||||
assert!(!painted(&fixture, "Layout"), "no caption over the options");
|
||||
assert!(second.rect.left() >= first.rect.right(), "the second option stands after the first");
|
||||
assert!((second.rect.center().y - first.rect.center().y).abs() < 1.0, "the options share one line");
|
||||
fixture.click(&second).settle();
|
||||
assert_eq!(values.borrow().text("layout"), Some("horizontal"));
|
||||
}
|
||||
|
||||
// A read-only row shows its text, selectable, and keeps no value.
|
||||
#[trial]
|
||||
fn a_read_only_row_shows_its_text_and_keeps_no_value() {
|
||||
|
||||
Reference in New Issue
Block a user