mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
This commit is contained in:
commit
2ef27e4f32
4 files changed
+104
-18
No files matched your search
@@ -6,7 +6,6 @@
|
||||
//! The lock is `app.workspaces.set.locked`.
|
||||
|
||||
use craft::behavior::dock::{Action, DockEdge, DockPlacement, Layout, Node, PanelPlace, PanelState, Permissions, SplitSize, Target};
|
||||
use craft::behavior::overlay::Side;
|
||||
use craft::behavior::{DockSide, EditEvent, EditEvents, IconId};
|
||||
use craft::ui::contract::{Bind, BodyCx, Lazy, SizeLimits};
|
||||
use craft::ui::docking::{
|
||||
@@ -56,16 +55,6 @@ pub(crate) fn is_front(app: &PhotocraftApp, id: &str) -> bool {
|
||||
layout.panel_state(&panel) == PanelState::Front || (layout.opens_in_flyout(&panel) && app.ui.flyout.as_ref() == Some(&panel))
|
||||
}
|
||||
|
||||
/// The side of the Toolbar its flyouts and drawer open on: the side of the canvas. A toolbar in the end dock opens
|
||||
/// towards the start, any other toward the end.
|
||||
pub(crate) fn toolbar_opens(app: &PhotocraftApp) -> Side {
|
||||
let layout = &app.ui.docking.layout;
|
||||
match layout.place(&TOOLBAR.to_owned()) {
|
||||
Some(PanelPlace::Dock { path, .. }) if layout.dock_path(DockEdge::End).is_some_and(|end| end == path) => Side::Start,
|
||||
_ => Side::End,
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows or hides panel `id` (an id or a label). `Some(true)` opens a hidden panel at its place, and brings a shown
|
||||
/// one to the front, expanding its minimized group; `Some(false)` closes it; `None` shows a panel that is hidden,
|
||||
/// minimized or behind another tab and closes one that is in front. A panel in a column collapsed to icons opens and
|
||||
|
||||
@@ -40,8 +40,8 @@ pub(crate) fn panel(app: &PhotocraftApp, id: &str) -> u64 {
|
||||
}
|
||||
|
||||
/// The version of the Toolbar's rail: the toolbar slots (the preferences revision), the remembered group tools, the
|
||||
/// Edit Toolbar drawer, the side its flyouts open on, Quick Mask and the screen mode. The active tool and the colours
|
||||
/// are in every version.
|
||||
/// Edit Toolbar drawer, Quick Mask and the screen mode. Its flyouts always open on the same side. The active tool and
|
||||
/// the colours are in every version.
|
||||
pub(crate) fn toolbar(app: &PhotocraftApp) -> u64 {
|
||||
toolbar_with(app, 0)
|
||||
}
|
||||
@@ -55,9 +55,8 @@ pub(crate) fn toolbar_drawn(app: &PhotocraftApp, ui: &egui::Ui) -> u64 {
|
||||
/// [`toolbar`] with the tokens it was drawn with named by `tokens`.
|
||||
fn toolbar_with(app: &PhotocraftApp, tokens: usize) -> u64 {
|
||||
let quick_mask = app.session.active().is_some_and(|st| st.doc.quick_mask.is_some());
|
||||
let opens_start = crate::panel_docking::toolbar_opens(app) == craft::behavior::overlay::Side::Start;
|
||||
let screen_mode = format!("{:?}", app.ui.view.screen_mode);
|
||||
version(app, (app.session.prefs.rev(), &app.ui.group_tools, app.ui.toolbar_drawer, opens_start, quick_mask, screen_mode, tokens))
|
||||
version(app, (app.session.prefs.rev(), &app.ui.group_tools, app.ui.toolbar_drawer, quick_mask, screen_mode, tokens))
|
||||
}
|
||||
|
||||
/// What every region may show, joined with `extra`: the commands run (any of them may change anything), the active
|
||||
|
||||
@@ -14,6 +14,9 @@ use photocraft_engine::prefs::ToolbarCustomization;
|
||||
|
||||
use super::tool_commands;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "toolbar_docking_tests.rs"]
|
||||
mod toolbar_docking_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "toolbar_tab_reveal_tests.rs"]
|
||||
mod toolbar_tab_reveal_tests;
|
||||
@@ -158,7 +161,13 @@ fn quick_mask_button(app: &PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let _ = FlyoutButton::new(&tools, &0).id_salt("quick-mask").selected(on).show(ui);
|
||||
}
|
||||
|
||||
/// The rail over `slots`, its flyouts and drawer opening on `opens`, the side of the canvas.
|
||||
/// The side of the toolbar its tool flyouts, "…" flyout and Edit Toolbar drawer open on: the end (the right in a
|
||||
/// left-to-right layout) wherever the toolbar is docked or floats, as in the reference application, which opens them
|
||||
/// to the right even when the toolbar sits on the right between the dock's columns. The overlay flips them to the
|
||||
/// other side only when they would leave the window.
|
||||
const FLYOUTS_OPEN: Side = Side::End;
|
||||
|
||||
/// The rail over `slots`, its flyouts and drawer opening on `opens`.
|
||||
fn rail<'a>(slots: &'a [ToolSlot<Tool>], current: &'a Tool, remembered: &'a LastUsed<Tool>, opens: Side, editing: bool) -> ToolRail<'a, Tool> {
|
||||
let rail = ToolRail::new(Label::Empty, slots, current, remembered).opens(opens).edit_toolbar(tl!("Edit Toolbar…").to_string());
|
||||
// The drawer's open flag is the one source of "editing".
|
||||
@@ -244,7 +253,7 @@ fn measure_now(app: &mut PhotocraftApp, ui: &egui::Ui, width: f32) -> f32 {
|
||||
let slots = app.toolbar_slots.get(&app.session.prefs);
|
||||
let remembered = last_used(&slots, &app.ui.group_tools);
|
||||
let current = app.ui.tool;
|
||||
let (opens, editing) = (crate::panel_docking::toolbar_opens(app), app.ui.toolbar_drawer);
|
||||
let (opens, editing) = (FLYOUTS_OPEN, app.ui.toolbar_drawer);
|
||||
rail(&slots, ¤t, &remembered, opens, editing).measure_rail(ui, width, |ui, at| footer(app, ui, at)).y
|
||||
}
|
||||
|
||||
@@ -259,7 +268,7 @@ pub fn toolbar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let slots = app.toolbar_slots.get(&app.session.prefs);
|
||||
let remembered = last_used(&slots, &app.ui.group_tools);
|
||||
let current = app.ui.tool;
|
||||
let (opens, editing) = (crate::panel_docking::toolbar_opens(app), app.ui.toolbar_drawer);
|
||||
let (opens, editing) = (FLYOUTS_OPEN, app.ui.toolbar_drawer);
|
||||
let out = rail(&slots, ¤t, &remembered, opens, editing).show_rail(ui, |ui, at| footer(app, ui, at));
|
||||
|
||||
if let Some(tool) = out.select {
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
//! The toolbar as a dock panel (#12517): its tool flyouts open to the right of the button wherever it is docked, and
|
||||
//! flip to the left only where they would leave the window.
|
||||
|
||||
use super::*;
|
||||
use crate::panels::registry::TOOLBAR;
|
||||
use craft::behavior::dock::{Action, DockPlacement, Target};
|
||||
use egui::{PointerButton, Pos2, Rect};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::json;
|
||||
|
||||
const SIZE: egui::Vec2 = egui::vec2(1200.0, 800.0);
|
||||
|
||||
/// The whole app in a 1200 x 800 window with a small document open.
|
||||
fn harness() -> Harness<'static, Box<PhotocraftApp>> {
|
||||
let mut h = Harness::builder().with_size(SIZE).with_max_steps(64).build_eframe(|cc| {
|
||||
PhotocraftApp::setup_context(&cc.egui_ctx, crate::theme::AppTheme::pro());
|
||||
let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 64})).expect("new document");
|
||||
app
|
||||
});
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
/// Moves the toolbar's column beside the column holding `anchor`, after it in the dock's column order or before it.
|
||||
fn dock_toolbar_beside(h: &mut Harness<'static, Box<PhotocraftApp>>, anchor: &str, after: bool) {
|
||||
let action = Action::move_column(TOOLBAR.to_owned(), Target::at(anchor.to_owned(), DockPlacement::column(after)));
|
||||
crate::panel_docking::apply(h.state_mut(), vec![action]).expect("the toolbar docks beside the column");
|
||||
h.run_steps(6);
|
||||
}
|
||||
|
||||
/// The rect of the innermost node named `label`.
|
||||
fn rect_of(h: &Harness<'static, Box<PhotocraftApp>>, label: &str) -> Option<Rect> {
|
||||
h.query_all_by_label(label).last().map(|node| node.rect())
|
||||
}
|
||||
|
||||
/// Right-clicks the middle of `rect`, which opens a tool slot's flyout.
|
||||
fn right_click(h: &mut Harness<'static, Box<PhotocraftApp>>, rect: Rect) {
|
||||
let at: Pos2 = rect.center();
|
||||
h.event(egui::Event::PointerMoved(at));
|
||||
h.run_steps(1);
|
||||
for pressed in [true, false] {
|
||||
h.event(egui::Event::PointerButton { pos: at, button: PointerButton::Secondary, pressed, modifiers: egui::Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
}
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
/// The Lasso slot's flyout rows, opened from the toolbar: the slot's button and the Polygonal Lasso row.
|
||||
fn lasso_flyout(h: &mut Harness<'static, Box<PhotocraftApp>>) -> (Rect, Rect) {
|
||||
let button = rect_of(h, "Lasso Tool").expect("the Lasso slot is drawn");
|
||||
right_click(h, button);
|
||||
let row = rect_of(h, "Polygonal Lasso Tool").expect("the Lasso flyout is open");
|
||||
(button, row)
|
||||
}
|
||||
|
||||
/// Docked on the right between the dock's icon column and its panel column, the toolbar still opens its flyouts to the
|
||||
/// right of the button, over the panels, as the reference application does (they used to open toward the canvas).
|
||||
#[test]
|
||||
fn flyouts_open_to_the_right_between_the_end_docks_columns() {
|
||||
let mut h = harness();
|
||||
dock_toolbar_beside(&mut h, "color", true);
|
||||
let toolbar = crate::panel_docking::probe::group_rect(&h, "toolbar");
|
||||
let panels = crate::panel_docking::probe::group_rect(&h, "color").expect("the Color group is drawn");
|
||||
let (button, row) = lasso_flyout(&mut h);
|
||||
assert!(button.right() < panels.left(), "the toolbar sits left of the panel column: {button:?}, {panels:?}, {toolbar:?}");
|
||||
assert!(button.center().x > SIZE.x * 0.5, "the toolbar is on the right half of the window: {button:?}");
|
||||
assert!(row.left() >= button.right() - 0.5, "the flyout opens to the right of the button: row {row:?}, button {button:?}");
|
||||
}
|
||||
|
||||
/// At the right window edge there is no room to the right, so the flyout flips to the left of the button.
|
||||
#[test]
|
||||
fn flyouts_flip_left_at_the_right_window_edge() {
|
||||
let mut h = harness();
|
||||
dock_toolbar_beside(&mut h, "color", false);
|
||||
let (button, row) = lasso_flyout(&mut h);
|
||||
assert!(button.right() > SIZE.x - 80.0, "the toolbar is at the right window edge: {button:?}");
|
||||
assert!(row.right() <= button.left() + 0.5, "the flyout flips to the left of the button: row {row:?}, button {button:?}");
|
||||
}
|
||||
|
||||
/// Docked at the left edge (the default), the flyout opens to the right.
|
||||
#[test]
|
||||
fn flyouts_open_to_the_right_at_the_left_edge() {
|
||||
let mut h = harness();
|
||||
let (button, row) = lasso_flyout(&mut h);
|
||||
assert!(button.left() < 80.0, "the toolbar is at the left window edge: {button:?}");
|
||||
assert!(row.left() >= button.right() - 0.5, "the flyout opens to the right of the button: row {row:?}, button {button:?}");
|
||||
}
|
||||
Reference in new issue
Block a user