mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 00:57:26 +00:00
Merge pull request #3343 from davidmann4/fix/16657-task-bar-fills-view
ui-canvas: a task bar whose anchor fills its area keeps its members (photocraft#16657)
This commit is contained in:
@@ -74,8 +74,9 @@ impl TaskBarPlace {
|
||||
/// or the bar grows; a press with no drag changes nothing. A moved bar whose offset place would cover the `keep_clear` point shows at its unmoved place and keeps
|
||||
/// its offset. Pinned, it stays where it shows.
|
||||
/// - Area: the bar shows inside `area` (the canvas rect): a move stays inside it, and a stored place outside it comes
|
||||
/// back inside, its left and top edges winning where the bar does not fit. Its members continue on a new line when
|
||||
/// the area is too narrow for them.
|
||||
/// back inside, its left and top edges winning where the bar does not fit. An anchor that leaves no room on either
|
||||
/// side (a crop frame larger than the view) has the bar over it, on its side's edge of the area, with all its
|
||||
/// members. Its members continue on a new line when the area is too narrow for them.
|
||||
/// - Menu: Hide bar reports `hide`; Reset bar position clears the place, so the bar follows its anchor again; Pin bar
|
||||
/// position keeps it where it shows and, picked again, lets it follow its anchor from where it shows.
|
||||
/// - `place` is the caller's value (`Bind::bound`): the bar reads it before it shows and writes the pass's change
|
||||
@@ -464,7 +465,7 @@ impl Hung {
|
||||
/// Where a bar of `size` hangs inside `area` before any offset: the place the overlay host computes for the
|
||||
/// anchored layer, taken from the one placement rule.
|
||||
fn unmoved(&self, size: Vec2, area: Rect, rtl: bool) -> Rect {
|
||||
let request = PlaceRequest::new(self.rect, size, area).side(self.side).align(self.align).rtl(rtl).flips_across(true);
|
||||
let request = PlaceRequest::new(self.rect, size, area).side(self.side).align(self.align).rtl(rtl).flips_across(true).covers_anchor(true);
|
||||
craft_behavior::overlay::place(&request).rect
|
||||
}
|
||||
}
|
||||
@@ -494,7 +495,7 @@ fn selection_overlay(hang: Option<&Hung>, area: Rect, dismiss: TaskBarDismiss) -
|
||||
};
|
||||
let overlay = Overlay::floating().modeless().body_scroll(false).dismiss(Dismiss::new().outside(outside));
|
||||
match hang {
|
||||
Some(hang) => overlay.bounds(area).place(Place::anchored(Anchor::Rect(hang.rect), hang.side, hang.align)),
|
||||
Some(hang) => overlay.bounds(area).place(Place::anchored(Anchor::Rect(hang.rect), hang.side, hang.align).covering_anchor()),
|
||||
None => overlay,
|
||||
}
|
||||
}
|
||||
@@ -509,7 +510,9 @@ fn layer_overlay(held: &TaskBarPlace, hang: Option<&Hung>, area: Rect, movable:
|
||||
if let Some(at) = held.placed_in(area).filter(|_| movable) {
|
||||
return overlay.placed_at(at);
|
||||
}
|
||||
let mut hung = Place::anchored(Anchor::Rect(hang.rect), hang.side, hang.align).flipping_across();
|
||||
// An anchor that fills the area (a crop frame larger than the view) leaves no room on either side: the bar keeps
|
||||
// its members and slides over the anchor, inside the area, instead of showing an empty surface.
|
||||
let mut hung = Place::anchored(Anchor::Rect(hang.rect), hang.side, hang.align).flipping_across().covering_anchor();
|
||||
if movable {
|
||||
hung = hung.offset(held.offset_in().unwrap_or(Vec2::ZERO));
|
||||
}
|
||||
|
||||
@@ -55,6 +55,12 @@ fn low_frame() -> Vec<Point> {
|
||||
[(120.0, 290.0), (520.0, 290.0), (520.0, 390.0), (120.0, 390.0)].into_iter().map(|(x, y)| Point::new(x, y)).collect()
|
||||
}
|
||||
|
||||
/// A frame far larger than the story canvas, as a crop frame on a document zoomed past the view: it leaves no room for
|
||||
/// a bar above or below it.
|
||||
fn filling_frame() -> Vec<Point> {
|
||||
[(-2000.0, -2000.0), (3000.0, -2000.0), (3000.0, 3000.0), (-2000.0, 3000.0)].into_iter().map(|(x, y)| Point::new(x, y)).collect()
|
||||
}
|
||||
|
||||
/// A canvas that shows the bar for the scene's anchor and place, with the More menu before a Done button: a movable
|
||||
/// bar, or a `fixed` one, which takes no place.
|
||||
fn fixture(scene: &Rc<RefCell<Scene>>, fixed: bool) -> Fixture {
|
||||
@@ -424,6 +430,36 @@ fn a_fixed_task_bar_ignores_a_drag_shows_no_more_menu_and_opens_above_with_no_ro
|
||||
);
|
||||
}
|
||||
|
||||
/// An anchor that fills the canvas leaves no room on either side: the task bar and a fixed bar still show all their
|
||||
/// members, over the anchor at the area's bottom edge, instead of an empty surface at its top (photocraft#16657).
|
||||
#[trial]
|
||||
fn a_bar_whose_anchor_fills_the_area_keeps_its_members_at_the_bottom_edge() {
|
||||
for fixed in [false, true] {
|
||||
let scene = Rc::new(RefCell::new(Scene {
|
||||
anchor: filling_frame(),
|
||||
place: TaskBarPlace::default(),
|
||||
bounds: Rect::NOTHING,
|
||||
area: Rect::NOTHING,
|
||||
rect: Rect::NOTHING,
|
||||
}));
|
||||
let mut fixture = fixture(&scene, fixed);
|
||||
fixture.settle();
|
||||
let shown = seen(&scene);
|
||||
assert!(shown.bounds.contains_rect(shown.area), "fixed {fixed}: the anchor {:?} covers the canvas {:?}", shown.bounds, shown.area);
|
||||
let done = fixture.by_label("Done").unwrap_or_else(|| panic!("fixed {fixed}: the bar shows its members"));
|
||||
assert!(done.rect.is_positive(), "fixed {fixed}: Done has a size: {:?}", done.rect);
|
||||
assert!(shown.rect.contains_rect(done.rect.shrink(SLACK)), "fixed {fixed}: Done {:?} lies in the bar {:?}", done.rect, shown.rect);
|
||||
assert!(inside_area(&shown), "fixed {fixed}: inside the canvas {:?}: {:?}", shown.area, shown.rect);
|
||||
assert!(
|
||||
(shown.area.bottom() - shown.rect.bottom()).abs() < SLACK,
|
||||
"fixed {fixed}: on the canvas's bottom edge {:?}: {:?}",
|
||||
shown.area,
|
||||
shown.rect
|
||||
);
|
||||
assert_eq!(fixture.by_label("More options").is_some(), !fixed, "fixed {fixed}: only the task bar has its More menu");
|
||||
}
|
||||
}
|
||||
|
||||
/// The grip is one of the bar's members: it sits on the members' line, centred with them, inside the bar's padding,
|
||||
/// and a drag on it still moves the bar.
|
||||
#[trial]
|
||||
|
||||
@@ -80,6 +80,10 @@ pub enum Place {
|
||||
offset: egui::Vec2,
|
||||
/// A rect the layer keeps clear of, in the layer's own space.
|
||||
clear: Option<egui::Rect>,
|
||||
/// Below or above the anchor, a layer that fits on neither side keeps its size and slides over the anchor,
|
||||
/// inside its bounds, instead of being cut to the room left beside it: a task bar under a crop frame that
|
||||
/// fills the canvas.
|
||||
covers: bool,
|
||||
},
|
||||
/// Free-standing.
|
||||
Float(FloatPlace),
|
||||
@@ -88,13 +92,15 @@ pub enum Place {
|
||||
impl Place {
|
||||
/// An anchored place.
|
||||
pub const fn anchored(anchor: Anchor, side: Side, align: Align) -> Self {
|
||||
Place::Anchored { anchor, side, align, flips_across: false, offset: egui::Vec2::ZERO, clear: None }
|
||||
Place::Anchored { anchor, side, align, flips_across: false, offset: egui::Vec2::ZERO, clear: None, covers: false }
|
||||
}
|
||||
|
||||
/// The place, beside its anchor, lining up with the anchor's other end when that fits and the aligned end does not.
|
||||
pub const fn flipping_across(self) -> Self {
|
||||
match self {
|
||||
Place::Anchored { anchor, side, align, offset, clear, .. } => Place::Anchored { anchor, side, align, flips_across: true, offset, clear },
|
||||
Place::Anchored { anchor, side, align, offset, clear, covers, .. } => {
|
||||
Place::Anchored { anchor, side, align, flips_across: true, offset, clear, covers }
|
||||
}
|
||||
float => float,
|
||||
}
|
||||
}
|
||||
@@ -107,6 +113,15 @@ impl Place {
|
||||
self
|
||||
}
|
||||
|
||||
/// The place, below or above its anchor, sliding over the anchor when it fits on neither side; no change off
|
||||
/// `Anchored`.
|
||||
pub fn covering_anchor(mut self) -> Self {
|
||||
if let Place::Anchored { covers, .. } = &mut self {
|
||||
*covers = true;
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// The place keeping clear of `rect`; no change off `Anchored`.
|
||||
pub fn clear_of(mut self, rect: egui::Rect) -> Self {
|
||||
if let Place::Anchored { clear, .. } = &mut self {
|
||||
|
||||
@@ -54,8 +54,12 @@ pub(super) fn opened_overlay(ctx: &Context, overlay: &Overlay, stored: Option<Op
|
||||
|
||||
/// Whether a layer of `overlay` may cover its anchor when it fits on neither side of it: a menu's layer (its key class
|
||||
/// is [`OwnerClass::Menu`]) hung at the pointer, at a point, or at the rect a context request named. No other overlay
|
||||
/// covers its anchor: a tooltip or a popover at the pointer stays off it. `stored` is the opening the layer decided.
|
||||
/// covers its anchor: a tooltip or a popover at the pointer stays off it, unless its place asks for it
|
||||
/// ([`Place::covering_anchor`]). `stored` is the opening the layer decided.
|
||||
pub(super) fn layer_covers_anchor(ctx: &Context, overlay: &Overlay, stored: Option<Opening>) -> bool {
|
||||
if matches!(overlay.place, Place::Anchored { covers: true, .. }) {
|
||||
return true;
|
||||
}
|
||||
if overlay.keys != OwnerClass::Menu {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user