Dock stories: columns in floating windows, a stepped toolbar column and a collapsed floating window

This commit is contained in:
aiongg
2026-11-17 03:50:28 +00:00
parent 92f11d415b
commit 19f1b7b4ea
3 changed files with 56 additions and 8 deletions
@@ -1,7 +1,7 @@
//! Stories of `DockColumn`.
use crate::contract::ShowContainer as _;
use crate::docking::{DockColumn, PanelSpec};
use crate::docking::{ColumnBar, DockColumn, PanelSpec};
use crate::sections::Panel;
use crate::testing::memory::global;
use crate::testing::{Drive, StoryData, StoryOutput, story};
@@ -22,3 +22,17 @@ fn two_groups(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
})
.into()
}
/// The column of a floating window: the window's title row is its bar, so it shows its groups and the dividers
/// between them only.
#[story(DockColumn<'static, u8>, covers = [Default], drive = Drive::Never)]
fn in_a_floating_window(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let column = Column::new(vec![Group::new(vec![0, 1], 0), Group::new(vec![2], 0)]);
DockColumn::new("Panels", global("dock column", "window story"), &column, &spec)
.bar(ColumnBar::Window)
.show_groups(ui, |group, rect, ui, _| {
let title = group.active_panel().map_or_else(String::new, |panel| spec(panel).label.as_str().to_owned());
Panel::new(title).show_at(ui, rect, |_, _| ());
})
.into()
}
+16 -1
View File
@@ -4,7 +4,7 @@ use super::CELL;
use crate::buttons::Button;
use crate::contract::ShowContainer as _;
use crate::contract::{Bind, BodyCx, Show as _, Validity};
use crate::docking::{GroupAt, IconicColumn, IconicColumnOutput, PanelSpec};
use crate::docking::{ColumnBar, GroupAt, IconicColumn, IconicColumnOutput, PanelSpec};
use crate::runtime::env::{Env, Message};
use crate::sections::Panel;
use crate::testing::memory::global;
@@ -50,6 +50,21 @@ fn icon_groups(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
.into()
}
/// The column of a floating window collapsed to icons: the window's title row is its bar, so the icons start at its
/// top, and its flyouts open towards the room.
#[story(IconicColumn<'static, u8>, covers = [Default], drive = Drive::Never)]
fn icons_in_a_floating_window(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let column = Column::new(vec![Group::new(vec![0, 1], 0), Group::new(vec![2], 0)]);
let column = IconicColumn::new("Panels", global("iconic column", "window story"), &column, Bind::kept(), &spec).bar(ColumnBar::Window);
at_stage(ui, column, |group, at, ui, _| {
let GroupAt::Show(rect) = at else { return None };
let title = group.active_panel().map_or_else(String::new, |panel| spec(panel).label.as_str().to_owned());
Panel::new(title).titled().show_at(ui, rect, |_, _| ());
None
})
.into()
}
/// A click on the first icon opens the flyout of its panel, which the bound value then names.
fn open_first_flyout(fixture: &mut Fixture) {
let Some(id) = fixture.root_id() else { return };
@@ -4,7 +4,7 @@ use super::DockArea;
use crate::contract::SizeLimits;
use crate::contract::{Bind, BodyCx, Show as _};
use crate::display::Text;
use crate::docking::{DockConfig, DockPanels, GroupAt, PanelSpec};
use crate::docking::{DockConfig, DockGrid, DockPanels, GroupAt, PanelSpec};
use crate::menu::PanelRow;
use crate::patterns::presets::{PresetPanelMenu, PresetView};
use crate::testing::{Drive, StoryData, StoryOutput, story};
@@ -18,8 +18,13 @@ const PROPERTIES: usize = 2;
const HISTORY: usize = 3;
const CANVAS: usize = 4;
const SWATCHES: usize = 5;
/// A toolbar: its content lays out in a grid, and its column never collapses or holds another group.
const TOOLS: usize = 6;
const NAVIGATOR: usize = 7;
const SIDE: f32 = 220.0;
const WINDOW: Rect = Rect { min: Pos2::new(320.0, 80.0), max: Pos2::new(520.0, 220.0) };
/// Where the collapsed floating window keeps its expanded size.
const COLLAPSED_WINDOW: Rect = Rect { min: Pos2::new(320.0, 240.0), max: Pos2::new(520.0, 380.0) };
/// Panels that show their own name.
struct Demo {
@@ -36,6 +41,8 @@ fn name(panel: usize) -> &'static str {
PROPERTIES => "Properties",
HISTORY => "History",
SWATCHES => "Swatches",
TOOLS => "Tools",
NAVIGATOR => "Navigator",
_ => "Canvas",
}
}
@@ -43,11 +50,19 @@ fn name(panel: usize) -> &'static str {
impl DockPanels<usize> for Demo {
fn spec(&self, panel: &usize) -> PanelSpec {
let spec = PanelSpec::new(name(*panel)).limits(SizeLimits::default());
if *panel == CANVAS { spec.canvas() } else { spec }
match *panel {
CANVAS => spec.canvas(),
TOOLS => spec.grid(DockGrid::new(40.0, 32.0, 4)),
_ => spec,
}
}
fn permissions(&self, panel: &usize) -> Permissions {
if *panel == CANVAS { Permissions::PROTECTED } else { Permissions::ALL }
match *panel {
CANVAS => Permissions::PROTECTED,
TOOLS => Permissions::ALL.collapses(false).shares_column(false),
_ => Permissions::ALL,
}
}
fn body(&mut self, panel: &usize, ui: &mut Ui, _: &mut BodyCx<'_>) {
@@ -73,15 +88,19 @@ impl DockPanels<usize> for Demo {
}
}
/// A canvas between a docked column of panels at the start and an iconic column at the end, with one floating group.
/// A canvas between a start dock, a toolbar column one step wide and a column of panels, and an iconic column at the
/// end, with one floating group and one floating window collapsed to icons.
fn workspace() -> Workspace<usize> {
let tools = Column::new(vec![Group::new(vec![TOOLS], 0)]).with_steps(1);
let side = Column::new(vec![Group::new(vec![LAYERS, CHANNELS], 0), Group::new(vec![PROPERTIES], 0)]).with_width(SIDE);
let mut icons = Column::new(vec![Group::new(vec![SWATCHES], 0)]).with_width(SIDE);
icons.iconic = true;
let centre = Node::split(Axis::X, SplitSize::Ratio(0.8), Node::tabs(vec![CANVAS], 0), Node::dock(DockEdge::End, vec![icons]));
let root = Node::split(Axis::X, SplitSize::FixedFirst(SIDE), Node::dock(DockEdge::Start, vec![side]), centre);
let root = Node::split(Axis::X, SplitSize::FixedFirst(SIDE), Node::dock(DockEdge::Start, vec![tools, side]), centre);
let window = Floating::single(vec![HISTORY], 0, WINDOW).with_id(1);
Workspace::new(Layout::new(Some(root), vec![window]))
let mut collapsed = Floating::single(vec![NAVIGATOR], 0, COLLAPSED_WINDOW).with_id(2);
collapsed.column.iconic = true;
Workspace::new(Layout::new(Some(root), vec![window, collapsed]))
}
fn dock(ui: &mut Ui, data: &mut StoryData, demo: &mut Demo) -> StoryOutput {