mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 04:27:49 +00:00
Merge pull request #3533 from aiongg/ports-combined
Ports: a click keeps the canvas focused, Escape from floats, rail drags dock
This commit is contained in:
@@ -658,6 +658,13 @@ pub fn moves(ctx: &Context, viewport: ViewportId) -> bool {
|
||||
board(ctx, |board| board.session.as_ref().is_some_and(|session| session.moving.viewport == Some(viewport)))
|
||||
}
|
||||
|
||||
/// Whether `source` started the running session, which after its release lives until a target in another window has
|
||||
/// taken the drop.
|
||||
#[doc(hidden)]
|
||||
pub fn sourced_by(ctx: &Context, source: Id) -> bool {
|
||||
board(ctx, |board| board.session.as_ref().is_some_and(|session| session.source == source))
|
||||
}
|
||||
|
||||
/// Starts a session whose source is the container `source`, as the title row of a dock window does, with no payload
|
||||
/// of its own. For trials.
|
||||
#[cfg(feature = "testing")]
|
||||
|
||||
@@ -62,6 +62,12 @@ pub(crate) fn focus_with_filter(ctx: &Context, id: Id, filter: KeyFilter) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Keeps egui from taking the focus of `id`, if it holds it, on a press or click elsewhere, until the focus moves or a
|
||||
/// request gives it again.
|
||||
pub(crate) fn never_surrender(ctx: &Context, id: Id) {
|
||||
ctx.memory_mut(|memory| memory.set_focus_surrender(id, SurrenderFocusOn::Never));
|
||||
}
|
||||
|
||||
/// Leaves the focus of the app's own widget `id`, if it holds it, to egui's rule, the app's `surrender_focus_on`, with
|
||||
/// the key filter it has.
|
||||
pub(crate) fn leave_to_egui(ctx: &Context, id: Id) {
|
||||
|
||||
@@ -200,6 +200,8 @@ pub(crate) struct State {
|
||||
/// The widget the runtime gave egui's focus, under its own press rule, until the end hook settles it
|
||||
/// (`settle_given`): the focus of an app's own widget is left to egui's rule there.
|
||||
given: Option<Id>,
|
||||
/// The app's document canvas whose focus is off egui's press rule (`hold_canvas_focus`).
|
||||
held_canvas: Option<Id>,
|
||||
/// The canvases the running pass declared with `host_canvas`, which the end hook looks up among egui's widgets.
|
||||
host_canvases: SmallVec<[Id; 1]>,
|
||||
/// A text widget that gave its Escape on to the enclosing scopes and lets focus go at the end of the pass.
|
||||
@@ -334,6 +336,11 @@ fn take_app_widgets(ctx: &Context, except: Option<Id>) {
|
||||
/// canvas cannot trap keyboard navigation. With the canvas focused, the same keys stay in egui, a Tab it keeps and
|
||||
/// Escape too, as for any focused widget of the app's own; Escape with nothing focused is the window's cancel.
|
||||
///
|
||||
/// A press that nothing takes leaves the canvas focused, whoever gave it the focus and whatever the app's
|
||||
/// `surrender_focus_on`: a press on the app's own widgets that take no focus or on empty space moves no focus. The canvas
|
||||
/// loses the focus to a component or widget that takes it, Tab, F6, a dialog, the app's own request or surrender, and
|
||||
/// when it is no longer drawn.
|
||||
///
|
||||
/// Call it in each pass the canvas shows, before or after the canvas is drawn, with the id of the focusable, enabled
|
||||
/// egui widget the app draws for it in every such pass (`Sense::click()`, `Sense::drag()`; the bare flags `Sense::CLICK`
|
||||
/// and `Sense::DRAG` are not focusable). egui drops the focus of an id that no such widget of the pass has, so Tab would
|
||||
@@ -1102,6 +1109,7 @@ pub(crate) fn begin(ctx: &Context, tab_all_controls: bool, dialog_tab: TabReach)
|
||||
dialog_tab,
|
||||
frame: crate::runtime::egui::pass::frame_nr(ctx, viewport(ctx)),
|
||||
};
|
||||
let focused = input.focused;
|
||||
let (acts, announcements, host_focus) = with(ctx, |state| {
|
||||
state.awaited = None;
|
||||
let host_focus = state.record.host_focus;
|
||||
@@ -1113,12 +1121,29 @@ pub(crate) fn begin(ctx: &Context, tab_all_controls: bool, dialog_tab: TabReach)
|
||||
if !host_focus || !acts.is_empty() {
|
||||
egui_focus::clear_directional_focus(ctx);
|
||||
}
|
||||
hold_canvas_focus(ctx, focused);
|
||||
apply(ctx, acts);
|
||||
for text in announcements {
|
||||
crate::runtime::frame::announce(ctx, text);
|
||||
}
|
||||
}
|
||||
|
||||
/// Takes the focus `focused` off egui's press rule while it is on the app's document canvas, as the last pass declared
|
||||
/// it: whoever gave that focus, only `State::apply_press` decides what a press does to it. A canvas the app no longer
|
||||
/// declares is one of the app's own widgets, whose focus is egui's again.
|
||||
fn hold_canvas_focus(ctx: &Context, focused: Option<Id>) {
|
||||
let (held, left) = with(ctx, |state| {
|
||||
let held = focused.filter(|id| nav::declared_canvas(&state.last_stops, *id));
|
||||
let before = std::mem::replace(&mut state.held_canvas, held);
|
||||
(held, before.filter(|id| held.is_none() && focused == Some(*id)))
|
||||
});
|
||||
if let Some(id) = held {
|
||||
egui_focus::never_surrender(ctx, id);
|
||||
} else if let Some(id) = left {
|
||||
egui_focus::leave_to_egui(ctx, id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Releases the text widget `widget` at the end of this pass, after the enclosing scopes have had its Escape: a scope
|
||||
/// deciding whether to close still finds the focused stop. No key is replayed and no other widget loses focus.
|
||||
pub(crate) fn surrender_after_scopes(ctx: &Context, widget: Id) {
|
||||
|
||||
@@ -734,6 +734,11 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `id` is the app's document canvas, as the pass that registered `stops` declared it (`host_canvas`).
|
||||
pub(super) fn declared_canvas(stops: &[StopRec], id: Id) -> bool {
|
||||
stops.iter().any(|rec| rec.stop.host && !rec.stop.automatic() && rec.stop.root == id)
|
||||
}
|
||||
|
||||
/// Focus on the egui widget of `stop`, with the key filter its keys ask for.
|
||||
pub(super) fn focus_act(stop: &Stop) -> Act {
|
||||
let roving = stop.group.is_some();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Focus on press (spec 8.3): the press is classified at the begin hook from last pass's shapes, and the
|
||||
//! classified focus move applies at the end hook.
|
||||
|
||||
use super::nav::declared_canvas;
|
||||
use super::{Act, State, StopKey};
|
||||
use crate::runtime::egui::focus as egui_focus;
|
||||
use crate::runtime::{pointer, sampler};
|
||||
@@ -148,10 +149,10 @@ impl State {
|
||||
self.stops.iter().chain(&self.last_stops).find(|rec| rec.stop.press_only && rec.stop.root == widget).cloned()
|
||||
}
|
||||
|
||||
/// The press's focus move at the end hook; `focused` is egui's focus now. The press moves the framework's focus
|
||||
/// only: when `focused` is an app's own widget (`on_app_widget`), egui's own surrender rule, by the app's
|
||||
/// `surrender_focus_on`, decides whether a press elsewhere takes it; a press a component takes still moves focus
|
||||
/// to the component.
|
||||
/// The press's focus move at the end hook; `focused` is egui's focus now. A press a component takes moves focus to
|
||||
/// the component, whatever has it. A press nothing takes ends the focus of a component only: it leaves the app's
|
||||
/// document canvas focused (`declared_canvas`), and when `focused` is an app's own widget (`on_app_widget`),
|
||||
/// egui's own surrender rule, by the app's `surrender_focus_on`, decides whether a press elsewhere takes it.
|
||||
pub(super) fn apply_press(&mut self, focused: Option<Id>, on_app_widget: bool) -> Vec<Act> {
|
||||
let Some(plan) = self.press.plan.take() else { return Vec::new() };
|
||||
match plan.kind {
|
||||
@@ -166,7 +167,12 @@ impl State {
|
||||
None if self.in_trapping_scope() => Vec::new(),
|
||||
None => focused.map(Act::Surrender).into_iter().collect(),
|
||||
},
|
||||
PressFocus::Unclaimed if focused == self.press.focus_at_begin && !on_app_widget && !self.in_trapping_scope() => {
|
||||
PressFocus::Unclaimed
|
||||
if focused == self.press.focus_at_begin
|
||||
&& !on_app_widget
|
||||
&& !focused.is_some_and(|id| declared_canvas(&self.stops, id))
|
||||
&& !self.in_trapping_scope() =>
|
||||
{
|
||||
focused.map(Act::Surrender).into_iter().collect()
|
||||
}
|
||||
_ => Vec::new(),
|
||||
|
||||
@@ -871,6 +871,8 @@ pub(crate) fn end_pass(ui: &mut Ui) {
|
||||
paint_frame_layers(&ctx);
|
||||
}
|
||||
toast::end_pass(&ctx);
|
||||
// Every taker of the pass has run, and the layers and the focus are the pass's still.
|
||||
keys::hand_on_cancel(&ctx);
|
||||
overlay::end_pass(&ctx);
|
||||
focus::end(&ctx);
|
||||
let sweeps: Vec<fn(&Context)> = pass_state::with::<FrameState, _>(&ctx, |state| state.sweeps.values().copied().collect());
|
||||
|
||||
@@ -42,8 +42,8 @@ pub use intents::settle;
|
||||
#[doc(hidden)]
|
||||
pub use intents::take_submit;
|
||||
pub(crate) use intents::{
|
||||
Lent, context_part, context_request, context_requests, give_back, lend, request_context, route_whole_reset, scope_escape, take_cancel,
|
||||
take_every_escape, take_window_cancel,
|
||||
Lent, context_part, context_request, context_requests, give_back, hand_on_cancel, lend, request_context, route_whole_reset, scope_escape,
|
||||
take_cancel, take_every_escape, take_window_cancel,
|
||||
};
|
||||
pub use intents::{with_canvas_window_intents, with_window_intents};
|
||||
pub(crate) use nodes::{redirect_node, register_expanded, register_node};
|
||||
@@ -337,6 +337,9 @@ pub(crate) struct Stage {
|
||||
held_over: Vec<Key>,
|
||||
/// The modifiers of the last Escape of the pass that became a `Cancel`.
|
||||
escape_mods: Option<Mods>,
|
||||
/// The Escapes that windows opened from this one handed on (`intents::hand_on_cancel`), by their modifiers: the next
|
||||
/// pass's `Cancel`s.
|
||||
handed_cancels: Vec<Mods>,
|
||||
/// How many lent keys session members have taken (`lend`), counted over the viewport's life.
|
||||
lent_taken: u64,
|
||||
/// The pane moves that menu, palette or automation fires of `NavCommand` asked for: `true` is forward.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The intents routed to a component and what it leaves untaken: Submit, Cancel, Escape and context requests.
|
||||
|
||||
use super::route::push;
|
||||
use super::{Nudge, Source, Stage, current};
|
||||
use super::{Nudge, Source, Stage, current, with};
|
||||
use crate::runtime::focus::{self};
|
||||
use craft_behavior::focus::{EscapeFacts, EscapeStep, escape_step};
|
||||
use craft_behavior::{AccessRequest, CancelRule, EditCommand, EditorInput, Intent, MoveMods, NavMove, OwnerClass, PartRef};
|
||||
@@ -442,6 +442,28 @@ pub(crate) fn take_window_cancel(ctx: &Context) -> bool {
|
||||
with_canvas_window_intents(ctx, false, |window| window.take(Intent::Cancel))
|
||||
}
|
||||
|
||||
/// The end hook's hand-on: an Escape that nothing in the running window took, not even a reader of its intents, is the
|
||||
/// Cancel of the window it was opened from, where its spec says so (`WindowSpec::hands_on_cancel`). That window reads it
|
||||
/// in its next pass, which is requested. A popup or a modal open in the running window keeps the Escapes it leaves.
|
||||
pub(crate) fn hand_on_cancel(ctx: &Context) {
|
||||
let Some(opener) = crate::runtime::windows::cancel_to(ctx) else { return };
|
||||
if crate::runtime::overlay::popup_or_modal_open(ctx) {
|
||||
return;
|
||||
}
|
||||
let mut left = 0;
|
||||
with_window_intents(ctx, false, |window| {
|
||||
while window.take(Intent::Cancel) {
|
||||
left += 1;
|
||||
}
|
||||
left > 0
|
||||
});
|
||||
if left > 0 {
|
||||
let mods = current(ctx, |stage| stage.escape_mods).unwrap_or(Mods::NONE);
|
||||
with(ctx, opener, |stage| stage.handed_cancels.extend(std::iter::repeat_n(mods, left)));
|
||||
crate::runtime::egui::repaint::request_of(ctx, opener);
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes back what a component left untaken, so a scope's `Submit` and `Cancel` rules see it.
|
||||
#[doc(hidden)]
|
||||
pub fn settle(ctx: &Context, id: Option<Id>, intents: &Intents) {
|
||||
|
||||
@@ -209,6 +209,17 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
|
||||
push(&mut routed, focused, Intent::Cancel, false);
|
||||
cancel_mods = Some(escape.mods);
|
||||
}
|
||||
// The Escapes the windows opened from this one handed on are the window's. A modal that opened meanwhile blocks the
|
||||
// window they were pressed in, so they reach nothing.
|
||||
let handed = current(ctx, |stage| std::mem::take(&mut stage.handed_cancels));
|
||||
if !handed.is_empty() && overlay::app_modal_viewport(ctx).is_none() {
|
||||
for mods in handed {
|
||||
push(&mut routed, None, Intent::Cancel, false);
|
||||
cancel_mods = Some(mods);
|
||||
}
|
||||
// A view that reads what is sent (`Input::Sent`) runs for them as for a key of the window's own.
|
||||
current(ctx, |stage| stage.sent += 1);
|
||||
}
|
||||
// A text opener's list keys arrive as claimed chords, withheld from its text part: they go to the list. The chords
|
||||
// fired commands stood for go to the owners of their claims.
|
||||
let mut claimed = fired_claims;
|
||||
|
||||
@@ -449,6 +449,12 @@ pub fn any_open(ctx: &Context, filter: OpenFilter) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether a popup or a modal of the running viewport was shown last frame: the layers whose rank takes keys, which the
|
||||
/// window of a dock is not.
|
||||
pub(crate) fn popup_or_modal_open(ctx: &Context) -> bool {
|
||||
with_pass(ctx, |pass| pass.last.iter().any(|entry| !entry.exiting && entry.rank.takes_keys()))
|
||||
}
|
||||
|
||||
/// The layer that receives Cancel: the newest member of the topmost family that takes keys.
|
||||
pub fn top(ctx: &Context) -> Option<Id> {
|
||||
crate::runtime::replay::note_input(ctx, crate::runtime::inputs::Input::Overlays);
|
||||
|
||||
@@ -1233,18 +1233,24 @@ pub fn shapes_at(ctx: &Context, at: Pos2) -> Vec<(Id, Option<PartRef>)> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The part of `owner` holding a press in this viewport that was open when the pass began: in the pass that ends the
|
||||
/// press too, and in none after it.
|
||||
pub fn pressed_part(ctx: &Context, owner: Id) -> Option<PartRef> {
|
||||
PerViewport::<Shapes>::with(ctx, pass::current_viewport(ctx), |record| {
|
||||
record.pressed_parts.iter().find_map(|(id, part)| (*id == owner).then_some(*part))
|
||||
})
|
||||
}
|
||||
|
||||
/// The part of `owner` holding the pointer's hover or an open press in this viewport.
|
||||
///
|
||||
/// An open press keeps its part while the pointer moves away. A press open at the start of the pass keeps its part
|
||||
/// for that whole pass, so a child can still declare it after an enclosing arena has processed the release.
|
||||
pub fn active_part(ctx: &Context, owner: Id) -> Option<PartRef> {
|
||||
let viewport = pass::current_viewport(ctx);
|
||||
let pressed =
|
||||
PerViewport::<Shapes>::with(ctx, viewport, |record| record.pressed_parts.iter().find_map(|(id, part)| (*id == owner).then_some(*part)));
|
||||
let pressed = pressed_part(ctx, owner);
|
||||
if pressed.is_some() {
|
||||
return pressed;
|
||||
}
|
||||
with_hover(ctx, viewport, |under, captured| {
|
||||
with_hover(ctx, pass::current_viewport(ctx), |under, captured| {
|
||||
if captured {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -161,6 +161,9 @@ pub(crate) struct Record {
|
||||
min_size: Option<Vec2>,
|
||||
/// For a popup window ([`show_popup`]): the window its layer was opened from, while the layer shows.
|
||||
opener: Option<ViewportId>,
|
||||
/// The window an Escape nothing in this one takes goes to: the one it was opened from, where its spec says so
|
||||
/// (`WindowSpec::hands_on_cancel`).
|
||||
cancel_to: Option<ViewportId>,
|
||||
}
|
||||
|
||||
/// The raise of the window holding an app-modal layer above the palettes the modal lowered. The raise goes out in the
|
||||
@@ -217,6 +220,11 @@ pub(crate) fn os_resizes(ctx: &Context, viewport: ViewportId) -> bool {
|
||||
chrome == WindowChrome::Inset && PerViewport::<Record>::with(ctx, viewport, |record| record.resizable != Some(false))
|
||||
}
|
||||
|
||||
/// The window an Escape nothing in the running viewport's window takes goes to (`WindowSpec::hands_on_cancel`).
|
||||
pub(crate) fn cancel_to(ctx: &Context) -> Option<ViewportId> {
|
||||
PerViewport::<Record>::with_existing(ctx, pass::current_viewport(ctx), |record| record.cancel_to).flatten()
|
||||
}
|
||||
|
||||
/// Whether the app runs the move of `viewport`'s window (`Overlay::moved_by_app`).
|
||||
pub(crate) fn app_moves(ctx: &Context, viewport: ViewportId) -> bool {
|
||||
PerViewport::<Record>::with(ctx, viewport, |record| record.moved_by_app)
|
||||
|
||||
@@ -89,6 +89,9 @@ pub struct WindowSpec {
|
||||
pub takes_focus: bool,
|
||||
/// Whether pointer input passes through the window to the window below it.
|
||||
pub passes_pointer: bool,
|
||||
/// Whether an Escape nothing in the window takes is the Cancel of the window it was opened from (a dock window's):
|
||||
/// no component, layer, capture or app widget of the window, and no reader of its intents.
|
||||
pub hands_on_cancel: bool,
|
||||
}
|
||||
|
||||
impl WindowSpec {
|
||||
@@ -121,6 +124,7 @@ impl WindowSpec {
|
||||
shown_after_first_paint: false,
|
||||
takes_focus: true,
|
||||
passes_pointer: false,
|
||||
hands_on_cancel: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +188,13 @@ impl WindowSpec {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets whether an Escape nothing in the window takes is the Cancel of the window it was opened from.
|
||||
#[must_use]
|
||||
pub fn hands_on_cancel(mut self, hands_on_cancel: bool) -> Self {
|
||||
self.hands_on_cancel = hands_on_cancel;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets whether the window opens hidden and appears after its first paint, so a window that shows a capture or
|
||||
/// other content that must be ready does not flash an empty frame.
|
||||
#[must_use]
|
||||
|
||||
@@ -54,6 +54,7 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im
|
||||
keep_placed(ctx, viewport, pos, size.filter(|_| open.follows_size));
|
||||
}
|
||||
let spec = open.spec;
|
||||
let cancel_to = spec.hands_on_cancel.then(|| crate::runtime::egui::pass::current_viewport(ctx));
|
||||
let state = shared(ctx, |shared| shared.app);
|
||||
let os = os_of(ctx);
|
||||
let (chrome, captions) = frame_of_spec(ctx, spec);
|
||||
@@ -64,6 +65,7 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im
|
||||
record.resizable = Some(open.resizable);
|
||||
record.min_size = open.limits.0;
|
||||
record.moved_by_app = open.moved_by_app;
|
||||
record.cancel_to = cancel_to;
|
||||
record.awaiting_first_paint |= spec.shown_after_first_paint && record.facts.is_none();
|
||||
if record.title.as_deref() != Some(open.title) {
|
||||
record.title = Some(open.title.to_owned());
|
||||
|
||||
@@ -932,6 +932,96 @@ fn focus_given_to_a_canvas_before_its_declaration_is_the_canvas_s() {
|
||||
assert_eq!(egui_focused(&frames.ctx), Some(canvas), "egui keeps the focus on the canvas over its Escape");
|
||||
}
|
||||
|
||||
/// A window of the app's own document canvas, declared while `declared` holds, beside the app's field of `host_window`, a
|
||||
/// button and an area of the app's own that take no focus, and the component `probe`, which takes it.
|
||||
struct CanvasWindow {
|
||||
declared: Rc<Cell<bool>>,
|
||||
host: Rc<RefCell<Host>>,
|
||||
/// egui's focus in each pass, at its start and after the canvas was drawn.
|
||||
in_pass: Rc<RefCell<Vec<Option<Id>>>>,
|
||||
}
|
||||
|
||||
impl CanvasWindow {
|
||||
const BUTTON: Rect = Rect { min: Pos2::new(300.0, 100.0), max: Pos2::new(380.0, 130.0) };
|
||||
const AREA: Rect = Rect { min: Pos2::new(300.0, 200.0), max: Pos2::new(380.0, 230.0) };
|
||||
const PROBE: Rect = Rect { min: Pos2::new(300.0, 300.0), max: Pos2::new(380.0, 330.0) };
|
||||
const CANVAS: Rect = Rect { min: Pos2::new(100.0, 400.0), max: Pos2::new(180.0, 430.0) };
|
||||
const EMPTY: Pos2 = Pos2::new(500.0, 450.0);
|
||||
|
||||
fn new() -> (Self, impl FnMut(&mut Ui)) {
|
||||
let (host, mut base) = host_window();
|
||||
let window = Self { declared: Rc::new(Cell::new(true)), host, in_pass: Rc::default() };
|
||||
let (declared, in_pass) = (Rc::clone(&window.declared), Rc::clone(&window.in_pass));
|
||||
let show = move |ui: &mut Ui| {
|
||||
in_pass.borrow_mut().push(egui_focused(ui.ctx()));
|
||||
base(ui);
|
||||
fixture::host_button(ui, named_id("app button"), Self::BUTTON);
|
||||
fixture::host_unfocusable_area(ui, named_id("app area"), Self::AREA);
|
||||
sensing::show(ui, &[ProbeRoot::new("probe", Self::PROBE, Sense::CLICK | Sense::TAKE_FOCUS)]);
|
||||
register_stop(ui.ctx(), Stop::new(ProbeRoot::id("probe"), KeyUse::of(Input::Pointer)));
|
||||
fixture::host_button(ui, Self::canvas(), Self::CANVAS);
|
||||
if declared.get() {
|
||||
host_canvas(ui.ctx(), Self::canvas(), KeyUse::CANVAS);
|
||||
}
|
||||
in_pass.borrow_mut().push(egui_focused(ui.ctx()));
|
||||
};
|
||||
(window, show)
|
||||
}
|
||||
|
||||
fn canvas() -> Id {
|
||||
named_id("host canvas")
|
||||
}
|
||||
|
||||
/// Gives the canvas the focus, by the app's own request or the framework's.
|
||||
fn focus(frames: &mut Frames, show: &mut impl FnMut(&mut Ui), app: bool) {
|
||||
if app {
|
||||
fixture::host_focus(&frames.ctx, Self::canvas());
|
||||
} else {
|
||||
request(&frames.ctx, FocusTarget::Id(Self::canvas()));
|
||||
}
|
||||
frames.idle(2, &mut *show);
|
||||
assert_eq!(egui_focused(&frames.ctx), Some(Self::canvas()));
|
||||
}
|
||||
}
|
||||
|
||||
/// A click that nothing takes leaves the app's document canvas focused in every pass, whoever gave it the focus: by the
|
||||
/// framework's press rule and by egui's. A canvas the app no longer declares follows egui's rule.
|
||||
#[trial]
|
||||
fn a_click_nothing_takes_leaves_the_app_s_canvas_focused() {
|
||||
for app in [true, false] {
|
||||
let (window, mut show) = CanvasWindow::new();
|
||||
let mut frames = Frames::new();
|
||||
frames.idle(2, &mut show);
|
||||
CanvasWindow::focus(&mut frames, &mut show, app);
|
||||
window.in_pass.take();
|
||||
for at in [CanvasWindow::BUTTON.center(), CanvasWindow::AREA.center(), CanvasWindow::EMPTY] {
|
||||
click_focus(&mut frames, &mut show, at);
|
||||
let passes = window.in_pass.take();
|
||||
assert!(!passes.is_empty() && passes.iter().all(|focused| *focused == Some(CanvasWindow::canvas())), "app {app}, {at:?}: {passes:?}");
|
||||
}
|
||||
window.declared.set(false);
|
||||
frames.idle(2, &mut show);
|
||||
let (pressed, clicked) = click_focus(&mut frames, &mut show, CanvasWindow::EMPTY);
|
||||
assert_eq!((pressed, clicked), (Some(CanvasWindow::canvas()), None), "app {app}: an app's plain widget loses it at the click");
|
||||
}
|
||||
}
|
||||
|
||||
/// A press on a component that takes focus, or on the app's own field, takes it from the app's document canvas.
|
||||
#[trial]
|
||||
fn a_press_that_takes_focus_takes_it_from_the_app_s_canvas() {
|
||||
for app in [true, false] {
|
||||
let (window, mut show) = CanvasWindow::new();
|
||||
let mut frames = Frames::new();
|
||||
frames.idle(2, &mut show);
|
||||
CanvasWindow::focus(&mut frames, &mut show, app);
|
||||
let probe = Some(ProbeRoot::id("probe"));
|
||||
assert_eq!(click_focus(&mut frames, &mut show, CanvasWindow::PROBE.center()), (probe, probe), "app {app}: the component");
|
||||
CanvasWindow::focus(&mut frames, &mut show, app);
|
||||
let at = window.host.borrow().rect.center();
|
||||
assert_eq!(click_focus(&mut frames, &mut show, at).1, Some(field()), "app {app}: the app's field");
|
||||
}
|
||||
}
|
||||
|
||||
/// Where Tab reaches only text fields (the Mac's default), it reaches the app's own text field and skips the app's
|
||||
/// own buttons, as it skips the framework's.
|
||||
#[trial]
|
||||
|
||||
@@ -111,7 +111,8 @@ pub struct DockConfig {
|
||||
pub tab_look: PanelTabLook,
|
||||
/// A floating window opens in an OS window of its own where the window host opens OS windows and reports where
|
||||
/// they are on the desktop (not on Wayland) and its panels allow it (`PanelSpec::allow_native`). Elsewhere, and
|
||||
/// with this off, it shows in the app window.
|
||||
/// with this off, it shows in the app window. A window that takes over a held press (`DockArea::continue_move`)
|
||||
/// opens its OS window once that press ends.
|
||||
pub native_windows: bool,
|
||||
/// Docked groups' menus get Minimize and Move Group Up and Down.
|
||||
pub group_order_items: bool,
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
use super::{DockConfig, FloatingGroupOutput, PanelSpec};
|
||||
use crate::runtime::windows::{WindowAction, WindowHost, WindowSpec};
|
||||
use crate::runtime::{drag, overlay};
|
||||
use craft_behavior::GesturePhase;
|
||||
use crate::runtime::{drag, overlay, pointer};
|
||||
use craft_behavior::dock::{Action, Floating};
|
||||
use craft_behavior::placement::{Defaults, monitor_of, place};
|
||||
use craft_behavior::{Buttons, GesturePhase};
|
||||
use craft_host::target::WindowKind;
|
||||
use egui::{Context, Pos2, Rect, Vec2, ViewportId};
|
||||
|
||||
@@ -29,6 +29,8 @@ pub struct Opening {
|
||||
pub rect: Rect,
|
||||
/// The OS window to open, or `None` where the group shows in the app window.
|
||||
pub spec: Option<WindowSpec>,
|
||||
/// The group shows in the app window until the drag that moves it there ends, and in an OS window after.
|
||||
pub waits: bool,
|
||||
}
|
||||
|
||||
/// Whether the groups of panels with `specs` open OS windows: the dock's `config` turns them on, the platform opens
|
||||
@@ -53,9 +55,11 @@ pub fn pixels_per_point(ctx: &Context, viewport: ViewportId) -> Option<f32> {
|
||||
}
|
||||
|
||||
/// The window a group of panels with `specs` opens: a document window when any panel is a document, else a tool
|
||||
/// window (a palette level, no taskbar entry).
|
||||
/// window (a palette level, no taskbar entry). An Escape nothing in it takes is the Cancel of the window the dock is in.
|
||||
pub fn spec_for(specs: &[PanelSpec]) -> WindowSpec {
|
||||
if specs.iter().any(|spec| spec.window_kind == WindowKind::Document) { WindowSpec::document() } else { WindowSpec::tool() }
|
||||
let document = specs.iter().any(|spec| spec.window_kind == WindowKind::Document);
|
||||
let spec = if document { WindowSpec::document() } else { WindowSpec::tool() };
|
||||
spec.hands_on_cancel(true)
|
||||
}
|
||||
|
||||
/// The rect in the main window's points of `desktop`, a rect in desktop points: where a window at `desktop` would sit
|
||||
@@ -87,17 +91,38 @@ pub fn restore<P>(ctx: &Context, window: &Floating<P>) -> Rect {
|
||||
/// at its own rect. `specs` are its panels' specs; `group` is the id of the group that shows it. A window that opens
|
||||
/// opens at its [`restore`]d rect; an open window stays at the placement the dock model recorded for it, so the
|
||||
/// monitor fit of `restore` never sends back a place the user gave it.
|
||||
///
|
||||
/// A window opens no OS window while a drag moves it in the app window: the OS gives an OS window no press that went
|
||||
/// down in another window, so the drag would end. `continues` says that the window takes over the held press in this
|
||||
/// pass (`DockArea::continue_move`), which a window never placed on the desktop does in the app window.
|
||||
#[doc(hidden)]
|
||||
pub fn opening<P>(ctx: &Context, config: &DockConfig, window: &Floating<P>, specs: &[PanelSpec], group: egui::Id) -> Opening {
|
||||
pub fn opening<P>(ctx: &Context, config: &DockConfig, window: &Floating<P>, specs: &[PanelSpec], group: egui::Id, continues: bool) -> Opening {
|
||||
let layer = Opening { rect: window.rect, spec: None, waits: false };
|
||||
if !allowed(ctx, config, specs) {
|
||||
return Opening { rect: window.rect, spec: None };
|
||||
return layer;
|
||||
}
|
||||
let open = WindowHost::of(ctx).viewport_of(group).is_some();
|
||||
if !open {
|
||||
let takes_over = continues && window.native.is_none() && pointer::frame(ctx).buttons.contains(Buttons::PRIMARY);
|
||||
if takes_over || pointer::pressed_part(ctx, group).is_some() || drag::sourced_by(ctx, group) {
|
||||
return Opening { waits: true, ..layer };
|
||||
}
|
||||
}
|
||||
let recorded = window.native.as_ref().filter(|_| open).and_then(|native| {
|
||||
let at = native.position()?;
|
||||
Some(Rect::from_min_size(Pos2::from(at), Vec2::from(native.normal.size)))
|
||||
});
|
||||
Opening { rect: recorded.unwrap_or_else(|| restore(ctx, window)), spec: Some(spec_for(specs)) }
|
||||
Opening { rect: recorded.unwrap_or_else(|| restore(ctx, window)), spec: Some(spec_for(specs)), waits: false }
|
||||
}
|
||||
|
||||
/// Asks for the pass in which a group that waits to open its OS window ([`Opening::waits`]) opens it: the next one once
|
||||
/// the press that moved it has ended, or the one after a target in another window had its chance to take the drop.
|
||||
#[doc(hidden)]
|
||||
pub fn waited(ctx: &Context, opening: &Opening, output: &FloatingGroupOutput) {
|
||||
let ended = output.placed.is_some_and(|change| matches!(change.phase, GesturePhase::Commit | GesturePhase::Cancel));
|
||||
if opening.waits && (ended || pointer::pressed_part(ctx, output.response.id).is_none()) {
|
||||
crate::runtime::frame::request_repaint(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/// The action that records where the OS put the native window `window`, shown in `viewport`: its placement, as an
|
||||
|
||||
@@ -172,8 +172,9 @@ pub struct DockArea<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> {
|
||||
/// The floating window holding the panel takes over the held primary press in this pass, with the pointer at the
|
||||
/// grab point inside the window ([`FloatingGroup::continue_move`]): the window follows the pointer and docks where it
|
||||
/// would dock on release. A request of the pass: a host that floats a panel from a rail's `torn_off` keeps it for
|
||||
/// the one pass after, when the window shows. Without a held press, or when no window holds the panel, it does
|
||||
/// nothing.
|
||||
/// the one pass after, when the window shows. Where the dock opens OS windows (`DockConfig::native_windows`), the
|
||||
/// window shows in the app window until the press ends, and then opens its OS window where it was released. Without
|
||||
/// a held press, when no window holds the panel, or when the window has shown in an OS window, it does nothing.
|
||||
#[prop(quantity = "panel and grab point")]
|
||||
continue_move: Option<(P, Vec2)>,
|
||||
/// Moves key focus to the group that shows the panel, as a press on the group's body does, and picks its tab, as a
|
||||
@@ -1725,7 +1726,8 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
let rights: Vec<Permissions> = window.panels().map(|panel| scene.permissions(panel)).collect();
|
||||
let dock = scene.dock.with(("floating", window.id));
|
||||
let group_id = dock.with("window");
|
||||
let opening = native::opening(&ctx, scene.config, window, &specs, group_id);
|
||||
let continued = scene.continue_move.filter(|(panel, _)| window.panels().any(|held| held == *panel)).map(|(_, grab)| grab);
|
||||
let opening = native::opening(&ctx, scene.config, window, &specs, group_id, continued.is_some());
|
||||
// An OS window lays out at its own monitor's scale, which sizes its chrome; one in the app window at the
|
||||
// main window's.
|
||||
let scale = opening
|
||||
@@ -1791,7 +1793,7 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
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)) {
|
||||
if let Some(grab) = continued {
|
||||
group = group.continue_move(grab);
|
||||
}
|
||||
if scene.raise.is_some_and(|raised| window.panels().any(|held| held == raised)) {
|
||||
@@ -1827,6 +1829,7 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
|
||||
});
|
||||
self.dock = area_dock;
|
||||
let output = shown.output;
|
||||
native::waited(&ctx, &opening, &output);
|
||||
// The window's grips, then everything it drew, in the OS window it shows in, if it has one.
|
||||
let grips = output.grip.map(|(rect, node)| DockSource::new(SourceKind::WindowGrip(anchor.clone()), rect, node));
|
||||
let resize =
|
||||
|
||||
@@ -35,6 +35,7 @@ pub(crate) mod tab_focus;
|
||||
pub(crate) mod workspace_dialogs;
|
||||
|
||||
pub(crate) mod native;
|
||||
pub(crate) mod native_drag;
|
||||
pub(crate) mod panes;
|
||||
|
||||
/// The docking sizes of the default theme with the given divider gap, least pane and strip height.
|
||||
|
||||
@@ -1606,6 +1606,101 @@ fn enter_and_escape_in_a_native_palettes_field_stay_the_fields() {
|
||||
}
|
||||
}
|
||||
|
||||
/// What panel 1's body holds that takes an Escape pressed in its window.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
enum Taker {
|
||||
Nothing,
|
||||
/// A field, which a click focuses.
|
||||
Field,
|
||||
/// A button whose context menu a secondary click opens.
|
||||
Menu,
|
||||
/// App code that reads the window's leftover Escape.
|
||||
App,
|
||||
}
|
||||
|
||||
/// Panels of which panel 1 holds `taker`.
|
||||
struct EscapePalette {
|
||||
taker: Taker,
|
||||
opacity: Option<f64>,
|
||||
}
|
||||
|
||||
impl DockPanels<u32> for EscapePalette {
|
||||
fn body(&mut self, panel: &u32, ui: &mut Ui, _: &mut BodyCx<'_>) {
|
||||
match self.taker {
|
||||
_ if *panel != 1 => {}
|
||||
Taker::Nothing => {}
|
||||
Taker::Field => {
|
||||
NumberField::new("Opacity", Bind::bound(&mut self.opacity)).show(ui);
|
||||
}
|
||||
Taker::Menu => {
|
||||
let target = Button::new("Target").show(ui);
|
||||
let _ = Menu::context("Target menu", &target).show(ui, |ui, _| {
|
||||
MenuItem::new("Row").show(ui);
|
||||
});
|
||||
}
|
||||
Taker::App => {
|
||||
keys::with_window_intents(ui.ctx(), false, |window| window.take(Intent::Cancel));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An Escape pressed in a native palette that holds `taker`, with the field focused or the menu open: how many of the
|
||||
/// main window's Cancels two readers found that the app runs before its dock, one after the other.
|
||||
fn main_window_cancels(taker: Taker) -> (usize, usize) {
|
||||
let mut dock = NativeDock::on(Os::Windows, Arc::new(FakeSystem::new()));
|
||||
let palette = dock.palette.expect("the palette's window opened");
|
||||
let mut panels = EscapePalette { taker, opacity: Some(50.0) };
|
||||
let mut read = (0, 0);
|
||||
let mut frame = |child: Vec<Event>| {
|
||||
dock.windows.frame(vec![], child, |ui| {
|
||||
let cancel = |ui: &Ui| usize::from(keys::with_window_intents(ui.ctx(), false, |window| window.take(Intent::Cancel)));
|
||||
read.0 += cancel(ui);
|
||||
read.1 += cancel(ui);
|
||||
let _ = DockArea::new("Native dock", Bind::bound(&mut dock.workspace), &dock.specs, &mut panels, DockConfig::default()).show(ui);
|
||||
})
|
||||
};
|
||||
frame(vec![]);
|
||||
let out = frame(vec![]);
|
||||
let at = |name: &str| {
|
||||
let tree = tree_of_viewport(&out, palette);
|
||||
let part = tree.keys().into_iter().find(|key| tree.name_of(*key) == Some(name) && tree.role_of(*key) != Some(Role::LABEL));
|
||||
part.and_then(|key| tree.bounds_of(key)).expect("the palette shows it").center()
|
||||
};
|
||||
let opened = match taker {
|
||||
Taker::Field => {
|
||||
let field = at("Opacity");
|
||||
vec![vec![moved(field), press(field)], vec![release(field)]]
|
||||
}
|
||||
Taker::Menu => {
|
||||
let target = at("Target");
|
||||
vec![vec![moved(target)], vec![secondary(target, true)], vec![secondary(target, false)]]
|
||||
}
|
||||
Taker::Nothing | Taker::App => vec![],
|
||||
};
|
||||
let escape = [vec![key_press(Key::Escape, Modifiers::NONE)], vec![key_release(Key::Escape, Modifiers::NONE)], vec![], vec![]];
|
||||
for events in opened.into_iter().chain([vec![], vec![]]).chain(escape) {
|
||||
frame(events);
|
||||
}
|
||||
read
|
||||
}
|
||||
|
||||
/// An Escape that nothing in a native palette takes is the main window's Cancel, once: the app reads it where it reads
|
||||
/// the main window's own, and the read takes it.
|
||||
#[trial]
|
||||
fn an_escape_nothing_in_a_native_palette_takes_is_the_main_windows_cancel_once() {
|
||||
assert_eq!(main_window_cancels(Taker::Nothing), (1, 0), "the first read finds the Escape, the second nothing");
|
||||
}
|
||||
|
||||
/// An Escape in a native palette that a focused field, an open menu or the app's own code there takes or keeps never
|
||||
/// reaches the main window.
|
||||
#[trial]
|
||||
fn an_escape_taken_in_a_native_palette_never_reaches_the_main_window() {
|
||||
for taker in [Taker::Field, Taker::Menu, Taker::App] {
|
||||
assert_eq!(main_window_cancels(taker), (0, 0), "{taker:?}: the Escape stays in the palette's window");
|
||||
}
|
||||
}
|
||||
|
||||
/// A palette float made in the app window.
|
||||
fn float() -> Floating<u32> {
|
||||
Floating::single(104, vec![1], 0, Rect::from_min_size(Pos2::new(40.0, 40.0), Vec2::new(300.0, 200.0)))
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
//! A host's own drag (a rail popup's title) that floats a panel and hands its press to the panel's window, in a dock
|
||||
//! that opens its floats in OS windows.
|
||||
|
||||
use super::Numbered;
|
||||
use craft_behavior::dock::{Floating, Layout, Node, Workspace};
|
||||
use craft_ui::contract::{Bind, BodyCx, Role, Tracked};
|
||||
use craft_ui::docking::{DockConfig, DockPanels, GroupDrag};
|
||||
use craft_ui::patterns::dock::DockArea;
|
||||
use craft_ui::runtime::drag;
|
||||
use craft_ui::testing::input::key_press;
|
||||
use craft_ui::testing::pointer::{moved, press, release};
|
||||
use craft_ui::testing::trial;
|
||||
use craft_ui_test_kit::windows::{Out, Windows};
|
||||
use egui::{Event, Key, Modifiers, Pos2, Rect, Sense, Ui, Vec2, ViewportId, ViewportInfo};
|
||||
use std::sync::Arc;
|
||||
|
||||
const DOCKED: usize = 1;
|
||||
const FLOATED: usize = 2;
|
||||
/// The main window on the desktop.
|
||||
const MAIN_AT: Rect = Rect { min: Pos2::new(100.0, 100.0), max: Pos2::new(900.0, 700.0) };
|
||||
/// Where the host floats the panel, in the main window.
|
||||
const WINDOW_AT: Rect = Rect { min: Pos2::new(130.0, 90.0), max: Pos2::new(330.0, 210.0) };
|
||||
/// The host's popup title, clear of the docked group's tab strip.
|
||||
const TITLE_AT: Rect = Rect { min: Pos2::new(130.0, 230.0), max: Pos2::new(290.0, 254.0) };
|
||||
/// The grab point inside the window the host hands its press over at.
|
||||
const GRAB: Vec2 = Vec2::new(40.0, 12.0);
|
||||
const SLACK: f32 = 1.5;
|
||||
|
||||
struct Empty;
|
||||
|
||||
impl DockPanels<usize> for Empty {
|
||||
fn body(&mut self, _: &usize, _: &mut Ui, _: &mut BodyCx<'_>) {}
|
||||
}
|
||||
|
||||
/// A dock over a host that shows a popup title, and the OS windows the dock opened.
|
||||
struct Host {
|
||||
windows: Windows,
|
||||
workspace: Arc<Workspace<usize>>,
|
||||
specs: Tracked<Numbered>,
|
||||
popup: bool,
|
||||
hand_over: Option<(usize, Vec2)>,
|
||||
/// Where the dock opened its first OS window on the desktop.
|
||||
opened_at: Option<Pos2>,
|
||||
}
|
||||
|
||||
impl Host {
|
||||
fn new(root: Option<Node<usize>>) -> Self {
|
||||
let windows = Windows::new();
|
||||
windows.root_info(info(MAIN_AT));
|
||||
windows.child_info(info(WINDOW_AT.translate(MAIN_AT.min.to_vec2())));
|
||||
let workspace = Arc::new(Workspace::new(Layout::new(root, Vec::new())));
|
||||
let mut host = Host { windows, workspace, specs: Tracked::new(Numbered), popup: true, hand_over: None, opened_at: None };
|
||||
for _ in 0..3 {
|
||||
host.frame(vec![]);
|
||||
}
|
||||
host
|
||||
}
|
||||
|
||||
fn frame(&mut self, events: Vec<Event>) -> Out {
|
||||
let Host { windows, workspace, specs, popup, hand_over, .. } = self;
|
||||
let out = windows.frame(events, vec![], |ui| {
|
||||
let mut panels = Empty;
|
||||
let config = DockConfig::default().title_bar_docks(false);
|
||||
let mut area = DockArea::new("Dock", Bind::bound(&mut *workspace), &*specs, &mut panels, config);
|
||||
if let Some(request) = hand_over.take() {
|
||||
area = area.continue_move(request);
|
||||
}
|
||||
area.show(ui);
|
||||
if !*popup {
|
||||
return;
|
||||
}
|
||||
egui::Area::new(egui::Id::unique("host popup")).order(egui::Order::Foreground).fixed_pos(TITLE_AT.min).show(ui.ctx(), |ui| {
|
||||
let (_, title) = ui.allocate_exact_size(TITLE_AT.size(), Sense::drag());
|
||||
if title.drag_started() {
|
||||
*popup = false;
|
||||
let mut floated = workspace.layout().clone();
|
||||
floated.floating.push(Floating::single(100, vec![FLOATED], 0, WINDOW_AT));
|
||||
*workspace = Arc::new(Workspace::new(floated));
|
||||
*hand_over = Some((FLOATED, GRAB));
|
||||
}
|
||||
});
|
||||
});
|
||||
if self.opened_at.is_none() {
|
||||
self.opened_at = out.builders.iter().find(|(viewport, _)| *viewport != ViewportId::ROOT).and_then(|(_, builder)| builder.position);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn frames(&mut self, first: Vec<Event>) {
|
||||
self.frame(first);
|
||||
for _ in 0..3 {
|
||||
self.frame(vec![]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Presses the popup's title and drags it to `to`, held there.
|
||||
fn drag_to(&mut self, to: Pos2) {
|
||||
let from = TITLE_AT.center();
|
||||
self.frame(vec![moved(from)]);
|
||||
self.frame(vec![press(from)]);
|
||||
for step in 1..=4 {
|
||||
self.frame(vec![moved(from + (to - from) * (step as f32 / 4.0))]);
|
||||
}
|
||||
self.frame(vec![]);
|
||||
}
|
||||
|
||||
fn dragging(&self) -> bool {
|
||||
drag::active::<GroupDrag<usize>>(&self.windows.ctx).is_some()
|
||||
}
|
||||
|
||||
fn floats(&self) -> bool {
|
||||
self.workspace.layout().floating.iter().any(|window| window.contains(&FLOATED))
|
||||
}
|
||||
}
|
||||
|
||||
fn info(rect: Rect) -> ViewportInfo {
|
||||
ViewportInfo {
|
||||
focused: Some(true),
|
||||
inner_rect: Some(rect),
|
||||
outer_rect: Some(rect),
|
||||
native_pixels_per_point: Some(1.0),
|
||||
..ViewportInfo::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// A dock of one docked group, and a point on the free room of its tab strip.
|
||||
fn docked() -> (Host, Pos2) {
|
||||
let mut host = Host::new(Some(Node::tabs(vec![DOCKED], 0)));
|
||||
let out = host.frame(vec![]);
|
||||
let tree = &out.trees.iter().find(|(viewport, _)| *viewport == ViewportId::ROOT).expect("the main window ran a pass").1;
|
||||
let tab = tree.with_role(Role::TAB).into_iter().find_map(|key| tree.bounds_of(key)).expect("the docked tab shows");
|
||||
(host, Pos2::new(tab.right() + 20.0, tab.center().y))
|
||||
}
|
||||
|
||||
/// Dropped on a docked group's tab strip, the panel joins the group: the drag shows the dock's mark, and no OS window
|
||||
/// opens at any point of it.
|
||||
#[trial]
|
||||
fn a_press_handed_to_a_float_docks_it_on_the_strip_it_is_released_on() {
|
||||
let (mut host, strip) = docked();
|
||||
host.drag_to(strip);
|
||||
assert_eq!(host.opened_at, None, "no OS window opens while the press is held");
|
||||
assert!(drag::mark(&host.windows.ctx).is_some(), "the strip under the pointer shows the drop mark");
|
||||
host.frames(vec![release(strip)]);
|
||||
let layout = host.workspace.layout();
|
||||
assert!(layout.floating.is_empty() && layout.place(&FLOATED).is_some_and(|at| layout.place(&DOCKED) == Some(at)), "it joins: {layout:?}");
|
||||
assert_eq!(host.opened_at, None, "a docked panel opens no OS window");
|
||||
}
|
||||
|
||||
/// Released where nothing takes it, the panel floats in an OS window at the place it was dropped.
|
||||
#[trial]
|
||||
fn a_press_handed_to_a_float_opens_its_os_window_where_it_is_released() {
|
||||
let mut host = Host::new(None);
|
||||
let to = Pos2::new(400.0, 300.0);
|
||||
host.drag_to(to);
|
||||
assert!(host.dragging(), "the panel's drag runs");
|
||||
assert_eq!(host.opened_at, None, "no OS window opens while the press is held");
|
||||
host.frames(vec![release(to)]);
|
||||
let at = host.opened_at.expect("the OS window opens after the release");
|
||||
assert!(at.distance(MAIN_AT.min + (to - GRAB).to_vec2()) < SLACK, "where it was dropped: {at:?}");
|
||||
assert!(host.floats() && !host.dragging(), "the panel floats and no drag is left");
|
||||
}
|
||||
|
||||
/// Escape, or the main window losing the focus, ends the drag: the panel's OS window opens where the host floated it,
|
||||
/// and the button's later release drops nothing.
|
||||
#[trial]
|
||||
fn a_cancelled_press_handed_to_a_float_leaves_it_floating() {
|
||||
for cancel in [key_press(Key::Escape, Modifiers::NONE), Event::WindowFocused(false)] {
|
||||
let (mut host, strip) = docked();
|
||||
host.drag_to(strip);
|
||||
assert!(host.dragging(), "{cancel:?}: the panel's drag runs");
|
||||
host.frames(vec![cancel.clone()]);
|
||||
assert!(!host.dragging(), "{cancel:?} ends the drag");
|
||||
host.frames(vec![release(strip)]);
|
||||
assert!(host.floats(), "{cancel:?}: the release docks nothing");
|
||||
let at = host.opened_at.expect("the panel's OS window opens");
|
||||
assert!(at.distance(MAIN_AT.min + WINDOW_AT.min.to_vec2()) < SLACK, "{cancel:?}: where the host floated it: {at:?}");
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,7 @@ An app with its own eframe `App` calls the hooks in `craft::ui::shell::embed`. `
|
||||
| IME | Taken while a framework editor owns the IME: its events and `PlatformOutput.ime` are the runtime's. Otherwise they stay egui's, for the app's own `TextEdit` or IME code. |
|
||||
| An app's own focused widget | While egui focus is on a widget no framework component made, or an egui popup is open, and no framework press or drag is captured, Escape, the plain Enter and egui's clipboard events stay in egui's input for it, and the runtime routes nothing for them; Tab and Shift+Tab are the window's focus moves (Tab row) unless the widget keeps Tab or the popup is open. While egui focus is on such a widget, the arrows move egui focus among the app's widgets as egui does; while a framework stop has the focus, egui's arrow moves are off. |
|
||||
| Releases | The release of every key the runtime took is taken too. |
|
||||
| Focus surrender | The runtime moves its own focus on press (8.3): a press a framework component takes moves focus to it; a press no component takes drops the framework's focus. egui's click-away never takes the framework's focus. egui's surrender option (`InputOptions::surrender_focus_on`) stays the app's and governs the focus of the app's own widgets, however they got it (the app's code, a click, Tab, F6, a framework request), as in egui alone: a press no component takes leaves that focus to egui's rule, except that a press that gives the focus, and its release, never take it back: the next press or click elsewhere does. Escape releases it too, unless the widget's egui key filter keeps Escape. |
|
||||
| Focus surrender | The runtime moves its own focus on press (8.3): a press a framework component takes moves focus to it; a press no component takes drops the framework's focus, and leaves the app's document canvas (`host_canvas`) focused, whoever gave it the focus and whatever egui's option says. egui's click-away never takes the framework's focus. egui's surrender option (`InputOptions::surrender_focus_on`) stays the app's and governs the focus of the app's own widgets, however they got it (the app's code, a click, Tab, F6, a framework request), as in egui alone: a press no component takes leaves that focus to egui's rule, except that a press that gives the focus, and its release, never take it back: the next press or click elsewhere does. Escape releases it too, unless the widget's egui key filter keeps Escape. |
|
||||
| Clicks | egui's click options (`InputOptions::max_click_dist`, `max_click_duration`) stay the app's, for its own widgets. A framework component clicks and drags by the framework's press lifecycle: a release within the slop (`HitSizes::slop`), whatever its duration. Read a component's click with `contract::clicked(&response)` or its output's `clicked()`; egui's `Response::clicked()` on a component's response also needs a click by egui's options. |
|
||||
| Zoom keys | egui's keyboard zoom is off and nothing takes its place: the interface scale is `RootEnv::scale`, and an app whose ⌘= and ⌘- changed it binds them itself. |
|
||||
| Quit | egui's quit shortcuts are cleared. ⌘Q (Ctrl+Q on Windows and Linux) is the default of the command `QuitCommand::Quit` (id `window.quit`), which the runtime runs from any source: it asks the root window to close through the close path below, so the app's close decision asks about unsaved work. It fires with a modal open; the close path then refuses under an app-modal layer. Its default is bound and yielded as F6 is; an app whose own shortcut table reads its quit key from egui unbinds it there. |
|
||||
@@ -169,7 +169,7 @@ An app with its own eframe `App` calls the hooks in `craft::ui::shell::embed`. `
|
||||
| App modals | A modal the app draws with its own egui code blocks nothing outside egui by itself. While one shows, the app names its window each frame with `FrameInput::app_modal(Some(viewport))`: the app's other windows, panels floated into windows of their own among them, are then blocked as under a framework app-modal layer (their presses, keys, wheel and text are dropped, a press there brings the modal's window forward, and they refuse to close). |
|
||||
| Input pacing | One press per pass: extra presses in one frame wait for the next passes. A press outside an open framework menu closes the menu and goes no further. After an OS resize of the window, the held pointer is released. |
|
||||
|
||||
The window's keys are the ones the runtime routes to no component: an Escape or a plain Enter while nothing has the focus, neither a framework stop nor one of the app's own widgets or popups, and the arrows' nudge. The window's plain Enter also stays in egui's input. `with_window_intents` offers them to its closure while nothing has framework focus. The closure takes what it handles (`Intents::take(Intent::Cancel)`; `Intent` and the other types `Intents` reads are in `ui::runtime::keys`) and returns whether it took anything; the rest stays for later readers. A framework scope that ran earlier in the pass takes them first (an open dialog takes the Escape that closes it), so the app reads them last in its UI to see what no component took. App code that read `Key::Escape`, `Key::Tab`, F6 or F10 from egui while none of its own widgets had focus reads these intents and `FrameOutput::chrome_toggles` instead; its own focused widgets and popups keep reading Escape and the plain Enter from egui (Tab only where the widget keeps it or a popup is open), and no window intent comes of them.
|
||||
The window's keys are the ones the runtime routes to no component: an Escape or a plain Enter while nothing has the focus, neither a framework stop nor one of the app's own widgets or popups, and the arrows' nudge. The window's plain Enter also stays in egui's input. `with_window_intents` offers them to its closure while nothing has framework focus. The closure takes what it handles (`Intents::take(Intent::Cancel)`; `Intent` and the other types `Intents` reads are in `ui::runtime::keys`) and returns whether it took anything; the rest stays for later readers. A framework scope that ran earlier in the pass takes them first (an open dialog takes the Escape that closes it), so the app reads them last in its UI to see what no component took. App code that read `Key::Escape`, `Key::Tab`, F6 or F10 from egui while none of its own widgets had focus reads these intents and `FrameOutput::chrome_toggles` instead; its own focused widgets and popups keep reading Escape and the plain Enter from egui (Tab only where the widget keeps it or a popup is open), and no window intent comes of them. An Escape pressed in the OS window of a floated dock panel that nothing there takes, not even a reader of that window's intents, is the Cancel of the window the dock is in, in its next pass, so the app reads it where it reads its own; a popup or a modal open over the panel keeps it, and any other OS window (an app's own viewport, a dialog or document window) keeps its Escape to itself (`WindowSpec::hands_on_cancel`).
|
||||
|
||||
Framework dialogs the app keeps as values run on a `DialogHost`: the app calls `run(ui)` once per pass after its own UI and reads results with `take`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user