mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 19:47:53 +00:00
Merge pull request #2127 from aiongg/toolbar-overlay-scroll
Toolbar: hover-only overlay scroll bar, one named drop mark per dock drag (photocraft#15524, photocraft#15526)
This commit is contained in:
@@ -94,11 +94,12 @@ pub(super) fn queue_jump(ctx: &Context, id: Id, offset: ScrollPos) {
|
||||
}
|
||||
|
||||
/// The room the scroll bars of `scroll` take from a view of `view` over content of `extent`: `bar` across the view
|
||||
/// for each axis whose content overflows it. Scroll strips take none across the view.
|
||||
/// for each axis whose content overflows it. Scroll strips and overlay bars take none across the view.
|
||||
pub(super) fn overflow_inset(scroll: Scroll, extent: Vec2, view: Vec2, bar: f32) -> Vec2 {
|
||||
let takes = !scroll.has_overlay();
|
||||
Vec2::new(
|
||||
if scroll.vertical_on() && !scroll.has_strips() && f64::from(extent.y) > f64::from(view.y) + 0.5 { bar } else { 0.0 },
|
||||
if scroll.horizontal_on() && f64::from(extent.x) > f64::from(view.x) + 0.5 { bar } else { 0.0 },
|
||||
if takes && scroll.vertical_on() && !scroll.has_strips() && f64::from(extent.y) > f64::from(view.y) + 0.5 { bar } else { 0.0 },
|
||||
if takes && scroll.horizontal_on() && f64::from(extent.x) > f64::from(view.x) + 0.5 { bar } else { 0.0 },
|
||||
)
|
||||
}
|
||||
|
||||
@@ -188,9 +189,13 @@ impl BodyHooks<'_> {
|
||||
ui.painter().extend(ScrollBar::fades(&look, view, HiddenContent::new(content, view.size(), offset, rtl), background));
|
||||
}
|
||||
if let Some(view) = self.view {
|
||||
use crate::contract::Pointer as _;
|
||||
let overlay = scroll_of(props).is_some_and(|scroll| scroll.has_overlay());
|
||||
for (bar, span) in self.scroll_geometry(props, view, rtl, tokens) {
|
||||
let overflow = span.content.end - span.content.start > span.visible.end - span.visible.start;
|
||||
if !overflow {
|
||||
// An overlay bar shows while the pointer is over the container, or keeps the press that drags it.
|
||||
let hidden = overlay && !cx.response.contains_pointer() && !cx.part_if_declared(bar.key).is_some_and(|track| track.pressed());
|
||||
if !overflow || hidden {
|
||||
continue;
|
||||
}
|
||||
let state = cx.core.scroll_bar_state(bar.key);
|
||||
@@ -280,21 +285,26 @@ impl<'b> BodyHooks<'b> {
|
||||
let thickness = scroll_bar_look(tokens).thickness;
|
||||
let (v_on, h_on) = (scroll.vertical_on(), scroll.horizontal_on());
|
||||
let (ex, ey) = self.last_extent;
|
||||
// An overlay bar's outer edge is the container's: the padding past the view's end edge holds it.
|
||||
let past = if scroll.has_overlay() { self.pads(props, tokens) } else { Vec2::ZERO };
|
||||
let mut bars = Vec::new();
|
||||
if v_on && !scroll.has_strips() {
|
||||
let track = if rtl {
|
||||
Rect::from_min_max(view.min, Pos2::new(view.min.x + thickness, view.max.y))
|
||||
let outer = view.min.x - past.x;
|
||||
Rect::from_min_max(Pos2::new(outer, view.min.y), Pos2::new(outer + thickness, view.max.y))
|
||||
} else {
|
||||
Rect::from_min_max(Pos2::new(view.max.x - thickness, view.min.y), view.max)
|
||||
let outer = view.max.x + past.x;
|
||||
Rect::from_min_max(Pos2::new(outer - thickness, view.min.y), Pos2::new(outer, view.max.y))
|
||||
};
|
||||
let content = f64::from(ey).max(f64::from(view.height()));
|
||||
let span = ScrollSpan::new(0.0..content, self.offset.y..self.offset.y + f64::from(view.height()));
|
||||
bars.push((Bar { key: SCROLL_Y, axis: Axis::Y, track }, span));
|
||||
}
|
||||
if h_on {
|
||||
let outer = view.max.y + past.y;
|
||||
let track = Rect::from_min_max(
|
||||
Pos2::new(view.min.x, view.max.y - thickness),
|
||||
Pos2::new(view.max.x - if v_on { thickness } else { 0.0 }, view.max.y),
|
||||
Pos2::new(view.min.x, outer - thickness),
|
||||
Pos2::new(view.max.x - if v_on && !scroll.has_overlay() { thickness } else { 0.0 }, outer),
|
||||
);
|
||||
let content = f64::from(ex).max(f64::from(view.width()));
|
||||
let span = ScrollSpan::new(0.0..content, self.offset.x..self.offset.x + f64::from(view.width()));
|
||||
|
||||
@@ -533,6 +533,10 @@ pub enum ScrollIndicator {
|
||||
/// A strip with an arrow above the view and one below it while the content overflows along y, as a menu shows:
|
||||
/// resting the pointer on a strip scrolls toward it. The strips take their height from the view, never width.
|
||||
Strips,
|
||||
/// A bar that takes no room from the content, as a tool rail or an options bar shows its overflow: it lies in the
|
||||
/// container's end padding (its bottom padding for x), over the content where the container has none, and shows
|
||||
/// only while the pointer is over the container or presses the bar.
|
||||
Overlay,
|
||||
}
|
||||
|
||||
/// A scrolling body.
|
||||
@@ -565,6 +569,18 @@ impl Scroll {
|
||||
matches!(self.indicator, ScrollIndicator::Strips) && self.vertical_on()
|
||||
}
|
||||
|
||||
/// Shows the overflow as a bar in the container's padding that takes no room from the content and shows only
|
||||
/// under the pointer ([`ScrollIndicator::Overlay`]).
|
||||
pub const fn overlay(mut self) -> Scroll {
|
||||
self.indicator = ScrollIndicator::Overlay;
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether the overflow shows as an overlay bar.
|
||||
pub const fn has_overlay(&self) -> bool {
|
||||
matches!(self.indicator, ScrollIndicator::Overlay)
|
||||
}
|
||||
|
||||
/// Scrolls along y.
|
||||
pub const fn vertical() -> Scroll {
|
||||
Scroll::on(ScrollAxes::Vertical)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
//! The ghost layer's content (8.4, 8.5): the running drag's preview beside the pointer, the mark of the drop target that
|
||||
//! would take the payload, and the painted pointer the cursor service settled on, which goes to the window as its
|
||||
//! cursor image instead where the window takes one. They come from the drag session's data and the cursor record; the
|
||||
//! layer takes no input.
|
||||
//! would take the payload (with the payload's name inside a region mark, for a drag that names it), and the painted
|
||||
//! pointer the cursor service settled on, which goes to the window as its cursor image instead where the window takes
|
||||
//! one. They come from the drag session's data and the cursor record; the layer takes no input.
|
||||
|
||||
use crate::primitives::pointer_art::{self as pointers, Art};
|
||||
|
||||
use crate::primitives::{Draw, DrawEnv, IconSet, Mirror, PaintRecord, PaintShape, RuleKind, SvgIcon, TextRun, outline};
|
||||
use crate::runtime::drag::{self, DragPreview, DropMark};
|
||||
use crate::runtime::egui::areas;
|
||||
use crate::runtime::env::Env;
|
||||
use crate::runtime::env::{Env, Label};
|
||||
use crate::runtime::{cursor, pointer};
|
||||
use crate::style::{Corners, Ink, RuleWidth, SurfaceKind, rule_look};
|
||||
use craft_behavior::Flow;
|
||||
@@ -116,6 +116,9 @@ fn pointer_art(env: &Env, cursor: &craft_behavior::PaintedCursor, closed: bool,
|
||||
fn paint_drag(ctx: &Context, env: &Env, painter: &egui::Painter, draw: &Draw<'_>, session: &drag::Ghost) {
|
||||
if let Some(mark) = session.mark {
|
||||
paint_mark(painter, env, mark);
|
||||
if let (DropMark::Region { area, .. }, DragPreview::Named(name)) = (mark, &session.preview) {
|
||||
paint_region_name(draw, env, area, name);
|
||||
}
|
||||
}
|
||||
let Some(at) = pointer::frame(ctx).pos else { return };
|
||||
match &session.preview {
|
||||
@@ -139,6 +142,22 @@ fn paint_drag(ctx: &Context, env: &Env, painter: &egui::Painter, draw: &Draw<'_>
|
||||
}
|
||||
}
|
||||
|
||||
/// The payload's name inside the region `area` a drop would take: at the reading start of its top, inside the mark's
|
||||
/// band, on one line elided to the area's width. A region too small for the line shows no name.
|
||||
fn paint_region_name(draw: &Draw<'_>, env: &Env, area: Rect, name: &Label) {
|
||||
let name = env.view().resolve(name);
|
||||
let inner = area.shrink(env.tokens.space.pad.control);
|
||||
if inner.width() <= 0.0 {
|
||||
return;
|
||||
}
|
||||
let layout = draw.layout(&TextRun::new(name.as_str()).elide(), inner.width());
|
||||
if layout.size().y > inner.height() {
|
||||
return;
|
||||
}
|
||||
let (at, _) = Flow::new(inner, env.direction.is_rtl()).take_start(layout.size().x.min(inner.width()));
|
||||
draw.galley(at.min, &layout);
|
||||
}
|
||||
|
||||
fn paint_drag_badge(draw: &Draw<'_>, env: &Env, at: Pos2, text: &str) {
|
||||
let space = &env.tokens.space;
|
||||
let run = TextRun::new(text);
|
||||
|
||||
@@ -28,8 +28,11 @@ pub enum DragPreview {
|
||||
None,
|
||||
/// A badge with a short text ("3 files").
|
||||
Badge(Label),
|
||||
/// A frame-sized outline centred on the pointer, with an optional label inside its top corner: the ghost of a
|
||||
/// panel or window being moved.
|
||||
/// Nothing beside the pointer: the payload's name shows inside the area of a region mark, as a panel or group
|
||||
/// being moved names the place it would take. With no mark, nothing shows.
|
||||
Named(Label),
|
||||
/// An outline of `size` centred on the pointer, with an optional label inside its top corner: the ghost of a part
|
||||
/// dragged out of a row (a thumbnail).
|
||||
#[non_exhaustive]
|
||||
Frame {
|
||||
/// The size of the frame, in points.
|
||||
|
||||
@@ -14,7 +14,7 @@ use craft_ui::testing::pointer::{moved, press, release};
|
||||
use craft_ui::testing::windows::FakeSystem;
|
||||
use craft_ui::testing::{Frames, trial};
|
||||
use craft_ui_test_kit::windows::Windows;
|
||||
use egui::{Pos2, Rect, Response, Ui, Vec2, ViewportBuilder, ViewportId, ViewportInfo};
|
||||
use egui::{Pos2, Rect, Response, Shape, Ui, Vec2, ViewportBuilder, ViewportId, ViewportInfo};
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -26,6 +26,9 @@ const SLOT: Rect = Rect { min: Pos2::new(200.0, 10.0), max: Pos2::new(300.0, 60.
|
||||
|
||||
const BADGE: &str = "3 files";
|
||||
|
||||
/// The name a named drag shows.
|
||||
const NAME: &str = "Layers";
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)]
|
||||
#[non_exhaustive]
|
||||
pub struct PlainStyle {
|
||||
@@ -84,7 +87,8 @@ impl Component for Chip<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
struct Accepts;
|
||||
/// Takes every drop and marks it with its mark.
|
||||
struct Accepts(DropMark);
|
||||
|
||||
impl DropTarget<Payload> for Accepts {
|
||||
type Drop = (u32, DropOperation);
|
||||
@@ -94,16 +98,17 @@ impl DropTarget<Payload> for Accepts {
|
||||
}
|
||||
|
||||
fn mark(&self, _: &Self::Drop) -> DropMark {
|
||||
DropMark::Into(SLOT)
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Takes drops of the payload.
|
||||
/// Takes drops of the payload, and marks them with `mark`.
|
||||
#[derive(Component)]
|
||||
struct Slot<'a> {
|
||||
#[common]
|
||||
common: Common,
|
||||
seen: &'a RefCell<Seen>,
|
||||
mark: DropMark,
|
||||
}
|
||||
|
||||
impl Component for Slot<'_> {
|
||||
@@ -120,7 +125,7 @@ impl Component for Slot<'_> {
|
||||
}
|
||||
|
||||
fn update(&mut self, cx: &mut Cx<'_, Self>) {
|
||||
if let Some(drop) = cx.drop_target(&Accepts) {
|
||||
if let Some(drop) = cx.drop_target(&Accepts(self.mark)) {
|
||||
self.seen.borrow_mut().dropped.push(drop);
|
||||
}
|
||||
}
|
||||
@@ -130,6 +135,38 @@ impl Component for Slot<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A drag whose preview names its payload shows nothing away from every target, and its name once, inside the region a
|
||||
/// target marks.
|
||||
#[trial]
|
||||
fn a_named_drag_shows_its_name_inside_a_region_mark_and_nothing_without_a_mark() {
|
||||
let seen = RefCell::new(Seen::default());
|
||||
let mut show = |ui: &mut Ui| {
|
||||
Chip { common: Common::new(), seen: &seen, preview: DragPreview::Named(Label::Static(NAME)) }.id_salt("chip").show_at(ui, CHIP);
|
||||
Slot { common: Common::new(), seen: &seen, mark: DropMark::region(SLOT) }.id_salt("slot").show_at(ui, SLOT);
|
||||
};
|
||||
let mut frames = Frames::new();
|
||||
let (from, open) = (CHIP.center(), Pos2::new(120.0, 200.0));
|
||||
frames.frame(vec![moved(from)], &mut show);
|
||||
frames.frame(vec![press(from)], &mut show);
|
||||
for step in 1..=4 {
|
||||
frames.frame(vec![moved(from + (open - from) * (step as f32 / 4.0))], &mut show);
|
||||
}
|
||||
assert!(drag::mark(&frames.ctx).is_none(), "no target takes the drag in open room");
|
||||
let away = texts(&frames.frame_shapes(&mut show));
|
||||
assert!(away.is_empty(), "nothing shows beside the pointer without a mark: {away:?}");
|
||||
frames.frame(vec![moved(SLOT.center())], &mut show);
|
||||
frames.idle(1, &mut show);
|
||||
assert!(matches!(drag::mark(&frames.ctx), Some(DropMark::Region { .. })), "the slot marks the region a drop takes");
|
||||
let over = texts(&frames.frame_shapes(&mut show));
|
||||
assert!(over.len() == 1 && SLOT.contains_rect(over[0]), "the name shows once, inside the region: {over:?}");
|
||||
frames.frame(vec![release(SLOT.center())], &mut show);
|
||||
}
|
||||
|
||||
/// The bounds of the text shapes among `shapes`.
|
||||
fn texts(shapes: &[Shape]) -> Vec<Rect> {
|
||||
shapes.iter().filter(|shape| matches!(shape, Shape::Text(_))).map(Shape::visual_bounding_rect).collect()
|
||||
}
|
||||
|
||||
/// A drag that starts in one window and ends over a target in another: the session maps the pointer to desktop
|
||||
/// space, the other window's target takes the drop one frame after the release, and the source learns the
|
||||
/// operation in the frame after that.
|
||||
@@ -145,7 +182,7 @@ fn a_drag_crosses_windows_and_the_target_in_the_other_window_takes_the_drop() {
|
||||
windows.frame(events, vec![], |ui| {
|
||||
Chip { common: Common::new(), seen: &seen, preview: DragPreview::Badge(Label::Static(BADGE)) }.id_salt("chip").show_at(ui, CHIP);
|
||||
ui.ctx().show_viewport_immediate(other, ViewportBuilder::default(), |other_ui, _| {
|
||||
Slot { common: Common::new(), seen: &seen }.id_salt("slot").show_at(other_ui, SLOT);
|
||||
Slot { common: Common::new(), seen: &seen, mark: DropMark::Into(SLOT) }.id_salt("slot").show_at(other_ui, SLOT);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
mod body;
|
||||
mod fill;
|
||||
mod memory;
|
||||
mod overlay_bar;
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
//! A scroll body with an overlay bar (`Scroll::overlay`): the content keeps the whole view, the bar lies in the
|
||||
//! container's end padding, and it shows only while the pointer is over the container.
|
||||
|
||||
use craft_ui::contract::{ContainerProps, Pad, Props as _, Scroll, Show as _, ShowContainer as _, Sizing};
|
||||
use craft_ui::runtime::env::{Direction, with_env};
|
||||
use craft_ui::testing::{Frames, pointer, trial};
|
||||
use craft_ui_test_kit::body::Slab;
|
||||
use craft_ui_test_kit::contract::{Probe, Seen};
|
||||
use egui::{Pos2, Rect, Shape, Ui, Vec2};
|
||||
use std::cell::RefCell;
|
||||
|
||||
/// Half a pixel at the scales the box runs.
|
||||
const SLACK: f32 = 0.5;
|
||||
|
||||
/// The container's rect: shorter than its content, so it scrolls.
|
||||
const AT: Rect = Rect { min: Pos2::new(20.0, 20.0), max: Pos2::new(180.0, 120.0) };
|
||||
|
||||
/// A point outside the container.
|
||||
const AWAY: Pos2 = Pos2::new(300.0, 300.0);
|
||||
|
||||
/// The padded container that scrolls along y under an overlay bar, holding a probe that fills its width and is three
|
||||
/// times its height.
|
||||
fn overlay(ui: &mut Ui, seen: &RefCell<Seen>) {
|
||||
let props = ContainerProps::new().pad(Pad::Control).sizing(Sizing::Fill).scroll(Scroll::vertical().overlay());
|
||||
Slab::new(props).id_salt("overlay").show_at(ui, AT, |ui, _| {
|
||||
Probe::new(seen).size(Vec2::new(40.0, AT.height() * 3.0)).sizing(Sizing::FillWidth).id_salt("content").show(ui);
|
||||
});
|
||||
}
|
||||
|
||||
/// Whether any of `shapes` lies inside `band` (and paints something).
|
||||
fn paints_in(shapes: &[Shape], band: Rect) -> bool {
|
||||
shapes.iter().map(Shape::visual_bounding_rect).any(|bounds| bounds.is_positive() && band.expand(SLACK).contains_rect(bounds))
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn an_overlay_bar_takes_no_room_lies_in_the_end_padding_and_shows_only_under_the_pointer() {
|
||||
for direction in [Direction::Ltr, Direction::Rtl] {
|
||||
let seen = RefCell::new(Seen::default());
|
||||
let mut show = |ui: &mut Ui| with_env(ui, |o| o.direction = Some(direction), |ui| overlay(ui, &seen));
|
||||
let mut frames = Frames::new();
|
||||
frames.frame(vec![pointer::moved(AWAY)], &mut show);
|
||||
frames.idle(4, &mut show);
|
||||
let content = seen.borrow().rect;
|
||||
let (start, end) = (content.min.x - AT.min.x, AT.max.x - content.max.x);
|
||||
assert!(start > 0.0 && (start - end).abs() < SLACK, "{direction:?}: the content keeps the whole view between equal pads: {content:?}");
|
||||
let band = match direction {
|
||||
Direction::Rtl => Rect::from_x_y_ranges(AT.min.x..=content.min.x, content.min.y.max(AT.min.y)..=AT.max.y),
|
||||
_ => Rect::from_x_y_ranges(content.max.x..=AT.max.x, content.min.y.max(AT.min.y)..=AT.max.y),
|
||||
};
|
||||
let away = frames.frame_shapes(&mut show);
|
||||
assert!(!paints_in(&away, band), "{direction:?}: no bar shows while the pointer is away");
|
||||
frames.frame(vec![pointer::moved(Pos2::new(content.center().x, AT.center().y))], &mut show);
|
||||
frames.idle(2, &mut show);
|
||||
let over = frames.frame_shapes(&mut show);
|
||||
assert!(paints_in(&over, band), "{direction:?}: the bar shows in the end padding while the pointer is over the container");
|
||||
}
|
||||
}
|
||||
@@ -262,7 +262,7 @@ pub fn float_drop<P: Clone + PartialEq>(
|
||||
DragUnit::Panel(panel) if edge.is_none() => Action::float(panel.clone(), rect),
|
||||
_ => to_target(unit, Target::float_with_edge(rect, edge)),
|
||||
};
|
||||
DockDropped { action, mark: DropMark::Into(mark) }
|
||||
DockDropped { action, mark: DropMark::region(mark) }
|
||||
}
|
||||
|
||||
/// The action a release of `drag` at `at` makes in the dock `dock`, by the spots of the previous pass; `None` where
|
||||
@@ -439,31 +439,28 @@ pub(crate) fn started(env: &EnvView<'_>) -> Option<Arrangement> {
|
||||
}
|
||||
|
||||
/// Starts the drag of `unit`, whose shown panel is `active` and whose size where it starts is `source`. A group or a
|
||||
/// column drags a ghost frame; `ghost` gives its size and label. A window moves itself, so its drag has no ghost and
|
||||
/// `ghost` is `None`.
|
||||
pub fn start_group_drag<P, C>(cx: &mut Cx<'_, C>, unit: DragUnit<P>, active: PanelKey, source: Option<Vec2>, ghost: Option<(Vec2, Label)>)
|
||||
/// column shows `name` inside the region its drop would take ([`DragPreview::Named`]). A window moves itself, so its
|
||||
/// drag shows nothing and `name` is `None`.
|
||||
pub fn start_group_drag<P, C>(cx: &mut Cx<'_, C>, unit: DragUnit<P>, active: PanelKey, source: Option<Vec2>, name: Option<Label>)
|
||||
where
|
||||
P: Clone + Send + Sync + 'static,
|
||||
C: Component,
|
||||
{
|
||||
let preview = match ghost {
|
||||
Some((size, label)) => DragPreview::frame(size, Some(label)),
|
||||
None => DragPreview::None,
|
||||
};
|
||||
let preview = name.map_or(DragPreview::None, DragPreview::Named);
|
||||
let started = started(&cx.env);
|
||||
cx.start_drag(GroupDrag { unit, active, source, strip: None, started }, preview);
|
||||
}
|
||||
|
||||
/// Starts the drag of `unit` out of a collapsed column, from its icons of size `strip`, whose shown panel is
|
||||
/// `active`: the ghost is a frame of that size with `label`, and a float of the unit lands collapsed with its strip
|
||||
/// under the pointer ([`float_drop`]).
|
||||
/// `active`: the region its drop would take shows `label`, and a float of the unit lands collapsed with its strip under
|
||||
/// the pointer ([`float_drop`]).
|
||||
pub fn start_icon_drag<P, C>(cx: &mut Cx<'_, C>, unit: DragUnit<P>, active: PanelKey, strip: Vec2, label: Label)
|
||||
where
|
||||
P: Clone + Send + Sync + 'static,
|
||||
C: Component,
|
||||
{
|
||||
let started = started(&cx.env);
|
||||
cx.start_drag(GroupDrag { unit, active, source: None, strip: Some(strip), started }, DragPreview::frame(strip, Some(label)));
|
||||
cx.start_drag(GroupDrag { unit, active, source: None, strip: Some(strip), started }, DragPreview::Named(label));
|
||||
}
|
||||
|
||||
/// Ends a running tab or group drag that started on `shown`'s dock under another revision: another arrangement
|
||||
|
||||
@@ -62,7 +62,7 @@ pub struct GroupGrip<P: Clone + Send + Sync + 'static> {
|
||||
common: Common,
|
||||
unit: DragUnit<P>,
|
||||
active: PanelKey,
|
||||
/// The ghost the drag shows: its extent and its label.
|
||||
/// The unit's extent where the drag starts and the name its drop region shows.
|
||||
#[prop]
|
||||
ghost: Option<(Vec2, Label)>,
|
||||
/// A drag on the grip drags the unit.
|
||||
@@ -109,7 +109,7 @@ impl<P: Clone + Send + Sync + 'static> Component for GroupGrip<P> {
|
||||
match self.ghost.clone() {
|
||||
Some((strip, label)) if self.icons => start_icon_drag(cx, self.unit.clone(), self.active, strip, label),
|
||||
// The ghost's extent is the group's own.
|
||||
ghost => start_group_drag(cx, self.unit.clone(), self.active, ghost.as_ref().map(|(size, _)| *size), ghost),
|
||||
ghost => start_group_drag(cx, self.unit.clone(), self.active, ghost.as_ref().map(|(size, _)| *size), ghost.map(|(_, label)| label)),
|
||||
}
|
||||
self.started = true;
|
||||
}
|
||||
@@ -260,7 +260,7 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> {
|
||||
/// The host's items before the tab strip.
|
||||
#[prop(func = "FnMut(&mut egui::Ui, &mut BodyCx<'_>)")]
|
||||
extra: Option<HeaderHook<'a>>,
|
||||
/// The size of the group this pass, for the drag ghost.
|
||||
/// The size of the group this pass, where its drag starts.
|
||||
size: Vec2,
|
||||
reported: Reported,
|
||||
}
|
||||
@@ -306,10 +306,9 @@ impl<'a, P: Clone + Hash + Send + Sync + 'static> DockGroup<'a, P> {
|
||||
IconButton::new(IconId::new("more")).size(ControlSize::Sm).popup(PopupKind::Menu).label(name)
|
||||
}
|
||||
|
||||
/// Starts a drag of the whole group: its ghost is the group's frame with its name.
|
||||
/// Starts a drag of the whole group: its drop region shows the group's name.
|
||||
fn start_drag(&mut self, cx: &mut Cx<'_, Self>) {
|
||||
let ghost = (self.size, cx.label());
|
||||
start_group_drag(cx, DragUnit::Group(self.anchor.clone()), self.active, Some(self.size), Some(ghost));
|
||||
start_group_drag(cx, DragUnit::Group(self.anchor.clone()), self.active, Some(self.size), Some(cx.label()));
|
||||
self.reported.drag_started = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,8 @@ type FooterFn<'a> = Box<dyn FnMut(&mut Ui, RailFooter) + 'a>;
|
||||
/// ([`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
|
||||
/// follows the last slot; the host's footer stays in view under the slots, which scroll when the room is short under
|
||||
/// an overlay bar in the end padding that shows only under the pointer (`Scroll::overlay`), 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.
|
||||
@@ -144,7 +145,7 @@ impl<'a, T: Value + 'static> ToolRail<'a, T> {
|
||||
.layout(BodyLayout::stack())
|
||||
.child_size(ControlSize::Md)
|
||||
.child_glyphs(GlyphRole::ToolRail)
|
||||
.scroll(Scroll::vertical())
|
||||
.scroll(Scroll::vertical().overlay())
|
||||
.footer(FooterRegion::new());
|
||||
ToolRail {
|
||||
common: Common::new(),
|
||||
|
||||
@@ -26,6 +26,9 @@ pub(crate) enum StoryTools {
|
||||
Stamp,
|
||||
}
|
||||
|
||||
/// The height of the story's short room: lower than its rows at one column.
|
||||
const SHORT_ROOM: f32 = 120.0;
|
||||
|
||||
/// The id of the brush tool; the tools that follow it are the pencil and the eraser.
|
||||
pub(crate) const BRUSH: u8 = 1;
|
||||
|
||||
@@ -39,10 +42,12 @@ 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.
|
||||
/// The rail in a room as wide as its grid at `columns` columns: the stage a dock column of that many steps gives it. A
|
||||
/// short room is lower than the rail's rows, so they scroll under the overlay bar.
|
||||
#[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..=4.0);
|
||||
let short = *data.choice("room", false, &[("Tall", false), ("Short", true)]);
|
||||
let hidden =
|
||||
data.choice("hidden", Vec::<u8>::new(), &[("None", Vec::new()), ("Pencil", vec![2]), ("Stamp", vec![4]), ("Eraser", vec![3])]).clone();
|
||||
let slots = slots();
|
||||
@@ -52,6 +57,9 @@ fn tool_rail(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let out = ui
|
||||
.scope(|ui| {
|
||||
ui.set_max_width(width);
|
||||
if short {
|
||||
ui.set_max_height(SHORT_ROOM);
|
||||
}
|
||||
ToolRail::new("Tools", &slots, &BRUSH, &last).hidden(&hidden).edit_toolbar("Edit Toolbar").show_rail(ui, |_, _| {})
|
||||
})
|
||||
.inner;
|
||||
|
||||
@@ -108,6 +108,9 @@ fn in_a_short_room_the_rows_scroll_above_the_footer_that_stays_in_view() {
|
||||
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");
|
||||
// The bar lies in the end padding, so the buttons keep the middle of the rail.
|
||||
let rail = rect(&fixture, "Tools");
|
||||
assert!(near(first.center().x, rail.center().x), "{height}: the buttons stay centred in a rail that scrolls: {first:?} in {rail:?}");
|
||||
|
||||
fixture.frame(vec![moved(first.center())]);
|
||||
for _ in 0..10 {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use craft_behavior::Axis;
|
||||
use craft_behavior::dock::{Layout, Node, SplitSize, Workspace};
|
||||
use craft_ui::contract::{Bind, BodyCx, Role};
|
||||
use craft_ui::docking::{DockConfig, DockPanels, GroupAt, PanelSpec};
|
||||
use craft_ui::docking::{DockConfig, DockPanels, DragUnit, FloatSpace, GroupAt, PanelSpec, float_drop};
|
||||
use craft_ui::patterns::dock::DockArea;
|
||||
use craft_ui::runtime::drag::{self, DropMark};
|
||||
use craft_ui::testing::pointer::{moved, press, release};
|
||||
@@ -151,3 +151,14 @@ fn a_tab_dropped_on_a_strip_at_the_layouts_top_edge_joins_its_group_and_the_edge
|
||||
assert!((row.width() - area.width()).abs() <= SLACK, "the edge drop takes the full width {area:?}: {row:?}");
|
||||
assert!(group_rect(&bed, 1).width() >= area.width() - SLACK, "the panel went to a full-width row on top");
|
||||
}
|
||||
|
||||
/// A drop that floats a panel in open room marks the region the window takes, as a docked drop marks its group's: one
|
||||
/// outline with a light fill around the pointer, where the window lands.
|
||||
#[trial]
|
||||
fn a_float_drop_marks_the_region_its_window_takes_under_the_pointer() {
|
||||
let space = FloatSpace::new(Rect::from_min_size(Pos2::ZERO, ROOM), &super::sizes(4.0, 60.0, 20.0));
|
||||
let at = Pos2::new(400.0, 250.0);
|
||||
let dropped = float_drop(&DragUnit::Panel(2_usize), &space, at, Some(Vec2::new(52.0, 400.0)), None, false);
|
||||
let DropMark::Region { area, line: None, .. } = dropped.mark else { panic!("a float marks a region: {:?}", dropped.mark) };
|
||||
assert!(area.contains(at), "the region {area:?} lies under the pointer {at:?}");
|
||||
}
|
||||
|
||||
@@ -81,7 +81,8 @@ impl Outcome for BarOutput {
|
||||
/// and its members sit on the line's middle, with its padding at the start and end only. A bar of one row lays its body out as a row; a bar of several rows as a stack whose rows the
|
||||
/// caller makes with `Row`. A member that fills (a leaf with `Sizing::FillWidth`, a fill-width `Row`) takes the room the view
|
||||
/// leaves. A row too long for the bar first narrows its selects and elidable text, the last first, down to their
|
||||
/// readable least (`TextRun::READABLE_CHARACTERS`), then scrolls, so a member past the edge is reached by Tab and
|
||||
/// readable least (`TextRun::READABLE_CHARACTERS`), then scrolls under an overlay bar (`Scroll::overlay`), so a member
|
||||
/// past the edge is reached by Tab and
|
||||
/// revealed. A member the view shows only in part (a control, or a captioned
|
||||
/// field with its caption) is not shown until a scroll brings it in whole. Under right-to-left the bar is the mirror of
|
||||
/// left-to-right. A select in a bar fits its widest entry, up to a field length. A rule between groups of members is a
|
||||
@@ -120,7 +121,7 @@ impl<'a> Bar<'a> {
|
||||
.child_size(size)
|
||||
.roving(Roving::new(NavShape::Flat))
|
||||
.layout(BodyLayout::row())
|
||||
.scroll(Scroll::horizontal());
|
||||
.scroll(Scroll::horizontal().overlay());
|
||||
if kind == BarKind::Status {
|
||||
props = props.live(Politeness::Polite);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user