mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
fix(ui): expose toolbar column toggle in all themes (#3538)
fix(ui): expose toolbar column toggle in all themes Also covers the same fix as #4680; thanks to its author. Co-authored-by: Marco Arnulfo <[email protected]>
This commit is contained in:
1 parent
d334d32c12
commit
23dc83928c
1 file changed
+45
-37
@@ -90,18 +90,16 @@ pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
.exact_size(w)
|
||||
.frame(egui::Frame::NONE.fill(t.chrome).inner_margin(egui::Margin::symmetric(m, 8)))
|
||||
.show(ui, |ui| {
|
||||
if t.pro {
|
||||
// Photoshop's toolbar header chevrons switch between one and two columns.
|
||||
let (cr, resp) = ui.allocate_exact_size(vec2(bx, 14.0), Sense::click());
|
||||
// The chevrons point the way the toolbar grows or shrinks: towards the canvas.
|
||||
let (shrink, grow) = if crate::direction::is_rtl() { ("chevrons-right", "chevrons-left") } else { ("chevrons-left", "chevrons-right") };
|
||||
icons::paint(ui, cr, if double { shrink } else { grow }, 11.0, if resp.hovered() { t.text } else { t.text_faint });
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tl!("Toolbar")));
|
||||
if resp.clicked() {
|
||||
app.ui.panels.toolbar_double = !app.ui.panels.toolbar_double;
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
// Toolbar width is a user preference, not a Pro-only feature.
|
||||
// Keep the same hit target in every theme (including RTL layouts).
|
||||
let (cr, resp) = ui.allocate_exact_size(vec2(bx, 14.0), Sense::click());
|
||||
let (shrink, grow) = if crate::direction::is_rtl() { ("chevrons-right", "chevrons-left") } else { ("chevrons-left", "chevrons-right") };
|
||||
icons::paint(ui, cr, if double { shrink } else { grow }, 11.0, if resp.hovered() { t.text } else { t.text_faint });
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, tl!("Toolbar")));
|
||||
if resp.clicked() {
|
||||
app.ui.panels.toolbar_double = !double;
|
||||
}
|
||||
ui.add_space(4.0);
|
||||
// Subtle violet wash at the bottom of the toolbar.
|
||||
let full = ui.max_rect();
|
||||
if !t.bevel && !t.pro && t.dark() {
|
||||
@@ -5437,35 +5435,45 @@ mod toolbar_tests {
|
||||
use super::*;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
|
||||
/// #1197: the header chevron switches the toolbar between one and two columns.
|
||||
/// #1197 / #3469: every theme can toggle the toolbar without changing its selection.
|
||||
#[test]
|
||||
fn header_chevron_toggles_two_columns() {
|
||||
let app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(800.0, 1400.0)).build_ui_state(
|
||||
|ui, app: &mut PhotocraftApp| {
|
||||
if ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
|
||||
toolbar(app, ui);
|
||||
let left = ui.available_rect_before_wrap().left();
|
||||
ui.data_mut(|d| d.insert_temp(egui::Id::new("toolbar-test-left"), left));
|
||||
}
|
||||
},
|
||||
app,
|
||||
);
|
||||
PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::Pro);
|
||||
h.run_steps(2);
|
||||
let left = |h: &egui_kittest::Harness<'_, PhotocraftApp>| h.ctx.data(|d| d.get_temp::<f32>(egui::Id::new("toolbar-test-left"))).unwrap_or(0.0);
|
||||
let single = left(&h);
|
||||
assert!(!h.state().ui.panels.toolbar_double);
|
||||
fn header_chevron_toggles_two_columns_in_every_layout() {
|
||||
for theme in [
|
||||
crate::theme::ThemeKind::Pro,
|
||||
crate::theme::ThemeKind::Studio,
|
||||
crate::theme::ThemeKind::StudioLight,
|
||||
crate::theme::ThemeKind::Classic,
|
||||
crate::theme::ThemeKind::AdwaitaDark,
|
||||
crate::theme::ThemeKind::SolarizedDark,
|
||||
crate::theme::ThemeKind::BreezeDark,
|
||||
] {
|
||||
let app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(800.0, 1400.0)).build_ui_state(
|
||||
|ui, app: &mut PhotocraftApp| {
|
||||
if ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
|
||||
toolbar(app, ui);
|
||||
let left = ui.available_rect_before_wrap().left();
|
||||
ui.data_mut(|d| d.insert_temp(egui::Id::new("toolbar-test-left"), left));
|
||||
}
|
||||
},
|
||||
app,
|
||||
);
|
||||
PhotocraftApp::setup_context(&h.ctx, theme);
|
||||
h.run_steps(2);
|
||||
let left = |h: &egui_kittest::Harness<'_, PhotocraftApp>| h.ctx.data(|d| d.get_temp::<f32>(egui::Id::new("toolbar-test-left"))).unwrap_or(0.0);
|
||||
let single = left(&h);
|
||||
assert!(!h.state().ui.panels.toolbar_double, "{theme:?}");
|
||||
|
||||
h.get_by_label("Toolbar").click();
|
||||
h.run_steps(2);
|
||||
assert!(h.state().ui.panels.toolbar_double);
|
||||
assert!(left(&h) > single + 20.0, "the toolbar did not widen: {single} -> {}", left(&h));
|
||||
h.get_by_label("Toolbar").click();
|
||||
h.run_steps(2);
|
||||
assert!(h.state().ui.panels.toolbar_double, "{theme:?}");
|
||||
assert!(left(&h) > single + 20.0, "{theme:?}: the toolbar did not widen: {single} -> {}", left(&h));
|
||||
|
||||
h.get_by_label("Toolbar").click();
|
||||
h.run_steps(2);
|
||||
assert!(!h.state().ui.panels.toolbar_double);
|
||||
assert_eq!(left(&h), single);
|
||||
h.get_by_label("Toolbar").click();
|
||||
h.run_steps(2);
|
||||
assert!(!h.state().ui.panels.toolbar_double, "{theme:?}");
|
||||
assert_eq!(left(&h), single, "{theme:?}");
|
||||
}
|
||||
}
|
||||
|
||||
fn click(h: &mut egui_kittest::Harness<'_, PhotocraftApp>, p: egui::Pos2) {
|
||||
|
||||
Reference in new issue
Block a user