mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 22:37:12 +00:00
Merge pull request #3315 from dylanmtaylor/filmcraft/float-raise
dock: the host's focus request brings the floating window that holds the panel to the front
This commit is contained in:
@@ -231,7 +231,8 @@ impl Outcome for FloatingGroupOutput {
|
||||
/// - Docking: with [`window_of`](FloatingGroup::window_of) set, a move by the title starts a window-unit drag
|
||||
/// (`GroupDrag`) for the dock's `DockDropTarget`, which shows the drop mark and docks the window on release.
|
||||
/// - Window: with `native` set the group opens in an OS window of that kind, with the layer as the fallback where
|
||||
/// the platform has no windows. The window comes to the front when the user begins to move or resize it.
|
||||
/// the platform has no windows. The window comes to the front when the user begins to move or resize it, and in
|
||||
/// the pass [`raise`](FloatingGroup::raise) is set.
|
||||
/// - Menu: the Menu action and a context request on the title row open the `menu` rows, under the action's part.
|
||||
/// - Show it with [`show_group`](FloatingGroup::show_group): the closure fills the body, and is not called while
|
||||
/// the group is minimized.
|
||||
@@ -310,6 +311,11 @@ pub struct FloatingGroup<'a> {
|
||||
/// ([`native`](FloatingGroup::native)) moves only when pressed again.
|
||||
#[prop(quantity = "grab point")]
|
||||
continue_move: Option<Vec2>,
|
||||
/// Brings the window to the front of the windows it overlaps in this pass: its layer above the other floating
|
||||
/// layers, or its OS window raised and focused. A request of the pass, for the pass the host reveals a panel of the
|
||||
/// window in.
|
||||
#[prop(flag)]
|
||||
raise: bool,
|
||||
/// The files dropped on the group's OS window that no target there took.
|
||||
files: Vec<OsFile>,
|
||||
}
|
||||
@@ -361,6 +367,7 @@ impl<'a> FloatingGroup<'a> {
|
||||
take_drop: None,
|
||||
moving: false,
|
||||
continue_move: None,
|
||||
raise: false,
|
||||
files: Vec::new(),
|
||||
}
|
||||
.label(title)
|
||||
@@ -565,7 +572,7 @@ impl Component for FloatingGroup<'_> {
|
||||
grip: cx.move_band(),
|
||||
resize: cx.resize_grips(),
|
||||
};
|
||||
native::raise(&cx.core.ctx, &output);
|
||||
native::raise(&cx.core.ctx, &output, self.raise);
|
||||
native::fade(&cx.core.ctx, &output);
|
||||
output
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
//! [`Placement`](craft_behavior::placement::Placement) app windows keep, and opens where [`place`] puts it.
|
||||
|
||||
use super::{DockConfig, FloatingGroupOutput, PanelSpec};
|
||||
use crate::runtime::drag;
|
||||
use crate::runtime::windows::{WindowAction, WindowHost, WindowSpec};
|
||||
use crate::runtime::{drag, overlay};
|
||||
use craft_behavior::GesturePhase;
|
||||
use craft_behavior::dock::{Action, Floating};
|
||||
use craft_behavior::placement::{Defaults, monitor_of, place};
|
||||
@@ -139,12 +139,22 @@ pub fn send_to(ctx: &Context, viewport: ViewportId, recorded: Rect, rect: Rect)
|
||||
}
|
||||
}
|
||||
|
||||
/// Raises the window of the native group that `output` reports on when the user began moving or resizing it this
|
||||
/// pass, so a palette comes to the front of the windows it overlaps. False when nothing was raised.
|
||||
pub(crate) fn raise(ctx: &Context, output: &FloatingGroupOutput) -> bool {
|
||||
let began = output.placed.is_some_and(|change| change.phase == GesturePhase::Begin);
|
||||
/// Brings the group that `output` reports on to the front of the windows it overlaps when `asked`
|
||||
/// ([`FloatingGroup::raise`](super::FloatingGroup::raise)), and an OS window also when the user began moving or
|
||||
/// resizing it this pass (that press already brings a layer forward). An OS window is raised and focused; a layer's
|
||||
/// family comes in front of the other layers at the end of the pass.
|
||||
pub(crate) fn raise(ctx: &Context, output: &FloatingGroupOutput, asked: bool) {
|
||||
let host = WindowHost::of(ctx);
|
||||
began && host.viewport_of(output.response.id).is_some_and(|viewport| host.act(viewport, WindowAction::Focus))
|
||||
match host.viewport_of(output.response.id) {
|
||||
Some(viewport) => {
|
||||
let began = output.placed.is_some_and(|change| change.phase == GesturePhase::Begin);
|
||||
if asked || began {
|
||||
host.act(viewport, WindowAction::Focus);
|
||||
}
|
||||
}
|
||||
None if asked => overlay::raise(ctx, output.response.id),
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Fades the native window of the group that `output` reports on while its drag highlights a drop target, and makes
|
||||
|
||||
@@ -159,7 +159,9 @@ pub struct DockArea<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> {
|
||||
#[prop(quantity = "panel and grab point")]
|
||||
continue_move: Option<(P, Vec2)>,
|
||||
/// Moves key focus to the group that shows the panel and picks its tab, as a click on the tab does: the group's
|
||||
/// stop takes focus in this pass, and the pick is one of the pass's `actions`. A request of the pass: a host that
|
||||
/// stop takes focus in this pass, and the pick is one of the pass's `actions`. A floating window that holds the
|
||||
/// panel comes to the front of the windows it overlaps (`FloatingGroup::raise`); that order is the view's, and
|
||||
/// the workspace does not keep it. A request of the pass: a host that
|
||||
/// focuses a panel itself (it opened something in it) sets it for one pass. A panel the area does not show in this
|
||||
/// pass (hidden, pruned by a maximize, in a closed flyout, or in a group the host's `group_view` draws) takes
|
||||
/// neither; `DockAreaOutput::focused` tells the host where focus is.
|
||||
@@ -1651,6 +1653,10 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
if let Some(scale) = scale {
|
||||
group = group.scale(scale);
|
||||
}
|
||||
// The host's focus request brings the window that holds its panel to the front.
|
||||
if scene.focus.is_some_and(|focus| window.panels().any(|held| held == focus)) {
|
||||
group = group.raise();
|
||||
}
|
||||
if let Some((_, grab)) = scene.continue_move.filter(|(panel, _)| window.panels().any(|held| held == *panel)) {
|
||||
group = group.continue_move(grab);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
//! does.
|
||||
|
||||
use super::Numbered;
|
||||
use craft_behavior::dock::{Action, Layout, Node, SplitSize, Workspace};
|
||||
use craft_behavior::dock::{Action, Column, Floating, Group, Layout, Node, SplitSize, Workspace};
|
||||
use craft_behavior::{Axis, PartKey};
|
||||
use craft_ui::contract::{Bind, BodyCx, Tracked};
|
||||
use craft_ui::docking::{DockConfig, DockPanels};
|
||||
use craft_ui::patterns::dock::DockArea;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Key, Modifiers, Ui, Vec2};
|
||||
use egui::{Key, Modifiers, Pos2, Rect, Ui, Vec2};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
@@ -95,3 +95,53 @@ fn the_hosts_focus_request_focuses_a_titled_groups_drag_band() {
|
||||
assert_eq!(part, Some(PartKey::new("grip")), "the drag band holds key focus");
|
||||
assert_eq!(seen.borrow().last().and_then(|pass| pass.focused), Some(2), "B holds the focus, with 2 shown");
|
||||
}
|
||||
|
||||
/// Floating window A (panel 10) overlaps floating window B (panel 20); the docked group shows panel 0.
|
||||
const A_AT: Rect = Rect::from_min_max(Pos2::new(100.0, 100.0), Pos2::new(400.0, 350.0));
|
||||
const B_AT: Rect = Rect::from_min_max(Pos2::new(250.0, 180.0), Pos2::new(550.0, 430.0));
|
||||
|
||||
/// A docked group (panel 0) and the overlapping floating windows A and B, with the host's focus request in the cell.
|
||||
fn two_windows() -> (Fixture, Rc<Cell<Option<usize>>>) {
|
||||
let window = |id, panel, at| Floating::new(id, Column::new(vec![Group::new(vec![panel], 0)]), at);
|
||||
let layout = Layout::new(Some(Node::tabs(vec![0], 0)), vec![window(100, 10, A_AT), window(101, 20, B_AT)]);
|
||||
let mut workspace = Arc::new(Workspace::new(layout));
|
||||
let request = Rc::new(Cell::new(None));
|
||||
let (asked, specs) = (Rc::clone(&request), Tracked::new(Numbered));
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let mut panels = Panels;
|
||||
let mut area = DockArea::new("Dock", Bind::bound(&mut workspace), &specs, &mut panels, DockConfig::default());
|
||||
if let Some(panel) = asked.take() {
|
||||
area = area.focus(panel);
|
||||
}
|
||||
let _ = area.show(ui);
|
||||
});
|
||||
fixture.room(Vec2::new(1200.0, 600.0)).settle();
|
||||
(fixture, request)
|
||||
}
|
||||
|
||||
/// With A in front, the host's focus request for B's panel brings B to the front: the overlap shows and hits B. The
|
||||
/// request for A's panel brings A back, and one for the docked panel leaves the windows' order alone. Guards against
|
||||
/// a revealed panel left under another floating window (FilmCraft's Text to Speech panel on a narration pick).
|
||||
#[trial]
|
||||
fn the_hosts_focus_request_brings_the_panels_floating_window_to_the_front() {
|
||||
let (mut fixture, request) = two_windows();
|
||||
let top_at = |fixture: &Fixture, at: Pos2| fixture.ctx().layer_id_at(at);
|
||||
let overlap = A_AT.intersect(B_AT).center();
|
||||
let (a_only, b_only) = (Pos2::new(A_AT.left() + 30.0, A_AT.bottom() - 30.0), Pos2::new(B_AT.right() - 30.0, B_AT.bottom() - 30.0));
|
||||
let (a, b) = (top_at(&fixture, a_only).expect("A's layer"), top_at(&fixture, b_only).expect("B's layer"));
|
||||
assert_ne!(a, b, "A and B are layers of their own");
|
||||
fixture.click_at(a_only).settle();
|
||||
assert_eq!(top_at(&fixture, overlap), Some(a), "a press on A brings it in front of B");
|
||||
|
||||
request.set(Some(20));
|
||||
fixture.idle(2);
|
||||
assert_eq!(top_at(&fixture, overlap), Some(b), "the request for B's panel brings B in front of A");
|
||||
|
||||
request.set(Some(10));
|
||||
fixture.idle(2);
|
||||
assert_eq!(top_at(&fixture, overlap), Some(a), "the request for A's panel brings A back");
|
||||
|
||||
request.set(Some(0));
|
||||
fixture.idle(2);
|
||||
assert_eq!(top_at(&fixture, overlap), Some(a), "a docked panel's request leaves the windows' order alone");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user