Shell and mock: AppShell::tools and Slot::columns removed; the gallery mock's toolbar is a stepped dock column drawn through group_view, with a collapsed Navigator column and flyout binding

This commit is contained in:
aiongg
2026-11-17 04:03:17 +00:00
parent 6d972e35ed
commit c3d7655b9e
14 changed files with 153 additions and 127 deletions
+5
View File
@@ -33,6 +33,9 @@ pub enum AppCommand {
/// Shows or hides the rulers.
#[command(label = "Rulers", kind = "toggle", default = "Cmd+R")]
Rulers,
/// Shows or hides the toolbar.
#[command(label = "Tools", kind = "toggle")]
ShowTools,
/// Shows or hides the canvas panel.
#[command(label = "Canvas", kind = "toggle")]
ShowCanvas,
@@ -48,6 +51,7 @@ impl AppCommand {
/// The command that shows or hides `panel`.
pub const fn showing(panel: Panel) -> AppCommand {
match panel {
Panel::Tools => AppCommand::ShowTools,
Panel::Canvas => AppCommand::ShowCanvas,
Panel::Navigator => AppCommand::ShowNavigator,
Panel::Layers => AppCommand::ShowLayers,
@@ -57,6 +61,7 @@ impl AppCommand {
/// The panel the command shows or hides.
pub const fn panel(self) -> Option<Panel> {
match self {
AppCommand::ShowTools => Some(Panel::Tools),
AppCommand::ShowCanvas => Some(Panel::Canvas),
AppCommand::ShowNavigator => Some(Panel::Navigator),
AppCommand::ShowLayers => Some(Panel::Layers),
+34 -25
View File
@@ -11,7 +11,7 @@ use craft_theme::variant::Tone;
use craft_ui::bars::{Bar, BarKind, StatusMessage, StatusReadout, StatusValues};
use craft_ui::buttons::{IconButton, Link};
use craft_ui::canvas::{PickStep, ViewCommands};
use craft_ui::contract::{Bind, BodyCx, PaneEdge, Props as _, Remember as _, SaveKey, Show as _, ShowContainer as _};
use craft_ui::contract::{Bind, BodyCx, Props as _, Remember as _, SaveKey, Show as _, ShowContainer as _};
use craft_ui::dialog::{DialogResult, PromptChoice, StandardPrompt};
use craft_ui::display::{Divider, Text};
use craft_ui::docking::{DockConfig, DockEvent, DockPanels as _};
@@ -20,7 +20,6 @@ use craft_ui::patterns::dock::DockArea;
use craft_ui::patterns::form_dialogs::{
DialogFields, HostedImageSize, HostedParamDialog, ImageSize, ImageSizeValues, Param, ParamDialog, ParamResult,
};
use craft_ui::rails::ToolRail;
use craft_ui::runtime::commands::{self, CommandRef, Commands as _, EditCommands};
use craft_ui::runtime::env::{Env, Label, WindowKey};
use craft_ui::shell::{AppShell, AppShellOutput, CaptionFamily, Captions, Frame, ScreenMode, ShellDialogsCx as _, Title, TitleBar};
@@ -36,10 +35,10 @@ const BLUR_KEY: &str = "gaussianBlur";
/// Where Gaussian Blur remembers its values.
const BLUR_MEMORY: SaveKey = SaveKey::new("craft_ui_gallery.gaussianBlur");
/// The mock editor: the shell with its title bar and menus, options bar, tool rail and status bar around a dock whose
/// canvas group holds the document tabs, the canvas with its rulers and pasteboard, and the Navigator and layer panels.
/// The mock editor: the shell with its title bar and menus, options bar and status bar around a dock whose canvas group
/// holds the document tabs, the canvas with its rulers and pasteboard, and the toolbar, Navigator and layer panels.
///
/// - Tool: the rail and the tool keys pick the current tool; Hand and Zoom run in the canvas's tool host.
/// - Tool: the toolbar (a stepped dock column) and the tool keys pick the current tool; Hand and Zoom run in the canvas's tool host.
/// - Menus: every row is an app command with its chord; the body takes them.
/// - Dialogs: Layer, Delete, Layer and Filter, Gaussian Blur open on the window's dialog host; Image, Image Size
/// shows its dialog over the document's size.
@@ -82,7 +81,6 @@ impl<'a> EditorMock<'a> {
.screen_mode(screen_mode)
.title_bar_if(true, |ui, _, state: &mut MockState| title_bar(ui, state))
.options_bar(true, |ui, _, state: &mut MockState| options_bar(ui, state))
.tools(PaneEdge::Start, 1, true, |ui, _, state: &mut MockState| tool_rail(ui, state))
.status(true, |ui, _, state: &mut MockState| status_bar(ui, state))
.body_label(label)
.body(|ui, cx, state: &mut MockState| body(ui, cx, state));
@@ -96,15 +94,22 @@ impl<'a> EditorMock<'a> {
/// The dock, then the commands and dialog answers of this pass.
fn body(ui: &mut Ui, cx: &mut BodyCx<'_>, state: &mut MockState) {
let mut tools = cx.keep::<Tools>().clone();
let events = {
let mut panels = Panels { document: &mut state.document, tool: state.tool, tools: &mut tools };
let ctx = ui.ctx().clone();
let (events, picked) = {
let mut panels =
Panels { document: &mut state.document, tool: state.tool, tools: &mut tools, last_used: &mut state.last_used, picked: None, ctx: &ctx };
// The mock app is a preview inside the gallery's page: its floats stay in it.
let mut area = DockArea::new("Dock", Bind::bound(&mut state.workspace), &mut panels, DockConfig::default().native_windows(false));
let mut area = DockArea::new("Dock", Bind::bound(&mut state.workspace), &mut panels, DockConfig::default().native_windows(false))
.flyout(Bind::bound(&mut state.flyout));
if let Some(panel) = state.maximized {
area = area.maximized(panel);
}
area.show(ui).events
let events = area.show(ui).events;
(events, panels.picked)
};
if let Some(tool) = picked {
select(ui, state, tool);
}
for event in events {
if let DockEvent::ToggleMaximize { panel, .. } = event {
state.maximized = if state.maximized == Some(panel) { None } else { Some(panel) };
@@ -132,8 +137,20 @@ fn body(ui: &mut Ui, cx: &mut BodyCx<'_>, state: &mut MockState) {
let mut dialogs = Vec::new();
for command in asked {
if let Some(panel) = command.panel() {
// A panel in a column collapsed to icons shows in its flyout: the command opens or closes that.
if state.workspace.layout.opens_in_flyout(&panel) {
state.flyout = if state.flyout == Some(panel) { None } else { Some(panel) };
continue;
}
let shown = state.workspace.layout.panel_state(&panel) != PanelState::Hidden;
let panels = Panels { document: &mut state.document, tool: state.tool, tools: &mut tools };
let panels = Panels {
document: &mut state.document,
tool: state.tool,
tools: &mut tools,
last_used: &mut state.last_used,
picked: None,
ctx: &ctx,
};
let _ = state.workspace.set_visible(panel, !shown, None, false, |panel| panels.permissions(panel));
continue;
}
@@ -249,7 +266,12 @@ fn title_bar(ui: &mut Ui, state: &MockState) {
}),
MenuTitle::new("&Window", |ui| {
for panel in Panel::ALL {
let shown = state.workspace.layout.panel_state(&panel) != PanelState::Hidden;
let layout = &state.workspace.layout;
let shown = if layout.opens_in_flyout(&panel) {
state.flyout == Some(panel)
} else {
layout.panel_state(&panel) != PanelState::Hidden
};
MenuItem::command(AppCommand::showing(panel)).check(shown).enabled(!panel.protected()).show(ui);
}
}),
@@ -269,19 +291,6 @@ fn options_bar(ui: &mut Ui, state: &MockState) {
});
}
fn tool_rail(ui: &mut Ui, state: &mut MockState) {
let slots = Tool::slots();
let current = state.tool;
let last_used = state.last_used.clone();
let output = ToolRail::new("Tools", &slots, &current, &last_used).show_rail(ui, |_, _| {});
if let Some(tool) = output.select {
select(ui, state, tool);
}
if let Some(last_used) = output.last_used {
state.last_used = last_used;
}
}
/// The status bar: the zoom and the chosen readout item, the colour mode, the layer count and the message, and the
/// render-path warning at the end.
fn status_bar(ui: &mut Ui, state: &mut MockState) {
+17 -3
View File
@@ -25,6 +25,9 @@ const DOCUMENT_HEIGHT: f64 = 800.0;
/// The share of the dock the canvas group takes.
const CANVAS_SHARE: f32 = 0.8;
/// The width of the dock that holds the toolbar: room for its column at two steps.
const TOOLS_DOCK_WIDTH: f32 = 120.0;
/// The tools of the rail. Each is a command of the `tools` group; a tool alone in its slot carries its letter, and the
/// letter of a slot with several is the pick command of [`ToolKey`].
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, CommandSet)]
@@ -146,6 +149,8 @@ impl ColorPair {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Panel {
/// The toolbar: a stepped column of tool buttons that docks and floats by dragging.
Tools,
/// The document tabs over the canvas.
Canvas,
/// The Navigator.
@@ -156,7 +161,7 @@ pub enum Panel {
impl Panel {
/// Every panel, in the Window menu's order.
pub const ALL: [Panel; 3] = [Panel::Canvas, Panel::Navigator, Panel::Layers];
pub const ALL: [Panel; 4] = [Panel::Tools, Panel::Canvas, Panel::Navigator, Panel::Layers];
/// Whether the panel stays docked and open: the canvas.
pub const fn protected(self) -> bool {
@@ -412,12 +417,20 @@ pub struct MockState {
pub colors: ColorPair,
/// The panel whose frame shows alone.
pub maximized: Option<Panel>,
/// The panel open in the flyout of a column collapsed to icons.
pub flyout: Option<Panel>,
}
impl Default for MockState {
fn default() -> Self {
let side = Column::new(vec![Group::new(vec![Panel::Navigator], 0), Group::new(vec![Panel::Layers], 0)]).with_width(SIDE_WIDTH);
let root = Node::split(Axis::X, SplitSize::Ratio(CANVAS_SHARE), Node::tabs(vec![Panel::Canvas], 0), Node::dock(DockEdge::End, vec![side]));
// The toolbar sits in a dock of its own at the start, one tool column wide; its column keeps that grid.
let tools = Column::new(vec![Group::new(vec![Panel::Tools], 0)]).with_steps(1);
let side = Column::new(vec![Group::new(vec![Panel::Layers], 0)]).with_width(SIDE_WIDTH);
let mut icons = Column::new(vec![Group::new(vec![Panel::Navigator], 0)]).with_width(SIDE_WIDTH);
icons.iconic = true;
let canvas =
Node::split(Axis::X, SplitSize::Ratio(CANVAS_SHARE), Node::tabs(vec![Panel::Canvas], 0), Node::dock(DockEdge::End, vec![side, icons]));
let root = Node::split(Axis::X, SplitSize::FixedFirst(TOOLS_DOCK_WIDTH), Node::dock(DockEdge::Start, vec![tools]), canvas);
MockState {
workspace: Workspace::new(Layout::new(Some(root), Vec::new())),
document: Document::default(),
@@ -427,6 +440,7 @@ impl Default for MockState {
status: None,
colors: ColorPair::default(),
maximized: None,
flyout: None,
}
}
}
+45 -3
View File
@@ -21,6 +21,7 @@ use craft_ui::docking::{DockPanels, GroupAt, PanelSpec};
use craft_ui::list::{ListRow, ToggleCell};
use craft_ui::patterns::canvas::NavigatorPanel;
use craft_ui::primitives::textures::Revision;
use craft_ui::rails::{LastUsed, ToolRail};
use craft_ui::runtime::env::UnitKind;
use craft_ui::shell::CanvasPanel;
use craft_ui::table::Table;
@@ -42,9 +43,36 @@ pub(super) struct Panels<'a> {
pub(super) document: &'a mut Document,
pub(super) tool: Tool,
pub(super) tools: &'a mut Tools,
/// The tool each toolbar slot showed last; the toolbar writes it.
pub(super) last_used: &'a mut LastUsed<Tool>,
/// The tool the toolbar picked in this pass.
pub(super) picked: Option<Tool>,
/// The context the toolbar's grid is measured in.
pub(super) ctx: &'a egui::Context,
}
impl Panels<'_> {
/// The toolbar's rail in the rect the dock gives it, or its height at a width: as many tool columns as the width
/// holds. The rail's own padding surrounds the buttons, so no group padding applies.
fn toolbar(&mut self, ui: &mut Ui, at: GroupAt) -> f32 {
let slots = Tool::slots();
let (current, last_used) = (self.tool, self.last_used.clone());
let rail = ToolRail::new("Tools", &slots, &current, &last_used);
match at {
GroupAt::Measure(width) => rail.measure_rail(ui, width, |_, _| {}).y,
GroupAt::Show(rect) => {
let output = rail.show_rail(ui, |_, _| {});
if output.select.is_some() {
self.picked = output.select;
}
if let Some(next) = output.last_used {
*self.last_used = next;
}
rect.height()
}
}
}
/// The document tab's title: the name, the zoom of the device and the current layer.
fn tab_title(&self, ui: &Ui, cx: &BodyCx<'_>) -> String {
let document = &self.document;
@@ -56,6 +84,7 @@ impl Panels<'_> {
fn name(panel: Panel) -> &'static str {
match panel {
Panel::Tools => "Tools",
Panel::Canvas => "Canvas",
Panel::Navigator => "Navigator",
Panel::Layers => "Layers",
@@ -65,11 +94,21 @@ fn name(panel: Panel) -> &'static str {
impl DockPanels<Panel> for Panels<'_> {
fn spec(&self, panel: &Panel) -> PanelSpec {
let spec = PanelSpec::new(name(*panel)).limits(SizeLimits::default());
if *panel == Panel::Canvas { spec.canvas() } else { spec }
match panel {
Panel::Canvas => spec.canvas(),
// The toolbar's column is whole tool columns wide.
Panel::Tools => spec.grid(ToolRail::<Tool>::dock_grid(self.ctx, Tool::slots().len())),
_ => spec,
}
}
fn permissions(&self, panel: &Panel) -> Permissions {
if panel.protected() { Permissions::PROTECTED } else { Permissions::ALL }
match panel {
// The toolbar never collapses to icons and never shares its column.
Panel::Tools => Permissions::ALL.collapses(false).shares_column(false),
_ if panel.protected() => Permissions::PROTECTED,
_ => Permissions::ALL,
}
}
fn body(&mut self, panel: &Panel, ui: &mut Ui, cx: &mut BodyCx<'_>) {
@@ -79,11 +118,14 @@ impl DockPanels<Panel> for Panels<'_> {
let _ = NavigatorPanel::new("Navigator", Bind::bound(&mut self.document.view), size).show(ui);
}
Panel::Layers => layers(ui, cx, self.document),
Panel::Canvas => {}
Panel::Canvas | Panel::Tools => {}
}
}
fn group_view(&mut self, panels: &[Panel], _: usize, ui: &mut Ui, at: GroupAt, cx: &mut BodyCx<'_>) -> Option<f32> {
if panels.contains(&Panel::Tools) {
return Some(self.toolbar(ui, at));
}
// The canvas fills the rect it is shown in; protected, it never sits in a flyout, which is what measures.
let GroupAt::Show(rect) = at else { return None };
if !panels.contains(&Panel::Canvas) {
+1
View File
@@ -1,5 +1,6 @@
//! The viewer's integration tests: one binary, run by `libtest-mimic` over the registered trials.
mod mock;
mod overview;
mod viewer;
+32
View File
@@ -0,0 +1,32 @@
//! The mock editor's dock: the toolbar is a stepped column and the Navigator a collapsed one.
use craft_ui::runtime::access::Role;
use craft_ui::testing::{Fixture, trial};
use craft_ui_gallery::mock::{EditorMock, MockState};
use egui::Vec2;
use std::cell::RefCell;
use std::rc::Rc;
fn editor() -> Fixture {
let state = Rc::new(RefCell::new(MockState::default()));
let mut fixture = Fixture::new(move |ui| {
let mut state = state.borrow_mut();
EditorMock::new("Editor", &mut state).show(ui);
});
fixture.room(Vec2::new(1000.0, 700.0)).settle();
fixture
}
/// The toolbar is one tool column of the dock, not a shell rail: its buttons stand in one column that ends above the
/// foot of the window, and the Navigator shows as an icon of a collapsed column.
#[trial]
fn the_mock_toolbar_is_a_stepped_dock_column_and_the_navigator_an_icon() {
let fixture = editor();
let rect = |label: &str| fixture.by_label(label).unwrap_or_else(|| panic!("{label} is shown")).rect;
let (first, last) = (rect("Move"), rect("Clone Stamp"));
assert!((first.left() - last.left()).abs() < 1.0, "the tools stand in one column: {first:?} and {last:?}");
assert!(last.bottom() < fixture.shown().bottom() - 20.0, "the column ends above the foot of the window: {last:?}");
let tree = fixture.tree();
let navigator = fixture.by_role(Role::BUTTON).into_iter().any(|button| tree.name_of(button.node) == Some("Navigator"));
assert!(navigator, "the Navigator shows as an icon of its collapsed column");
}
+5 -15
View File
@@ -191,7 +191,7 @@ impl<S> Placed<'_, S> {
}
}
/// The slot's extent along its edge: its size, or the default of its edge, with a rail's columns side by side.
/// The slot's extent along its edge: its size, or the default of its edge.
fn extent(&self, tokens: &UiTokens) -> f32 {
let size = self.slot.slot_size().unwrap_or(match self.edge {
PaneEdge::Top if self.title => SlotSize::TitleBar,
@@ -199,8 +199,7 @@ impl<S> Placed<'_, S> {
PaneEdge::Bottom => SlotSize::StatusBar,
_ => SlotSize::RailWidth,
});
let columns = if matches!(self.edge, PaneEdge::Start | PaneEdge::End) { self.slot.column_count() } else { 1 };
size.resolve(tokens) * columns as f32
size.resolve(tokens)
}
}
@@ -263,8 +262,8 @@ impl Outcome for AppShellOutput {
/// a reveal. The shell takes its own window's Tab toggles from the frame state in the pass that records them: in
/// normal mode Tab hides every slot and panel and shows them again.
/// - **Canvas preset.** [`title_bar_if`](Self::title_bar_if), [`options_bar`](Self::options_bar),
/// [`tools`](Self::tools) and [`status`](Self::status) add the slots of a document editor under the keys of
/// [`slots`](super::slots), named by `ShellWords`; each takes the host's `visible` flag, passed every frame.
/// and [`status`](Self::status) add the slots of a document editor under the keys of [`slots`](super::slots),
/// named by `ShellWords`; the toolbar is a panel of the dock, not a slot; each takes the host's `visible` flag, passed every frame.
/// - **Shell data.** Slots and the body read the skeleton with `BodyCx::shell()`.
/// - **App state.** `S` is the state the slots and the body edit; [`show`](Self::show) hands each of them `&mut S` in
/// turn, so a title bar, a rail and a body that edit one document share it without interior mutability. An app with
@@ -370,15 +369,6 @@ impl<'a, S> AppShell<'a, S> {
self
}
/// The tool rail, a slot keyed `"tools"` at `edge` (the reading start or end) that reveals in body-only mode, as
/// wide as the rail's `columns` (1 or 2, the count the host gives its `ToolRail`). It is the Tools region on either
/// edge.
pub fn tools(mut self, edge: PaneEdge, columns: usize, visible: bool, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
let slot = Slot::new(keys::TOOLS).columns(columns).visible(visible).reveal();
self.slots.push(Placed { slot, edge, title: false, named: Some(|words| words.tools.clone()), add: Box::new(add) });
self
}
/// The status bar, a bottom slot keyed `"status"` that never reveals.
pub fn status(mut self, visible: bool, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
let slot = Slot::new(keys::STATUS).visible(visible);
@@ -412,7 +402,7 @@ impl<'a, S> AppShell<'a, S> {
}
/// Gives the slot keyed `key`, added before, the version of the app data it shows ([`Slot::content`]), for the
/// slots the `options_bar`, `tools` and `status` builders make.
/// slots the `options_bar` and `status` builders make.
pub fn content(mut self, key: SlotKey, version: u64) -> Self {
for placed in self.title.iter_mut().chain(self.slots.iter_mut()).filter(|placed| placed.slot.key() == key) {
placed.slot = placed.slot.clone().content(version);
@@ -2,7 +2,7 @@
use super::{AppShell, ShellRegion};
use crate::choice::Checkbox;
use crate::contract::{Bind, PaneEdge, Props as _, Show as _, ShowContainer as _};
use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _};
use crate::dialog::Dialog;
use crate::display::Text;
use crate::layout_components::Grid;
@@ -45,9 +45,6 @@ fn app_shell_canvas(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
.options_bar(true, |ui, _, _| {
Text::new("Options").show(ui);
})
.tools(PaneEdge::Start, 1, true, |ui, _, _| {
Text::new("Tools").show(ui);
})
.status(true, |ui, _, _| {
Text::new("Status").show(ui);
})
+4 -6
View File
@@ -1,13 +1,13 @@
//! The canvas preset's slot keys and `CanvasPanel`, which lays out the canvas panel in the body of a document editor's
//! shell. The editor's slots are the canvas setters of `AppShell` (`title_bar_if`, `options_bar`, `tools`, `status`).
//! shell. The editor's slots are the canvas setters of `AppShell` (`title_bar_if`, `options_bar`, `status`).
//!
//! ```text
//! +-----------------------------------------+
//! | title |
//! | options |
//! +-------+---------------------------------+
//! | tools | body (dock with canvas panel) |
//! +-------+---------------------------------+
//! +-----------------------------------------+
//! | body (dock with toolbar, canvas panel) |
//! +-----------------------------------------+
//! | status |
//! +-----------------------------------------+
//!
@@ -37,8 +37,6 @@ pub mod slots {
pub const TITLE: SlotKey = "title";
/// The options bar, below the title.
pub const OPTIONS: SlotKey = "options";
/// The tool rail at the start edge.
pub const TOOLS: SlotKey = "tools";
/// The status bar, the lowest bottom bar.
pub const STATUS: SlotKey = "status";
}
+2 -15
View File
@@ -20,7 +20,7 @@ pub enum SlotSize {
OptionsBar,
/// `size.bar.options_narrow`: the options bar of a window too small for the full bar.
OptionsBarNarrow,
/// `size.rail.width`: one column of a rail; [`Slot::columns`] says how many columns the slot lays out.
/// `size.rail.width`: the default extent of a start or end slot.
RailWidth,
}
@@ -52,7 +52,6 @@ impl SlotSize {
pub struct Slot {
key: SlotKey,
size: Option<SlotSize>,
columns: usize,
visible: bool,
reveal: bool,
label: Option<Label>,
@@ -63,7 +62,7 @@ impl Slot {
/// A slot with a key that is stable and unique in the window. It is visible and does not show in a reveal. Without a
/// [`size`](Self::size) it takes the default of its edge: the title bar, options bar, status bar or rail width.
pub fn new(key: SlotKey) -> Self {
Self { key, size: None, columns: 1, visible: true, reveal: false, label: None, content: None }
Self { key, size: None, visible: true, reveal: false, label: None, content: None }
}
/// The size along the slot's edge, in place of the default of the edge.
@@ -72,13 +71,6 @@ impl Slot {
self
}
/// The number of rail columns of a start or end slot, clamped to 1 and 2. The slot keeps [`SlotSize::RailWidth`] per
/// column and the shell lays the columns out side by side, so the slot's extent is its columns wide.
pub fn columns(mut self, columns: usize) -> Self {
self.columns = columns.clamp(1, 2);
self
}
/// Whether the slot shows in normal mode: the host's flag, passed every frame. A slot that is not visible is not
/// built.
pub fn visible(mut self, visible: bool) -> Self {
@@ -128,11 +120,6 @@ impl Slot {
self.size
}
/// The number of rail columns, 1 or 2.
pub fn column_count(&self) -> usize {
self.columns
}
/// The host's visibility flag for normal mode.
pub fn is_visible(&self) -> bool {
self.visible
-1
View File
@@ -9,7 +9,6 @@ craft_ui::words! {
document: "appShell.document" = "Document";
document_tabs: "appShell.documentTabs" = "Document Tabs";
options: "appShell.options" = "Options";
tools: "appShell.tools" = "Tools";
status: "appShell.status" = "Status";
screen_mode: "appShell.screenMode" = "Screen Mode";
+2 -50
View File
@@ -1,9 +1,9 @@
//! The app shell's named slots: a slot keeps its region name on either edge, a bar in a top or bottom slot fills it
//! The app shell's named slots: a bar in a top or bottom slot fills it
//! with its members on the slot's middle, and a slot with a content version settles.
use craft_ui::bars::{Bar, BarKind};
use craft_ui::buttons::Button;
use craft_ui::contract::{PaneEdge, Role, Show as _, ShowContainer as _};
use craft_ui::contract::{Show as _, ShowContainer as _};
use craft_ui::display::Text;
use craft_ui::layout_components::{Row, Stack};
use craft_ui::runtime::env::WindowKey;
@@ -14,54 +14,6 @@ use egui::{Rect, Vec2};
use std::cell::Cell;
use std::rc::Rc;
/// A tool rail placed at the end edge sits at the window's end and screen readers still find it as the Tools region.
#[trial]
fn the_tool_rail_at_the_end_edge_is_the_tools_region() {
let mut frames = Frames::new();
let mut placed = None;
for _ in 0..3 {
frames.frame(vec![], |ui| {
let window = ui.max_rect();
let out = AppShell::new(WindowKey::main())
.tools(PaneEdge::End, 1, true, |ui, _, _: &mut ()| {
Text::new("Rail").show(ui);
})
.body(|_, _, _| {})
.show(ui, &mut ());
placed = out.regions.slots.first().map(|(_, rect)| (*rect, window));
});
}
let (rail, window) = placed.expect("the rail shows");
assert!(rail.center().x > window.center().x, "the rail sits at the end edge: {rail:?} in {window:?}");
let tree = frames.tree();
let names: Vec<&str> = tree.with_role(Role::GROUP).into_iter().filter_map(|key| tree.name_of(key)).collect();
assert!(names.contains(&"Tools"), "the end-edge rail is the Tools region: {names:?}");
}
/// A two-column tool rail gets a slot two rail columns wide, so its second column is not cut off.
#[trial]
fn a_two_column_tool_rail_is_twice_as_wide_as_one_column() {
let width = |columns: usize| {
let mut frames = Frames::new();
let mut width = 0.0;
for _ in 0..2 {
frames.frame(vec![], |ui| {
let out = AppShell::new(WindowKey::main())
.tools(PaneEdge::Start, columns, true, |ui, _, _: &mut ()| {
Text::new("Rail").show(ui);
})
.body(|_, _, _| {})
.show(ui, &mut ());
width = out.regions.slots.first().map_or(0.0, |(_, rect)| rect.width());
});
}
width
};
let (one, two) = (width(1), width(2));
assert!(one > 0.0, "the rail shows");
assert!((two - 2.0 * one).abs() < 0.5, "two columns take two rail widths: {one} and {two}");
}
/// What the options-bar trial saw: the slot, the bar, a member of the bar and a member of a row nested in it.
#[derive(Clone, Copy)]
struct InSlot {
+3 -3
View File
@@ -1,10 +1,10 @@
//! Tab in a window shell: it hides and shows the chrome, and a screen-mode change clears what it did.
use craft_ui::contract::{Bind, PaneEdge, Show as _};
use craft_ui::contract::{Bind, Show as _};
use craft_ui::display::Text;
use craft_ui::runtime::env::{RootEnv, WindowKey};
use craft_ui::runtime::focus::{KeyUse, host_canvas};
use craft_ui::shell::{AppShell, ScreenMode};
use craft_ui::shell::{AppShell, ScreenMode, Slot};
use craft_ui::testing::{Frames, trial};
use egui::{Event, Key, Modifiers, Sense};
@@ -24,7 +24,7 @@ fn shown(windows: &mut Frames, mode: &mut ScreenMode, events: Vec<Event>) -> (us
windows.frame(events, |ui| {
let out = AppShell::new(WindowKey::main())
.screen_mode(Bind::bound(&mut *mode))
.tools(PaneEdge::Start, 1, true, |ui, _, _: &mut ()| {
.start(Slot::new("tools").reveal(), |ui, _, _: &mut ()| {
Text::new("Tools").show(ui);
})
.options_bar(false, |ui, _, _: &mut ()| {
@@ -19,7 +19,7 @@ name = "CanvasShell"
old = "craft_ui::shell::CanvasShell"
new = ""
status = "removed"
note = "Deleted; its job is `craft_ui::shell::AppShell` with the canvas slot setters `title_bar_if(visible, f)`, `options_bar(visible, f)`, `tools(visible, f)` and `status(visible, f)`; the other setters are `AppShell`'s own. The slot keys are `craft_ui::shell::slots`."
note = "Deleted; its job is `craft_ui::shell::AppShell` with the canvas slot setters `title_bar_if(visible, f)`, `options_bar(visible, f)` and `status(visible, f)`; the toolbar is a panel of the dock, not a slot; the other setters are `AppShell`'s own. The slot keys are `craft_ui::shell::slots`."
[[type]]
name = "StartScreen"
@@ -120,7 +120,7 @@ note = "The runtime ends a press the operating system took over; an app installs
type = "Slot"
old = "height(f32)"
new = "size(SlotSize)"
note = "A size is a named theme size: `SlotSize::TitleBar`, `TabBar`, `StatusBar`, `OptionsBar`, `OptionsBarNarrow`, `RailWidth` (per column; `Slot::columns(n)` says how many rail columns)."
note = "A size is a named theme size: `SlotSize::TitleBar`, `TabBar`, `StatusBar`, `OptionsBar`, `OptionsBarNarrow`, `RailWidth` (the default extent of a start or end slot)."
[[setter]]
type = "Slot"