mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 05:37:04 +00:00
Merge pull request #3216 from storytold/design-port/pr-docking-rails
Docking and rails options
This commit is contained in:
@@ -232,7 +232,7 @@ impl Component for ColumnBar<'_> {
|
||||
start = end;
|
||||
}
|
||||
for (at, divider) in dividers(&shares, rect, cx.style.grab) {
|
||||
divider::declare(cx, rect, DIVIDER, at, ÷r);
|
||||
divider::declare_focusing(cx, rect, DIVIDER, at, ÷r);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -458,7 +458,7 @@ impl Component for MarginHandles<'_> {
|
||||
let (grab, strip) = (cx.style.grab, cx.style.strip);
|
||||
let words = cx.words::<MarginHandlesWords>();
|
||||
for &visible in self.edges_shown() {
|
||||
divider::declare(cx, rect, EDGE, visible.index(), &self.divider(&rules, visible, rect, (grab, strip)))
|
||||
divider::declare_focusing(cx, rect, EDGE, visible.index(), &self.divider(&rules, visible, rect, (grab, strip)))
|
||||
.tooltip(visible.name(&words).clone());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! its accessibility node. A container describes each divider as a [`Divider`] in reading order and applies the
|
||||
//! coordinate the drag or the keys ask for; this module owns everything that is the same for all of them, including
|
||||
//! the mirroring for right-to-left. A component that draws its own dividers (a column bar, a margin handle) calls
|
||||
//! [`declare`] in its parts, `pointer` and [`keys`] in its update, and [`describe`] in its access, and declares `KeyUse::SPLITTER` for the arrow keys.
|
||||
//! [`declare_focusing`] in its parts, `pointer` and [`keys`] in its update, and [`describe`] in its access, and declares `KeyUse::SPLITTER` for the arrow keys.
|
||||
|
||||
use crate::contract::{Access, Component, Cx, Focus as _, Name, Numeric, PartBuilder, PartsCx, Pointer as _, Role};
|
||||
use craft_behavior::dock::DockEdge;
|
||||
@@ -93,18 +93,26 @@ fn along_y(mv: NavMove) -> NavMove {
|
||||
}
|
||||
|
||||
/// Declares the part `key.at(index)` for `divider`: an edge part above the panes that takes drags and is its own Tab
|
||||
/// stop. `rect` is the container's rect, which the bar is mirrored across for right-to-left. The part is returned for
|
||||
/// what a caller adds (a tooltip that names the edge).
|
||||
/// stop. A press on it leaves key focus where it is (`Sense::KEEP_FOCUS`), so a pointer drag does not make the divider
|
||||
/// the key target: the arrow keys after it still reach whatever held them, and only a divider reached by Tab takes
|
||||
/// them to resize. `rect` is the container's rect, which the bar is mirrored across for right-to-left. The part is
|
||||
/// returned for what a caller adds (a tooltip that names the edge).
|
||||
pub fn declare<'a, C: Component>(cx: &'a mut PartsCx<'_, C>, rect: Rect, key: PartKey, index: u64, divider: &Divider) -> PartBuilder<'a> {
|
||||
let bar = Flow::new(rect, cx.flow.is_rtl()).to_physical(divider.bar);
|
||||
cx.part(key.at(index), bar)
|
||||
.sense(Sense::DRAG | Sense::TAKE_FOCUS)
|
||||
.sense(Sense::DRAG | Sense::KEEP_FOCUS)
|
||||
.priority(HitPriority::new(HitLevel::Edge, 0))
|
||||
.cursor(divider.cursor())
|
||||
.focusable()
|
||||
.over()
|
||||
}
|
||||
|
||||
/// [`declare`] for a value control drawn with dividers (a column bar, a margin handle) rather than a splitter between
|
||||
/// panes: a press on the divider takes key focus, so the arrow keys after a click step it.
|
||||
pub fn declare_focusing<'a, C: Component>(cx: &'a mut PartsCx<'_, C>, rect: Rect, key: PartKey, index: u64, divider: &Divider) -> PartBuilder<'a> {
|
||||
declare(cx, rect, key, index, divider).sense(Sense::DRAG | Sense::TAKE_FOCUS)
|
||||
}
|
||||
|
||||
/// What the pointer did to the divider `key.at(index)` this pass.
|
||||
pub fn pointer<C: Component>(cx: &Cx<'_, C>, key: PartKey, index: u64, divider: &Divider) -> Option<Drag> {
|
||||
drag(cx.part(key.at(index)).press.phase, cx.rect, cx.flow.is_rtl(), divider)
|
||||
|
||||
@@ -18,8 +18,8 @@ pub enum DockEvent<P> {
|
||||
},
|
||||
/// Auto-Collapse Iconic Panels was chosen in a column menu. The host flips its preference and passes it back.
|
||||
ToggleAutoCollapse,
|
||||
/// The area opened, switched or closed its flyout: an icon click, Escape, a press outside, or the focus
|
||||
/// leaving it under Auto-Collapse. A host that binds the flyout takes it as the request when its binding is given.
|
||||
/// The area opened, switched or closed its flyout: an icon click, Escape, or a press outside or the focus leaving
|
||||
/// it under Auto-Collapse. A host that binds the flyout takes it as the request when its binding is given.
|
||||
FlyoutChanged {
|
||||
/// The panel now in the flyout; `None` when it closed.
|
||||
panel: Option<P>,
|
||||
|
||||
@@ -51,8 +51,11 @@ impl Outcome for FlyoutOutput {
|
||||
|
||||
/// A popup beside an iconic column, on the side of the canvas, whose top left the caller places. Escape closes it; with
|
||||
/// Auto-Collapse Iconic Panels a press outside it and the focus leaving it close it too. Its body is measured at the
|
||||
/// flyout's width first: the flyout is as tall as the body measures within the room below its top, and at least its
|
||||
/// `size`'s height, and the body then shows in the rect that takes.
|
||||
/// flyout's width first: the flyout is as tall as the body measures, at most the height of `within`, and at least its
|
||||
/// `size`'s height, and the body then shows in the rect that takes. A flyout that fits below its top stays there; one
|
||||
/// taller than the room below its top moves up by what it overflows and no further, its bottom on `within`'s (the
|
||||
/// layer's keep rule moves it the least distance into its bounds), and only one taller than `within` starts at
|
||||
/// `within`'s top and scrolls.
|
||||
///
|
||||
/// The user resizes it by its top and bottom edges, the edge away from the column and the two corners there; the
|
||||
/// column side stays. The flyout keeps no rect of its own: each step comes back in [`FlyoutShown::placed`] and the
|
||||
@@ -140,8 +143,9 @@ impl Flyout {
|
||||
}
|
||||
};
|
||||
let size = self.size;
|
||||
// A body measures no taller than the room below the top, inside the bounds.
|
||||
let room = (self.within.bottom() - top_left.y).max(size.y);
|
||||
// A body measures no taller than the bounds: a flyout that does not fit below its top moves up by its overflow
|
||||
// alone, so only a body taller than the bounds is limited to them.
|
||||
let room = self.within.height().max(size.y);
|
||||
let overlay = self.overlay(top_left, ui.is_rtl());
|
||||
self.props = self.props.mount(Mount::Layer(overlay));
|
||||
let shown = ui.show_container(popup, self, |ui, cx| {
|
||||
|
||||
@@ -208,7 +208,8 @@ pub struct IconicColumnStyle {
|
||||
/// icon groups, the top and bottom of the stack and each icon group's cells, which join its tabs. The flyout shows
|
||||
/// its group through the `view` of [`show_flyouts`](IconicColumn::show_flyouts), with the opened panel active, as tall as the view measures the
|
||||
/// group within the room and at least the height of its panels' default heights; a group the user sized keeps that
|
||||
/// size. The flyout's top is level with its group's icons, shifted by the group's `flyout_offset`, inside `within`.
|
||||
/// size. The flyout's top is level with its group's icons, shifted by the group's `flyout_offset`, inside `within`;
|
||||
/// a flyout taller than the room below that top moves up by what it overflows and no further.
|
||||
/// The user resizes it by its top and bottom edges and the edge away from the column; each step comes back in
|
||||
/// [`IconicColumnOutput::flyout`], which the host keeps in the group (`flyout_width`, `height`, `flyout_offset`).
|
||||
///
|
||||
|
||||
@@ -422,6 +422,112 @@ fn a_flyout_with_an_offset_in_a_short_viewport_stays_inside_and_resizes_its_widt
|
||||
}
|
||||
}
|
||||
|
||||
/// The names of the panels of the tall-body trials, which set no heights.
|
||||
const TALL: [&str; 8] = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"];
|
||||
/// What the body of a flyout in the tall-body trial measures.
|
||||
const TALL_BODY: f32 = 300.0;
|
||||
/// The room below the last group's icon in the short-window trial.
|
||||
const ROOM_BELOW: f32 = 200.0;
|
||||
/// How much shorter than that room the body of the flyout that fits measures, and how much taller the one that does not.
|
||||
const OVERFLOW: f32 = 40.0;
|
||||
|
||||
/// What [`tall_flyouts`] returns: the fixture, the panel whose flyout is open (the trial sets it) and the rect the open
|
||||
/// flyout's body showed in, last pass.
|
||||
type TallFlyouts = (Fixture, Rc<Cell<Option<u8>>>, Rc<Cell<Option<Rect>>>);
|
||||
|
||||
/// A column of the [`TALL`] panels, each in a group of its own, on the left window edge; its flyouts stay inside the
|
||||
/// bounds `within` holds and their bodies measure the height `body` holds. Returns the fixture, the panel whose flyout
|
||||
/// is open (the trial sets it) and the rect the open flyout's body showed in, last pass.
|
||||
fn tall_flyouts(within: &Rc<Cell<Rect>>, body: &Rc<Cell<f32>>) -> TallFlyouts {
|
||||
let (open, shown) = (Rc::new(Cell::new(None)), Rc::new(Cell::new(None)));
|
||||
let (bounds, measures, now, seen) = (Rc::clone(within), Rc::clone(body), Rc::clone(&open), Rc::clone(&shown));
|
||||
let mut column = Column::new((0..TALL.len() as u8).map(|panel| Group::new(vec![panel], 0)).collect());
|
||||
column.iconic = true;
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let current = now.get();
|
||||
let mut opened = current;
|
||||
IconicColumn::new("Panels", global("iconic column", "tall flyouts"), &column, Bind::bound(&mut opened), &|panel: &u8| {
|
||||
PanelSpec::new(TALL[usize::from(*panel) % TALL.len()])
|
||||
})
|
||||
.edge(DockEdge::Start)
|
||||
.opens(Side::End)
|
||||
.within(bounds.get())
|
||||
.show_flyouts_at(ui, Rect::from_min_size(Pos2::ZERO, Vec2::new(RAIL, SCREEN.y)), |group, at, ui, _| {
|
||||
match at {
|
||||
GroupAt::Measure(_) => return Some(measures.get()),
|
||||
GroupAt::Show(rect) => {
|
||||
if group.active_panel().is_some_and(|panel| Some(*panel) == current) {
|
||||
seen.set(Some(rect));
|
||||
}
|
||||
Panel::new("Flyout").show_at(ui, rect, |_, _| ());
|
||||
}
|
||||
}
|
||||
None
|
||||
});
|
||||
now.set(opened);
|
||||
});
|
||||
fixture.room(SCREEN).settle();
|
||||
(fixture, open, shown)
|
||||
}
|
||||
|
||||
/// Closes the open flyout of [`tall_flyouts`] and opens the last group's.
|
||||
fn reopen_last(fixture: &mut Fixture, open: &Cell<Option<u8>>) {
|
||||
open.set(None);
|
||||
fixture.settle();
|
||||
open.set(Some(TALL.len() as u8 - 1));
|
||||
fixture.settle();
|
||||
}
|
||||
|
||||
/// A flyout whose body measures taller than the room below its group's icons moves up to stay inside the bounds, as
|
||||
/// tall as the body (or as the bounds when those are shorter): it is not cut to the room below its top with the rest
|
||||
/// of its body laid out below the bounds. The panels set no heights, so the group's height does not give the room.
|
||||
#[trial]
|
||||
fn a_flyout_taller_than_the_room_below_its_icons_moves_up_inside_the_bounds() {
|
||||
let (within, body) = (Rc::new(Cell::new(screen())), Rc::new(Cell::new(TALL_BODY)));
|
||||
let (mut fixture, open, shown) = tall_flyouts(&within, &body);
|
||||
let last = TALL[TALL.len() - 1];
|
||||
let icon = fixture.by_label(last).expect("the last group's icon").rect;
|
||||
for height in [icon.bottom() + 8.0, 200.0] {
|
||||
// The bounds end just below the last icon, or are shorter than the body.
|
||||
let bounds = Rect::from_min_size(Pos2::ZERO, Vec2::new(SCREEN.x, height));
|
||||
within.set(bounds);
|
||||
reopen_last(&mut fixture, &open);
|
||||
let rect = shown.get().expect("the last group's flyout is open");
|
||||
let wanted = TALL_BODY.min(bounds.height());
|
||||
assert!(bounds.bottom() - icon.top() < TALL_BODY, "the bounds leave less room below the icon than the body takes: {icon:?} in {bounds:?}");
|
||||
assert!(bounds.contains_rect(rect), "{height}: the flyout {rect:?} stays inside {bounds:?}");
|
||||
assert!(rect.height() > wanted || near(rect.height(), wanted), "{height}: the flyout {rect:?} takes the body's height {wanted}");
|
||||
assert!(rect.top() < icon.top(), "{height}: the flyout {rect:?} moves up from its icon {icon:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// On a short window a flyout whose body fits below its group's icons keeps its top at the icons, and one whose body
|
||||
/// is taller than the room below them moves up only by what it overflows, its bottom on the bounds' bottom: neither
|
||||
/// takes the whole height of the bounds over the column's other icons.
|
||||
#[trial]
|
||||
fn a_flyout_on_a_short_window_moves_up_only_by_its_overflow() {
|
||||
let (within, body) = (Rc::new(Cell::new(screen())), Rc::new(Cell::new(TALL_BODY)));
|
||||
let (mut fixture, open, shown) = tall_flyouts(&within, &body);
|
||||
let icon = fixture.by_label(TALL[TALL.len() - 1]).expect("the last group's icon").rect;
|
||||
let bounds = Rect::from_min_size(Pos2::ZERO, Vec2::new(SCREEN.x, icon.top() + ROOM_BELOW));
|
||||
within.set(bounds);
|
||||
let sizes = StyleCx::with_root(fixture.ctx(), DockSizes::style);
|
||||
let least = sizes.strip + sizes.least;
|
||||
assert!(icon.top() - OVERFLOW > bounds.top(), "the bounds leave room above the icon for the taller flyout to move up: {icon:?}");
|
||||
for over in [-OVERFLOW, OVERFLOW] {
|
||||
let height = ROOM_BELOW + over;
|
||||
assert!(height > least, "{over}: the body {height} measures taller than the flyout's least height {least}");
|
||||
body.set(height);
|
||||
reopen_last(&mut fixture, &open);
|
||||
let rect = shown.get().expect("the last group's flyout is open");
|
||||
// A body that fits stays at the icon's top; a taller one moves up by its overflow alone.
|
||||
let top = icon.top() - over.max(0.0);
|
||||
assert!(near(rect.height(), height), "{over}: the flyout {rect:?} takes its body's height {height}");
|
||||
assert!(near(rect.top(), top), "{over}: the flyout {rect:?} has its top at {top}, below the icon {icon:?} or up by its overflow");
|
||||
assert!(bounds.contains_rect(rect), "{over}: the flyout {rect:?} stays inside {bounds:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Each icon group's grip strip has its own room at the group's top: across the group, below the bar or the group
|
||||
/// before it and above the group's first icon, overlapping no icon. A drag that starts on a grip moves its whole
|
||||
/// group, as a drag on an icon moves its panel.
|
||||
|
||||
@@ -440,7 +440,9 @@ impl<T: Value + 'static> ToolbarDrawer<'_, T> {
|
||||
if let Some(run) = run_of(&groups[group].slots, tool) {
|
||||
row = row.run(run);
|
||||
}
|
||||
if let Some(icon) = &command.icon {
|
||||
if let Some(icon) = &groups[group].tools[tool].icon {
|
||||
row = row.icon(icon.clone());
|
||||
} else if let Some(icon) = &command.icon {
|
||||
row = row.icon(IconSpec::svg(IconId::from(icon.clone())));
|
||||
}
|
||||
if on_toolbar(toolbar, &groups[group].tools[tool].id, grouped_tools_drag) {
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::contract::{
|
||||
use crate::display::TargetMark;
|
||||
use crate::layout_components::Row;
|
||||
use crate::menu::{self, Menu, MenuItem};
|
||||
use crate::primitives::{PaintShape, StrokeWidth};
|
||||
use crate::primitives::{IconSpec, PaintShape, StrokeWidth};
|
||||
use crate::runtime::commands::{CommandRef, FireSource, ResolvedCommand};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::style::{ComponentStyle, GlyphRole, StyleColor, StyleCx};
|
||||
@@ -200,7 +200,11 @@ impl<'a, T: Value + 'static> FlyoutButton<'a, T> {
|
||||
/// enabled state, marked dot).
|
||||
/// The button itself runs the command, so the face only wears it, and the button's selected state with it.
|
||||
fn face(&self, laid: &Laid, selected: bool, glyphs: GlyphRole) -> IconButton<'static> {
|
||||
let icon = self.lead(laid).and_then(|resolved| resolved.icon.clone()).map_or_else(|| IconId::new("more"), IconId::from);
|
||||
// The shown tool's own icon, when it has one and the face stands for it, else its command's.
|
||||
let own = if self.click.is_none() { self.tools.get(laid.shown).and_then(|tool| tool.icon.clone()) } else { None };
|
||||
let icon = own.unwrap_or_else(|| {
|
||||
IconSpec::svg(self.lead(laid).and_then(|resolved| resolved.icon.clone()).map_or_else(|| IconId::new("more"), IconId::from))
|
||||
});
|
||||
let command = self.click.clone().or_else(|| self.tools.get(laid.shown).map(|tool| tool.command.clone()));
|
||||
let face = match command {
|
||||
Some(command) => IconButton::command(icon, command),
|
||||
@@ -381,7 +385,10 @@ impl<T: Value + 'static> Component for FlyoutButton<'_, T> {
|
||||
let rows = Menu::inline(name.clone()).show(ui, |ui, _| {
|
||||
let mut ran = None;
|
||||
for (at, tool) in tools.iter().enumerate() {
|
||||
let item = MenuItem::command(tool.command.clone()).radio_mark(tool.id == *shown);
|
||||
let mut item = MenuItem::command(tool.command.clone()).radio_mark(tool.id == *shown);
|
||||
if let Some(icon) = &tool.icon {
|
||||
item = item.icon(icon.clone());
|
||||
}
|
||||
let row = match tips.filter(|tips| tips.has(&tool.id)) {
|
||||
Some(tips) => item.show_with_tip(ui, |ui| tips.show(&tool.id, ui)),
|
||||
None => item.show(ui),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! The data of a tool rail: tools, slots and the tool each slot showed last.
|
||||
|
||||
use crate::primitives::IconSpec;
|
||||
use crate::runtime::commands::CommandRef;
|
||||
use crate::runtime::env::Label;
|
||||
use egui::Ui;
|
||||
@@ -8,7 +9,7 @@ use egui::Ui;
|
||||
pub type SlotId = u32;
|
||||
|
||||
/// One tool of a slot. A tool is a command: the command gives the label, the icon, the chord and the enabled state,
|
||||
/// and picking the tool runs it.
|
||||
/// and picking the tool runs it. An [`icon`](RailTool::icon) of the tool's own replaces the command's.
|
||||
#[derive(Clone, Debug, PartialEq, crate::contract::MemoProps, crate::contract::PlainData)]
|
||||
#[non_exhaustive]
|
||||
pub struct RailTool<T> {
|
||||
@@ -16,12 +17,24 @@ pub struct RailTool<T> {
|
||||
pub id: T,
|
||||
/// The command the tool runs.
|
||||
pub command: CommandRef,
|
||||
/// The icon the tool shows in place of its command's: the app's own artwork, a value glyph, where the icon sets
|
||||
/// have none.
|
||||
#[plain_data(assume = "an icon is a value: an SVG name, a colour or a 'static glyph compared by address, never written through")]
|
||||
pub icon: Option<IconSpec<'static>>,
|
||||
}
|
||||
|
||||
impl<T> RailTool<T> {
|
||||
/// A tool reported as `id` that runs `command`.
|
||||
/// A tool reported as `id` that runs `command`, showing its command's icon.
|
||||
pub fn new(id: T, command: impl Into<CommandRef>) -> Self {
|
||||
RailTool { id, command: command.into() }
|
||||
RailTool { id, command: command.into(), icon: None }
|
||||
}
|
||||
|
||||
/// Shows `icon` for the tool, on its rail button, its flyout row and its drawer row, in place of its command's
|
||||
/// icon: an app's own tool artwork (`IconSpec::glyph`).
|
||||
#[must_use]
|
||||
pub fn icon(mut self, icon: impl Into<IconSpec<'static>>) -> Self {
|
||||
self.icon = Some(icon.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -476,3 +476,55 @@ fn idle_key_bytes(count: u8) -> usize {
|
||||
fn a_tool_rails_idle_key_bytes_do_not_grow_with_its_slots() {
|
||||
assert_eq!(idle_key_bytes(10), idle_key_bytes(100), "the key follows revisions, not the slots, the hidden or the remembered tools");
|
||||
}
|
||||
|
||||
/// A tool's own icon replaces its command's: the app's glyph paints the rail button that shows the tool and the tool's
|
||||
/// row in the flyout, and a tool without one keeps its command's icon.
|
||||
#[trial]
|
||||
fn a_tools_own_icon_paints_its_button_and_its_flyout_row() {
|
||||
use crate::primitives::{Glyph, IconSpec};
|
||||
use crate::style::UiTokens;
|
||||
|
||||
// An app's tool artwork: one ellipse across its rect, a shape nothing else on the rail paints, so the frame's
|
||||
// shapes say where the glyph painted.
|
||||
#[derive(crate::contract::MemoProps)]
|
||||
struct Artwork;
|
||||
impl Glyph for Artwork {
|
||||
fn paint(&self, painter: &egui::Painter, _: &UiTokens, rect: Rect, color: egui::Color32, _: bool) {
|
||||
painter.add(egui::Shape::ellipse_filled(rect.center(), rect.size() / 2.0, color));
|
||||
}
|
||||
}
|
||||
// Where the glyph painted in the fixture's next frame. A frame that replays a memoized view repeats its shapes, so
|
||||
// the shapes of one frame show every place the glyph is on screen.
|
||||
let painted = |fixture: &mut Fixture| -> Vec<Rect> {
|
||||
fixture
|
||||
.frame_shapes()
|
||||
.iter()
|
||||
.filter_map(|shape| match shape {
|
||||
egui::Shape::Ellipse(ellipse) => Some(Rect::from_center_size(ellipse.center, ellipse.radius * 2.0)),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
|
||||
let mut group = tools(&[1, 2]);
|
||||
group[0] = group[0].clone().icon(IconSpec::glyph(&Artwork));
|
||||
let (slots, last) = (Tracked::new(vec![ToolSlot::new(0, group)]), Tracked::new(LastUsed::default()));
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
ToolRail::new("Tools", &slots, &1, &last).show_rail(ui, |_, _| {});
|
||||
});
|
||||
fixture.room(Vec2::new(200.0, 400.0)).settle();
|
||||
let button = rect(&fixture, "Brush");
|
||||
let face = painted(&mut fixture);
|
||||
assert!(!face.is_empty() && face.iter().all(|at| button.contains_rect(*at)), "the glyph paints the Brush button: {face:?} in {button:?}");
|
||||
|
||||
// With the flyout open the glyph paints the Brush row too, and the Pencil row keeps its command's icon.
|
||||
fixture.frame(vec![secondary(button.center(), true), secondary(button.center(), false)]);
|
||||
fixture.settle();
|
||||
let pencil = rect(&fixture, "Pencil");
|
||||
let shown = painted(&mut fixture);
|
||||
assert!(
|
||||
shown.iter().any(|at| !button.intersects(*at) && !pencil.contains(at.center())),
|
||||
"the open flyout's Brush row paints the glyph too: {shown:?}, button {button:?}, Pencil row {pencil:?}"
|
||||
);
|
||||
assert!(shown.iter().all(|at| !pencil.contains_rect(*at)), "the Pencil row keeps its command's icon: {shown:?} in {pencil:?}");
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use craft_ui::docking::{DockColumn, HidePanels, PanelKey, PanelSpec};
|
||||
use craft_ui::testing::memory::global;
|
||||
use craft_ui::testing::pointer;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Pos2, Rect};
|
||||
use egui::{Key, Modifiers, Pos2, Rect, Vec2};
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeSet;
|
||||
use std::rc::Rc;
|
||||
@@ -80,3 +80,35 @@ fn a_resize_under_a_pruned_view_keeps_the_hidden_panels() {
|
||||
"the resize reached the layout"
|
||||
);
|
||||
}
|
||||
|
||||
/// Tabs until the divider holds key focus.
|
||||
fn tab_to_divider(fixture: &mut Fixture) {
|
||||
for _ in 0..12 {
|
||||
if craft_ui::testing::access::focused_key(fixture.tree()) == divider(fixture).node {
|
||||
return;
|
||||
}
|
||||
fixture.key(Key::Tab, Modifiers::NONE).idle(2);
|
||||
}
|
||||
panic!("Tab never reached the divider");
|
||||
}
|
||||
|
||||
/// A pointer drag of a divider leaves key focus where it was, so the next arrow key does not resize the dock; a
|
||||
/// divider reached by Tab still resizes with the arrows.
|
||||
#[trial]
|
||||
fn a_dragged_divider_does_not_keep_the_arrow_keys_but_a_tabbed_one_takes_them() {
|
||||
let (mut fixture, rects) = column();
|
||||
fixture.settle();
|
||||
let grip = divider(&fixture);
|
||||
fixture.drag(&grip, Vec2::new(0.0, 20.0)).idle(2);
|
||||
let dragged = rects.borrow()[0].bottom();
|
||||
assert_ne!(craft_ui::testing::access::focused_key(fixture.tree()), divider(&fixture).node, "the drag did not focus the divider");
|
||||
fixture.key(Key::ArrowDown, Modifiers::NONE).idle(2);
|
||||
assert!((rects.borrow()[0].bottom() - dragged).abs() < 0.5, "the arrows after a pointer drag left the dock as it was");
|
||||
|
||||
let (mut fixture, rects) = column();
|
||||
fixture.settle();
|
||||
tab_to_divider(&mut fixture);
|
||||
let tabbed = rects.borrow()[0].bottom();
|
||||
fixture.key(Key::ArrowDown, Modifiers::NONE).idle(2);
|
||||
assert!((rects.borrow()[0].bottom() - tabbed).abs() > 0.5, "an arrow key moves the divider Tab reached");
|
||||
}
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ The theme's docking sizes (`DockSizes`) set the drop bands and zones. `DockWords
|
||||
- A drag ends without a change when another arrangement replaces the workspace it started on: it records the workspace's generation, which `Workspace::replace` and the `WorkspaceSet` switch and reset change. The dock's own edits keep the generation, so they keep the drag. Every write moves the workspace's revision (`Workspace::revision`), which keys what the area derives.
|
||||
- A floating window's id comes from a counter its layout owns (`Layout::fresh_window_id`). It starts above every id the layout is built or loaded with and only grows while the layout lives; `Workspace::replace` gives the incoming windows ids the replaced layout never gave out, and a dock area keeps the windows its actions add above every id it has shown, so a workspace an undo brings back draws no id twice (`Workspace::raise_window_floor`). An OS window never passes to another window.
|
||||
- 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.
|
||||
- Split handles are Tab stops, and the arrow keys move them. A divider drag is one gesture in `DockAreaOutput::edit`.
|
||||
- Split handles are Tab stops, and the arrow keys move them. A pointer press or drag on a handle leaves key focus where it was, so the arrows after a drag still reach the app; only a handle reached by Tab takes them. A divider drag is one gesture in `DockAreaOutput::edit`.
|
||||
- A pointer press on a panel tab (a click, a drag's press, the tab menu's secondary press) leaves key focus where it was, so the document's keys keep working; Tab still reaches the tab row.
|
||||
- Floating windows stack with the app's own egui windows in egui's area order: the one shown, pressed or raised last (`FloatingGroup::raise`, which the host's `DockArea::focus` request sets on the window holding the panel) is on top, so a dialog the app opens over a floating panel shows above it.
|
||||
- A panel command (`DockCommands`) acts on the shown panel of the group that takes it. A menu row, a key and the command palette run the same code: `actions` turns the command into `Action`s.
|
||||
|
||||
Reference in New Issue
Block a user