mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 19:14:26 +00:00
Dock UI: a stepped column's double arrow is named for the steps it switches to; a floating stepped window's left grip keeps its right edge
This commit is contained in:
@@ -30,7 +30,7 @@ mod sizing;
|
||||
|
||||
use bar::panel_names;
|
||||
|
||||
pub(super) use bar::{BarRecord, CHEVRON, bar_name, bar_slots, chevron_name, describe_chevron, paint_chevron, show_bar};
|
||||
pub(super) use bar::{BarRecord, CHEVRON, bar_name, bar_slots, describe_chevron, paint_chevron, show_bar};
|
||||
use sizing::group_sizes;
|
||||
pub use sizing::{GroupSize, fit_widths, group_heights, scale_widths, stacked, stepped, width_bounds};
|
||||
|
||||
@@ -61,6 +61,56 @@ impl ColumnBar {
|
||||
}
|
||||
}
|
||||
|
||||
/// What a column's double arrow does, which names it and sets where it points.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum ColumnArrow {
|
||||
/// Collapses the column to icons, or expands it.
|
||||
#[default]
|
||||
Collapse,
|
||||
/// Switches a stepped column ([`stepped`]) between one and two steps. Holds the steps it shows.
|
||||
Steps(u16),
|
||||
}
|
||||
|
||||
impl ColumnArrow {
|
||||
/// The arrow of `column`: an expanded stepped column whose panels do not collapse (`collapses` false) switches
|
||||
/// steps; any other column collapses or expands.
|
||||
pub fn of<P>(column: &Column<P>, spec: &dyn Fn(&P) -> PanelSpec, collapses: bool) -> Self {
|
||||
match stepped(column, spec) {
|
||||
Some((_, steps)) if !collapses && !column.iconic => ColumnArrow::Steps(steps),
|
||||
_ => ColumnArrow::Collapse,
|
||||
}
|
||||
}
|
||||
|
||||
/// The steps a click gives a stepped column: two from one, else one. `None` for an arrow that collapses.
|
||||
pub fn switched_steps(self) -> Option<u16> {
|
||||
match self {
|
||||
ColumnArrow::Collapse => None,
|
||||
ColumnArrow::Steps(steps) => Some(if steps == 1 { 2 } else { 1 }),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a click sends the column towards the edge it keeps to: collapsing the `expanded` column, or narrowing a
|
||||
/// stepped one.
|
||||
pub(super) fn towards_edge(self, expanded: bool) -> bool {
|
||||
match self {
|
||||
ColumnArrow::Collapse => expanded,
|
||||
ColumnArrow::Steps(steps) => steps > 1,
|
||||
}
|
||||
}
|
||||
|
||||
/// The arrow's name: what a click on it does to the `expanded` or collapsed column.
|
||||
pub(super) fn name(self, words: &DockWords, expanded: bool) -> Label {
|
||||
let word = match self {
|
||||
ColumnArrow::Collapse if expanded => &words.collapse_column,
|
||||
ColumnArrow::Collapse => &words.expand_column,
|
||||
ColumnArrow::Steps(1) => &words.two_steps,
|
||||
ColumnArrow::Steps(_) => &words.one_step,
|
||||
};
|
||||
Label::from(word.as_str().to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
/// The caller's view of one group: the group, the rect it takes and the body step's context. The dock passes the
|
||||
/// group to `DockPanels::group_view` or shows a `DockGroup` in it.
|
||||
pub type GroupView<'a, P> = Box<dyn FnMut(&Group<P>, Rect, &mut Ui, &mut BodyCx<'_>) + 'a>;
|
||||
@@ -131,6 +181,9 @@ pub struct DockColumn<'a, P: Value + Hash + 'static> {
|
||||
/// Where the column's bar is: its own (a dock column) or its floating window's title row.
|
||||
#[prop]
|
||||
bar: ColumnBar,
|
||||
/// What the double arrow of the column's own bar does ([`ColumnArrow::of`]).
|
||||
#[prop]
|
||||
arrow: ColumnArrow,
|
||||
/// The rect the dock may grow within, which bounds how wide its inner edge can make the column.
|
||||
#[prop]
|
||||
within: Rect,
|
||||
@@ -155,6 +208,7 @@ impl<'a, P: Value + Hash + 'static> DockColumn<'a, P> {
|
||||
auto_collapse: false,
|
||||
edge: DockEdge::Start,
|
||||
bar: ColumnBar::Own,
|
||||
arrow: ColumnArrow::Collapse,
|
||||
within: Rect::NOTHING,
|
||||
laid: None,
|
||||
resized: Vec::new(),
|
||||
@@ -341,7 +395,7 @@ impl<P: Value + Hash + 'static> Component for DockColumn<'_, P> {
|
||||
let plan = column_plan(self.column, self.spec, rect, self.bar, &sizes, |_, _| None);
|
||||
if self.bar == ColumnBar::Own {
|
||||
let (chevron, _) = bar_slots(plan.bar, self.edge, cx.flow.is_rtl());
|
||||
let name = chevron_name(&cx.words::<DockWords>(), true);
|
||||
let name = self.arrow.name(&cx.words::<DockWords>(), true);
|
||||
let _ = cx.part(CHEVRON, chevron).sense(Sense::CLICK | Sense::FOCUS).focusable().tooltip(name);
|
||||
}
|
||||
let dividers = plan.dividers(rect, sizes.reach);
|
||||
@@ -395,7 +449,7 @@ impl<P: Value + Hash + 'static> Component for DockColumn<'_, P> {
|
||||
ui.draw().surface(cx.rect, SurfaceKind::Panel, Corners::All);
|
||||
if self.bar == ColumnBar::Own {
|
||||
ui.draw().surface(plan.bar, SurfaceKind::Background, Corners::None);
|
||||
paint_chevron(ui, self.edge, true, cx.flow.is_rtl(), chevron_name(&cx.words::<DockWords>(), true));
|
||||
paint_chevron(ui, self.edge, self.arrow, true, cx.flow.is_rtl(), &cx.words::<DockWords>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,7 +482,7 @@ impl<P: Value + Hash + 'static> Component for DockColumn<'_, P> {
|
||||
if self.bar == ColumnBar::Own {
|
||||
let edge = self.edge_divider(cx.rect, &sizes);
|
||||
divider::describe(access, EDGE, 0, &edge, words.resize.as_str(), sizes.step);
|
||||
describe_chevron(access, &chevron_name(&words, true));
|
||||
describe_chevron(access, &self.arrow.name(&words, true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::buttons::icon_button::IconButtonStyleKey;
|
||||
use crate::contract::overlay::Trigger;
|
||||
use crate::contract::{Access, BodyCx, Name, PaintUi, Props as _, Role, Show as _, ShowContainer as _, WordSetCx as _};
|
||||
use crate::docking::group::GroupGrip;
|
||||
use crate::docking::{DockWords, PanelSpec};
|
||||
use crate::docking::{ColumnArrow, DockWords, PanelSpec};
|
||||
use crate::menu::{GroupItem, Menu, MenuWords, PanelMenu, PanelRow};
|
||||
use crate::runtime::env::Label;
|
||||
use craft_behavior::PartKey;
|
||||
@@ -38,11 +38,11 @@ fn collapse_look(tokens: &Tokens) -> VariantLook {
|
||||
|
||||
const COLLAPSE: CustomVariant = CustomVariant::new::<IconButtonStyleKey>("craft_ui.dock-collapse", collapse_look);
|
||||
|
||||
/// Whether the column's collapse control points to the right of the screen: towards the window edge when it collapses
|
||||
/// to icons and away from it when it expands.
|
||||
fn points_right(edge: DockEdge, expanded: bool, rtl: bool) -> bool {
|
||||
/// Whether the column's double arrow points to the right of the screen: towards the edge it keeps to when a click sends
|
||||
/// the column there (`towards_edge`), else away from it.
|
||||
fn points_right(edge: DockEdge, towards_edge: bool, rtl: bool) -> bool {
|
||||
let at_left = (edge == DockEdge::Start) != rtl;
|
||||
at_left != expanded
|
||||
at_left != towards_edge
|
||||
}
|
||||
|
||||
/// The chevron's slot at the bar's outer end, the window edge the dock is on, as high and wide as the bar is high; and
|
||||
@@ -58,15 +58,11 @@ pub(in crate::docking) fn bar_slots(bar: Rect, edge: DockEdge, rtl: bool) -> (Re
|
||||
}
|
||||
}
|
||||
|
||||
/// The name of the chevron of an expanded or an iconic column.
|
||||
pub(in crate::docking) fn chevron_name(words: &DockWords, expanded: bool) -> Label {
|
||||
Label::from(if expanded { words.collapse_column.as_str() } else { words.expand_column.as_str() }.to_owned())
|
||||
}
|
||||
|
||||
/// Paints the chevron part: a small ghost button with the double chevron pointing where the column goes.
|
||||
pub(in crate::docking) fn paint_chevron(ui: &mut PaintUi<'_>, edge: DockEdge, expanded: bool, rtl: bool, name: Label) {
|
||||
let chevrons = crate::collapse::chevrons(points_right(edge, expanded, rtl));
|
||||
ui.face(CHEVRON, IconButton::new(chevrons).size(ControlSize::Sm).variant(Variant::Custom(COLLAPSE)).label(name));
|
||||
/// Paints the chevron part of the `expanded` or collapsed column whose double arrow is `arrow`: a small ghost button
|
||||
/// with the double chevron pointing where the column goes, named for what a click does.
|
||||
pub(in crate::docking) fn paint_chevron(ui: &mut PaintUi<'_>, edge: DockEdge, arrow: ColumnArrow, expanded: bool, rtl: bool, words: &DockWords) {
|
||||
let chevrons = crate::collapse::chevrons(points_right(edge, arrow.towards_edge(expanded), rtl));
|
||||
ui.face(CHEVRON, IconButton::new(chevrons).size(ControlSize::Sm).variant(Variant::Custom(COLLAPSE)).label(arrow.name(words, expanded)));
|
||||
}
|
||||
|
||||
/// The chevron's node.
|
||||
@@ -89,7 +85,7 @@ pub(in crate::docking) fn show_bar<P: Clone + Send + Sync + 'static>(
|
||||
let words = body.words::<DockWords>();
|
||||
let menu_words = body.words::<MenuWords>();
|
||||
let rtl = crate::runtime::env::Env::of(ui).direction.is_rtl();
|
||||
let toggle = chevron_name(&words, expanded);
|
||||
let toggle = ColumnArrow::Collapse.name(&words, expanded);
|
||||
let (_, band) = bar_slots(bar, edge, rtl);
|
||||
let mut record = BarRecord::default();
|
||||
if band.width() <= 0.0 {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//! opens the `menu` rows. The body step supplies the move band, the edge grips and the keyboard Move and Size modes.
|
||||
//! A dock window's title row is also the bar of the column the window holds, with the column's double arrow.
|
||||
|
||||
use super::dock_column::{CHEVRON, chevron_name, describe_chevron, paint_chevron};
|
||||
use super::dock_column::{CHEVRON, ColumnArrow, describe_chevron, paint_chevron};
|
||||
use super::drop::{DragUnit, start_group_drag};
|
||||
use super::{DockDropTarget, DockDropped, DockWords, GroupDrag, PanelDrag, PanelKey, native};
|
||||
use crate::contract::BodyCx;
|
||||
@@ -56,24 +56,32 @@ pub struct WindowColumn {
|
||||
/// The size of an expanded column whose content sets it (a column with steps) under the title row; `None` for a
|
||||
/// column the rect sizes.
|
||||
pub fitted: Option<Vec2>,
|
||||
/// What the double arrow does: collapse or expand the column unless [`arrow`](Self::arrow) says otherwise.
|
||||
pub arrow: ColumnArrow,
|
||||
}
|
||||
|
||||
impl WindowColumn {
|
||||
/// An expanded column that keeps to `edge`.
|
||||
pub fn expanded(edge: DockEdge) -> Self {
|
||||
WindowColumn { edge, collapsed: None, fitted: None }
|
||||
WindowColumn { edge, collapsed: None, fitted: None, arrow: ColumnArrow::Collapse }
|
||||
}
|
||||
|
||||
/// A column collapsed to icons, `size` under the title row, that keeps to `edge`.
|
||||
pub fn collapsed(edge: DockEdge, size: Vec2) -> Self {
|
||||
WindowColumn { edge, collapsed: Some(size), fitted: None }
|
||||
WindowColumn { edge, collapsed: Some(size), fitted: None, arrow: ColumnArrow::Collapse }
|
||||
}
|
||||
|
||||
/// An expanded column whose content is `size` under the title row, that keeps to `edge`. The window shows at
|
||||
/// that size at its rect's place; a resize the user makes is reported for the host to turn into the column's
|
||||
/// steps, and a move keeps the rect's size.
|
||||
pub fn fitted(edge: DockEdge, size: Vec2) -> Self {
|
||||
WindowColumn { edge, collapsed: None, fitted: Some(size) }
|
||||
WindowColumn { edge, collapsed: None, fitted: Some(size), arrow: ColumnArrow::Collapse }
|
||||
}
|
||||
|
||||
/// The column with the double arrow `arrow` ([`ColumnArrow::of`]).
|
||||
pub fn arrow(mut self, arrow: ColumnArrow) -> Self {
|
||||
self.arrow = arrow;
|
||||
self
|
||||
}
|
||||
|
||||
/// The edge of `bounds`, in reading order, nearer the window at `rect`: the start edge when the window's centre is
|
||||
@@ -363,7 +371,7 @@ impl Component for FloatingGroup<'_> {
|
||||
fn parts(&mut self, _: Rect, cx: &mut PartsCx<'_, Self>) {
|
||||
let (Some(edge), Some(column)) = (self.chevron_edge(), self.column) else { return };
|
||||
let Some(slot) = cx.header_slot(edge) else { return };
|
||||
let name = chevron_name(&cx.words::<DockWords>(), column.collapsed.is_none());
|
||||
let name = column.arrow.name(&cx.words::<DockWords>(), column.collapsed.is_none());
|
||||
let _ = cx.header_part(edge, CHEVRON, slot).sense(Sense::CLICK | Sense::FOCUS).focusable().tooltip(name);
|
||||
self.chevron_declared = true;
|
||||
}
|
||||
@@ -386,13 +394,12 @@ impl Component for FloatingGroup<'_> {
|
||||
/// The double arrow, over the title row's surface.
|
||||
fn paint_over(&mut self, ui: &mut PaintUi<'_>, cx: &Cx<'_, Self>) {
|
||||
let Some(column) = self.column.filter(|_| self.chevron_declared) else { return };
|
||||
let expanded = column.collapsed.is_none();
|
||||
paint_chevron(ui, column.edge, expanded, cx.flow.is_rtl(), chevron_name(&cx.words::<DockWords>(), expanded));
|
||||
paint_chevron(ui, column.edge, column.arrow, column.collapsed.is_none(), cx.flow.is_rtl(), &cx.words::<DockWords>());
|
||||
}
|
||||
|
||||
fn access(&self, access: &mut Access, cx: &Cx<'_, Self>) {
|
||||
if let Some(column) = self.column.filter(|_| self.chevron_declared) {
|
||||
describe_chevron(access, &chevron_name(&cx.words::<DockWords>(), column.collapsed.is_none()));
|
||||
describe_chevron(access, &column.arrow.name(&cx.words::<DockWords>(), column.collapsed.is_none()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use super::divider::{self, Divider, Drag};
|
||||
use super::dock_column::{
|
||||
BarRecord, CHEVRON, ColumnBar, bar_slots, chevron_name, column_grip, describe_chevron, paint_chevron, register_edges, show_bar,
|
||||
BarRecord, CHEVRON, ColumnArrow, ColumnBar, bar_slots, column_grip, describe_chevron, paint_chevron, register_edges, show_bar,
|
||||
};
|
||||
use super::{DockSizes, DockSpot, DockTargets, DockWords, DragUnit, Flyout, GroupAt, PanelKey, PanelSpec, Splitter, start_group_drag};
|
||||
use crate::buttons::IconButton;
|
||||
@@ -419,7 +419,7 @@ impl<P: Value + Hash + 'static> Component for IconicColumn<'_, P> {
|
||||
self.bar_rect = plan.bar;
|
||||
if self.bar == ColumnBar::Own {
|
||||
let (chevron, _) = bar_slots(plan.bar, self.edge, cx.flow.is_rtl());
|
||||
let name = chevron_name(&cx.words::<DockWords>(), false);
|
||||
let name = ColumnArrow::Collapse.name(&cx.words::<DockWords>(), false);
|
||||
let _ = cx.header_part(chevron_edge(self.edge), CHEVRON, chevron).sense(Sense::CLICK | Sense::FOCUS).focusable().tooltip(name);
|
||||
}
|
||||
for (at, (_, _, cell)) in plan.cells.iter().enumerate() {
|
||||
@@ -525,7 +525,7 @@ impl<P: Value + Hash + 'static> Component for IconicColumn<'_, P> {
|
||||
ui.draw().surface(cx.rect, SurfaceKind::Panel, Corners::All);
|
||||
if self.bar == ColumnBar::Own {
|
||||
ui.draw().surface(self.bar_rect, SurfaceKind::Background, Corners::None);
|
||||
paint_chevron(ui, self.edge, false, cx.flow.is_rtl(), chevron_name(&cx.words::<DockWords>(), false));
|
||||
paint_chevron(ui, self.edge, ColumnArrow::Collapse, false, cx.flow.is_rtl(), &cx.words::<DockWords>());
|
||||
}
|
||||
let flat = self.flat();
|
||||
for (at, (group, panel)) in flat.iter().enumerate() {
|
||||
@@ -562,7 +562,7 @@ impl<P: Value + Hash + 'static> Component for IconicColumn<'_, P> {
|
||||
}
|
||||
divider::describe(access, EDGE, 0, &self.edge_divider(cx.rect, &sizes.column), words.resize.as_str(), sizes.column.step);
|
||||
if self.bar == ColumnBar::Own {
|
||||
describe_chevron(access, &chevron_name(&words, false));
|
||||
describe_chevron(access, &ColumnArrow::Collapse.name(&words, false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ mod flyout;
|
||||
mod iconic;
|
||||
|
||||
pub use dock_column::{
|
||||
ColumnBar, DockColumn, DockColumnOutput, DockColumnStyle, GroupSize, GroupView, fit_widths, group_heights, scale_widths, stacked, stepped,
|
||||
ColumnArrow, ColumnBar, DockColumn, DockColumnOutput, DockColumnStyle, GroupSize, GroupView, fit_widths, group_heights, scale_widths, stacked, stepped,
|
||||
width_bounds,
|
||||
};
|
||||
pub use flyout::{Flyout, FlyoutOutput, FlyoutShown, FlyoutStyle, GroupAt};
|
||||
|
||||
@@ -14,6 +14,10 @@ craft_ui::words! {
|
||||
move_column: template "dockColumn.move" = "Move panel column";
|
||||
collapse_column: "dockColumn.collapse" = "Collapse column to icons";
|
||||
expand_column: "dockColumn.expand" = "Expand column";
|
||||
/// The double arrow of a stepped column at one step, which widens it to two.
|
||||
two_steps: "dockColumn.twoSteps" = "Show in two columns";
|
||||
/// The double arrow of a stepped column at more than one step, which narrows it to one.
|
||||
one_step: "dockColumn.oneStep" = "Show in one column";
|
||||
move_window: "floatingGroup.move" = "Move panel window";
|
||||
close_window: "floatingGroup.close" = "Close panel window";
|
||||
/// The tooltip and accessible name of the panel-menu button.
|
||||
|
||||
@@ -11,16 +11,17 @@ use crate::docking::stack::{StackSection, StackSections, section_heights};
|
||||
use crate::docking::tree::FrameRules;
|
||||
use crate::docking::{Arrangement, close_requests, cross_window, end_replaced_drags, float_drop, native, open_requests};
|
||||
use crate::docking::{
|
||||
ColumnBar, DockColumn, DockCommands, DockConfig, DockDropTarget, DockDropped, DockEvent, DockGroup, DockPanels, DockRoot, DockScene, DockSizes,
|
||||
DockSpot, DockTargets, DockTo, DockWords, DragUnit, FloatSpace, FloatingGroup, FlyoutResize, GroupAt, GroupDrag, HidePanels, IconicColumn,
|
||||
IconicSizes, PanelDrag, PanelKey, PanelSpec, PanelTitle, SplitArea, WindowColumn, actions, dock_states, fit_widths, frame, move_actions, stepped,
|
||||
ColumnArrow, ColumnBar, DockColumn, DockCommands, DockConfig, DockDropTarget, DockDropped, DockEvent, DockGroup, DockPanels, DockRoot, DockScene,
|
||||
DockSizes, DockSpot, DockTargets, DockTo, DockWords, DragUnit, FloatSpace, FloatingGroup, FlyoutResize, GroupAt, GroupDrag, HidePanels,
|
||||
IconicColumn, IconicSizes, PanelDrag, PanelKey, PanelSpec, PanelTitle, SplitArea, WindowColumn, actions, dock_states, fit_widths, frame,
|
||||
move_actions, stepped,
|
||||
};
|
||||
use crate::menu::{GroupItem, MenuWords, PanelMenu, PanelRow};
|
||||
use crate::runtime::commands::{CommandRef, CommandSet as _, Commands as _, focus_within};
|
||||
use crate::runtime::drag;
|
||||
use crate::runtime::env::{Env, Label, RevealEdge, ShellCx, ShellEntry};
|
||||
use crate::runtime::memory::Remember as _;
|
||||
use crate::runtime::windows::WindowHost;
|
||||
use crate::runtime::windows::{ResizeEdge, WindowHost};
|
||||
use crate::sections::HeaderAction;
|
||||
use craft_behavior::dock::{
|
||||
Action, Column, DockEdge, DockError, Group, Layout, Location, Node, PanelPlace, Permissions, SplitSize, Workspace, node_at,
|
||||
@@ -944,16 +945,20 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
Some(height)
|
||||
}
|
||||
|
||||
/// What a click on the double arrow of `column`, whose first panel is `first`, asks for when it reports
|
||||
/// `iconic`: an expanded stepped column whose panels do not collapse switches between one and two steps; any
|
||||
/// other column collapses to icons or expands.
|
||||
fn arrow(&self, column: &Column<P>, first: &P, iconic: bool) -> Action<P> {
|
||||
/// What the double arrow of `column` does ([`ColumnArrow::of`]): it names the arrow and decides what a click asks
|
||||
/// for.
|
||||
fn arrow_of(&self, column: &Column<P>) -> ColumnArrow {
|
||||
let scene = self.scene;
|
||||
let spec = |panel: &P| scene.spec(panel);
|
||||
let collapses = column.panels().all(|panel| scene.permissions(panel).collapses);
|
||||
match stepped(column, &spec) {
|
||||
Some((_, steps)) if !collapses && !column.iconic => Action::set_column_steps(first.clone(), if steps == 1 { 2 } else { 1 }),
|
||||
_ => Action::set_iconic(first.clone(), iconic),
|
||||
ColumnArrow::of(column, &spec, column.panels().all(|panel| scene.permissions(panel).collapses))
|
||||
}
|
||||
|
||||
/// What a click on the double arrow of `column`, whose first panel is `first`, asks for when it reports
|
||||
/// `iconic`: the steps it switches to, or the collapse or expansion of the column.
|
||||
fn arrow(&self, column: &Column<P>, first: &P, iconic: bool) -> Action<P> {
|
||||
match self.arrow_of(column).switched_steps() {
|
||||
Some(steps) => Action::set_column_steps(first.clone(), steps),
|
||||
None => Action::set_iconic(first.clone(), iconic),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -981,6 +986,7 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
let output = DockColumn::new(name, dock, column, &spec)
|
||||
.edge(edge)
|
||||
.bar(bar)
|
||||
.arrow(self.arrow_of(column))
|
||||
.within(within)
|
||||
.auto_collapse(scene.auto_collapse)
|
||||
.show_groups_at(ui, cell, |group, rect, ui, body| {
|
||||
@@ -1050,7 +1056,8 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
///
|
||||
/// A window whose column has steps ([`stepped`]) is as wide as its steps and as tall as its content at that
|
||||
/// width, at its rect's place: a drag of its side sets the most steps that fit the width, one of its top or
|
||||
/// bottom the fewest whose content fits the height, and the window keeps its place.
|
||||
/// bottom the fewest whose content fits the height, and the window keeps its place; a drag of its left side keeps
|
||||
/// its right edge.
|
||||
fn windows(&mut self, ui: &mut Ui, body: &mut BodyCx<'_>, open: &Option<P>, started: Option<&Layout<P>>) -> Option<(P, PlacementChange)> {
|
||||
let scene = self.scene;
|
||||
let ctx = ui.ctx().clone();
|
||||
@@ -1097,7 +1104,8 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
WindowColumn::fitted(edge, Vec2::new(width, content))
|
||||
} else {
|
||||
WindowColumn::expanded(edge)
|
||||
};
|
||||
}
|
||||
.arrow(self.arrow_of(&window.column));
|
||||
let mut group = FloatingGroup::new(spec.label, opening.rect)
|
||||
.limits(scene.spec(&anchor).limits)
|
||||
.sized(Sizing::Fill)
|
||||
@@ -1151,17 +1159,28 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
&& let Some((grid, steps)) = stepped(&window.column, &spec_of)
|
||||
{
|
||||
let column = &window.column;
|
||||
let to = if (change.rect.width() - fitted.x).abs() > 0.5 {
|
||||
grid.steps_within(change.rect.width())
|
||||
} else {
|
||||
// A grip on the top or bottom edge sets the steps by height, any other grip by width; keyboard Size
|
||||
// mode, which names no grip, by the side it changed.
|
||||
let by_height = match change.kind {
|
||||
PlacementKind::Size(grip) => matches!(grip, ResizeEdge::Top | ResizeEdge::Bottom),
|
||||
_ => (change.rect.width() - fitted.x).abs() <= 0.5,
|
||||
};
|
||||
let to = if by_height {
|
||||
let room = change.rect.height() - scene.sizes.strip;
|
||||
grid.steps_for_height(room, |width| self.stepped_height(ui, body, column, width, true).unwrap_or(0.0))
|
||||
} else {
|
||||
grid.steps_within(change.rect.width())
|
||||
};
|
||||
if to != steps {
|
||||
self.report.actions.push(Action::set_column_steps(anchor.clone(), to));
|
||||
}
|
||||
// The window keeps its place; its steps set its size.
|
||||
change.rect = Rect::from_min_size(change.rect.min, opening.rect.size());
|
||||
// The window keeps its place and its steps set its size. A grip on the left keeps the right edge
|
||||
// where it is, so the window grows or shrinks to the left.
|
||||
let left = match change.kind {
|
||||
PlacementKind::Size(ResizeEdge::Left | ResizeEdge::TopLeft | ResizeEdge::BottomLeft) => change.rect.right() - grid.width(to),
|
||||
_ => change.rect.left(),
|
||||
};
|
||||
change.rect = Rect::from_min_size(Pos2::new(left, change.rect.top()), opening.rect.size());
|
||||
}
|
||||
if change.phase == GesturePhase::Commit {
|
||||
self.report.events.push(DockEvent::FloatPlaced { panel: anchor.clone(), rect: change.rect });
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
//! Dock columns: room sharing between groups, and a dock side's total width shared between its columns.
|
||||
|
||||
use craft_behavior::Axis;
|
||||
use craft_behavior::dock::{Action, Column, DockEdge, Group, Layout, Node, Permissions, SplitSize, Workspace, node_at};
|
||||
use craft_behavior::dock::{Action, Column, DockEdge, Floating, Group, Layout, Node, Permissions, SplitSize, Workspace, node_at};
|
||||
use craft_ui::contract::{Bind, BodyCx, Role, Show as _, SizeLimits};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::docking::{DockConfig, DockGrid, DockHeights, DockPanels, GroupSize, PanelSpec, group_heights};
|
||||
use craft_ui::patterns::dock::DockArea;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Rect, Ui, Vec2};
|
||||
use egui::{Pos2, Rect, Ui, Vec2};
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
@@ -164,7 +164,7 @@ impl DockPanels<u32> for Tools {
|
||||
}
|
||||
|
||||
/// A docked stepped column is only as tall as its content, not the dock's height; the double arrow of a column that
|
||||
/// does not collapse switches it between one and two steps.
|
||||
/// does not collapse switches it between one and two steps, and is named for the steps it switches to.
|
||||
#[trial]
|
||||
fn a_docked_stepped_column_fits_its_content_and_its_double_arrow_switches_one_and_two_steps() {
|
||||
let dock = Node::dock(DockEdge::Start, vec![Column::new(vec![Group::new(vec![TOOLS], 0)]).with_steps(1)]);
|
||||
@@ -191,14 +191,38 @@ fn a_docked_stepped_column_fits_its_content_and_its_double_arrow_switches_one_an
|
||||
},
|
||||
other => panic!("{other:?}"),
|
||||
};
|
||||
for expected in [2, 1] {
|
||||
for (name, expected) in [("Show in two columns", 2), ("Show in one column", 1)] {
|
||||
let tree = fixture.tree();
|
||||
let arrow = fixture
|
||||
.by_role(Role::BUTTON)
|
||||
.into_iter()
|
||||
.find(|button| craft_ui::testing::access::name(tree, button.node) == Some("Collapse column to icons"))
|
||||
.expect("the column bar shows its double arrow");
|
||||
.find(|button| craft_ui::testing::access::name(tree, button.node) == Some(name))
|
||||
.expect("the column bar shows its double arrow, named for the steps it switches to");
|
||||
fixture.click(&arrow).settle();
|
||||
assert_eq!(steps(&workspace.borrow()), Some(expected), "the double arrow switches the steps");
|
||||
}
|
||||
}
|
||||
|
||||
/// A drag of a floating stepped window's left edge widens it in whole steps to the left: its right edge stays.
|
||||
#[trial]
|
||||
fn a_floating_stepped_windows_left_edge_drag_keeps_its_right_edge() {
|
||||
let at = Rect::from_min_size(Pos2::new(200.0, 80.0), Vec2::new(100.0, 100.0));
|
||||
let window = Floating::new(Column::new(vec![Group::new(vec![TOOLS], 0)]).with_steps(1), at);
|
||||
let workspace = Rc::new(RefCell::new(Workspace::new(Layout::new(None, vec![window]))));
|
||||
let held = Rc::clone(&workspace);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let mut workspace = held.borrow().clone();
|
||||
DockArea::new("Floating tools", Bind::bound(&mut workspace), &mut Tools, DockConfig::default()).show(ui);
|
||||
*held.borrow_mut() = workspace;
|
||||
});
|
||||
fixture.settle();
|
||||
let shown = |fixture: &Fixture| fixture.by_role(Role::TAB_PANEL).first().map(|group| group.rect).expect("the window shows its group");
|
||||
let before = shown(&fixture);
|
||||
// The left grip straddles the window's left edge, which is its rect's.
|
||||
fixture.drag_at(Pos2::new(at.left(), before.center().y), Vec2::new(-1.5 * grid().step, 0.0)).settle();
|
||||
let after = shown(&fixture);
|
||||
let steps = workspace.borrow().layout.floating[0].column.steps;
|
||||
assert!(steps.is_some_and(|steps| steps > 1), "the drag widened the window by whole steps: {steps:?}");
|
||||
assert!((after.right() - before.right()).abs() <= 1.5, "the right edge stays: {before:?}, then {after:?}");
|
||||
assert!(after.left() < before.left(), "the window grew to the left: {before:?}, then {after:?}");
|
||||
}
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ The theme's docking sizes (`DockSizes`) set the drop bands and zones. `DockWords
|
||||
- A column collapsed to icons takes drops as an expanded column does: its edges (a new column beside it, docked only), the seams between its icon groups, the top of the first group and the bottom of the last (a new group above or below), and each icon group's cells (join its tabs). The column's state wins: a panel dropped into a collapsed column shows as an icon, one dropped into an expanded column shows expanded.
|
||||
- Nothing goes beside a floating window: its column registers no edge bands, and its groups (`DockGroup::in_window`) take no drop on their start and end sides.
|
||||
- A collapsed column's flyouts open on the side `IconicColumn::opens` names: away from a dock's window edge, and towards the room of the float area for a floating window. A floating window keeps to the edge of the float area nearer it; a move keeps the edge it began with, and a collapsed window's move ends with its strip where it was dropped (`WindowColumn::anchored`).
|
||||
- A panel that lays its content in a grid (a toolbar) declares it with `PanelSpec::grid` (`DockGrid`: the width at one content column, the width each further column adds, and the most columns). Its column, given steps (`Column::steps`), is a whole number of content columns wide and as tall as the content measures at that width: docked from the top of the dock, content taller than the dock scrolls inside; floating under the title row, at the window's place. A drag of the column's edge, or of a floating window's side, sets the most steps that fit; a drag of a floating window's top or bottom the fewest whose content fits. When the column's panels do not collapse, its double arrow switches between one and two steps. A dock side's total width (`DockSizes::resize_side`) leaves a stepped column's width alone.
|
||||
- A panel that lays its content in a grid (a toolbar) declares it with `PanelSpec::grid` (`DockGrid`: the width at one content column, the width each further column adds, and the most columns). Its column, given steps (`Column::steps`), is a whole number of content columns wide and as tall as the content measures at that width: docked from the top of the dock, content taller than the dock scrolls inside; floating under the title row, at the window's place. A drag of the column's edge, or of a floating window's side, sets the most steps that fit, and a drag of a floating window's left side keeps its right edge; a drag of a floating window's top or bottom sets the fewest whose content fits. When the column's panels do not collapse, its double arrow switches between one and two steps (`ColumnArrow::Steps`), named for the count it switches to and pointing the way the column grows or shrinks. A dock side's total width (`DockSizes::resize_side`) leaves a stepped column's width alone.
|
||||
- Ctrl or Cmd held at the release floats the drop. A release over the dragged unit's own group leaves it where it is.
|
||||
- A drag ends without a change when another arrangement replaces the workspace it started on: it records the workspace's revision, which `Workspace::replace` and the `WorkspaceSet` switch and reset change. The dock's own edits keep the revision, so they keep the drag.
|
||||
- A dock column's last open group fills the column: it takes the height the other groups leave and asks for its `DockHeights::fill`. The other groups keep the height the user gave them, or take their `DockHeights::default`, which shrinks towards `compact` before the filling group gets less than its fill. Groups that ask for no heights share the free height with the filling group.
|
||||
|
||||
@@ -637,6 +637,13 @@ new = "craft_ui::docking::DockColumn"
|
||||
status = "replaced"
|
||||
note = "A column of a side dock: the column bar over the stacked groups. Replaces the hand-rolled column bar, collapse button and group stacking of the dock renderer."
|
||||
|
||||
[[type]]
|
||||
name = "ColumnArrow"
|
||||
old = ""
|
||||
new = "craft_ui::docking::ColumnArrow"
|
||||
status = "replaced"
|
||||
note = "What a column's double arrow does, which names it and sets where it points: `Collapse`, or `Steps(n)` for a stepped column whose panels do not collapse, which switches between one and two steps. `ColumnArrow::of(&Column<P>, spec, collapses)`; `DockColumn::arrow` and `WindowColumn::arrow` take it. Replaces `ToolRail`'s column toggle."
|
||||
|
||||
[[type]]
|
||||
name = "IconicColumn"
|
||||
old = ""
|
||||
|
||||
Reference in New Issue
Block a user