mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 15:44:26 +00:00
Rails: ToolRail lays out the columns its width holds with a measure and dock grid; PanelRail and the CanvasPanel rail removed
This commit is contained in:
@@ -126,7 +126,6 @@ pub(super) const SURFACES: &[(&str, &str, Surface)] = &[
|
||||
("craft_ui", "PaneArea", Own),
|
||||
("craft_ui", "PaneFrame", Own),
|
||||
("craft_ui", "Panel", Own),
|
||||
("craft_ui", "PanelRail", Chrome),
|
||||
("craft_ui", "ParamDialog", Own),
|
||||
("craft_ui", "ParamRows", Own),
|
||||
("craft_ui", "PasswordDialog", Own),
|
||||
|
||||
@@ -33,7 +33,7 @@ pub enum GlyphRole {
|
||||
Tool,
|
||||
/// A tool rail: `size.icon.lg`, resting in `text.muted` and in the variant's ink under the pointer.
|
||||
ToolRail,
|
||||
/// A panel rail, or a list row's trailing icon button: the control glyph, resting in `text.faint` and in the variant's ink under the pointer.
|
||||
/// A list row's trailing icon button: the control glyph, resting in `text.faint` and in the variant's ink under the pointer.
|
||||
PanelRail,
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ pub use crate::runtime::measure::{
|
||||
pub use craft_ui_macros::{story, trial};
|
||||
pub use fixture::{Fixture, Impure, Room, Target};
|
||||
pub use frames::Frames;
|
||||
pub use stage::{in_edge_pane, room_height, stage, stage_fitting, stage_width};
|
||||
pub use stage::{room_height, stage, stage_fitting, stage_width};
|
||||
#[doc(hidden)]
|
||||
pub use story::{
|
||||
CollectionKind, Drive, EditKind, Grip, Required, Story, StoryData, StoryOutput, StoryRegistration, StorySnapshot, show_as_only_item, stories,
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
//! The room a story that fills both axes is shown in.
|
||||
|
||||
use crate::contract::PaneEdge;
|
||||
use crate::layout::flow_room;
|
||||
use crate::primitives::{RectSide, Rule};
|
||||
use crate::runtime::env::Env;
|
||||
use crate::style::{RuleKind, rule_look};
|
||||
use egui::{Rect, Ui};
|
||||
|
||||
/// Allocates the stage of a story of a canvas control or a root that fills both axes, and returns its rect: the width
|
||||
@@ -37,16 +34,3 @@ pub fn stage_width(ui: &Ui) -> f32 {
|
||||
let room = if room.is_finite() { room } else { ui.available_width() };
|
||||
room.clamp(story.width_min, story.width_max)
|
||||
}
|
||||
|
||||
/// Runs `story` as the content of an edge pane at `edge`, as a rail or panel docked at that edge of an app window
|
||||
/// shows: with the divider the pane draws along its inner edge (`ContainerProps::edge_rule`), here along the edge of
|
||||
/// what the story drew.
|
||||
pub fn in_edge_pane<R>(ui: &mut Ui, edge: PaneEdge, story: impl FnOnce(&mut Ui) -> R) -> R {
|
||||
let shown = ui.scope(story);
|
||||
let env = Env::of(ui);
|
||||
if let Some(side) = RectSide::toward_centre(edge, env.direction.is_rtl()) {
|
||||
let rule = rule_look(&env.tokens, RuleKind::Divider);
|
||||
ui.painter().extend(Rule::edge(&rule, shown.response.rect, side, ui.ctx().pixels_per_point()));
|
||||
}
|
||||
shown.inner
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//! `ToolbarDrawer`: Edit Toolbar's All Tools drawer beside the tool rail, where tools move between the toolbar and the
|
||||
//! drawer.
|
||||
|
||||
use super::tool::{DropAt, RailTool, SlotId, ToolDrag, ToolDropped, ToolSlot, canvas_side};
|
||||
use super::tool::{DropAt, RailTool, SlotId, ToolDrag, ToolDropped, ToolSlot};
|
||||
use super::words::RailWords;
|
||||
use crate::buttons::{Button, IconButton};
|
||||
use crate::contract::overlay::{Anchor, Dismiss, Overlay, Place};
|
||||
use crate::contract::{
|
||||
ActivateOn, Bind, CollectionEvent, Gap, ListDrag, NoValue, Outcome, PaneEdge, Props as _, SelectMode, Show as _, ShowCollection as _,
|
||||
ShowContainer as _, Sizing, clicked,
|
||||
ActivateOn, Bind, CollectionEvent, Gap, ListDrag, NoValue, Outcome, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _,
|
||||
Sizing, clicked,
|
||||
};
|
||||
use crate::display::{Shade, Text};
|
||||
use crate::layout_components::{Row, Stack};
|
||||
@@ -19,7 +19,7 @@ use crate::runtime::env::{Env, Label};
|
||||
use crate::runtime::windows::os_of;
|
||||
use crate::sections::DropAction;
|
||||
use crate::style::TypeRole;
|
||||
use craft_behavior::overlay::Align;
|
||||
use craft_behavior::overlay::{Align, Side};
|
||||
use craft_behavior::{DisplayOrder, IconId, ItemSource, Value};
|
||||
use egui::{Rect, Response, Ui};
|
||||
use std::borrow::Cow;
|
||||
@@ -132,9 +132,9 @@ pub struct ToolbarDrawer<'a, T: Value + 'static> {
|
||||
rail: Rect,
|
||||
groups: &'a [DrawerGroup<T>],
|
||||
toolbar: &'a [ToolSlot<T>],
|
||||
/// The window edge the rail sits at, as given to `ToolRail::edge`: the drawer opens on the rail's canvas side.
|
||||
/// The side of the rail the drawer opens on, as given to `ToolRail::opens`: the side of the canvas.
|
||||
#[prop]
|
||||
edge: PaneEdge,
|
||||
opens: Side,
|
||||
dropped: Option<ToolDropped>,
|
||||
opener: Option<Response>,
|
||||
}
|
||||
@@ -143,7 +143,7 @@ impl<'a, T: Value + 'static> ToolbarDrawer<'a, T> {
|
||||
/// A drawer beside `rail` (the rail's rect), listing `groups`, over a toolbar of `toolbar` slots. `dropped` is the
|
||||
/// drag the rail took in this pass (`ToolRailOutput::dropped`); the drawer turns it into an edit.
|
||||
pub fn new(rail: Rect, groups: &'a [DrawerGroup<T>], toolbar: &'a [ToolSlot<T>], dropped: Option<ToolDropped>) -> Self {
|
||||
ToolbarDrawer { rail, groups, toolbar, edge: PaneEdge::Start, dropped, opener: None }
|
||||
ToolbarDrawer { rail, groups, toolbar, opens: Side::End, dropped, opener: None }
|
||||
}
|
||||
|
||||
/// The control that opened the drawer, the rail's Edit Toolbar button (`ToolRailOutput::edit_toolbar`): the focus
|
||||
@@ -216,8 +216,7 @@ fn on_toolbar<T: PartialEq>(toolbar: &[ToolSlot<T>], id: &T) -> bool {
|
||||
impl<T: Value + 'static> ToolbarDrawer<'_, T> {
|
||||
/// Shows the drawer and reports what the user changed.
|
||||
pub fn show(self, ui: &mut Ui) -> ToolbarDrawerOutput<T> {
|
||||
let ToolbarDrawer { rail, groups, toolbar, edge, dropped, opener } = self;
|
||||
let opens = canvas_side(edge);
|
||||
let ToolbarDrawer { rail, groups, toolbar, opens, dropped, opener } = self;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<RailWords>();
|
||||
let os = os_of(ui.ctx());
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
//! `PanelRail`, `ToolRail`, `FlyoutButton` and `ToolbarDrawer`.
|
||||
//! `ToolRail`, `FlyoutButton` and `ToolbarDrawer`.
|
||||
|
||||
mod words;
|
||||
|
||||
// The panel rail and the Edit Toolbar drawer.
|
||||
// The Edit Toolbar drawer.
|
||||
mod drawer;
|
||||
mod panel_rail;
|
||||
|
||||
// The tool rail and its flyout button.
|
||||
mod flyout;
|
||||
@@ -12,7 +11,6 @@ mod tool;
|
||||
|
||||
pub use drawer::{DrawerGroup, ToolbarDrawer, ToolbarDrawerOutput, ToolbarEdit, apply_toolbar_edit, drop_edit};
|
||||
pub use flyout::{FlyoutButton, FlyoutButtonStyle, FlyoutOutput, SlotEdit};
|
||||
pub use panel_rail::{PanelRail, PanelRailOutput, PanelRailRequest, PanelRailStyle};
|
||||
pub use tool::{
|
||||
DropAt, LastUsed, RailFooter, RailTool, SlotId, ToolDrag, ToolDropped, ToolRail, ToolRailOutput, ToolRailStyle, ToolSlot, drop_in_slot,
|
||||
remembered, shown_tool, visible_slots,
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
//! `PanelRail`: the rail of icons that open panels.
|
||||
|
||||
use super::flyout::FlyoutButton;
|
||||
use super::tool::RailTool;
|
||||
use super::words::RailWords;
|
||||
use crate::contract::{
|
||||
Access, BodyCx, BodyLayout, Common, Component, Container, ContainerProps, Cx, FooterRegion, Gap, NoValue, Outcome, Pad, Props as _, Role, Scroll,
|
||||
Show as _, ShowContainer as _, Sizing, WordSetCx as _,
|
||||
};
|
||||
use crate::runtime::access::Name;
|
||||
use crate::runtime::commands;
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::{ComponentStyle, GlyphRole, StyleCx, SurfaceKind};
|
||||
use craft_behavior::{Metrics, NavShape, Roving, Sense, Value};
|
||||
use craft_theme::ControlSize;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
#[cfg(feature = "testing")]
|
||||
pub(super) mod stories;
|
||||
#[cfg(feature = "testing")]
|
||||
mod trials;
|
||||
|
||||
/// The style of a panel rail: it paints its chrome surface and takes its spacing from the body gap its props name.
|
||||
#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)]
|
||||
#[non_exhaustive]
|
||||
pub struct PanelRailStyle {
|
||||
#[style(metrics)]
|
||||
metrics: Metrics,
|
||||
}
|
||||
|
||||
/// What a click on a panel's icon asks the host to do.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum PanelRailRequest<P> {
|
||||
/// Open the panel: its icon was clicked while the panel was closed.
|
||||
Open(P),
|
||||
/// Close the panel: its icon was clicked while the panel was open.
|
||||
Close(P),
|
||||
}
|
||||
|
||||
/// What a panel rail reports.
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub struct PanelRailOutput<P> {
|
||||
/// The rail's response.
|
||||
pub response: Response,
|
||||
/// The panel the user asked to open or close this pass. Its command has run.
|
||||
pub request: Option<PanelRailRequest<P>>,
|
||||
/// Each icon's response, in order, so the host can hang a context menu on an icon or start a dock drag from it.
|
||||
/// The rail does neither.
|
||||
pub items: Vec<(P, Response)>,
|
||||
}
|
||||
|
||||
impl<P: Value> Outcome for PanelRailOutput<P> {
|
||||
type Value = NoValue;
|
||||
|
||||
fn response(&self) -> &Response {
|
||||
&self.response
|
||||
}
|
||||
}
|
||||
|
||||
type FooterFn<'a> = Box<dyn FnMut(&mut Ui) + 'a>;
|
||||
|
||||
/// The rail of icons that open panels, as a side panel at one edge of the window; the pane it sits in draws the rule
|
||||
/// along the edge that faces the canvas. A panel is a toggle command: its
|
||||
/// label, icon, chord and enabled state come from the command, the icon shows the on look while the command is
|
||||
/// checked (the panel is open), and the command's `marked` state and `hint` mark a closed panel that has content
|
||||
/// to show. A click runs the command and reports the request that matches the panel's state. The icons are one
|
||||
/// roving group: Up and Down move between them, Enter and Space toggle. The host's footer stays in view under the
|
||||
/// icons, which scroll when the window is short.
|
||||
#[derive(crate::contract::Component, crate::contract::Props)]
|
||||
#[component(container, probe(PanelRail<'static, u8>))]
|
||||
pub struct PanelRail<'a, P: Value + 'static> {
|
||||
#[common]
|
||||
common: Common,
|
||||
#[container]
|
||||
props: ContainerProps,
|
||||
panels: &'a [RailTool<P>],
|
||||
footer: Option<FooterFn<'a>>,
|
||||
}
|
||||
|
||||
impl<'a, P: Value + 'static> PanelRail<'a, P> {
|
||||
/// A rail named `label` of `panels`, each a panel key with the toggle command that opens and closes it.
|
||||
pub fn new(label: impl Into<Label>, panels: &'a [RailTool<P>]) -> Self {
|
||||
let props = ContainerProps::new()
|
||||
.surface(SurfaceKind::Chrome)
|
||||
.pad(Pad::Control)
|
||||
.sizing(Sizing::Content)
|
||||
.layout(BodyLayout::stack())
|
||||
.body_gap(Gap::Tight)
|
||||
.child_size(ControlSize::Md)
|
||||
.child_glyphs(GlyphRole::PanelRail)
|
||||
.roving(Roving::new(NavShape::Flat))
|
||||
.scroll(Scroll::vertical())
|
||||
.footer(FooterRegion::new());
|
||||
PanelRail { common: Common::new(), props, panels, footer: None }.label(label)
|
||||
}
|
||||
|
||||
/// Shows the rail. `footer` draws under the last icon; it stays in view when the window is short.
|
||||
pub fn show_rail(mut self, ui: &mut Ui, footer: impl FnMut(&mut Ui) + 'a) -> PanelRailOutput<P> {
|
||||
self.footer = Some(Box::new(footer));
|
||||
let panels = self.panels;
|
||||
let mut request = None;
|
||||
let mut items = Vec::new();
|
||||
let shown = self.show(ui, |ui, _| {
|
||||
items.clear();
|
||||
let ctx = ui.ctx().clone();
|
||||
for (at, panel) in panels.iter().enumerate() {
|
||||
let open = commands::resolve(&ctx, panel.command.clone()).checked.unwrap_or(false);
|
||||
let button = FlyoutButton::new(std::slice::from_ref(panel), &panel.id).selected(open).id_salt(("panel", at)).show(ui);
|
||||
if button.select.is_some() {
|
||||
request = Some(if open { PanelRailRequest::Close(panel.id.clone()) } else { PanelRailRequest::Open(panel.id.clone()) });
|
||||
}
|
||||
items.push((panel.id.clone(), button.response));
|
||||
}
|
||||
});
|
||||
PanelRailOutput { request, items, ..shown.output }
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: Value + 'static> Component for PanelRail<'_, P> {
|
||||
const ROLE: Role = Role::TOOLBAR;
|
||||
const PARTS: bool = false;
|
||||
const STOPS: bool = false;
|
||||
const OVERLAYS: bool = false;
|
||||
type Style = PanelRailStyle;
|
||||
type Output = PanelRailOutput<P>;
|
||||
|
||||
fn style(_: &StyleCx<'_>, _: PanelRailStyleKey<P>) -> PanelRailStyle {
|
||||
PanelRailStyle::default()
|
||||
}
|
||||
|
||||
fn sense(&self) -> Sense {
|
||||
Sense::empty()
|
||||
}
|
||||
|
||||
/// A rail the caller did not label is named by the words of the family.
|
||||
fn access(&self, access: &mut Access, cx: &Cx<'_, Self>) {
|
||||
if cx.resolved.label.is_empty() {
|
||||
access.name(Name::Text(cx.words::<RailWords>().panels.as_str().to_owned()));
|
||||
}
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> PanelRailOutput<P> {
|
||||
PanelRailOutput { response: cx.response.clone(), request: None, items: Vec::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: Value + 'static> Container for PanelRail<'_, P> {
|
||||
/// The host's footer.
|
||||
fn footer(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) {
|
||||
if let Some(footer) = &mut self.footer {
|
||||
footer(ui);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
//! Stories of `PanelRail`.
|
||||
|
||||
use super::PanelRail;
|
||||
use crate::contract::PaneEdge;
|
||||
use crate::rails::tool::stories::tools;
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, in_edge_pane, story};
|
||||
use egui::Ui;
|
||||
|
||||
#[story(PanelRail<'static, u8>, covers = [Default], drive = Drive::Never)]
|
||||
fn panel_rail(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let panels = tools(&[0, 1, 2, 3]);
|
||||
// Docked at the window's end edge, as an app shows it: its divider runs along the canvas side.
|
||||
in_edge_pane(ui, PaneEdge::End, |ui| PanelRail::new("Panels", &panels).show_rail(ui, |_| {})).into()
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
//! Trials of `PanelRail`: a short window, the content mark and the icons' responses.
|
||||
#![allow(clippy::panic, clippy::expect_used, reason = "trials assert by panicking")]
|
||||
|
||||
use super::PanelRail;
|
||||
use crate::buttons::Button;
|
||||
use crate::contract::Show as _;
|
||||
use crate::rails::tool::stories::{StoryTools, tools};
|
||||
use crate::runtime::commands::CommandState;
|
||||
use crate::testing::pointer::{moved, wheel};
|
||||
use crate::testing::relations::{above, centred_across, grows_with, on_one_line};
|
||||
use crate::testing::{Fixture, trial};
|
||||
use egui::{Rect, Shape, Vec2};
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// The bounds of the node labelled `label`.
|
||||
fn rect(fixture: &Fixture, label: &str) -> Rect {
|
||||
fixture.by_label(label).unwrap_or_else(|| panic!("{label} is shown")).rect
|
||||
}
|
||||
|
||||
/// When the window is too short for every icon, the footer stays in view at the bottom and the icons scroll in the
|
||||
/// room above it, down to a room smaller than one scroll region's usual least height.
|
||||
#[trial]
|
||||
fn in_a_short_window_the_icons_scroll_above_the_footer_that_stays_in_view() {
|
||||
for height in [160.0, 100.0] {
|
||||
let mut fixture = Fixture::new(|ui| {
|
||||
let panels = tools(&[0, 1, 2, 3, 4]);
|
||||
PanelRail::new("Panels", &panels).show_rail(ui, |ui| {
|
||||
Button::new("Foot").show(ui);
|
||||
});
|
||||
});
|
||||
fixture.room(Vec2::new(48.0, height)).settle();
|
||||
let foot = rect(&fixture, "Foot");
|
||||
assert!(foot.bottom() <= height, "{height}: the footer is in the room: {foot:?}");
|
||||
let first = rect(&fixture, "Move");
|
||||
assert!(first.top() < foot.top(), "{height}: the first icon is above the footer: {first:?}");
|
||||
assert!(rect(&fixture, "Clone Stamp").bottom() > foot.top(), "{height}: the last icon starts out of view");
|
||||
|
||||
fixture.frame(vec![moved(first.center())]);
|
||||
for _ in 0..10 {
|
||||
fixture.frame(vec![wheel(-120.0)]);
|
||||
}
|
||||
fixture.settle();
|
||||
let last = rect(&fixture, "Clone Stamp");
|
||||
assert!(grows_with(first.top(), last.top()), "{height}: the last icon is in view after scrolling: {last:?}");
|
||||
assert!(above(last, foot), "{height}: the last icon is above the footer after scrolling: {last:?}");
|
||||
assert_eq!(rect(&fixture, "Foot"), foot, "{height}: the footer stays put");
|
||||
}
|
||||
}
|
||||
|
||||
/// The dots painted inside the Move icon while its panel's command is marked and `open` or closed, and how many item
|
||||
/// responses the rail reported.
|
||||
fn marked_move(open: bool) -> (usize, usize) {
|
||||
let items = Rc::new(Cell::new(0));
|
||||
let reported = Rc::clone(&items);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let panels = tools(&[0, 1, 2]);
|
||||
let out = PanelRail::new("Panels", &panels).show_rail(ui, |_| {});
|
||||
reported.set(out.items.len());
|
||||
});
|
||||
fixture.command_state(StoryTools::Move, CommandState::new().marked(true).checked(open)).room(Vec2::new(48.0, 200.0)).settle();
|
||||
let icon = rect(&fixture, "Move");
|
||||
let dots = fixture.frame_shapes().iter().filter(|shape| matches!(shape, Shape::Circle(dot) if icon.contains(dot.center))).count();
|
||||
(dots, items.get())
|
||||
}
|
||||
|
||||
/// A marked panel's icon shows the mark while the panel is closed, not while it is open, and the rail reports one
|
||||
/// response per icon for the host's menus and drags.
|
||||
#[trial]
|
||||
fn a_marked_panel_icon_shows_its_mark_only_while_the_panel_is_closed_and_each_icon_reports_its_response() {
|
||||
let (closed, items) = marked_move(false);
|
||||
let (open, _) = marked_move(true);
|
||||
assert!(closed > open, "the mark shows while the panel is closed ({closed}) and not while open ({open})");
|
||||
assert_eq!(items, 3, "one response per icon");
|
||||
}
|
||||
|
||||
/// The rails set the glyph role of their buttons: the tool rail's icons are larger than a lone icon button's and rest
|
||||
/// in a quieter ink than they show under the pointer; the panel rail's keep the lone button's side and rest quieter
|
||||
/// than it.
|
||||
#[trial]
|
||||
fn the_rails_show_their_buttons_icons_in_their_glyph_roles() {
|
||||
use crate::buttons::IconButton;
|
||||
use crate::contract::Props as _;
|
||||
use crate::rails::{LastUsed, ToolRail, ToolSlot};
|
||||
use craft_behavior::IconId;
|
||||
let glyphs = |rail: Option<bool>| {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let panels = tools(&[0, 1]);
|
||||
match rail {
|
||||
Some(true) => {
|
||||
let slots = vec![ToolSlot::new(0, panels.clone())];
|
||||
ToolRail::new("Tools", &slots, &0, &LastUsed::default()).show_rail(ui, |_, _| {});
|
||||
}
|
||||
Some(false) => {
|
||||
PanelRail::new("Panels", &panels).show_rail(ui, |_| {});
|
||||
}
|
||||
None => {
|
||||
IconButton::new(IconId::new("move")).label("Alone").show(ui);
|
||||
}
|
||||
}
|
||||
});
|
||||
fixture.settle();
|
||||
let seen = fixture.styles_of(std::any::type_name::<IconButton<'static>>());
|
||||
let glyph = seen.first().and_then(|seen| seen.looks.icons.first().cloned());
|
||||
glyph.unwrap_or_else(|| panic!("an icon button showed ({rail:?})"))
|
||||
};
|
||||
let (alone, tool, panel) = (glyphs(None), glyphs(Some(true)), glyphs(Some(false)));
|
||||
assert!(tool.side > alone.side, "a tool rail icon ({}) is larger than a lone one ({})", tool.side, alone.side);
|
||||
assert!(tool.color.off.rest != tool.color.off.hover, "a tool rail icon rests quieter than under the pointer");
|
||||
assert_eq!(panel.side, alone.side, "a panel rail icon keeps the control glyph");
|
||||
assert!(panel.color.off.rest != alone.color.off.rest, "a panel rail icon rests quieter than a lone one");
|
||||
}
|
||||
|
||||
/// A tool rail is as wide as its columns and centres its buttons across them, so no button reaches past the rail's
|
||||
/// edge; its two header toggles share one line inside it.
|
||||
#[trial]
|
||||
fn a_tool_rail_centres_its_buttons_in_its_columns_and_keeps_its_toggles_on_one_line() {
|
||||
use crate::rails::{LastUsed, ToolRail, ToolSlot};
|
||||
use std::num::NonZeroU8;
|
||||
for columns in [1_u8, 2] {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let slots = vec![ToolSlot::new(0, tools(&[0])), ToolSlot::new(1, tools(&[1])), ToolSlot::new(2, tools(&[3]))];
|
||||
ToolRail::new("Tools", &slots, &0, &LastUsed::default())
|
||||
.columns(NonZeroU8::new(columns).unwrap_or(NonZeroU8::MIN))
|
||||
.column_toggle("Toolbar")
|
||||
.side_toggle("Move Toolbar")
|
||||
.show_rail(ui, |_, _| {});
|
||||
});
|
||||
fixture.settle();
|
||||
let rail = rect(&fixture, "Tools");
|
||||
for label in ["Move", "Brush", "Eraser", "Toolbar", "Move Toolbar"] {
|
||||
let shown = rect(&fixture, label);
|
||||
assert!(rail.contains_rect(shown), "{columns} columns: {label} lies inside the rail: {shown:?} in {rail:?}");
|
||||
}
|
||||
let (first, last) = (rect(&fixture, "Move"), rect(&fixture, if columns == 1 { "Move" } else { "Brush" }));
|
||||
let grid = first.union(last);
|
||||
assert!(centred_across(grid, rail), "{columns} columns: the buttons are centred: {grid:?} in {rail:?}");
|
||||
let (toggle, side) = (rect(&fixture, "Toolbar"), rect(&fixture, "Move Toolbar"));
|
||||
assert!(on_one_line(toggle, side), "the toggles share a line: {toggle:?} and {side:?}");
|
||||
assert!(above(toggle, first), "the toggles are above the buttons");
|
||||
}
|
||||
}
|
||||
+142
-153
@@ -1,29 +1,32 @@
|
||||
//! `ToolRail`: the rail of tool slots, with hidden tools, the last-used tool per slot and one or two columns.
|
||||
//! `ToolRail`: the rail of tool slots, with hidden tools, the last-used tool per slot and as many columns as its width
|
||||
//! holds.
|
||||
|
||||
use super::flyout::{FlyoutButton, SlotEdit};
|
||||
use super::words::RailWords;
|
||||
use crate::buttons::IconButton;
|
||||
use crate::contract::{
|
||||
Access, Common, Component, Container, ContainerProps, Cx, FooterRegion, Gap, HeaderRegion, LeastWidth, NoValue, Outcome, Pad, PadEdges, PaneEdge,
|
||||
Props as _, Role, Scroll, Show as _, ShowContainer as _, Sizing, WordSetCx as _, clicked,
|
||||
Access, Common, Component, Container, ContainerProps, Cx, FooterRegion, Gap, NoValue, Outcome, Pad, Props as _, Role, Scroll, Show as _,
|
||||
ShowContainer as _, Sizing, WordSetCx as _,
|
||||
};
|
||||
use crate::contract::{BodyCx, BodyLayout};
|
||||
use crate::docking::DockGrid;
|
||||
use crate::layout::RowAlign;
|
||||
use crate::layout_components::{Row, Stack};
|
||||
use crate::runtime::access::Name;
|
||||
use crate::runtime::commands::Commands as _;
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::{ComponentStyle, GlyphRole, StyleCx, SurfaceKind};
|
||||
use craft_behavior::overlay::Side;
|
||||
use craft_behavior::{IconId, Metrics, NavShape, Roving, Sense, Value};
|
||||
use craft_behavior::{IconId, Metrics, NavShape, Proposal, Roving, Sense, Value};
|
||||
use craft_theme::ControlSize;
|
||||
use egui::{Response, Ui};
|
||||
use std::num::NonZeroU8;
|
||||
use egui::{Response, Ui, Vec2};
|
||||
|
||||
mod data;
|
||||
mod drag;
|
||||
#[cfg(feature = "testing")]
|
||||
pub(super) mod stories;
|
||||
#[cfg(feature = "testing")]
|
||||
mod trials;
|
||||
|
||||
use data::row_groups;
|
||||
pub use data::{LastUsed, RailTool, SlotId, ToolSlot, remembered, shown_tool, visible_slots};
|
||||
@@ -34,16 +37,10 @@ pub use drag::{DropAt, ToolDrag, ToolDropped, drop_in_slot};
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub struct RailFooter {
|
||||
/// The rail's columns: with two, the host lays its two mode buttons side by side.
|
||||
/// The rail's columns: with more than one, the host lays its buttons side by side.
|
||||
pub columns: usize,
|
||||
}
|
||||
|
||||
/// Whether the column toggle points to the right of the screen: widening (from one column) points away from the
|
||||
/// rail's edge, towards the canvas; narrowing points back to the edge.
|
||||
fn column_toggle_points_right(columns: usize, at_left: bool) -> bool {
|
||||
(columns == 1) == at_left
|
||||
}
|
||||
|
||||
/// The style of a tool rail: it paints its chrome surface and takes its spacing from the body gap its props name.
|
||||
#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)]
|
||||
#[non_exhaustive]
|
||||
@@ -63,10 +60,6 @@ pub struct ToolRailOutput<T> {
|
||||
pub select: Option<T>,
|
||||
/// The shown tool of a slot that was double clicked; the host decides what that means.
|
||||
pub double_clicked: Option<T>,
|
||||
/// The column toggle was clicked; the host flips its column count.
|
||||
pub toggle_columns: bool,
|
||||
/// The side toggle was clicked; the host moves the rail to the other edge.
|
||||
pub toggle_side: bool,
|
||||
/// The Edit Toolbar button's response while the rail shows it: a click on it opens the drawer, and the drawer
|
||||
/// takes it as its opener ([`ToolbarDrawer::opened_by`](crate::rails::ToolbarDrawer::opened_by)).
|
||||
pub edit_toolbar: Option<Response>,
|
||||
@@ -103,15 +96,16 @@ impl<T> Default for Collected<T> {
|
||||
|
||||
type FooterFn<'a> = Box<dyn FnMut(&mut Ui, RailFooter) + 'a>;
|
||||
|
||||
/// The rail of tool slots, as a side panel at one edge of the window: one `FlyoutButton` per visible slot showing the
|
||||
/// slot's shown tool, the slot with the current tool toggled on. A click selects the shown tool, a row of the flyout
|
||||
/// selects that tool. With two columns the slots fill rows in reading order. Each column is `size.rail.width` wide,
|
||||
/// the width of the shell's tools slot per column, and the buttons sit centred across the columns with the control
|
||||
/// padding above and below. A slot that ends a group leaves `space.gap.inline` after its row; slots within a group sit
|
||||
/// `space.gap.tight` apart. The column toggle and the side toggle share the header's one line at the small control
|
||||
/// size; the Edit Toolbar button follows the last slot; the host's footer stays in view under the slots, which scroll
|
||||
/// when the window is short, and its buttons show the rail's glyphs. The buttons are one roving group: arrow keys move between them by the grid. While the toolbar is
|
||||
/// edited the buttons are dragged and take drops, and report the drop in the output.
|
||||
/// The rail of tool slots, laid out in a grid of columns: one `FlyoutButton` per visible slot showing the slot's shown
|
||||
/// tool, the slot with the current tool toggled on. A click selects the shown tool, a row of the flyout selects that
|
||||
/// tool. The rail takes as many columns as the width it gets holds, the most whole columns that fit
|
||||
/// ([`dock_grid`](ToolRail::dock_grid)): it is `first` wide at one column and `step` wider for each further column,
|
||||
/// and the slots fill the rows in reading order. The control padding surrounds the buttons; a slot that ends a group
|
||||
/// leaves `space.gap.inline` after its row; slots within a group sit `space.gap.tight` apart. The Edit Toolbar button
|
||||
/// follows the last slot; the host's footer stays in view under the slots, which scroll when the room is short, and its
|
||||
/// buttons show the rail's glyphs. The rail is exactly as tall as its rows and footer at the width it gets
|
||||
/// ([`measure_rail`](ToolRail::measure_rail)). The buttons are one roving group: arrow keys move between them by the
|
||||
/// grid. While the toolbar is edited the buttons are dragged and take drops, and report the drop in the output.
|
||||
#[derive(crate::contract::Component, crate::contract::Props)]
|
||||
#[component(container, probe(ToolRail<'static, u8>))]
|
||||
pub struct ToolRail<'a, T: Value + 'static> {
|
||||
@@ -122,20 +116,9 @@ pub struct ToolRail<'a, T: Value + 'static> {
|
||||
slots: &'a [ToolSlot<T>],
|
||||
current: &'a T,
|
||||
last_used: &'a LastUsed<T>,
|
||||
/// One or two columns of slots (more count as two); the host owns the count.
|
||||
/// The side of the rail its flyouts and drawer open on: the side of the canvas.
|
||||
#[prop]
|
||||
columns: NonZeroU8,
|
||||
/// The edge the rail sits at: `PaneEdge::End` for the end edge, any other value for the start edge. The
|
||||
/// flyouts open towards the canvas and the column toggle points that way.
|
||||
#[prop]
|
||||
edge: PaneEdge,
|
||||
/// Shows the column toggle at the top, named by the label.
|
||||
#[prop(into)]
|
||||
column_toggle: Option<Label>,
|
||||
/// Shows a button beside the column toggle, named by the label, that asks the host to move the rail to the other
|
||||
/// edge.
|
||||
#[prop(into)]
|
||||
side_toggle: Option<Label>,
|
||||
opens: Side,
|
||||
/// Shows the Edit Toolbar button after the last slot, named by the label.
|
||||
#[prop(into)]
|
||||
edit_toolbar: Option<Label>,
|
||||
@@ -146,8 +129,8 @@ pub struct ToolRail<'a, T: Value + 'static> {
|
||||
#[prop]
|
||||
hidden: &'a [T],
|
||||
footer: Option<FooterFn<'a>>,
|
||||
toggled: bool,
|
||||
side_toggled: bool,
|
||||
/// The columns the rail lays out in this pass.
|
||||
columns: usize,
|
||||
}
|
||||
|
||||
impl<'a, T: Value + 'static> ToolRail<'a, T> {
|
||||
@@ -157,7 +140,6 @@ impl<'a, T: Value + 'static> ToolRail<'a, T> {
|
||||
let props = ContainerProps::new()
|
||||
.surface(SurfaceKind::Chrome)
|
||||
.pad(Pad::Control)
|
||||
.pad_edges(PadEdges::Block)
|
||||
.sizing(Sizing::Content)
|
||||
.layout(BodyLayout::stack())
|
||||
.child_size(ControlSize::Md)
|
||||
@@ -170,107 +152,133 @@ impl<'a, T: Value + 'static> ToolRail<'a, T> {
|
||||
slots,
|
||||
current,
|
||||
last_used,
|
||||
columns: NonZeroU8::MIN,
|
||||
edge: PaneEdge::Start,
|
||||
column_toggle: None,
|
||||
side_toggle: None,
|
||||
opens: Side::End,
|
||||
edit_toolbar: None,
|
||||
editing: false,
|
||||
hidden: &[],
|
||||
footer: None,
|
||||
toggled: false,
|
||||
side_toggled: false,
|
||||
columns: 1,
|
||||
}
|
||||
.label(label)
|
||||
}
|
||||
|
||||
fn column_count(&self) -> usize {
|
||||
usize::from(self.columns.get().min(2))
|
||||
/// The grid of a rail of `cells` cells (its visible slots and the Edit Toolbar button) as its dock column sizes
|
||||
/// it ([`PanelSpec::grid`](crate::docking::PanelSpec::grid)): `first` is a button and the control padding on both
|
||||
/// sides, `step` a button and the tight gap before it, and `most` the cells.
|
||||
pub fn dock_grid(ctx: &egui::Context, cells: usize) -> DockGrid {
|
||||
StyleCx::with_root(ctx, |cx| {
|
||||
let button = cx.tokens.size.rail.button;
|
||||
let most = u16::try_from(cells).unwrap_or(u16::MAX).max(1);
|
||||
DockGrid::new(button + 2.0 * cx.tokens.space.pad.control, button + cx.tokens.space.gap.tight, most)
|
||||
})
|
||||
}
|
||||
|
||||
fn at_end(&self) -> bool {
|
||||
self.edge == PaneEdge::End
|
||||
/// The cells the rail lays out: its visible slots and the Edit Toolbar button.
|
||||
fn cells(&self) -> usize {
|
||||
visible_slots(self.slots, self.hidden).len() + usize::from(self.edit_toolbar.is_some())
|
||||
}
|
||||
|
||||
/// Sets up the pass for a rail `width` wide: its columns, its roving grid and its footer. Returns what the body
|
||||
/// draws from.
|
||||
fn prepare(&mut self, ctx: &egui::Context, width: f32, footer: impl FnMut(&mut Ui, RailFooter) + 'a) -> Draw<'a, T> {
|
||||
self.columns = usize::from(Self::dock_grid(ctx, self.cells()).steps_within(width));
|
||||
self.props = self.props.roving(Roving::new(NavShape::wrapped_grid(self.columns)));
|
||||
self.footer = Some(Box::new(footer));
|
||||
Draw {
|
||||
slots: self.slots,
|
||||
current: self.current,
|
||||
last_used: self.last_used,
|
||||
hidden: self.hidden,
|
||||
editing: self.editing,
|
||||
edit_label: self.edit_toolbar.clone(),
|
||||
opens: self.opens,
|
||||
columns: self.columns,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The side of a rail at `edge` that faces the canvas, where its flyouts and drawer open: `PaneEdge::End` is the end
|
||||
/// edge, any other value the start edge.
|
||||
pub(crate) fn canvas_side(edge: PaneEdge) -> Side {
|
||||
if edge == PaneEdge::End { Side::Start } else { Side::End }
|
||||
/// What the body of one pass draws from.
|
||||
struct Draw<'a, T> {
|
||||
slots: &'a [ToolSlot<T>],
|
||||
current: &'a T,
|
||||
last_used: &'a LastUsed<T>,
|
||||
hidden: &'a [T],
|
||||
editing: bool,
|
||||
edit_label: Option<Label>,
|
||||
opens: Side,
|
||||
columns: usize,
|
||||
}
|
||||
|
||||
impl<T: Value + 'static> Draw<'_, T> {
|
||||
/// The grid of buttons in rows of `columns`, with the pass's results in `collected`.
|
||||
fn run(&self, ui: &mut Ui, cx: &mut BodyCx<'_>, collected: &mut Collected<T>) {
|
||||
let Draw { slots, current, last_used, hidden, editing, columns, opens, .. } = *self;
|
||||
*collected = Collected::default();
|
||||
let visible = visible_slots(slots, hidden);
|
||||
let cells = visible.len() + usize::from(self.edit_label.is_some());
|
||||
let enabled = |tool: &RailTool<T>| cx.resolve_command(tool.command.clone()).is_some_and(|resolved| resolved.enabled);
|
||||
let at: Vec<usize> = visible.iter().map(|(index, _)| *index).collect();
|
||||
// The grid of buttons sits at the centre of the rail's width.
|
||||
Row::new().fill_width().align(RowAlign::Center).show(ui, |ui, _| {
|
||||
Stack::new().gap(Gap::Inline).show(ui, |ui, _| {
|
||||
for group in row_groups(slots, &at, cells, columns) {
|
||||
Stack::new().gap(Gap::Tight).show(ui, |ui, _| {
|
||||
for &first in &group {
|
||||
Row::new().gap(Gap::Tight).show(ui, |ui, _| {
|
||||
for k in first..(first + columns).min(cells) {
|
||||
match visible.get(k) {
|
||||
Some((index, tools)) => {
|
||||
let slot = &slots[*index];
|
||||
let owned: Vec<RailTool<T>> = tools.iter().map(|tool| (*tool).clone()).collect();
|
||||
let Some(shown) = shown_tool(current, slot.id, tools, last_used, enabled) else { continue };
|
||||
let selected = tools.iter().any(|tool| tool.id == *current);
|
||||
let mut button = FlyoutButton::new(&owned, &shown.id)
|
||||
.id_salt(("slot", slot.id))
|
||||
.selected(selected)
|
||||
.enabled(tools.iter().any(|tool| enabled(tool)))
|
||||
.opens(opens);
|
||||
if editing {
|
||||
button = button.edit(SlotEdit::new(slot.id, *index, slot.tools.len(), columns == 1));
|
||||
}
|
||||
let out = button.show(ui);
|
||||
if out.select.is_some() {
|
||||
collected.select = out.select;
|
||||
}
|
||||
if out.double_clicked {
|
||||
collected.double_clicked = Some(shown.id.clone());
|
||||
}
|
||||
if out.opened {
|
||||
collected.flyout = Some(slot.id);
|
||||
}
|
||||
if out.dropped.is_some() {
|
||||
collected.dropped = out.dropped;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let label = self.edit_label.clone().unwrap_or(Label::Empty);
|
||||
let more = IconButton::new(IconId::new("more")).id_salt("edit-toolbar").label(label).show(ui);
|
||||
collected.edit_toolbar = Some(more.response);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: Value + 'static> ToolRail<'a, T> {
|
||||
/// Shows the rail. `footer` draws under the last slot (colour chips, Quick Mask, Screen Mode); it stays in view
|
||||
/// when the window is short.
|
||||
/// Shows the rail in the width `ui` has left. `footer` draws under the last slot (colour chips, Quick Mask,
|
||||
/// Screen Mode); it stays in view when the room is short.
|
||||
pub fn show_rail(mut self, ui: &mut Ui, footer: impl FnMut(&mut Ui, RailFooter) + 'a) -> ToolRailOutput<T> {
|
||||
let columns = self.column_count();
|
||||
let wide = u8::try_from(columns).ok().and_then(NonZeroU8::new).unwrap_or(NonZeroU8::MIN);
|
||||
self.props = self.props.roving(Roving::new(NavShape::wrapped_grid(columns))).least_width(LeastWidth::Rail(wide));
|
||||
if self.column_toggle.is_some() || self.side_toggle.is_some() {
|
||||
self.props = self.props.header(HeaderRegion::new());
|
||||
}
|
||||
self.footer = Some(Box::new(footer));
|
||||
let (slots, current, last_used, hidden) = (self.slots, self.current, self.last_used, self.hidden);
|
||||
let (editing, edit_label) = (self.editing, self.edit_toolbar.clone());
|
||||
let opens = canvas_side(self.edge);
|
||||
let last = remembered(slots, current, last_used);
|
||||
let room = ui.available_width();
|
||||
let draw = self.prepare(ui.ctx(), room, footer);
|
||||
let last = remembered(draw.slots, draw.current, draw.last_used);
|
||||
let mut collected = Collected::default();
|
||||
let shown = self.show(ui, |ui, cx| {
|
||||
collected = Collected::default();
|
||||
let visible = visible_slots(slots, hidden);
|
||||
let cells = visible.len() + usize::from(edit_label.is_some());
|
||||
let enabled = |tool: &RailTool<T>| cx.resolve_command(tool.command.clone()).is_some_and(|resolved| resolved.enabled);
|
||||
let at: Vec<usize> = visible.iter().map(|(index, _)| *index).collect();
|
||||
// The grid of buttons sits at the centre of the rail's columns.
|
||||
Row::new().fill_width().align(RowAlign::Center).show(ui, |ui, _| {
|
||||
Stack::new().gap(Gap::Inline).show(ui, |ui, _| {
|
||||
for group in row_groups(slots, &at, cells, columns) {
|
||||
Stack::new().gap(Gap::Tight).show(ui, |ui, _| {
|
||||
for &first in &group {
|
||||
Row::new().gap(Gap::Tight).show(ui, |ui, _| {
|
||||
for k in first..(first + columns).min(cells) {
|
||||
match visible.get(k) {
|
||||
Some((index, tools)) => {
|
||||
let slot = &slots[*index];
|
||||
let owned: Vec<RailTool<T>> = tools.iter().map(|tool| (*tool).clone()).collect();
|
||||
let Some(shown) = shown_tool(current, slot.id, tools, last_used, enabled) else { continue };
|
||||
let selected = tools.iter().any(|tool| tool.id == *current);
|
||||
let mut button = FlyoutButton::new(&owned, &shown.id)
|
||||
.id_salt(("slot", slot.id))
|
||||
.selected(selected)
|
||||
.enabled(tools.iter().any(|tool| enabled(tool)))
|
||||
.opens(opens);
|
||||
if editing {
|
||||
button = button.edit(SlotEdit::new(slot.id, *index, slot.tools.len(), columns == 1));
|
||||
}
|
||||
let out = button.show(ui);
|
||||
if out.select.is_some() {
|
||||
collected.select = out.select;
|
||||
}
|
||||
if out.double_clicked {
|
||||
collected.double_clicked = Some(shown.id.clone());
|
||||
}
|
||||
if out.opened {
|
||||
collected.flyout = Some(slot.id);
|
||||
}
|
||||
if out.dropped.is_some() {
|
||||
collected.dropped = out.dropped;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let label = edit_label.clone().unwrap_or(Label::Empty);
|
||||
let more = IconButton::new(IconId::new("more")).id_salt("edit-toolbar").label(label).show(ui);
|
||||
collected.edit_toolbar = Some(more.response);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
let shown = self.show(ui, |ui, cx| draw.run(ui, cx, &mut collected));
|
||||
ToolRailOutput {
|
||||
select: collected.select,
|
||||
double_clicked: collected.double_clicked,
|
||||
@@ -281,6 +289,13 @@ impl<'a, T: Value + 'static> ToolRail<'a, T> {
|
||||
..shown.output
|
||||
}
|
||||
}
|
||||
|
||||
/// The size of the rail laid out `width` wide, with `footer` under its rows: as many columns as `width` holds,
|
||||
/// as tall as its rows and footer (at most the room along the axis it scrolls on).
|
||||
pub fn measure_rail(mut self, ui: &Ui, width: f32, footer: impl FnMut(&mut Ui, RailFooter) + 'a) -> Vec2 {
|
||||
let draw = self.prepare(ui.ctx(), width, footer);
|
||||
self.measure_in(ui, Proposal::Width(width), |ui, cx| draw.run(ui, cx, &mut Collected::default()))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Value + 'static> Component for ToolRail<'_, T> {
|
||||
@@ -311,8 +326,6 @@ impl<T: Value + 'static> Component for ToolRail<'_, T> {
|
||||
response: cx.response.clone(),
|
||||
select: None,
|
||||
double_clicked: None,
|
||||
toggle_columns: self.toggled,
|
||||
toggle_side: self.side_toggled,
|
||||
edit_toolbar: None,
|
||||
flyout: None,
|
||||
dropped: None,
|
||||
@@ -322,33 +335,9 @@ impl<T: Value + 'static> Component for ToolRail<'_, T> {
|
||||
}
|
||||
|
||||
impl<T: Value + 'static> Container for ToolRail<'_, T> {
|
||||
/// The column toggle and the side toggle, side by side on one line at the small control size with the control
|
||||
/// glyph: two of them touch to fit one rail column.
|
||||
fn header(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) {
|
||||
let (columns, rtl) = (self.column_count(), Env::of(ui).direction.is_rtl());
|
||||
let at_left = !self.at_end() != rtl;
|
||||
let (column_toggle, side_toggle) = (self.column_toggle.clone(), self.side_toggle.clone());
|
||||
let (mut toggled, mut side_toggled) = (false, false);
|
||||
Row::new().fill_width().align(RowAlign::Center).gap(Gap::None).show(ui, |ui, _| {
|
||||
if let Some(label) = column_toggle.clone() {
|
||||
let icon = crate::collapse::chevrons(column_toggle_points_right(columns, at_left));
|
||||
let toggle = IconButton::new(icon).id_salt("column-toggle").label(label).size(ControlSize::Sm).glyphs(GlyphRole::Control).show(ui);
|
||||
toggled |= clicked(&toggle);
|
||||
}
|
||||
if let Some(label) = side_toggle.clone() {
|
||||
// The icon shows the edge the rail moves to.
|
||||
let icon = IconId::new(if at_left { "panel_right" } else { "panel_left" });
|
||||
let toggle = IconButton::new(icon).id_salt("side-toggle").label(label).size(ControlSize::Sm).glyphs(GlyphRole::Control).show(ui);
|
||||
side_toggled |= clicked(&toggle);
|
||||
}
|
||||
});
|
||||
self.toggled |= toggled;
|
||||
self.side_toggled |= side_toggled;
|
||||
}
|
||||
|
||||
/// The host's footer.
|
||||
fn footer(&mut self, ui: &mut Ui, _: &mut BodyCx<'_>) {
|
||||
let columns = self.column_count();
|
||||
let columns = self.columns;
|
||||
if let Some(footer) = &mut self.footer {
|
||||
footer(ui, RailFooter { columns });
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
use super::{LastUsed, RailTool, ToolRail, ToolSlot};
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
use std::num::NonZeroU8;
|
||||
|
||||
/// The tools of the stories.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, craft_ui_macros::CommandSet)]
|
||||
@@ -40,29 +39,26 @@ fn slots() -> Vec<ToolSlot<u8>> {
|
||||
vec![ToolSlot::new(0, tools(&[0])), ToolSlot::new(1, tools(&[BRUSH, BRUSH + 1])), ToolSlot::new(2, tools(&[3])), ToolSlot::new(3, tools(&[4]))]
|
||||
}
|
||||
|
||||
/// The rail in a room as wide as its grid at `columns` columns: the stage a dock column of that many steps gives it.
|
||||
#[story(ToolRail<'static, u8>, covers = [Default], drive = Drive::Never)]
|
||||
fn tool_rail(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let columns = *data.ranged("columns", 1_u8, 1.0..=2.0);
|
||||
let columns = *data.ranged("columns", 1_u8, 1.0..=4.0);
|
||||
let hidden =
|
||||
data.choice("hidden", Vec::<u8>::new(), &[("None", Vec::new()), ("Pencil", vec![2]), ("Stamp", vec![4]), ("Eraser", vec![3])]).clone();
|
||||
let slots = slots();
|
||||
let last = LastUsed::default();
|
||||
let out = ToolRail::new("Tools", &slots, &BRUSH, &last)
|
||||
.columns(NonZeroU8::new(columns.max(1)).unwrap_or(NonZeroU8::MIN))
|
||||
.hidden(&hidden)
|
||||
.column_toggle("Toolbar")
|
||||
.side_toggle("Move Toolbar to the Other Side")
|
||||
.edit_toolbar("Edit Toolbar")
|
||||
.show_rail(ui, |_, _| {});
|
||||
let width = ToolRail::<u8>::dock_grid(ui.ctx(), slots.len() + 1).width(u16::from(columns));
|
||||
let out = ui
|
||||
.scope(|ui| {
|
||||
ui.set_max_width(width);
|
||||
ToolRail::new("Tools", &slots, &BRUSH, &last).hidden(&hidden).edit_toolbar("Edit Toolbar").show_rail(ui, |_, _| {})
|
||||
})
|
||||
.inner;
|
||||
let note = data.note("note", "Nothing yet".to_owned());
|
||||
if let Some(tool) = out.select {
|
||||
*note = format!("selected {tool}");
|
||||
} else if let Some(tool) = out.double_clicked {
|
||||
*note = format!("double clicked {tool}");
|
||||
} else if out.toggle_columns {
|
||||
*note = "toggle columns".to_owned();
|
||||
} else if out.toggle_side {
|
||||
*note = "toggle side".to_owned();
|
||||
} else if out.edit_toolbar.as_ref().is_some_and(crate::contract::clicked) {
|
||||
*note = "edit toolbar".to_owned();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
//! Trials of `ToolRail`: its columns for a width, its measure, a short room and its glyph role.
|
||||
#![allow(clippy::panic, clippy::expect_used, reason = "trials assert by panicking")]
|
||||
|
||||
use super::stories::tools;
|
||||
use super::{LastUsed, ToolRail, ToolSlot};
|
||||
use crate::buttons::Button;
|
||||
use crate::contract::Show as _;
|
||||
use crate::testing::pointer::{moved, wheel};
|
||||
use crate::testing::relations::{above, grows_with};
|
||||
use crate::testing::{Fixture, trial};
|
||||
use egui::{Rect, Vec2};
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// The slots of the trials: one tool each, labelled Move, Brush, Pencil, Eraser and Clone Stamp.
|
||||
const LABELS: [&str; 5] = ["Move", "Brush", "Pencil", "Eraser", "Clone Stamp"];
|
||||
|
||||
fn slots() -> Vec<ToolSlot<u8>> {
|
||||
(0..5_u8).map(|id| ToolSlot::new(u32::from(id), tools(&[id]))).collect()
|
||||
}
|
||||
|
||||
/// The bounds of the node labelled `label`.
|
||||
fn rect(fixture: &Fixture, label: &str) -> Rect {
|
||||
fixture.by_label(label).unwrap_or_else(|| panic!("{label} is shown")).rect
|
||||
}
|
||||
|
||||
/// How many columns the buttons of the rail stand in: the distinct left edges.
|
||||
fn columns_of(fixture: &Fixture) -> usize {
|
||||
let mut lefts: Vec<f32> = Vec::new();
|
||||
for label in LABELS {
|
||||
let left = rect(fixture, label).left();
|
||||
if !lefts.iter().any(|seen| (seen - left).abs() < 1.0) {
|
||||
lefts.push(left);
|
||||
}
|
||||
}
|
||||
lefts.len()
|
||||
}
|
||||
|
||||
/// A rail in a room `width` wide and `height` high with a one-button footer, and the size `measure_rail` gives it at
|
||||
/// that width in the same pass.
|
||||
fn rail_in(width: f32, height: f32) -> (Fixture, Rc<Cell<Vec2>>) {
|
||||
let measured = Rc::new(Cell::new(Vec2::ZERO));
|
||||
let report = Rc::clone(&measured);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let slots = slots();
|
||||
let last = LastUsed::default();
|
||||
let size = ToolRail::new("Tools", &slots, &0, &last).measure_rail(ui, width, |ui, _| {
|
||||
Button::new("Foot").show(ui);
|
||||
});
|
||||
report.set(size);
|
||||
ToolRail::new("Tools", &slots, &0, &last).show_rail(ui, |ui, _| {
|
||||
Button::new("Foot").show(ui);
|
||||
});
|
||||
});
|
||||
fixture.room(Vec2::new(width, height)).settle();
|
||||
(fixture, measured)
|
||||
}
|
||||
|
||||
/// The rail lays out the most whole columns its width holds: a width of n steps shows n columns, a width a pixel short
|
||||
/// of them one fewer, and a wider one no more columns than the rail has cells.
|
||||
#[trial]
|
||||
fn a_tool_rail_lays_out_the_most_whole_columns_its_width_holds() {
|
||||
let grid = ToolRail::<u8>::dock_grid(Fixture::new(|_| {}).ctx(), LABELS.len());
|
||||
for steps in 1..=3_u16 {
|
||||
let (fixture, _) = rail_in(grid.width(steps), 800.0);
|
||||
assert_eq!(columns_of(&fixture), usize::from(steps), "a width of {steps} steps shows {steps} columns");
|
||||
let rail = rect(&fixture, "Tools");
|
||||
assert!((rail.width() - grid.width(steps)).abs() < 1.0, "{steps} steps: the rail is as wide as its columns: {rail:?}");
|
||||
if steps > 1 {
|
||||
let (short, _) = rail_in(grid.width(steps) - 1.0, 800.0);
|
||||
assert_eq!(columns_of(&short), usize::from(steps) - 1, "a width short of {steps} steps shows one column fewer");
|
||||
}
|
||||
}
|
||||
let (wide, _) = rail_in(grid.width(grid.most) * 2.0, 800.0);
|
||||
assert_eq!(columns_of(&wide), LABELS.len(), "a wide room fills one row");
|
||||
}
|
||||
|
||||
/// The measure at a width is the size the rail shows at it: exactly its rows plus the footer between equal paddings,
|
||||
/// and fewer columns need more rows.
|
||||
#[trial]
|
||||
fn a_tool_rail_measures_its_rows_plus_its_footer_at_a_width() {
|
||||
let grid = ToolRail::<u8>::dock_grid(Fixture::new(|_| {}).ctx(), LABELS.len());
|
||||
let mut heights = Vec::new();
|
||||
for steps in [1_u16, 2] {
|
||||
let (fixture, measured) = rail_in(grid.width(steps), 800.0);
|
||||
let (rail, foot, first) = (rect(&fixture, "Tools"), rect(&fixture, "Foot"), rect(&fixture, "Move"));
|
||||
let size = measured.get();
|
||||
assert!((size.y - rail.height()).abs() < 1.0, "{steps} steps: the measure ({size:?}) is the shown rail ({rail:?})");
|
||||
assert!((size.x - rail.width()).abs() < 1.0, "{steps} steps: the measure is as wide as the shown rail");
|
||||
let (top, bottom) = (first.top() - rail.top(), rail.bottom() - foot.bottom());
|
||||
assert!(
|
||||
(top - bottom).abs() < 1.0,
|
||||
"{steps} steps: the rows and the footer fill the rail between equal paddings ({top} above, {bottom} below)"
|
||||
);
|
||||
heights.push(size.y);
|
||||
}
|
||||
assert!(grows_with(heights[1], heights[0]), "one column is taller than two: {heights:?}");
|
||||
}
|
||||
|
||||
/// When the room is too short for every row, the footer stays in view at the bottom and the rows scroll in the room
|
||||
/// above it, down to a room smaller than one scroll region's usual least height.
|
||||
#[trial]
|
||||
fn in_a_short_room_the_rows_scroll_above_the_footer_that_stays_in_view() {
|
||||
let grid = ToolRail::<u8>::dock_grid(Fixture::new(|_| {}).ctx(), LABELS.len());
|
||||
for height in [160.0, 100.0] {
|
||||
let (mut fixture, measured) = rail_in(grid.width(1), height);
|
||||
let foot = rect(&fixture, "Foot");
|
||||
assert!(foot.bottom() <= height, "{height}: the footer is in the room: {foot:?}");
|
||||
assert!(measured.get().y > height, "{height}: the rows do not fit the room");
|
||||
let first = rect(&fixture, "Move");
|
||||
assert!(first.top() < foot.top(), "{height}: the first button is above the footer: {first:?}");
|
||||
assert!(rect(&fixture, "Clone Stamp").bottom() > foot.top(), "{height}: the last button starts out of view");
|
||||
|
||||
fixture.frame(vec![moved(first.center())]);
|
||||
for _ in 0..10 {
|
||||
fixture.frame(vec![wheel(-120.0)]);
|
||||
}
|
||||
fixture.settle();
|
||||
let last = rect(&fixture, "Clone Stamp");
|
||||
assert!(grows_with(first.top(), last.top()), "{height}: the last button is in view after scrolling: {last:?}");
|
||||
assert!(above(last, foot), "{height}: the last button is above the footer after scrolling: {last:?}");
|
||||
assert_eq!(rect(&fixture, "Foot"), foot, "{height}: the footer stays put");
|
||||
}
|
||||
}
|
||||
|
||||
/// The tool rail's buttons are larger than a lone icon button's and rest in a quieter ink than they show under the
|
||||
/// pointer.
|
||||
#[trial]
|
||||
fn the_tool_rail_shows_its_buttons_icons_in_its_glyph_role() {
|
||||
use crate::buttons::IconButton;
|
||||
use craft_behavior::IconId;
|
||||
let glyphs = |rail: bool| {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
if rail {
|
||||
let slots = vec![ToolSlot::new(0, tools(&[0, 1]))];
|
||||
ToolRail::new("Tools", &slots, &0, &LastUsed::default()).show_rail(ui, |_, _| {});
|
||||
} else {
|
||||
IconButton::new(IconId::new("move")).label("Alone").show(ui);
|
||||
}
|
||||
});
|
||||
fixture.settle();
|
||||
let seen = fixture.styles_of(std::any::type_name::<IconButton<'static>>());
|
||||
let glyph = seen.first().and_then(|seen| seen.looks.icons.first().cloned());
|
||||
glyph.unwrap_or_else(|| panic!("an icon button showed (rail {rail})"))
|
||||
};
|
||||
let (alone, tool) = (glyphs(false), glyphs(true));
|
||||
assert!(tool.side > alone.side, "a tool rail icon ({}) is larger than a lone one ({})", tool.side, alone.side);
|
||||
assert!(tool.color.off.rest != tool.color.off.hover, "a tool rail icon rests quieter than under the pointer");
|
||||
}
|
||||
@@ -4,7 +4,6 @@ craft_ui::words! {
|
||||
/// The words of the rails family; each id is `<type>.<name>`.
|
||||
pub struct RailWords {
|
||||
tools: "toolRail.name" = "Tools";
|
||||
panels: "panelRail.name" = "Panels";
|
||||
drawer_title: "toolbarDrawer.title" = "Edit Toolbar";
|
||||
drawer_tools: "toolbarDrawer.allTools" = "All Tools";
|
||||
drawer_hint: "toolbarDrawer.hint" = "Drag tools to or from the toolbar.";
|
||||
|
||||
@@ -133,24 +133,24 @@ fn a_slot_that_ends_a_group_leaves_a_wider_gap_than_slots_within_a_group() {
|
||||
assert!(between > within, "the gap after the group ({between}) is wider than the gap inside it ({within})");
|
||||
}
|
||||
|
||||
/// The drawer opens on the canvas side of the rail, away from the window edge the rail sits at, for either edge.
|
||||
/// The drawer opens on the side of the rail it is told to, for either side.
|
||||
#[trial]
|
||||
fn the_drawer_opens_away_from_the_rails_edge() {
|
||||
use craft_ui::contract::PaneEdge;
|
||||
fn the_drawer_opens_on_the_side_it_is_given() {
|
||||
use craft_behavior::overlay::Side;
|
||||
use craft_ui::rails::{DrawerGroup, ToolbarDrawer};
|
||||
use egui::{Pos2, Rect};
|
||||
const ROOM: Vec2 = Vec2::new(480.0, 320.0);
|
||||
for edge in [PaneEdge::Start, PaneEdge::End] {
|
||||
let x = if edge == PaneEdge::End { ROOM.x - 48.0 } else { 0.0 };
|
||||
for opens in [Side::End, Side::Start] {
|
||||
let x = if opens == Side::Start { ROOM.x - 48.0 } else { 0.0 };
|
||||
let rail = Rect::from_min_size(Pos2::new(x, 0.0), Vec2::new(48.0, ROOM.y));
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let toolbar = [slot(0, &[UNDO])];
|
||||
let groups = [DrawerGroup::new("Edit", vec![tool(UNDO), tool(REDO), tool(CUT)])];
|
||||
ToolbarDrawer::new(rail, &groups, &toolbar, None).edge(edge).show(ui);
|
||||
ToolbarDrawer::new(rail, &groups, &toolbar, None).opens(opens).show(ui);
|
||||
});
|
||||
fixture.room(ROOM).settle();
|
||||
let row = fixture.by_label("Cut").expect("the drawer lists Cut").rect;
|
||||
let away = if edge == PaneEdge::End { row.right() <= rail.left() } else { row.left() >= rail.right() };
|
||||
assert!(away, "{edge:?}: the drawer row {row:?} lies on the canvas side of the rail {rail:?}");
|
||||
let away = if opens == Side::Start { row.right() <= rail.left() } else { row.left() >= rail.right() };
|
||||
assert!(away, "{opens:?}: the drawer row {row:?} lies on that side of the rail {rail:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,21 +11,21 @@
|
||||
//! | status |
|
||||
//! +-----------------------------------------+
|
||||
//!
|
||||
//! canvas panel: +----------------------+------+
|
||||
//! | document tabs | panel|
|
||||
//! +----------------------+ rail |
|
||||
//! | document | |
|
||||
//! +----------------------+------+
|
||||
//! canvas panel: +----------------------+
|
||||
//! | document tabs |
|
||||
//! +----------------------+
|
||||
//! | document |
|
||||
//! +----------------------+
|
||||
//! ```
|
||||
|
||||
#[cfg(feature = "testing")]
|
||||
mod stories;
|
||||
|
||||
use super::app_shell::{RegionBody, RegionFn, ShellRegion};
|
||||
use super::app_shell::{RegionBody, ShellRegion};
|
||||
use super::words::ShellWords;
|
||||
use crate::contract::{BodyCx, NoValue, Outcome, PaneEdge, Props as _, ShellPane, ShowContainer as _};
|
||||
use crate::primitives::{CheckerArea, paint_surround};
|
||||
use crate::runtime::env::{BodyMode, Env, Label, ShellEntry};
|
||||
use crate::runtime::env::{BodyMode, Env, ShellEntry};
|
||||
use crate::style::{SurfaceKind, SurroundLook};
|
||||
use egui::{CornerRadius, Rect, Response, Ui};
|
||||
|
||||
@@ -49,8 +49,6 @@ pub mod slots {
|
||||
pub struct CanvasPanelOutput {
|
||||
/// The response of the document region.
|
||||
pub response: Response,
|
||||
/// The rail's rect, when it showed.
|
||||
pub rail: Option<Rect>,
|
||||
/// The tab strip's rect, when it showed.
|
||||
pub tabs: Option<Rect>,
|
||||
/// The document area.
|
||||
@@ -67,15 +65,11 @@ impl Outcome for CanvasPanelOutput {
|
||||
}
|
||||
}
|
||||
|
||||
/// The canvas panel of a dock: the panel rail at the end edge, spanning the tabs and the document; then, in what is
|
||||
/// left, the document tab strip flush against the document; then the document area, over the canvas surround. Fill the
|
||||
/// rail with `rails::PanelRail` and the tab strip with `tabs::DocumentTabs`.
|
||||
/// The canvas panel of a dock: the document tab strip flush against the document, then the document area, over the
|
||||
/// canvas surround. Fill the tab strip with `tabs::DocumentTabs`.
|
||||
///
|
||||
/// - **Tabs.** They show in normal mode when the host says so (`ShellCx::tabs_visible`), or while documents are
|
||||
/// [`opening`](CanvasPanel::opening) (a file that is still loading has a tab). Body-only mode shows neither tabs nor
|
||||
/// rail, but the rail shows during a reveal that shows the dock.
|
||||
/// - **Rail.** It is skipped when the dock is hidden (`ShellCx::dock_visible`, or the panels are hidden with
|
||||
/// Shift+Tab).
|
||||
/// [`opening`](CanvasPanel::opening) (a file that is still loading has a tab). Body-only mode shows no tabs.
|
||||
/// - **Surround.** The document area shows the canvas surround, and a double click on its empty room is
|
||||
/// [`empty_double`](CanvasPanelOutput::empty_double).
|
||||
///
|
||||
@@ -84,7 +78,6 @@ impl Outcome for CanvasPanelOutput {
|
||||
#[must_use = "show the panel with `show`"]
|
||||
#[derive(crate::contract::Pattern, crate::contract::Props)]
|
||||
pub struct CanvasPanel<'a> {
|
||||
rail: Option<(Label, RegionFn<'a>)>,
|
||||
/// The document tab strip.
|
||||
#[prop(func = "FnMut(&mut Ui, &mut BodyCx<'_>)")]
|
||||
tabs: Option<RegionBody<'a>>,
|
||||
@@ -94,34 +87,20 @@ pub struct CanvasPanel<'a> {
|
||||
}
|
||||
|
||||
impl<'a> CanvasPanel<'a> {
|
||||
/// A panel with no rail and no tab strip.
|
||||
/// A panel with no tab strip.
|
||||
pub fn new() -> Self {
|
||||
CanvasPanel { rail: None, tabs: None, opening: false }
|
||||
}
|
||||
|
||||
/// The panel rail, named `label`.
|
||||
pub fn rail(mut self, label: impl Into<Label>, add: impl FnMut(&mut Ui, &mut BodyCx<'_>) + 'a) -> Self {
|
||||
self.rail = Some((label.into(), Box::new(add)));
|
||||
self
|
||||
CanvasPanel { tabs: None, opening: false }
|
||||
}
|
||||
|
||||
/// Lays the panel out in `ui`, the body of the dock's canvas panel, with `document` in the area left.
|
||||
pub fn show(self, ui: &mut Ui, mut document: impl FnMut(&mut Ui, &mut BodyCx<'_>)) -> CanvasPanelOutput {
|
||||
let CanvasPanel { rail, tabs, opening } = self;
|
||||
let CanvasPanel { tabs, opening } = self;
|
||||
let env = Env::of(ui);
|
||||
let words = env.words::<ShellWords>();
|
||||
let shell = env.get::<ShellEntry>().0;
|
||||
let dock = shell.as_ref().is_none_or(|shell| shell.dock_visible());
|
||||
let normal = shell.as_ref().is_none_or(|shell| shell.body_mode() == BodyMode::Normal);
|
||||
let tabs_shown = shell.as_ref().is_none_or(|shell| shell.tabs_visible()) || (opening && normal);
|
||||
|
||||
let mut rail_rect = None;
|
||||
if let (Some((label, mut add)), true) = (rail, dock) {
|
||||
// One rail column wide, as the shell's rails are.
|
||||
let pane = ShellPane::new("panel_rail").edge(PaneEdge::End).extent(env.tokens.size.rail.width);
|
||||
let out = ShellRegion::chrome(pane).id_salt("panel_rail").label(label).show(ui, |ui, cx| add(ui, cx));
|
||||
rail_rect = Some(out.response.rect);
|
||||
}
|
||||
let mut tabs_rect = None;
|
||||
if let (Some(mut add), true) = (tabs.map(|RegionBody(add)| add), tabs_shown) {
|
||||
// The document tabs sit on the window's background, as tab strips do.
|
||||
@@ -141,7 +120,7 @@ impl<'a> CanvasPanel<'a> {
|
||||
empty_double |= cx.surface_double_pressed();
|
||||
document(ui, cx);
|
||||
});
|
||||
CanvasPanelOutput { document: out.response.rect, response: out.output.response, rail: rail_rect, tabs: tabs_rect, empty_double }
|
||||
CanvasPanelOutput { document: out.response.rect, response: out.output.response, tabs: tabs_rect, empty_double }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,6 @@ use egui::Ui;
|
||||
#[story(CanvasPanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn canvas_panel(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
CanvasPanel::new()
|
||||
.rail("Panels", |ui, _| {
|
||||
Text::new("Rail").show(ui);
|
||||
})
|
||||
.tabs(|ui, _| {
|
||||
Text::new("Tabs").show(ui);
|
||||
})
|
||||
@@ -21,13 +18,10 @@ fn canvas_panel(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
.into()
|
||||
}
|
||||
|
||||
/// The empty workspace: rail and tabs with no document, so the canvas surround fills the document area.
|
||||
/// The empty workspace: tabs with no document, so the canvas surround fills the document area.
|
||||
#[story(CanvasPanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn empty_canvas_panel(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
CanvasPanel::new()
|
||||
.rail("Panels", |ui, _| {
|
||||
Text::new("Rail").show(ui);
|
||||
})
|
||||
.tabs(|ui, _| {
|
||||
Text::new("Tabs").show(ui);
|
||||
})
|
||||
|
||||
@@ -45,7 +45,7 @@ impl Component for Document {
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows a panel with rail and tabs, and a document filling its document area when `with_document`; after two
|
||||
/// Shows a panel with tabs, and a document filling its document area when `with_document`; after two
|
||||
/// settling frames, moves to the area's centre and clicks there `clicks` times, one frame per press and per release.
|
||||
/// Returns the steps (0 the move) in which the panel reported `empty_double`.
|
||||
fn empty_doubles(with_document: bool, clicks: usize) -> Vec<usize> {
|
||||
@@ -54,7 +54,7 @@ fn empty_doubles(with_document: bool, clicks: usize) -> Vec<usize> {
|
||||
let mut reported = false;
|
||||
let frame = |events: Vec<Event>, document: &mut Rect, reported: &mut bool| {
|
||||
windows.frame(events, vec![], |ui| {
|
||||
let shown = CanvasPanel::new().rail("Panels", |_, _| {}).tabs(|_, _| {}).show(ui, |ui, cx| {
|
||||
let shown = CanvasPanel::new().tabs(|_, _| {}).show(ui, |ui, cx| {
|
||||
if with_document {
|
||||
Document { common: Common::new() }.show_at(ui, cx.rect);
|
||||
}
|
||||
@@ -90,24 +90,3 @@ fn an_empty_canvas_panel_reports_a_double_click_on_its_room() {
|
||||
assert_eq!(empty_doubles(false, 2), vec![3], "the second press on the empty room reports once");
|
||||
assert_eq!(empty_doubles(true, 2), Vec::<usize>::new(), "a document that takes the press leaves the room's double click unreported");
|
||||
}
|
||||
|
||||
/// The panel rail is one rail column wide at the panel's end edge, and the document area runs up to it: no band of the
|
||||
/// rail's chrome is left between them, whatever the room.
|
||||
#[trial]
|
||||
fn the_panel_rail_is_one_rail_column_at_the_end_edge() {
|
||||
let windows = Windows::new();
|
||||
let (mut rail, mut document, mut room, mut column) = (None, Rect::NOTHING, Rect::NOTHING, 0.0);
|
||||
for _ in 0..2 {
|
||||
windows.frame(vec![], vec![], |ui| {
|
||||
room = ui.max_rect();
|
||||
column = craft_ui::runtime::env::Env::of(ui).tokens.size.rail.width;
|
||||
let shown = CanvasPanel::new().rail("Panels", |_, _| {}).show(ui, |_, _| {});
|
||||
rail = shown.rail;
|
||||
document = shown.document;
|
||||
});
|
||||
}
|
||||
let rail = rail.expect("the rail shows");
|
||||
assert!((rail.right() - room.right()).abs() < 0.5, "the rail ends at the panel's end edge: {rail:?} in {room:?}");
|
||||
assert!((rail.width() - column).abs() < 0.5, "the rail is one rail column wide: {rail:?}, column {column}");
|
||||
assert!(document.right() <= rail.left() + 0.5 && rail.left() - document.right() < column, "the document meets the rail: {document:?} {rail:?}");
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ include-tests = false
|
||||
deny-unused = true
|
||||
|
||||
[[exempt]]
|
||||
path = "crates/ui-panels/src/rails/panel_rail/trials.rs"
|
||||
path = "crates/ui-panels/src/rails/tool/trials.rs"
|
||||
rules = ["literal-size"]
|
||||
reason = "trial rooms, not looks"
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
config_version = 1
|
||||
|
||||
[[exception]]
|
||||
name = "panel-rail-trial-rooms"
|
||||
name = "tool-rail-trial-rooms"
|
||||
kind = "exempt"
|
||||
rule = "literal-size"
|
||||
path = "crates/ui-panels/src/rails/panel_rail/trials.rs"
|
||||
path = "crates/ui-panels/src/rails/tool/trials.rs"
|
||||
reason = "Trial rooms, not looks."
|
||||
count = 1
|
||||
|
||||
@@ -147,13 +147,12 @@ Grouped by gallery level, then shape, then name.
|
||||
| `ModalDragStrip` | Body | `craft_ui_panels::dialog::modal` | The chrome a modal dialog puts over a drag area of the window it covers, so that the window still moves by it |
|
||||
| `PaneFrame` | Body | `craft_ui_patterns::patterns::dock::panes` | A docked pane: a shell pane on one edge of the area, with a title row and a scrolling body |
|
||||
| `Panel` | Body | `craft_ui_panels::sections::panel` | A panel of a workspace: scrolling body, optional footer, optional title row |
|
||||
| `PanelRail` | Body | `craft_ui_panels::rails::panel_rail` | The rail of icons that open panels, as a side panel at one edge of the window; the pane it sits in draws the rule along the edge that faces the canvas |
|
||||
| `Popover` | Body | `craft_ui_widgets::popover::anchored` | A non-modal popup that hangs from the control that opened it and holds the app's body (a colour picker, a stroke editor, a settings form) |
|
||||
| `PopupList` | Body | `craft_ui_widgets::popover::popup_list` | A list popup under a field the app owns (a combo, a history picker) |
|
||||
| `SplitArea` | Body | `craft_ui_panels::docking` | The docked tree of a layout, with a handle between neighbouring groups |
|
||||
| `StackSections` | Body | `craft_ui_panels::docking::stack` | An accordion laid out in the rect it is shown at (`section_heights` with the strip height of the docking sizes), with a divider between its open sections |
|
||||
| `TitleBar` | Body | `craft_ui_shell::shell::title_bar::bar` | The bar of a window whose frame the app draws |
|
||||
| `ToolRail` | Body | `craft_ui_panels::rails::tool` | The rail of tool slots, as a side panel at one edge of the window: one `FlyoutButton` per visible slot showing the slot's shown tool, the slot with the current tool toggled on |
|
||||
| `ToolRail` | Body | `craft_ui_panels::rails::tool` | The rail of tool slots in a grid of as many columns as its width holds: one `FlyoutButton` per visible slot showing the slot's shown tool, the slot with the current tool toggled on; its dock column is whole tool columns wide and as tall as its rows and footer |
|
||||
| `AboutDialog` | Pattern | `craft_ui_patterns::patterns::form_dialogs::about` | Help > About: tabs About, Contributors and Models over the app's [`AboutInfo`] and [`Credits`], with an OK button |
|
||||
| `Alert` | Pattern | `craft_ui_panels::dialog::alert` | A modal notice with one OK button: a prompt whose only answer is OK, which OK, Enter, Escape and the close action all give |
|
||||
| `AlignBar` | Pattern | `craft_ui_widgets::bars::align` | The two sections of four align and distribute buttons, then the menu button, shown as children of a `Bar` |
|
||||
@@ -235,7 +234,7 @@ Grouped by gallery level, then shape, then name.
|
||||
| `DocumentWindow` | Body | `craft_ui_shell::shell::document_window` | A document's window: the container of one entry of the app's window list, in its own OS window |
|
||||
| `ShellRegion` | Body | `craft_ui_shell::shell::app_shell` | A region of the window skeleton: the root window's content, the scope that carries the shell to its slots, or one pane (a bar, a rail or the body) |
|
||||
| `AppShell` | Pattern | `craft_ui_shell::shell::app_shell` | The window skeleton |
|
||||
| `CanvasPanel` | Pattern | `craft_ui_shell::shell::canvas_shell` | The canvas panel of a dock: the panel rail at the end edge, spanning the tabs and the document; then, in what is left, the document tab strip flush against the document; then the document area, over the canvas surround |
|
||||
| `CanvasPanel` | Pattern | `craft_ui_shell::shell::canvas_shell` | The canvas panel of a dock: the document tab strip flush against the document; then the document area, over the canvas surround |
|
||||
| `OpeningCard` | Pattern | `craft_ui_shell::shell::opening` | A centred card: "Opening {name}…" elided on one line with the full text on hover, the muted message, a progress bar (indeterminate without a fraction), the percentage at the start and Cancel at the end of the last row |
|
||||
| `ScreenModeButton` | Pattern | `craft_ui_shell::shell::screen_mode_button` | A flyout button over the three screen modes, with `mode` marked: a click, Enter or Space cycles; a hold, a drag away or a right click lists the three modes without cycling |
|
||||
| `StartScreen` | Pattern | `craft_ui_shell::shell::start` | The start screen, shown in a shell's body when no document is open |
|
||||
|
||||
@@ -3981,7 +3981,6 @@ The fixture, the suite runner and the story helpers.
|
||||
- `craft_ui::testing::Room`: re-export of `craft_ui::testing::fixture::Room`.
|
||||
- `craft_ui::testing::Target`: re-export of `craft_ui::testing::fixture::Target`.
|
||||
- `craft_ui::testing::forget_measurements`: re-export of `craft_ui::runtime::layout_memory::forget_kept`.
|
||||
- `craft_ui::testing::in_edge_pane`: `pub fn in_edge_pane<R>(ui: &mut Ui, edge: PaneEdge, story: impl FnOnce(&mut Ui) -> R) -> R`. Runs `story` as the content of an edge pane at `edge`, as a rail or panel docked at that edge of an app window
|
||||
- `craft_ui::testing::install_spec`: re-export of `craft_ui::testing::windows::install_spec`.
|
||||
- `craft_ui::testing::is_measuring`: re-export of `craft_ui::runtime::measure::active` (defined outside these crates).
|
||||
- `craft_ui::testing::last_pass_measuring_runs`: re-export of `craft_ui::runtime::measure::last_pass_body_runs` (defined outside these crates).
|
||||
|
||||
@@ -994,7 +994,7 @@ A theme with its own shape replaces the radii or adds an offset to control, surf
|
||||
| `size.groove` | Groove of a value track |
|
||||
| `size.ramp.bar` | Colour band: a gradient ramp drawn as a bar of its own (levels output bar, gradient thumb row) or as the face of a triangle-pointer channel slider |
|
||||
| `size.ramp.groove` | Gradient drawn as the groove of a value track (faced sliders) and the span between two thumbs of a gradient's thumb row |
|
||||
| `size.rail.width`, `size.rail.button` | Tool rail and panel rail |
|
||||
| `size.rail.width`, `size.rail.button` | Tool rail buttons and the cells of iconic dock columns |
|
||||
| `size.length.field.sm`, `size.length.field.md` | Text or value field, one width per control size: a field in a small options bar is narrower than one in a dialog |
|
||||
| `size.length.number.sm`, `size.length.number.md` | Number field and the number cell over a slider, one width per control size |
|
||||
| `size.length.track`, `size.length.short` | Value track, short field |
|
||||
@@ -1735,7 +1735,7 @@ The derives and macros of the UI library: `Component`, `Props`, `ComponentStyle`
|
||||
| `canvas_data` | The canvas data patterns read and write without the canvas: guides and the navigator's panel options | exists |
|
||||
| `dialog` | `Dialog`, `DialogFrame`, `BlockingOverlay`, `Prompt` and its configurations, `DialogStack`, `DialogHost` ([ui-dialogs.md](ui-dialogs.md)) | exists |
|
||||
| `docking` | `SplitArea`, `Splitter`, `DockGroup`, floating groups, the dock column, drop resolution and the dock commands ([ui-docking.md](ui-docking.md)) | exists |
|
||||
| `rails` | `PanelRail`, `ToolRail`, `FlyoutButton`, `ToolbarDrawer` | exists |
|
||||
| `rails` | `ToolRail`, `FlyoutButton`, `ToolbarDrawer` | exists |
|
||||
| `sections` | `TitleRow`, `FooterBar`, `Section`, `GroupBox`, `Panel` | exists |
|
||||
|
||||
#### craft-ui-patterns
|
||||
|
||||
@@ -216,7 +216,7 @@ name = "CanvasOutput"
|
||||
old = "craft_ui::shell::CanvasOutput"
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "`craft_ui::shell::CanvasPanelOutput { response, rail, tabs, document }`."
|
||||
note = "`craft_ui::shell::CanvasPanelOutput { response, tabs, document }`."
|
||||
|
||||
[[type]]
|
||||
name = "CanvasPanelOutput"
|
||||
@@ -230,7 +230,7 @@ name = "PanelOptions"
|
||||
old = "craft_ui::shell::PanelOptions"
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "`craft_ui::shell::CanvasPanel`: `rail(label, f)`, `tabs(f)` and `opening(bool)`; the rail and tabs are filled with `rails::PanelRail` and `tabs::DocumentTabs`."
|
||||
note = "`craft_ui::shell::CanvasPanel`: `tabs(f)` and `opening(bool)`; the tabs are filled with `tabs::DocumentTabs`."
|
||||
|
||||
[[type]]
|
||||
name = "CanvasPanel"
|
||||
@@ -244,7 +244,7 @@ name = "PanelRail"
|
||||
old = "craft_ui::shell::PanelRail"
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "The shell's own rail configuration; use `craft_ui::rails::PanelRail` inside `CanvasPanel::rail`."
|
||||
note = "The shell's own rail configuration. A collapsed dock column is the panel rail."
|
||||
|
||||
[[type]]
|
||||
name = "tab_toggles_chrome"
|
||||
|
||||
@@ -10,16 +10,16 @@ new_module = "craft_ui::rails"
|
||||
[[type]]
|
||||
name = "PanelRail"
|
||||
old = "craft_ui::patterns::rail::panel_rail::PanelRail"
|
||||
new = "craft_ui::rails::PanelRail"
|
||||
status = "moved"
|
||||
note = "A container: `PanelRail::new(label, &panels)` takes `RailTool`s (a panel key and its toggle command) and `show_rail(ui, footer)` shows it and returns `PanelRailOutput`. The shell's config `craft_ui::shell::canvas::PanelRail` (the `PanelRail<'a>` in `shell/canvas.rs`) maps onto this type in L4. `craft_ui::panes::rail::Rail` is replaced by it."
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[type]]
|
||||
name = "ToolRail"
|
||||
old = "craft_ui::patterns::rail::tool::ToolRail"
|
||||
new = "craft_ui::rails::ToolRail"
|
||||
status = "moved"
|
||||
note = "A container: `ToolRail::new(label, &slots, ¤t, &last_used)` takes the data, and `show_rail(ui, footer)` shows it and returns `ToolRailOutput` (`response` and `dropped` are new). The surface is the chrome surface and the column toggle is the header. `pick_by_key` is not ported: tool commands carry their chords in the keymap."
|
||||
note = "A container: `ToolRail::new(label, &slots, ¤t, &last_used)` takes the data, and `show_rail(ui, footer)` shows it and returns `ToolRailOutput` (`response` and `dropped` are new). The surface is the chrome surface. The rail lays out as many columns as the width it gets holds (`ToolRail::dock_grid(ctx, cells)` is its dock column's grid) and `measure_rail(ui, width, footer)` gives its size at a width. It has no column or side toggle: the dock column's double arrow switches its columns and the toolbar moves by dragging. `pick_by_key` is not ported: tool commands carry their chords in the keymap."
|
||||
|
||||
[[type]]
|
||||
name = "FlyoutButton"
|
||||
@@ -39,8 +39,8 @@ note = "A pattern: `ToolbarDrawer::new(rail_rect, &groups, &toolbar, rail_out.dr
|
||||
name = "Rail"
|
||||
old = "craft_ui::panes::rail::Rail"
|
||||
new = ""
|
||||
status = "replaced"
|
||||
note = "`craft_ui::rails::PanelRail`; the legacy `Rail` was deprecated in its favour."
|
||||
status = "removed"
|
||||
note = "Removed with `PanelRail`. A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[type]]
|
||||
name = "FlyoutItem"
|
||||
@@ -149,27 +149,28 @@ name = "PanelRailItem"
|
||||
old = "craft_ui::patterns::rail::panel_rail::PanelRailItem"
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "A panel is `RailTool::new(key, command)` with a toggle command: label, icon and chord come from the command, `checked` is the open state, `marked` and `hint` are the content marker."
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[type]]
|
||||
name = "PanelRailRequest"
|
||||
old = "craft_ui::patterns::rail::panel_rail::PanelRailRequest"
|
||||
new = "craft_ui::rails::PanelRailRequest"
|
||||
status = "moved"
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[type]]
|
||||
name = "PanelRailOutput"
|
||||
old = "craft_ui::patterns::rail::panel_rail::PanelRailOutput"
|
||||
new = "craft_ui::rails::PanelRailOutput"
|
||||
status = "moved"
|
||||
note = "`focused`, `responses` and `rect` are not reported: focus is the roving group's, each icon's response is its button's, and the rect is `response.rect`."
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[type]]
|
||||
name = "PanelRailStyle"
|
||||
old = "craft_ui::patterns::rail::panel_rail::PanelRailStyle"
|
||||
new = "craft_ui::rails::PanelRailStyle"
|
||||
status = "moved"
|
||||
note = "Opaque: the look comes from the theme."
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[type]]
|
||||
name = "DrawerGroup"
|
||||
@@ -209,21 +210,21 @@ name = "RailItem"
|
||||
old = "craft_ui::panes::rail::RailItem"
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "A panel is `RailTool::new(key, command)`; see `PanelRail`."
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[type]]
|
||||
name = "RailRequest"
|
||||
old = "craft_ui::panes::rail::RailRequest"
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "`PanelRailRequest`."
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[type]]
|
||||
name = "RailOutput"
|
||||
old = "craft_ui::panes::rail::RailOutput"
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "`PanelRailOutput`."
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[type]]
|
||||
name = "RAIL_WIDTH"
|
||||
@@ -253,17 +254,19 @@ new = "new(label, slots, current, last_used)"
|
||||
[[setter]]
|
||||
type = "ToolRail"
|
||||
old = "edge(Edge)"
|
||||
new = "edge(PaneEdge)"
|
||||
new = "opens(Side)"
|
||||
|
||||
[[setter]]
|
||||
type = "ToolRail"
|
||||
old = "columns(usize)"
|
||||
new = "columns(NonZeroU8)"
|
||||
new = ""
|
||||
note = "The width the rail gets sets its columns."
|
||||
|
||||
[[setter]]
|
||||
type = "ToolRail"
|
||||
old = "column_toggle(impl Into<String>)"
|
||||
new = "column_toggle(impl Into<Label>)"
|
||||
new = ""
|
||||
note = "The dock column bar carries the double arrow."
|
||||
|
||||
[[setter]]
|
||||
type = "ToolRail"
|
||||
@@ -341,7 +344,8 @@ new = "show(ui)"
|
||||
[[setter]]
|
||||
type = "PanelRail"
|
||||
old = "new(id_salt)"
|
||||
new = "new(label, panels)"
|
||||
new = ""
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[setter]]
|
||||
type = "PanelRail"
|
||||
@@ -352,7 +356,8 @@ note = "The rail sits where the shell mounts it."
|
||||
[[setter]]
|
||||
type = "PanelRail"
|
||||
old = "label(impl Into<String>)"
|
||||
new = "new(label, ..)"
|
||||
new = ""
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[setter]]
|
||||
type = "PanelRail"
|
||||
@@ -369,13 +374,13 @@ note = "Each icon is found by its accessible name."
|
||||
[[setter]]
|
||||
type = "PanelRail"
|
||||
old = "show(ui, items, open, foot)"
|
||||
new = "show_rail(ui, footer)"
|
||||
note = "The open panels are the checked state of each panel's command."
|
||||
new = ""
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[setter]]
|
||||
type = "Rail"
|
||||
old = "new(id)"
|
||||
new = "PanelRail::new(label, panels)"
|
||||
new = ""
|
||||
|
||||
[[setter]]
|
||||
type = "Rail"
|
||||
@@ -437,7 +442,8 @@ new = "label: Label"
|
||||
[[setter]]
|
||||
type = "PanelRailItem"
|
||||
old = "new(panel, icon, label)"
|
||||
new = "RailTool::new(panel, command)"
|
||||
new = ""
|
||||
note = "A collapsed dock column is the panel rail: panels open from the icons of their column."
|
||||
|
||||
[[setter]]
|
||||
type = "PanelRailItem"
|
||||
|
||||
Reference in New Issue
Block a user