mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 02:36:54 +01:00
ui-contract press winners: a window's move band takes no drag from under a control over it, so a press-drag on a title bar's Home, menu title or caption button no longer moves the window and a double click on it no longer maximizes it; the free band still moves and zooms the window. Title bar trial under a press on a control over the band
This commit is contained in:
1 parent
2157b8afc8
commit
7102556d5c
2 files changed
+75
-5
No files matched your search
@@ -846,8 +846,9 @@ pub(crate) fn made_by_component(ctx: &Context, viewport: ViewportId, id: Id) ->
|
||||
/// their winning shapes' place in the pass's paint order, top first. The top one takes every kind of press its shape
|
||||
/// senses. Under a top shape that only drags (a window's resize grip), the click goes to the first root below whose
|
||||
/// shape clicks; under one that only clicks (a button), the drag goes to the first root below whose shape drags, when
|
||||
/// that root takes no click anywhere. Under a top shape that clicks and passes its drag (`Sense::PASSES_DRAG`), the
|
||||
/// drag goes to the next shape under it that drags: its own root's, else the first root's below.
|
||||
/// that root takes no click anywhere and that shape is no move band (`MOVE_BAND`). Under a top shape that clicks and
|
||||
/// passes its drag (`Sense::PASSES_DRAG`), the drag goes to the next shape under it that drags: its own root's, else the
|
||||
/// first root's below.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
pub(crate) struct PressWinners {
|
||||
pub click: Option<(Winner<Id>, Id)>,
|
||||
@@ -1123,12 +1124,15 @@ fn winners_of(mut ranked: Vec<Ranked>) -> PressWinners {
|
||||
}
|
||||
}
|
||||
// Under a top shape that only clicks, the first root below whose shape drags takes the drag, unless the
|
||||
// root takes clicks anywhere: a drag-only root (a scroll view) is dragged from a button in it. Under a top
|
||||
// shape that passes its drag, the next shape that drags takes it, in the same root or one below.
|
||||
// root takes clicks anywhere: a drag-only root (a scroll view) is dragged from a button in it. A move band
|
||||
// is not: a press on a control over the band (a title bar's Home, a menu title, a caption button) never
|
||||
// moves the window, and its double click never zooms it. Under a top shape that passes its drag, the next
|
||||
// shape that drags takes it, in the same root or one below, a move band too.
|
||||
(true, false) => {
|
||||
let passes = winners.click.is_some_and(|(top, _)| top.sense.contains(craft_behavior::Sense::PASSES_DRAG));
|
||||
let root_target = winners.click.is_some_and(|(top, owner)| top.drag_to_root && root != owner);
|
||||
if drags && !root_target && (passes || !(clicks || root_clicks)) {
|
||||
let band = winner.part.is_some_and(|part| part.key == crate::contract::MOVE_BAND);
|
||||
if drags && !root_target && (passes || !(clicks || root_clicks || band)) {
|
||||
winners.drag = Some((winner, root));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -94,6 +94,72 @@ fn a_title_bar_in_an_embedded_shell_acts_on_no_window() {
|
||||
assert!(!commands.is_empty(), "the window's bar acts on the window");
|
||||
}
|
||||
|
||||
/// The window commands a title bar with a Home button in its leading content sends for each step list of `gestures`,
|
||||
/// in order, given the Home button's centre and a free point of the band.
|
||||
fn home_bar_sent(gestures: impl Fn(Pos2, Pos2) -> Vec<Vec<Vec<Event>>>) -> Vec<Vec<ViewportCommand>> {
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::Show as _;
|
||||
let layout = craft_window::Layout { left: vec![], right: vec![Caption::Minimize, Caption::Maximize, Caption::Close] };
|
||||
let frame = Frame::Integrated(Captions { family: CaptionFamily::Windows, layout });
|
||||
let desktop = Desktop { kind: DesktopKind::Other, ssd: None, gtk_theme: None, icon_theme: None };
|
||||
let windows = Windows::with(InstallSpec::new(ShellInfo::default(), Arc::new(NoWindows)).frame(Decision { frame, overridden: None, desktop }));
|
||||
let bar = Cell::new(Rect::NOTHING);
|
||||
let frame = |events: Vec<Event>| {
|
||||
windows.frame(events, vec![], |ui| {
|
||||
let shown = TitleBar::new().show_titled(
|
||||
ui,
|
||||
Title::new("Landscape.psd"),
|
||||
|ui, _| {
|
||||
Button::new("Home").show(ui);
|
||||
},
|
||||
|_, _| {},
|
||||
);
|
||||
bar.set(shown.response.rect);
|
||||
})
|
||||
};
|
||||
frame(vec![]);
|
||||
let settled = frame(vec![]);
|
||||
let tree = &settled.trees.iter().rev().find(|(viewport, _)| *viewport == ViewportId::ROOT).expect("the root pass ran").1;
|
||||
let home = tree
|
||||
.with_role(Role::BUTTON)
|
||||
.into_iter()
|
||||
.find(|key| tree.name_of(*key) == Some("Home"))
|
||||
.and_then(|key| tree.bounds_of(key))
|
||||
.expect("the bar shows its Home button")
|
||||
.center();
|
||||
// The title is no control: the band lies under it.
|
||||
let band = bar.get().center();
|
||||
gestures(home, band)
|
||||
.into_iter()
|
||||
.map(|steps| {
|
||||
steps
|
||||
.into_iter()
|
||||
.flat_map(|events| frame(events).commands)
|
||||
.map(|(_, command)| command)
|
||||
.filter(|command| matches!(command, ViewportCommand::StartDrag | ViewportCommand::Maximized(_) | ViewportCommand::OuterPosition(_)))
|
||||
.collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A press on a control over the band is the control's: a press-drag that starts on the bar's Home button neither
|
||||
/// moves the window nor drags, and a double click on it does not maximize the window. The band used to take the drag
|
||||
/// under the button, as a drag-only root under a button in it does, so the drag moved the window and the double click
|
||||
/// zoomed it. The free band still moves the window, and its double click still maximizes it.
|
||||
#[trial]
|
||||
fn a_press_on_a_control_over_the_band_never_moves_or_zooms_the_window() {
|
||||
let sent = home_bar_sent(|home, band| {
|
||||
let drag = |at: Pos2| vec![vec![moved(at)], vec![press(at)], vec![moved(at + vec2(40.0, 0.0))], vec![release(at + vec2(40.0, 0.0))], vec![]];
|
||||
let double = |at: Pos2| vec![vec![moved(at)], vec![press(at)], vec![release(at)], vec![press(at)], vec![release(at)], vec![]];
|
||||
vec![drag(home), double(home), drag(band), double(band)]
|
||||
});
|
||||
let [home_drag, home_double, band_drag, band_double] = &sent[..] else { panic!("four gestures ran: {sent:?}") };
|
||||
assert!(home_drag.is_empty(), "a drag from Home does not move the window: {home_drag:?}");
|
||||
assert!(home_double.is_empty(), "a double click on Home does not maximize the window: {home_double:?}");
|
||||
assert!(band_drag.contains(&ViewportCommand::StartDrag), "a drag of the free band moves the window: {band_drag:?}");
|
||||
assert!(band_double.contains(&ViewportCommand::Maximized(true)), "a double click on the free band maximizes the window: {band_double:?}");
|
||||
}
|
||||
|
||||
/// The shell sends the window title once after a change and not again while the viewport reports it; an embedded shell
|
||||
/// sends none.
|
||||
#[trial]
|
||||
|
||||
Reference in new issue
Block a user