mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 09:08:11 +00:00
Merge pull request #3586 from dotCooCoo/fix/shortcuts-tab-strip-names
menu: Keyboard Shortcuts' tab strips have readable names
This commit is contained in:
@@ -23,6 +23,7 @@ use craft_ui::contract::{BodyCx, CollectionEvent, Props as _, Scroll, Show as _,
|
||||
use craft_ui::display::Icon;
|
||||
use craft_ui::layout_components::{Grid, Row, Stack};
|
||||
use craft_ui::primitives::IconSpec;
|
||||
use craft_ui::runtime::env::Label;
|
||||
use craft_ui::runtime::motion::Animate as _;
|
||||
use craft_ui::tabs::{Tab, TabKind, TabStrip};
|
||||
use egui::Ui;
|
||||
@@ -111,10 +112,10 @@ impl DisplayOrder<usize> for Titles<'_> {
|
||||
|
||||
impl ItemSource<usize> for Titles<'_> {}
|
||||
|
||||
/// A strip of text tabs over `titles` with `shown` selected; the tab picked this pass.
|
||||
pub(super) fn tab_strip(ui: &mut Ui, name: &'static str, titles: &[String], shown: usize) -> Option<usize> {
|
||||
/// A strip of text tabs named `name`, keyed by `id`, over `titles` with `shown` selected; the tab picked this pass.
|
||||
pub(super) fn tab_strip(ui: &mut Ui, id: &'static str, name: impl Into<Label>, titles: &[String], shown: usize) -> Option<usize> {
|
||||
let strip = TabStrip::new(name)
|
||||
.id_salt(name)
|
||||
.id_salt(id)
|
||||
.kind(TabKind::Text)
|
||||
.shown(shown)
|
||||
.show_items(ui, &Titles(titles), &mut |key, _| Tab::new(titles[*key].clone()).id_salt(("tab", *key)));
|
||||
@@ -139,7 +140,13 @@ fn app_tabs(ui: &mut Ui, env: &mut Env<'_>, state: &mut DialogState) -> Option<u
|
||||
state.set_tab(None);
|
||||
}
|
||||
let shown = current.map_or(0, |i| i + 1);
|
||||
let picked = Stack::new().fill_width().enabled(!state.modal()).show(ui, |ui, _| tab_strip(ui, "shortcuts.tab", &titles, shown)).inner.flatten();
|
||||
let name = env.title();
|
||||
let picked = Stack::new()
|
||||
.fill_width()
|
||||
.enabled(!state.modal())
|
||||
.show(ui, |ui, _| tab_strip(ui, "shortcuts.tab", name.clone(), &titles, shown))
|
||||
.inner
|
||||
.flatten();
|
||||
let shown = match picked {
|
||||
Some(i) => {
|
||||
state.set_tab(i.checked_sub(1).and_then(|k| ids.get(k).copied()));
|
||||
|
||||
@@ -23,7 +23,7 @@ const HOLD_DELAY_STEP: f64 = 0.05;
|
||||
/// The header for one pass.
|
||||
pub(super) fn show(ui: &mut Ui, _cx: &mut BodyCx<'_>, now: f64, env: &mut Env<'_>, state: &mut DialogState) {
|
||||
if env.options.area_tabs {
|
||||
area_tabs(ui, state);
|
||||
area_tabs(ui, env, state);
|
||||
}
|
||||
Row::new().show(ui, |ui, _| {
|
||||
if !env.options.area_tabs {
|
||||
@@ -66,11 +66,11 @@ fn holds(ui: &mut Ui, env: &mut Env<'_>, state: &mut DialogState) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Show as tabs.
|
||||
fn area_tabs(ui: &mut Ui, state: &mut DialogState) {
|
||||
/// Show as tabs, named like the Show select.
|
||||
fn area_tabs(ui: &mut Ui, env: &Env<'_>, state: &mut DialogState) {
|
||||
let titles: Vec<String> = state.areas.iter().map(|area| area.label.clone()).collect();
|
||||
let shown = state.areas.iter().position(|area| area.id == state.area).unwrap_or(0);
|
||||
if let Some(i) = tab_strip(ui, "shortcuts.area", &titles, shown)
|
||||
if let Some(i) = tab_strip(ui, "shortcuts.area", env.text.words().show.clone(), &titles, shown)
|
||||
&& let Some(area) = state.areas.get(i)
|
||||
{
|
||||
let id = area.id.clone();
|
||||
|
||||
@@ -145,6 +145,13 @@ fn own_areas_show_only_the_apps_entries_and_open_on_the_first() {
|
||||
assert_eq!(area(&rig), "all");
|
||||
}
|
||||
|
||||
/// Show as tabs is a tab list named like the Show select it replaces.
|
||||
#[trial]
|
||||
fn area_tabs_are_named_show() {
|
||||
let rig = Rig::tuned(Platform::Mac, |options| options.area_tabs = true);
|
||||
assert_eq!(rig.names_with(Role::TAB_LIST, ""), ["Show:"]);
|
||||
}
|
||||
|
||||
/// A dialog opened with a command selected, with Show listing only the app's entries, opens on the entry that lists it.
|
||||
#[trial]
|
||||
fn own_areas_open_on_the_selected_commands_entry() {
|
||||
|
||||
@@ -74,6 +74,16 @@ fn app_tabs_show_full_labels_at_125_percent_and_switch_pages() {
|
||||
}
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn app_tabs_are_named_after_the_dialog() {
|
||||
let (mut frames, mut show) = dialog_at_125_percent("Toolbar");
|
||||
frames.idle(12, &mut show);
|
||||
let tree = frames.tree();
|
||||
let lists: Vec<&str> =
|
||||
tree.keys().into_iter().filter(|&key| tree.role_of(key) == Some(Role::TAB_LIST)).filter_map(|key| tree.name_of(key)).collect();
|
||||
assert_eq!(lists, ["Keyboard Shortcuts and Menus"]);
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn app_tabs_keep_overflow_when_the_labels_do_not_fit() {
|
||||
let long_label = "Toolbar ".repeat(200);
|
||||
|
||||
Reference in New Issue
Block a user