Hide the floating Tools palette on Home

(cherry picked from commit 0a6166936e)
This commit is contained in:
yoriswind
2026-12-01 16:45:37 +01:00
committed by Codex
parent 2a289b32e8
commit f74e13140a
3 changed files with 68 additions and 7 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ pub(crate) fn home_key(app: &VectorcraftApp) -> (Option<u64>, usize) {
/// and Preferences › General › Show The Home Screen When No Documents Are Open is on (#394). Off,
/// an app with no document shows an empty window, and the Home button still opens the screen.
pub(crate) fn home_showing(app: &VectorcraftApp) -> bool {
app.ui.home.is_some() || (app.session.active().is_none() && app.session.prefs.show_home_screen)
app.ui.home == Some(home_key(app)) || (app.session.active().is_none() && app.session.prefs.show_home_screen)
}
/// A label the layout writes itself, in the UI language: `{app}` is filled in before the lookup
+19 -1
View File
@@ -68,6 +68,8 @@ pub(crate) struct Runtime {
specs: Tracked<Specs>,
/// The tool rails of the layout, which Shift+Tab keeps shown, kept up to date by [`refresh_specs`].
rails: Tracked<BTreeSet<PanelKey>>,
/// The panels kept when Home hides the floating Tools palette.
home_panels: Option<Tracked<BTreeSet<PanelKey>>>,
/// What each tool rail of the layout reads across passes, by its panel.
pub(crate) rail_models: HashMap<String, crate::toolbar::RailModel>,
/// A panel just floated out of a tool rail, whose window takes over the held press on the next
@@ -1363,9 +1365,24 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, keeps_tools: boo
// The specs and rails leave the app for the pass, which lends the app to the panel bodies.
let specs = std::mem::take(&mut app.dock_rt.specs);
let rails = std::mem::take(&mut app.dock_rt.rails);
// The rails are what Shift+Tab keeps; while the panels show, the area hides none.
// Home leaves a floating Tools palette out of the frame without changing its saved placement.
// Shift+Tab can still restrict the other visible panels to rails.
let mut home_panels = app.dock_rt.home_panels.take();
let hide = if presenting {
HidePanels::All
} else if crate::menus::home_showing(app) && floating_window(workspace.layout(), "tools").is_some() {
let kept = workspace
.layout()
.panels()
.into_iter()
.filter(|panel| panel.as_str() != "tools" && (!keeps_tools || is_rail(panel)))
.map(PanelKey::of)
.collect();
let home_panels = home_panels.get_or_insert_with(Tracked::default);
if **home_panels != kept {
home_panels.edit(|panels| *panels = kept);
}
HidePanels::Except(home_panels)
} else if keeps_tools {
HidePanels::Except(&rails)
} else {
@@ -1396,6 +1413,7 @@ pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui, keeps_tools: boo
};
app.dock_rt.specs = specs;
app.dock_rt.rails = rails;
app.dock_rt.home_panels = home_panels;
// A workspace a command switched to or changed in this pass (`Workspace::replace`) stays; the
// pass's edits were to the one it replaced.
let mut expand = Vec::new();
@@ -145,16 +145,20 @@ struct Harness {
impl Harness {
fn new() -> Self {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
let mut h = Self::with_app(app);
h.frames(3);
h
}
fn with_app(app: VectorcraftApp) -> Self {
let host = Rc::new(RefCell::new(Host { windows: HashMap::new(), focus: ViewportId::ROOT, time: 0.0 }));
let shared = host.clone();
egui::Context::set_immediate_viewport_renderer(move |ctx, viewport| Host::render(&shared, ctx, viewport));
let ctx = crate::testing::ui_context();
ctx.set_embed_viewports(false);
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
let mut h = Self { app, ctx, host };
h.frames(3);
h
Self { app, ctx, host }
}
fn frame(&mut self, events: Vec<Event>) {
@@ -284,6 +288,45 @@ fn a_group_float_of_a_tab_group_resizes_its_native_window() {
assert_eq!(h.host.borrow().windows[&viewport].rect, Rect::from_min_size(before.min, vec2(400.0, before.height())));
}
#[test]
fn home_hides_floating_tools_and_restores_their_placement() {
let mut h = Harness::new();
let tools = h.float("tools");
let swatches = h.float("swatches");
let placement = floating_window(layout_of(&h.app.ui), "tools").unwrap().rect;
let before = h.host.borrow().windows[&tools].rect;
h.app.run("app.home", json!({})).unwrap();
let home = h.main_frame(vec![]);
assert!(!home.viewport_output.contains_key(&tools));
assert!(home.viewport_output.contains_key(&swatches));
assert_eq!(floating_window(layout_of(&h.app.ui), "tools").unwrap().rect, placement);
let saved = toml::to_string(&crate::settings::from_app(&h.app)).unwrap();
h.host.borrow_mut().windows.remove(&tools);
h.app.run("file.new", json!({})).unwrap();
let editor = h.main_frame(vec![]);
assert!(editor.viewport_output.contains_key(&tools));
assert_eq!(h.host.borrow().windows[&tools].rect, before);
h.app.run("file.close", json!({})).unwrap();
h.app.run("file.close", json!({})).unwrap();
assert!(h.app.session.documents().is_empty());
assert!(!h.main_frame(vec![]).viewport_output.contains_key(&tools));
h.app.session.prefs.show_home_screen = false;
assert!(h.main_frame(vec![]).viewport_output.contains_key(&tools));
let settings: crate::settings::AppSettings = toml::from_str(&saved).unwrap();
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.ui = settings.ui.sanitized();
crate::prefs_dialog::restore(&mut app);
let mut restarted = Harness::with_app(app);
restarted.frame(vec![]);
assert!(crate::menus::home_showing(&restarted.app));
assert!(window_viewport(&restarted.app, "tools").is_none());
assert_eq!(floating_window(layout_of(&restarted.app.ui), "tools").unwrap().rect, placement);
}
/// `window.toolbar.float` with x, y moves the OS window a toolbar made with New Toolbar already has.
#[test]
fn floating_a_toolbar_at_a_point_moves_its_native_window() {