Files
craft-libs/crates/ui-patterns/tests/it/docking/float_order.rs
T
aiongg 1b0ffe1ada Hosted egui apps on next: dock tabs keep key focus, floats stack with app windows, host bodies keep the app's background
- A pointer press on a dock's panel tab (a click, a drag's press, the tab menu's secondary press)
  leaves key focus where it was (`TabStrip::keeps_focus`), so an app's own shortcuts keep working
  after a tab drag or the tab menu; Tab still reaches the tabs. A press on a `host_body` panel's
  body is the app's and no longer focuses the group's tabs.
- Floating windows leave the overlay's `set_layer_order` list and stack in egui's own area order,
  which raises a layer when it first shows and when it is pressed: an app's own egui dialog opened
  over a floating panel shows above it.
- A `host_body` panel's body is filled with the host style's panel fill (`HostStyle::paint_panel`)
  and gets no body padding, as it showed outside the dock.
- Trials: tab presses keep focus, float order against an app window, the host body's fill and room,
  and an unbound F6 reaching a hosted canvas (alone, and in a dock of host_body panels).
2026-11-24 00:31:19 +00:00

55 lines
2.6 KiB
Rust

//! A dock's floating windows stack with the app's own egui windows in egui's area order: the window shown or pressed
//! last is on top, so a dialog the app opens over a floating panel shows above it.
use super::Numbered;
use craft_behavior::dock::{Floating, Layout, Node, Workspace};
use craft_ui::contract::{Bind, BodyCx, Tracked};
use craft_ui::docking::{DockConfig, DockPanels};
use craft_ui::patterns::dock::DockArea;
use craft_ui::testing::pointer::{moved, press, release};
use craft_ui::testing::{Fixture, trial};
use egui::{Pos2, Rect, Ui, Vec2};
use std::cell::Cell;
use std::rc::Rc;
use std::sync::Arc;
const WINDOW_AT: Rect = Rect { min: Pos2::new(130.0, 90.0), max: Pos2::new(330.0, 210.0) };
/// The app's dialog: it covers the floating window's right part.
const DIALOG_AT: Pos2 = Pos2::new(220.0, 120.0);
/// Inside both the floating window and the dialog.
const BOTH: Pos2 = Pos2::new(260.0, 170.0);
/// Inside the floating window only.
const WINDOW_ONLY: Pos2 = Pos2::new(160.0, 190.0);
struct Panels;
impl DockPanels<usize> for Panels {
fn body(&mut self, _: &usize, _: &mut Ui, _: &mut BodyCx<'_>) {}
}
#[trial]
fn an_app_dialog_opened_over_a_floating_window_shows_above_it_until_the_window_is_pressed() {
let layout = Layout::new(Some(Node::tabs(vec![1], 0)), vec![Floating::single(100, vec![2], 0, WINDOW_AT)]);
let mut workspace = Arc::new(Workspace::new(layout));
let dialog = Rc::new(Cell::new(false));
let shows = Rc::clone(&dialog);
let specs = Tracked::new(Numbered);
let mut fixture = Fixture::new(move |ui| {
DockArea::new("Dock", Bind::bound(&mut workspace), &specs, &mut Panels, DockConfig::default()).show(ui);
if shows.get() {
egui::Window::new("App dialog").fixed_pos(DIALOG_AT).fixed_size(Vec2::new(300.0, 200.0)).collapsible(false).show(ui.ctx(), |ui| {
ui.label("Dialog");
});
}
});
fixture.room(Vec2::new(800.0, 600.0)).settle();
let float = fixture.ctx().layer_id_at(BOTH).expect("the floating window shows");
dialog.set(true);
fixture.settle();
let top = fixture.ctx().layer_id_at(BOTH).expect("a layer shows there");
assert_ne!(top, float, "the dialog the app opened last is above the floating window");
assert_eq!(fixture.ctx().layer_id_at(WINDOW_ONLY), Some(float), "the floating window still shows beside the dialog");
fixture.frame(vec![moved(WINDOW_ONLY)]).frame(vec![press(WINDOW_ONLY)]).frame(vec![release(WINDOW_ONLY)]).settle();
assert_eq!(fixture.ctx().layer_id_at(BOTH), Some(float), "a press raises the floating window above the dialog");
}