mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 05:37:04 +00:00
dock, iconic column: under IconGroupSeparator::Rule each icon group keeps a bare grip band that drags the group, as production's: the first group's over the top space.gap.inline of its first icon, a later group's over the room above it and that much of its first icon; the band takes a press there (a click in it opens no flyout), and below it every icon, the first included, drags its own panel; Grip keeps its strips
This commit is contained in:
@@ -49,6 +49,9 @@ pub struct IconicSizes {
|
||||
/// The height of the grip strip at the top of each icon group, above its first icon: none with
|
||||
/// [`IconGroupSeparator::Rule`].
|
||||
pub grip: f32,
|
||||
/// How far a group's grip band reaches into its first icon: none with [`IconGroupSeparator::Grip`], whose strip is
|
||||
/// the band, `space.gap.inline` with [`IconGroupSeparator::Rule`].
|
||||
pub band: f32,
|
||||
/// The room between two icon groups: the tight gap, or with [`IconGroupSeparator::Rule`] the stack gap and the
|
||||
/// rule.
|
||||
pub separator: f32,
|
||||
@@ -63,11 +66,12 @@ impl IconicSizes {
|
||||
/// The sizes of the style context `cx`.
|
||||
pub fn style(cx: &StyleCx<'_>) -> Self {
|
||||
let size = &cx.tokens.size;
|
||||
let (grip, separator) = match cx.env::<IconGroupSeparator>() {
|
||||
IconGroupSeparator::Grip => (super::group::grip_strip(cx.tokens), cx.tokens.space.gap.tight),
|
||||
IconGroupSeparator::Rule => (0.0, cx.tokens.space.gap.stack + cx.rule(RuleKind::Edge).width.points(cx.frame_ctx().pixels_per_point())),
|
||||
let gap = &cx.tokens.space.gap;
|
||||
let (grip, band, separator) = match cx.env::<IconGroupSeparator>() {
|
||||
IconGroupSeparator::Grip => (super::group::grip_strip(cx.tokens), 0.0, gap.tight),
|
||||
IconGroupSeparator::Rule => (0.0, gap.inline, gap.stack + cx.rule(RuleKind::Edge).width.points(cx.frame_ctx().pixels_per_point())),
|
||||
};
|
||||
IconicSizes { column: DockSizes::style(cx), cell: size.rail.button, grip, separator, labels: size.rail.width * LABELS_IN_RAIL_WIDTHS }
|
||||
IconicSizes { column: DockSizes::style(cx), cell: size.rail.button, grip, band, separator, labels: size.rail.width * LABELS_IN_RAIL_WIDTHS }
|
||||
}
|
||||
|
||||
/// The sizes in the root scope's style, for code outside a style pass:
|
||||
@@ -107,9 +111,11 @@ pub enum IconGroupSeparator {
|
||||
/// `line.grip`) and drags the group.
|
||||
#[default]
|
||||
Grip,
|
||||
/// No grip strips: a group's first icon drags the group, its first icon stands right under the column's bar, and an
|
||||
/// edge rule (`line.border`) lies level in the middle of the `space.gap.stack` between two groups,
|
||||
/// `space.gap.inline` short of the column's sides: VectorCraft's icon groups, as production drew them.
|
||||
/// No grip strips: a group's first icon stands right under the column's bar, and an edge rule (`line.border`) lies
|
||||
/// level in the middle of the `space.gap.stack` between two groups, `space.gap.inline` short of the column's sides.
|
||||
/// A bare band drags the group: the first group's top `space.gap.inline` of its first icon, a later group's room
|
||||
/// above it and that much of its first icon. The band takes a press there, so a click in it opens no flyout;
|
||||
/// below it the icon drags its own panel. VectorCraft's icon groups, as production drew them.
|
||||
Rule,
|
||||
}
|
||||
|
||||
@@ -295,7 +301,7 @@ struct Plan {
|
||||
cells: Vec<(usize, usize, Rect)>,
|
||||
/// The rest of each row in a wide column, where the panel's name shows; empty in a narrow column.
|
||||
names: Vec<Rect>,
|
||||
/// `(group, rect)` of each group's grip strip, above its first icon.
|
||||
/// `(group, rect)` of each group's grip: its strip above its first icon, or its band (`IconicSizes::band`).
|
||||
grips: Vec<(usize, Rect)>,
|
||||
/// `(group, rect)` of the whole of each group: its grip strip and its cells.
|
||||
groups: Vec<(usize, Rect)>,
|
||||
@@ -455,12 +461,14 @@ impl<'a, P: Value + Hash + Debug + 'static> IconicColumn<'a, P> {
|
||||
let wide = body.width() >= sizes.labels;
|
||||
let (mut y, mut cells, mut names, mut grips, mut groups) = (body.top(), Vec::new(), Vec::new(), Vec::new(), Vec::new());
|
||||
for (at, group) in self.column.groups.iter().enumerate() {
|
||||
let above = y;
|
||||
if at > 0 {
|
||||
y += sizes.separator;
|
||||
}
|
||||
let top = y;
|
||||
let grip = Rect::from_min_max(Pos2::new(body.left(), top), Pos2::new(body.right(), top + sizes.grip));
|
||||
y = grip.bottom();
|
||||
y = top + sizes.grip;
|
||||
// The grip strip, or a band that reaches into the first icon and covers the room above the group.
|
||||
let band = if sizes.band > 0.0 { above..=y + sizes.band } else { top..=y };
|
||||
for panel in 0..group.panels.len() {
|
||||
let row = Rect::from_min_size(Pos2::new(body.left(), y), Vec2::new(body.width(), sizes.cell));
|
||||
if wide {
|
||||
@@ -472,9 +480,7 @@ impl<'a, P: Value + Hash + Debug + 'static> IconicColumn<'a, P> {
|
||||
}
|
||||
y += sizes.cell;
|
||||
}
|
||||
if grip.height() > 0.0 {
|
||||
grips.push((at, grip));
|
||||
}
|
||||
grips.push((at, Rect::from_x_y_ranges(body.x_range(), *band.start()..=band.end().min(y))));
|
||||
groups.push((at, Rect::from_min_max(Pos2::new(body.left(), top), Pos2::new(body.right(), y))));
|
||||
}
|
||||
Plan { bar, cells, names, grips, groups, body }
|
||||
@@ -594,6 +600,8 @@ impl<P: Value + Hash + Debug + 'static> Component for IconicColumn<'_, P> {
|
||||
cx.part(GRIP.at(*group as u64), *grip)
|
||||
.sense(Sense::DRAG)
|
||||
.exact_hit()
|
||||
// A band over the first icon's top takes the press there, as production's, drawn after the icons, did.
|
||||
.stacking(u32::from(sizes.band > 0.0))
|
||||
.cursor(CursorIcon::Grab)
|
||||
.drag_cursor(CursorIcon::Grabbing)
|
||||
.pointer_only("Move Panel To in the panel menu moves the group's panels");
|
||||
@@ -614,30 +622,22 @@ impl<P: Value + Hash + Debug + 'static> Component for IconicColumn<'_, P> {
|
||||
let dragging =
|
||||
|phase: PressPhase| matches!(phase, PressPhase::DragStart { start, .. } if start.button == craft_behavior::PointerButton::Primary);
|
||||
let mut began = false;
|
||||
// A group drags by its grip strip, or without one by its first icon.
|
||||
let group_drag = |cx: &mut Cx<'_, Self>, group: usize| {
|
||||
let lead = self.column.groups.get(group)?;
|
||||
let anchor = lead.panels.first()?;
|
||||
let extent = plan.groups.iter().find(|(at, _)| *at == group)?.1;
|
||||
let shown = lead.active_panel().unwrap_or(anchor);
|
||||
let label = Label::from((self.spec)(shown).label.as_str().to_owned());
|
||||
start_icon_drag(cx, DragUnit::Group(anchor.clone()), PanelKey::of(shown), extent.size(), label);
|
||||
Some(())
|
||||
};
|
||||
for (group, _) in &plan.grips {
|
||||
if cx.part_if_declared(GRIP.at(*group as u64)).is_some_and(|grip| dragging(grip.press.phase)) {
|
||||
began |= group_drag(cx, *group).is_some();
|
||||
for (group, extent) in &plan.groups {
|
||||
if dragging(cx.part(GRIP.at(*group as u64)).press.phase)
|
||||
&& let Some(lead) = self.column.groups.get(*group)
|
||||
&& let Some(anchor) = lead.panels.first()
|
||||
{
|
||||
let shown = lead.active_panel().unwrap_or(anchor);
|
||||
let label = Label::from((self.spec)(shown).label.as_str().to_owned());
|
||||
start_icon_drag(cx, DragUnit::Group(anchor.clone()), PanelKey::of(shown), extent.size(), label);
|
||||
began = true;
|
||||
}
|
||||
}
|
||||
let gripless = plan.grips.is_empty();
|
||||
for (at, (group, panel, cell)) in plan.cells.iter().enumerate() {
|
||||
let named = cx.part_if_declared(NAME.at(at as u64)).is_some_and(|name| dragging(name.press.phase));
|
||||
if !(dragging(cx.part(CELL.at(at as u64)).press.phase) || named) {
|
||||
continue;
|
||||
}
|
||||
if gripless && *panel == 0 {
|
||||
began |= group_drag(cx, *group).is_some();
|
||||
} else if let Some(panel) = self.panel(*group, *panel) {
|
||||
if (dragging(cx.part(CELL.at(at as u64)).press.phase) || named)
|
||||
&& let Some(panel) = self.panel(*group, *panel)
|
||||
{
|
||||
let label = Label::from((self.spec)(panel).label.as_str().to_owned());
|
||||
start_icon_drag(cx, DragUnit::Panel(panel.clone()), PanelKey::of(panel), cell.size(), label);
|
||||
began = true;
|
||||
|
||||
@@ -663,39 +663,47 @@ fn a_themes_bar_grip_is_one_level_bar() {
|
||||
assert!((bar.center().x - strip.center().x).abs() <= 0.5, "centred across the strip: {bar:?} in {strip:?}");
|
||||
}
|
||||
|
||||
/// The icons of the two groups of a collapsed column whose groups stand apart by `separator`: the column's id and the
|
||||
/// fixture.
|
||||
fn separated(separator: IconGroupSeparator) -> (Fixture, Id) {
|
||||
/// The icons of the two groups of a collapsed column `width` wide whose groups stand apart by `separator`: the fixture,
|
||||
/// the column's id and the panel whose flyout is open.
|
||||
fn separated(separator: IconGroupSeparator, width: f32) -> (Fixture, Id, Rc<Cell<Option<u8>>>) {
|
||||
let open = Rc::new(Cell::new(None));
|
||||
let seen = Rc::clone(&open);
|
||||
let mut fixture = Fixture::hosted(move |ui| {
|
||||
let mut column = Column::new(vec![Group::new(vec![1, 2], 0), Group::new(vec![3], 0)]);
|
||||
column.iconic = true;
|
||||
let place = Rect::from_min_size(Pos2::ZERO, Vec2::new(RAIL, SCREEN.y));
|
||||
with_env(
|
||||
ui,
|
||||
|overrides| {
|
||||
overrides.values.set(separator);
|
||||
},
|
||||
|ui| {
|
||||
let output = IconicColumn::new("Panels", global("iconic column", "rule"), &column, Bind::kept(), &named)
|
||||
.within(screen())
|
||||
.show_flyouts_at(ui, place, |_, _, _, _| None);
|
||||
Some(output.into())
|
||||
},
|
||||
)
|
||||
let place = Rect::from_min_size(Pos2::ZERO, Vec2::new(width, SCREEN.y));
|
||||
let mut now = seen.get();
|
||||
let output =
|
||||
with_env(
|
||||
ui,
|
||||
|overrides| {
|
||||
overrides.values.set(separator);
|
||||
},
|
||||
|ui| {
|
||||
IconicColumn::new("Panels", global("iconic column", "rule"), &column, Bind::bound(&mut now), &named)
|
||||
.within(screen())
|
||||
.show_flyouts_at(ui, place, |_, _, _, _| None)
|
||||
},
|
||||
);
|
||||
seen.set(now);
|
||||
Some(output.into())
|
||||
});
|
||||
fixture.room(SCREEN).settle();
|
||||
let id = fixture.root_id().expect("the column shows");
|
||||
(fixture, id)
|
||||
(fixture, id, open)
|
||||
}
|
||||
|
||||
/// An app's `IconGroupSeparator::Rule` (VectorCraft's): no grip strips, so the first icon stands higher than under grip
|
||||
/// strips; one level edge rule lies in the middle of the room between the two groups, short of the column's sides, and
|
||||
/// none over the first group; a drag on a group's first icon moves the group, on its next icon only that panel.
|
||||
/// none over the first group. Each group keeps a bare grip band, as production's: the first group's over its first
|
||||
/// icon's top edge, a later group's over the room above it and its first icon's top edge. A drag from a band moves the
|
||||
/// group, from an icon below the band, the first included, only that icon's panel; a click in the band opens no flyout
|
||||
/// (the band takes the press there, as production's did), a click below it does, in a narrow and in a wide column.
|
||||
#[trial]
|
||||
fn icon_groups_apart_by_a_rule_show_one_level_rule_between_them() {
|
||||
let (gripped, gripped_id) = separated(IconGroupSeparator::Grip);
|
||||
let (gripped, gripped_id, _) = separated(IconGroupSeparator::Grip, RAIL);
|
||||
let gripped_first = gripped.part_rect(gripped_id, CELL.at(0)).expect("the first icon under grips");
|
||||
let (mut fixture, id) = separated(IconGroupSeparator::Rule);
|
||||
let (mut fixture, id, _) = separated(IconGroupSeparator::Rule, RAIL);
|
||||
let border = StyleCx::with_root(fixture.ctx(), |cx| cx.tokens.color.line.border);
|
||||
let shapes = fixture.frame_shapes();
|
||||
let level: Vec<(Pos2, Pos2, egui::Color32)> = shapes
|
||||
@@ -705,12 +713,22 @@ fn icon_groups_apart_by_a_rule_show_one_level_rule_between_them() {
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
for group in [0, 1] {
|
||||
assert!(fixture.part_rect(id, GRIP.at(group)).is_none(), "group {group} has no grip strip");
|
||||
}
|
||||
let cell = |at: u64| fixture.part_rect(id, CELL.at(at)).expect("the icon shows");
|
||||
let band = |group: u64| fixture.part_rect(id, GRIP.at(group)).expect("each group keeps a grip band");
|
||||
let (first, last, next) = (cell(0), cell(1), cell(2));
|
||||
let (top, lower) = (band(0), band(1));
|
||||
assert!(first.top() < gripped_first.top() - 0.5, "the first icon {first:?} stands higher than under a grip strip {gripped_first:?}");
|
||||
for (group, band) in [top, lower].into_iter().enumerate() {
|
||||
assert!(grip_ticks(&shapes, band).is_none(), "group {group}: the band shows no marks");
|
||||
}
|
||||
assert!(
|
||||
near(top.top(), first.top()) && top.bottom() > first.top() && top.bottom() < first.center().y,
|
||||
"the first band {top:?} is the top edge of {first:?}"
|
||||
);
|
||||
assert!(
|
||||
near(lower.top(), last.bottom()) && lower.bottom() > next.top() && lower.bottom() < next.center().y,
|
||||
"the later band {lower:?} covers the room from {last:?} and the top edge of {next:?}"
|
||||
);
|
||||
assert!(!level.iter().any(|(a, _, _)| a.y < first.bottom()), "no rule over the first group: {level:?}");
|
||||
let between: Vec<_> = level.iter().filter(|(a, _, _)| a.y > last.bottom() && a.y < next.top()).collect();
|
||||
let [(a, b, ink)] = between.as_slice() else { panic!("one rule between the groups: {level:?}") };
|
||||
@@ -721,11 +739,30 @@ fn icon_groups_apart_by_a_rule_show_one_level_rule_between_them() {
|
||||
assert!(left > 0.0 && right < RAIL && span > RAIL - span, "the rule reaches across the column, short of its sides: {a:?} to {b:?}");
|
||||
let [r, g, bl, al] = border.0;
|
||||
assert_eq!(*ink, egui::Color32::from_rgba_unmultiplied(r, g, bl, al), "the rule is in line.border");
|
||||
for (icon, unit) in [(first, DragUnit::Group(1)), (last, DragUnit::Panel(2)), (next, DragUnit::Group(3))] {
|
||||
fixture.drag_hold_at(icon.center(), Vec2::new(RAIL * 2.0, 0.0));
|
||||
let dragged = drag::active::<GroupDrag<u8>>(fixture.ctx()).map(|drag| drag.unit.clone());
|
||||
assert_eq!(dragged, Some(unit.clone()), "a drag on the icon {icon:?} moves {unit:?}");
|
||||
fixture.release_at(icon.center() + Vec2::new(RAIL * 2.0, 0.0)).settle();
|
||||
for width in [RAIL, WIDE_COLUMN] {
|
||||
let (mut fixture, id, open) = separated(IconGroupSeparator::Rule, width);
|
||||
let cell = |at: u64| fixture.part_rect(id, CELL.at(at)).expect("the icon shows");
|
||||
let band = |group: u64| fixture.part_rect(id, GRIP.at(group)).expect("each group keeps a grip band");
|
||||
let (first, last, next, top, lower) = (cell(0), cell(1), cell(2), band(0), band(1));
|
||||
let in_top = Pos2::new(first.center().x, top.center().y);
|
||||
let drags = [
|
||||
(in_top, DragUnit::Group(1)),
|
||||
(Pos2::new(next.center().x, (last.bottom() + next.top()) / 2.0), DragUnit::Group(3)),
|
||||
(Pos2::new(next.center().x, (next.top() + lower.bottom()) / 2.0), DragUnit::Group(3)),
|
||||
(first.center(), DragUnit::Panel(1)),
|
||||
(last.center(), DragUnit::Panel(2)),
|
||||
(next.center(), DragUnit::Panel(3)),
|
||||
];
|
||||
for (from, unit) in drags {
|
||||
fixture.drag_hold_at(from, Vec2::new(SCREEN.x / 2.0, 0.0));
|
||||
let dragged = drag::active::<GroupDrag<u8>>(fixture.ctx()).map(|drag| drag.unit.clone());
|
||||
assert_eq!(dragged, Some(unit.clone()), "{width} wide: a drag from {from:?} moves {unit:?}");
|
||||
fixture.release_at(from + Vec2::new(SCREEN.x / 2.0, 0.0)).settle();
|
||||
}
|
||||
fixture.click_at(in_top).idle(3);
|
||||
assert_eq!(open.get(), None, "{width} wide: a click in the band opens no flyout");
|
||||
fixture.click_at(first.center()).idle(3);
|
||||
assert_eq!(open.get(), Some(1), "{width} wide: a click on the first icon below the band opens its flyout");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user