Framework fwb10-a: port follow-ups (see runs/fwb10-a.md)

This commit is contained in:
Dylan M. Taylor committed 2026-11-20 07:41:45 -05:00
1 parent 43c6ca52f2
commit 103c968e28
4 files changed
+143 -17

No files matched your search

+4
View File
@@ -35,6 +35,10 @@ pub trait DockPanels<P> {
/// (`PanelSpec::window_kind` `Document`) gets the group's body edge to edge.
fn body(&mut self, panel: &P, ui: &mut Ui, cx: &mut BodyCx<'_>);
/// Shows the fixed trailing controls of the rail containing `panel`, in top-to-bottom order. The dock calls this
/// only when the area names a panel with `DockArea::rail_footer`; the controls remain in view while icons scroll.
fn rail_footer(&mut self, _panel: &P, _ui: &mut Ui, _cx: &mut BodyCx<'_>) {}
/// Shows `panel`'s footer in `ui`: a footer bar pinned under the body, across the group, that stays in view while
/// the body scrolls (a panel's actions on everything its body lists). The dock calls it only for a panel whose
/// spec has `PanelSpec::footer` (the default shows nothing).
+49 -13
View File
@@ -16,13 +16,14 @@ use crate::docking::{
IconicColumn, IconicMode, IconicSizes, PanelDrag, PanelKey, PanelSpec, PanelTitle, SplitArea, WindowColumn, actions, dock_states, fit_widths,
frame, move_actions, stepped,
};
use crate::layout_components::Stack;
use crate::menu::{GroupItem, MenuWords, PanelMenu, PanelRow};
use crate::runtime::commands::{CommandRef, CommandSet as _, Commands as _, focus_within};
use crate::runtime::drag;
use crate::runtime::env::{Env, Label, RevealEdge, ShellCx, ShellEntry, in_room};
use crate::runtime::memory::Remember as _;
use crate::runtime::windows::{ResizeEdge, WindowHost};
use crate::sections::HeaderAction;
use crate::sections::{HeaderAction, Panel};
use craft_behavior::dock::{
Action, Column, DockEdge, DockError, Group, Layout, Location, Node, PanelPlace, Permissions, SplitSize, Workspace, node_at,
};
@@ -136,6 +137,7 @@ pub struct DockArea<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> {
/// binding: the panel shows in its flyout, and the layout does not change.
#[prop]
flyout: Option<Bind<'a, Option<P>>>,
rail_footer: Option<P>,
}
impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
@@ -153,6 +155,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
auto_collapse: false,
locked: false,
flyout: None,
rail_footer: None,
}
}
@@ -161,6 +164,15 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
pub fn read_only(label: impl Into<Label>, layout: &Layout<P>, panels: &'a mut dyn DockPanels<P>, config: DockConfig) -> Self {
DockArea { locked: true, ..Self::new(label, Bind::given(Workspace::new(layout.clone())), panels, config) }
}
/// Adds the host's fixed trailing controls to the docked rail containing `panel`. The panel identifies the
/// column as it moves between dock sides. The host draws the controls through [`DockPanels::rail_footer`]; its
/// icons scroll above them when the rail is short. Has no effect in flyout mode or on floating columns.
#[must_use]
pub fn rail_footer(mut self, panel: P) -> Self {
self.rail_footer = Some(panel);
self
}
}
/// What the area keeps in its root container.
@@ -240,6 +252,7 @@ struct Scene<'s, P> {
rtl: bool,
/// The docked places floating panels left, for Dock Panel.
floated: &'s [(P, Location<P>)],
rail_footer: Option<&'s P>,
}
impl<P: Clone + Eq + Hash> Scene<'_, P> {
@@ -352,7 +365,7 @@ struct Pass<'s, P> {
impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
/// Shows the area across the room offered.
pub fn show(self, ui: &mut Ui) -> DockAreaOutput<P> {
let DockArea { label, mut workspace, panels, config, hide, maximized, auto_collapse, locked, mut flyout } = self;
let DockArea { label, mut workspace, panels, config, hide, maximized, auto_collapse, locked, mut flyout, rail_footer } = self;
let ctx = ui.ctx().clone();
let (rtl, window) = {
let env = Env::of(ui);
@@ -405,6 +418,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> {
auto_collapse,
sizes,
rtl,
rail_footer: rail_footer.as_ref(),
};
let mut result = show_area(ui, body, &input, &rights, &mut *panels, flyout.as_mut());
for edit in &result.edit {
@@ -503,6 +517,7 @@ struct Input<'i, P> {
auto_collapse: bool,
sizes: DockSizes,
rtl: bool,
rail_footer: Option<&'i P>,
}
fn open_of<P: Clone + Send + Sync + 'static + PartialEq + Debug>(
@@ -527,7 +542,7 @@ fn show_area<P: Clone + Eq + Hash + Debug + Send + Sync + 'static>(
panels: &mut dyn DockPanels<P>,
mut flyout: Option<&mut Bind<'_, Option<P>>>,
) -> Passed<P> {
let Input { id, ctx, current, config, specs, hide, maximized, auto_collapse, sizes, rtl } = *input;
let Input { id, ctx, current, config, specs, hide, maximized, auto_collapse, sizes, rtl, rail_footer } = *input;
let shell = body.shell();
let mut memory = body.memory::<AreaMemory<P>>().clone();
let keys: HashMap<PanelKey, P> = current.layout.panels().into_iter().map(|panel| (PanelKey::of(panel), panel.clone())).collect();
@@ -549,6 +564,7 @@ fn show_area<P: Clone + Eq + Hash + Debug + Send + Sync + 'static>(
auto_collapse,
rtl,
floated: &current.floated,
rail_footer,
};
let open = open_of(&mut flyout, body, &memory);
let mut pass = Pass {
@@ -1020,17 +1036,37 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
// Only a docked column's icons are a rail; a floating window's open flyouts.
let mode = if in_window { IconicMode::Flyouts } else { scene.config.iconic_mode };
let mut icons = |cell: Rect, open: Option<P>| {
IconicColumn::new(name.clone(), dock, column, Bind::given(open), &spec)
.edge(edge)
.opens(opens)
.bar(bar)
.within(within)
.auto_collapse(scene.auto_collapse)
.mode(mode)
.show_flyouts_at(ui, cell, |group, at, ui, body| self.group_of(ui, body, group, at, in_window))
let footer = scene.rail_footer.filter(|panel| mode == IconicMode::Rail && column.panels().any(|item| item == *panel));
let pass = RefCell::new(&mut *self);
let draw = |ui: &mut Ui, rect: Rect, open: Option<P>| {
IconicColumn::new(name.clone(), dock, column, Bind::given(open), &spec)
.edge(edge)
.opens(opens)
.bar(bar)
.within(within)
.auto_collapse(scene.auto_collapse)
.mode(mode)
.show_flyouts_at(ui, rect, |group, at, ui, body| pass.borrow_mut().group_of(ui, body, group, at, in_window))
};
if let Some(panel) = footer {
let height = IconicSizes::of(ui.ctx()).icons_height(column) + scene.sizes.bar;
Panel::new(name.clone())
.id(dock.with(("rail footer", panel)))
.pad(Pad::None)
.footer(|ui, _| {
Stack::new().fill_width().show(ui, |ui, body| pass.borrow_mut().panels.rail_footer(panel, ui, body));
})
.show_at(ui, cell, |ui, _| {
let (rect, _) = ui.allocate_exact_size(Vec2::new(ui.available_width(), height), egui::Sense::hover());
draw(ui, rect, open.clone())
})
.inner
} else {
Some(draw(ui, cell, open))
}
};
let work = if column.iconic {
let output = icons(cell, open);
let Some(output) = icons(cell, open) else { return };
self.report.flyout.extend(output.edit.events);
self.rail_work(output.front);
ColumnWork { iconic: output.iconic, picked: output.picked, resized: Vec::new(), width: output.width, flyout: output.flyout }
@@ -1045,7 +1081,7 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
(cell.with_min_x(cell.right() - rail), cell.with_max_x(cell.right() - rail))
};
cell = rest;
let output = icons(rail_cell, None);
let Some(output) = icons(rail_cell, None) else { return };
self.rail_work(output.front);
// The rail's inner edge sets its own width, not the expanded column's.
self.column_work(column, ColumnWork { iconic: output.iconic, picked: output.picked, resized: Vec::new(), width: None, flyout: None });
@@ -1,15 +1,16 @@
//! Stories of the dock area.
use super::DockArea;
use crate::buttons::IconButton;
use crate::contract::SizeLimits;
use crate::contract::{Bind, BodyCx, Show as _};
use crate::contract::{Bind, BodyCx, Props as _, Show as _};
use crate::display::Text;
use crate::docking::{DockConfig, DockGrid, DockPanels, GroupAt, PanelSpec};
use crate::docking::{DockConfig, DockGrid, DockPanels, GroupAt, IconicMode, PanelSpec};
use crate::menu::PanelRow;
use crate::patterns::presets::{PresetPanelMenu, PresetView};
use crate::testing::{Drive, StoryData, StoryOutput, story};
use craft_behavior::dock::{Column, DockEdge, Floating, Group, Layout, Node, Permissions, SplitSize, Workspace};
use craft_behavior::{Axis, Proposal};
use craft_behavior::{Axis, IconId, Proposal};
use egui::{Pos2, Rect, Ui};
const LAYERS: usize = 0;
@@ -69,6 +70,11 @@ impl DockPanels<usize> for Demo {
Text::new(name(*panel)).show(ui);
}
fn rail_footer(&mut self, _: &usize, ui: &mut Ui, _: &mut BodyCx<'_>) {
IconButton::new(IconId::new("chevron-up")).label("Previous").show(ui);
IconButton::new(IconId::new("chevron-down")).label("Next").show(ui);
}
fn panel_rows(&mut self, panel: &usize) -> Vec<PanelRow> {
if self.host_rows && *panel == SWATCHES { PresetPanelMenu::<usize>::new(PresetView::Grid).new_group(true).rows() } else { Vec::new() }
}
@@ -122,3 +128,17 @@ fn a_canvas_group_the_host_draws(ui: &mut Ui, data: &mut StoryData) -> StoryOutp
fn host_rows_above_the_dock_rows_in_a_panel_menu(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
dock(ui, data, &mut Demo { canvas_view: false, host_rows: true })
}
#[story(DockArea<'static, usize>, covers = [Default], drive = Drive::Never, title = "Rail with fixed controls")]
fn rail_with_fixed_controls(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let workspace = data.value("rail workspace", {
let side = Column::new(vec![Group::new(vec![LAYERS, CHANNELS, PROPERTIES, HISTORY, SWATCHES, NAVIGATOR], 0)]).with_iconic(true);
let root = Node::split(Axis::X, SplitSize::Ratio(0.8), Node::tabs(vec![CANVAS], 0), Node::dock(DockEdge::End, vec![side]));
Workspace::new(Layout::new(Some(root), Vec::new()))
});
let mut demo = Demo { canvas_view: false, host_rows: false };
DockArea::new("Rail dock", Bind::bound(&mut *workspace), &mut demo, DockConfig::default().iconic_mode(IconicMode::Rail))
.rail_footer(LAYERS)
.show(ui)
.into()
}
+67 -1
View File
@@ -6,7 +6,7 @@ use craft_ui::contract::{Bind, BodyCx, Role, Show as _, SizeLimits};
use craft_ui::display::Text;
use craft_ui::docking::{DockConfig, DockGrid, DockHeights, DockPanels, GroupSize, IconicMode, PanelSpec, group_heights};
use craft_ui::patterns::dock::DockArea;
use craft_ui::testing::{Fixture, trial};
use craft_ui::testing::{Fixture, pointer, trial};
use egui::{Pos2, Rect, Ui, Vec2};
use std::cell::RefCell;
use std::rc::Rc;
@@ -266,6 +266,72 @@ impl DockPanels<u32> for Sides {
}
}
struct RailWithFooter;
impl DockPanels<u32> for RailWithFooter {
fn spec(&self, panel: &u32) -> PanelSpec {
PanelSpec::new(format!("Panel {panel}"))
}
fn body(&mut self, _: &u32, _: &mut Ui, _: &mut BodyCx<'_>) {}
fn rail_footer(&mut self, _: &u32, ui: &mut Ui, _: &mut BodyCx<'_>) {
Text::new("Rail controls").show(ui);
Text::new("More controls").show(ui);
}
}
/// A rail's host controls stay below its overflowing icons and travel with the dock side.
#[trial]
fn rail_footer_stays_clear_of_icons_on_either_dock_side() {
for edge in [DockEdge::Start, DockEdge::End] {
let side = Column::new(vec![Group::new((10..30).collect(), 0)]).with_iconic(true);
let dock = Node::dock(edge, vec![side]);
let root = if edge == DockEdge::Start {
Node::split(Axis::X, SplitSize::Ratio(0.4), dock, Node::tabs(vec![1], 0))
} else {
Node::split(Axis::X, SplitSize::Ratio(0.6), Node::tabs(vec![1], 0), dock)
};
let workspace = Rc::new(RefCell::new(Workspace::new(Layout::new(Some(root), Vec::new()))));
let held = Rc::clone(&workspace);
let actions = Rc::new(RefCell::new(Vec::new()));
let seen = Rc::clone(&actions);
let mut fixture = Fixture::new(move |ui| {
let mut workspace = held.borrow().clone();
let out = DockArea::new("Rail dock", Bind::given(workspace.clone()), &mut RailWithFooter, DockConfig::default().iconic_mode(IconicMode::Rail))
.rail_footer(10)
.show(ui);
for action in out.actions {
drop(workspace.apply(action.clone(), false, |_| Permissions::ALL));
seen.borrow_mut().push(action);
}
*held.borrow_mut() = workspace;
});
fixture.room(Vec2::new(900.0, 300.0)).settle();
let footer = fixture.by_label("Rail controls").expect("the rail shows its host controls").rect;
let more = fixture.by_label("More controls").expect("the rail shows the remaining controls").rect;
let first = fixture.by_label("Panel 10").expect("the first rail icon shows").rect;
assert!(first.bottom() <= footer.top(), "icons stay above the fixed controls");
assert!(footer.bottom() <= more.top(), "the host controls form a column");
assert!((first.center().x - footer.center().x).abs() < footer.width(), "controls share the rail's side");
assert!(footer.bottom() <= 300.0, "the controls stay inside the window");
fixture.frame(vec![pointer::moved(first.center())]);
for _ in 0..12 {
fixture.frame(vec![pointer::wheel(-200.0)]);
}
fixture.settle();
let after = fixture.by_label("Rail controls").expect("the controls remain visible").rect;
let last = fixture.by_label("Panel 29").expect("the last rail icon shows").rect;
assert!((after.top() - footer.top()).abs() < 1.0, "the controls stay fixed while the icons scroll");
assert!(last.bottom() <= after.top() && last.top() >= 0.0, "scrolling brings the last icon above the controls: {last:?}, {after:?}");
let last = fixture.by_label("Panel 29").expect("the last icon can be clicked");
fixture.click(&last).settle();
assert!(actions.borrow().iter().any(|action| matches!(action, Action::Activate { panel: 29, .. })), "the scrolled icon still activates its panel");
let expanded = fixture.by_label("Rail controls").expect("the controls remain on the expanded rail").rect;
assert!((expanded.center().x - footer.center().x).abs() < footer.width(), "the controls stay at the same dock edge when expanded");
}
}
/// With the rail mode, a click on an icon expands its column with that panel in front, and the icons stay beside
/// it, between the panel and the window edge; a click on another icon switches the panel, and a click on the icon of
/// the panel in front collapses the column again.