mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
- hide::shown reads ShellCx::panels_hidden: the host's Except stays, any other hide hides every panel; a hidden dock (Tab) hides every panel. The columns no longer skip themselves on the shell's dock visibility. - DockTo::Docked tries the dock columns' groups, then the docked tree's, as tabs, and takes the first the model takes under the permissions (drop::takes), so a toolbar's group is passed over. - DockSizes::title_row is FloatingGroup's title row height; the window commands' source, stepped window heights and FloatSpace::title_row use it. - Trials: hidden.rs, dock_back.rs, and the window group under the area's title row in floating_area.rs.
86 lines
3.9 KiB
Rust
86 lines
3.9 KiB
Rust
//! What a dock area shows while the shell hides the panels and keeps the tools (Shift+Tab) or hides the dock (Tab).
|
|
|
|
use craft_behavior::Axis;
|
|
use craft_behavior::dock::{Column, DockEdge, Floating, Group, Layout, Node, Permissions, SplitSize, Workspace};
|
|
use craft_ui::contract::{Bind, BodyCx};
|
|
use craft_ui::docking::{DockConfig, DockPanels, HidePanels, PanelSpec};
|
|
use craft_ui::patterns::dock::DockArea;
|
|
use craft_ui::runtime::env::{BodyMode, ShellCx, ShellEntry, WindowKey};
|
|
use craft_ui::testing::{Fixture, trial};
|
|
use egui::{Pos2, Rect, Ui, Vec2};
|
|
use std::cell::RefCell;
|
|
use std::collections::BTreeSet;
|
|
use std::rc::Rc;
|
|
|
|
const CANVAS: usize = 1;
|
|
/// Docked, and named by the host's `HidePanels::Except`.
|
|
const TOOLBAR: usize = 2;
|
|
const LAYERS: usize = 3;
|
|
/// Floating, and named by the host's `HidePanels::Except`.
|
|
const PALETTE: usize = 4;
|
|
const NAVIGATOR: usize = 5;
|
|
|
|
/// Records the panels whose bodies ran.
|
|
struct Panels {
|
|
shown: Rc<RefCell<BTreeSet<usize>>>,
|
|
}
|
|
|
|
impl DockPanels<usize> for Panels {
|
|
fn spec(&self, panel: &usize) -> PanelSpec {
|
|
PanelSpec::new(format!("Panel {panel}"))
|
|
}
|
|
|
|
fn permissions(&self, panel: &usize) -> Permissions {
|
|
if *panel == CANVAS { Permissions::PROTECTED } else { Permissions::ALL }
|
|
}
|
|
|
|
fn body(&mut self, panel: &usize, _: &mut Ui, _: &mut BodyCx<'_>) {
|
|
self.shown.borrow_mut().insert(*panel);
|
|
}
|
|
}
|
|
|
|
/// The toolbar in a start dock, the canvas, Layers in an end dock, and two floating windows.
|
|
fn layout() -> Layout<usize> {
|
|
let start = Node::dock(DockEdge::Start, vec![Column::new(vec![Group::new(vec![TOOLBAR], 0)])]);
|
|
let end = Node::dock(DockEdge::End, vec![Column::new(vec![Group::new(vec![LAYERS], 0)])]);
|
|
let root = Node::split(Axis::X, SplitSize::Ratio(0.2), start, Node::split(Axis::X, SplitSize::Ratio(0.7), Node::tabs(vec![CANVAS], 0), end));
|
|
let window = |panel: usize, x: f32| Floating::single(vec![panel], 0, Rect::from_min_size(Pos2::new(x, 60.0), Vec2::new(120.0, 120.0)));
|
|
Layout::new(Some(root), vec![window(PALETTE, 90.0), window(NAVIGATOR, 220.0)])
|
|
}
|
|
|
|
/// The panels the area shows under `shell`, with the host keeping the toolbar and the palette when `keeps`.
|
|
fn shown_under(shell: ShellCx, keeps: bool) -> BTreeSet<usize> {
|
|
let shown: Rc<RefCell<BTreeSet<usize>>> = Rc::default();
|
|
let seen = Rc::clone(&shown);
|
|
let mut fixture = Fixture::new(move |ui| {
|
|
seen.borrow_mut().clear();
|
|
let mut workspace = Workspace::new(layout());
|
|
let mut panels = Panels { shown: Rc::clone(&seen) };
|
|
let keep = |panel: &usize| *panel == TOOLBAR || *panel == PALETTE;
|
|
let mut area = DockArea::new("Hidden dock", Bind::bound(&mut workspace), &mut panels, DockConfig::default());
|
|
if keeps {
|
|
area = area.hide(HidePanels::Except(&keep));
|
|
}
|
|
area.show(ui);
|
|
});
|
|
fixture.root_value(ShellEntry(Some(shell))).settle();
|
|
shown.take()
|
|
}
|
|
|
|
#[trial]
|
|
fn shift_tab_keeps_the_panels_the_host_names_docked_and_floating_and_tab_hides_them_all() {
|
|
let room = Rect::from_min_size(Pos2::ZERO, Vec2::new(400.0, 300.0));
|
|
let normal = ShellCx::detached(WindowKey::main(), BodyMode::Normal, room);
|
|
let all = BTreeSet::from([CANVAS, TOOLBAR, LAYERS, PALETTE, NAVIGATOR]);
|
|
assert_eq!(shown_under(normal.clone(), false), all, "every panel shows while nothing hides them");
|
|
let shift_tab = normal.with_panels_hidden(true);
|
|
assert_eq!(
|
|
shown_under(shift_tab.clone(), true),
|
|
BTreeSet::from([CANVAS, TOOLBAR, PALETTE]),
|
|
"Shift+Tab keeps the canvas and what the host names, docked and floating"
|
|
);
|
|
assert_eq!(shown_under(shift_tab, false), BTreeSet::from([CANVAS]), "Shift+Tab with nothing named keeps the canvas only");
|
|
let tab = ShellCx::detached(WindowKey::main(), BodyMode::Only, room);
|
|
assert_eq!(shown_under(tab, true), BTreeSet::from([CANVAS]), "Tab keeps the canvas only, whatever the host names");
|
|
}
|