mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 09:08:11 +00:00
Merge pull request #3563 from aiongg/float-popup-focus
Floating windows: a modal takes the keyboard from a window it blocks, menus in popup windows keep their state; egui b9770908e
This commit is contained in:
Generated
+14
-14
@@ -5581,7 +5581,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "ecolor"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"emath",
|
||||
@@ -5637,7 +5637,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "eframe"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -5672,7 +5672,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"ahash",
|
||||
@@ -5691,7 +5691,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-wgpu"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -5710,7 +5710,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui-winit"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"bytemuck",
|
||||
@@ -5730,7 +5730,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_glow"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"egui",
|
||||
@@ -5743,7 +5743,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "egui_kittest"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"egui",
|
||||
@@ -5820,7 +5820,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "emath"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
@@ -5893,7 +5893,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
@@ -5919,7 +5919,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "epaint_default_fonts"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
|
||||
[[package]]
|
||||
name = "equator"
|
||||
@@ -15251,19 +15251,19 @@ dependencies = [
|
||||
[[patch.unused]]
|
||||
name = "egui_demo_lib"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_extras"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_inspection"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
|
||||
[[patch.unused]]
|
||||
name = "egui_system_font_provider"
|
||||
version = "0.37.0"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec"
|
||||
source = "git+https://github.com/storytold/egui.git?rev=b9770908e0f304896f9658d239a7b29cf8af1564#b9770908e0f304896f9658d239a7b29cf8af1564"
|
||||
|
||||
+14
-14
@@ -317,20 +317,20 @@ hayro-postscript = { path = "vendor/hayro-postscript" }
|
||||
linesweeper = { path = "vendor/linesweeper" }
|
||||
vello_common = { path = "vendor/vello_common" }
|
||||
vello_cpu = { path = "vendor/vello_cpu" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
|
||||
|
||||
# symphonia's FLAC decoder restores LPC samples as `residual + (prediction as i32)`. In a valid
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/// The egui fork the library is built and tested with. Apps patch egui to exactly this.
|
||||
pub const GIT: &str = "https://github.com/storytold/egui.git";
|
||||
/// The commit of [`GIT`].
|
||||
pub const REV: &str = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec";
|
||||
pub const REV: &str = "b9770908e0f304896f9658d239a7b29cf8af1564";
|
||||
|
||||
/// The packages the workspace patches to the fork (the `[patch.crates-io]` entries that name [`GIT`]).
|
||||
pub const PACKAGES: &[&str] = &[
|
||||
|
||||
@@ -78,21 +78,15 @@ pub(super) fn dismissal(
|
||||
/// own pass decides: a layer that closes on outside presses closes on one in the opener outside it and its anchor
|
||||
/// (absorbed or not, as its rule says), and on one in any other window of the app; a popup also closes once the app
|
||||
/// has no focus. An absorbing layer can't keep a press in another OS window from reaching that window.
|
||||
pub(super) fn popup_dismissal(
|
||||
ctx: &Context,
|
||||
layer: &Layer<'_>,
|
||||
rect: Rect,
|
||||
anchor: Rect,
|
||||
popup: egui::ViewportId,
|
||||
appears: bool,
|
||||
) -> Option<CloseReason> {
|
||||
pub(super) fn popup_dismissal(ctx: &Context, layer: &Layer<'_>, rect: Rect, anchor: Rect, popup: egui::ViewportId) -> Option<CloseReason> {
|
||||
let here = match layer.overlay.dismiss.outside {
|
||||
Outside::Keep => return None,
|
||||
Outside::Absorb => overlay::absorbed_press(ctx).is_some(),
|
||||
Outside::Close => press_outside(ctx, layer, rect, anchor),
|
||||
};
|
||||
let away = layer.overlay.rank == Rank::Popup && crate::runtime::windows::app_away(ctx);
|
||||
(here || away || crate::runtime::windows::pressed_elsewhere(ctx, popup, appears)).then_some(CloseReason::Outside)
|
||||
let appeared = overlay::appeared_this_frame(ctx, layer.id);
|
||||
(here || away || crate::runtime::windows::pressed_elsewhere(ctx, popup, appeared)).then_some(CloseReason::Outside)
|
||||
}
|
||||
|
||||
/// Whether a primary press landed outside the layer, its anchor and the layers opened from inside it. A press the
|
||||
|
||||
@@ -73,6 +73,27 @@ fn recall(layer: &Layer<'_>, ctx: &Context) -> LayerMemory {
|
||||
MemoryStage::peek::<LayerMemory>(ctx, memory_slot(layer.id))
|
||||
}
|
||||
|
||||
/// What the layer remembers as its host's pass starts. A layer that `appears` starts with nothing it remembered while
|
||||
/// shown before, also when it opens again during its exit fade or its host never saw it hide: the focus that was inside
|
||||
/// it does not close it as `focus_left`. A right-click on a context opener while its layer is open hangs the layer at
|
||||
/// the new pointer.
|
||||
fn recall_shown(layer: &Layer<'_>, ctx: &Context, appears: bool) -> LayerMemory {
|
||||
if appears {
|
||||
return LayerMemory::default();
|
||||
}
|
||||
let mut memory = recall(layer, ctx);
|
||||
let pointed = layer
|
||||
.overlay
|
||||
.opener
|
||||
.as_ref()
|
||||
.is_some_and(|first| first.all().any(|opener| opener.fired && opener.trigger == Trigger::Context && opener.opening == Opening::Pointer));
|
||||
if pointed {
|
||||
memory.opening = None;
|
||||
memory.pointer_at = None;
|
||||
}
|
||||
memory
|
||||
}
|
||||
|
||||
fn remember(layer: &Layer<'_>, ctx: &Context, memory: LayerMemory) {
|
||||
let mut stage = MemoryStage::open_owned(ctx, memory_slot(layer.id), layer.owner);
|
||||
*stage.shown::<LayerMemory>(memory_slot(layer.id)) = memory;
|
||||
@@ -116,20 +137,8 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U
|
||||
{
|
||||
return host_in_popup(ctx, layer, popup, body);
|
||||
}
|
||||
// A layer that appears starts with nothing it remembered while shown before, also when it opens again during its
|
||||
// exit fade or its host never saw it hide: the focus that was inside it does not close it as `focus_left`.
|
||||
let appears = overlay::appears(ctx, layer.id, layer.exiting);
|
||||
let mut memory = if appears { LayerMemory::default() } else { recall(layer, ctx) };
|
||||
// A right-click on a context opener while its layer is open hangs the layer at the new pointer.
|
||||
let pointed = layer
|
||||
.overlay
|
||||
.opener
|
||||
.as_ref()
|
||||
.is_some_and(|first| first.all().any(|opener| opener.fired && opener.trigger == Trigger::Context && opener.opening == Opening::Pointer));
|
||||
if pointed {
|
||||
memory.opening = None;
|
||||
memory.pointer_at = None;
|
||||
}
|
||||
let mut memory = recall_shown(layer, ctx, appears);
|
||||
let opened = opened_overlay(ctx, layer.overlay, memory.opening);
|
||||
if let Some((_, opening)) = &opened {
|
||||
memory.opening.get_or_insert(*opening);
|
||||
@@ -284,8 +293,8 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U
|
||||
/// laid out in the popup's pass first, in the room its unplaced form has, and placed by the size it took there.
|
||||
/// A popup that takes keys (a menu, a flyout) takes the OS focus; a tooltip takes none and lets the pointer through.
|
||||
fn host_in_popup(ctx: &Context, layer: &Layer<'_>, popup: PopupRoom, body: &mut dyn FnMut(&mut Ui)) -> LayerOut {
|
||||
let appears = overlay::appears(ctx, layer.id, layer.exiting);
|
||||
let mut memory = if appears { LayerMemory::default() } else { recall(layer, ctx) };
|
||||
let appears = overlay::note_appeared(ctx, layer.id, layer.exiting);
|
||||
let mut memory = recall_shown(layer, ctx, appears);
|
||||
let opened = opened_overlay(ctx, layer.overlay, memory.opening);
|
||||
if let Some((_, opening)) = &opened {
|
||||
memory.opening.get_or_insert(*opening);
|
||||
@@ -336,7 +345,7 @@ fn host_in_popup(ctx: &Context, layer: &Layer<'_>, popup: PopupRoom, body: &mut
|
||||
entry.popup = true;
|
||||
overlay::record(ctx, entry);
|
||||
let viewport = crate::runtime::egui::viewports::viewport_id(layer.id);
|
||||
let dismissed = if layer.exiting { None } else { dismissed.or_else(|| popup_dismissal(ctx, layer, rect, anchor, viewport, appears)) };
|
||||
let dismissed = if layer.exiting { None } else { dismissed.or_else(|| popup_dismissal(ctx, layer, rect, anchor, viewport)) };
|
||||
close_family(ctx, layer, layer.exiting || dismissed.is_some(), &mut memory);
|
||||
remember(layer, ctx, memory);
|
||||
LayerOut { dismissed }
|
||||
|
||||
@@ -34,9 +34,10 @@ pub struct FrameInput {
|
||||
pub latched: Mods,
|
||||
/// The window in which the app's own egui code shows a modal this frame (a dialog the app draws itself, not a
|
||||
/// framework layer). It blocks the app's other windows as a framework app-modal layer open in it does: their
|
||||
/// presses, keys, wheel and text go nowhere, a press there brings the modal's window forward, and they refuse to
|
||||
/// close. A panel floated into a window of its own is one of them. `None` (the default) when the app shows no such
|
||||
/// modal; set every frame from the app's own state.
|
||||
/// presses, keys, wheel and text go nowhere, a press there brings the modal's window forward, they refuse to close,
|
||||
/// and the modal's window takes the keyboard if one of them has it when the modal opens. A panel floated into a
|
||||
/// window of its own is one of them. `None` (the default) when the app shows no such modal; set every frame from
|
||||
/// the app's own state.
|
||||
pub app_modal: Option<ViewportId>,
|
||||
/// Whether the window system's input reaches the OS windows the runtime hosts.
|
||||
pub window_input: WindowInput,
|
||||
|
||||
@@ -313,7 +313,8 @@ pub(crate) struct Persist {
|
||||
popup_over_modal: bool,
|
||||
/// The layers that first showed while the primary button was held, until that press ends.
|
||||
held_open: IdSet,
|
||||
/// The root frame and pass each shown layer first ran its body in; gone with the layer's last entry.
|
||||
/// The root frame and pass each shown layer first ran its body in, and for a layer of this window that shows in a
|
||||
/// popup window of its own, the pass it first asked for it in; gone with the layer's last entry.
|
||||
appeared: IdMap<(u64, u64)>,
|
||||
/// The roots whose asked raise ran in a pass where a floating window (re)appeared: egui raises every layer that
|
||||
/// shows again, and its area order keeps the old order among the layers raised in one pass, so the raise is asked
|
||||
@@ -552,19 +553,37 @@ fn reopened(ctx: &Context, id: Id, exiting: bool) -> bool {
|
||||
!exiting && with_pass(ctx, |pass| pass.last.iter().any(|entry| entry.id == id && entry.exiting))
|
||||
}
|
||||
|
||||
/// Whether the layer `id` appears in this pass, read before its `begin_layer`: it was hidden in the last pass, or it
|
||||
/// Whether the layer `id` appears in this pass, read before its `note_appeared`: it was hidden in the last pass, or it
|
||||
/// faded out and is open again. What the layer remembers starts fresh then; a discard pass that repeats the frame
|
||||
/// keeps what the first pass of the frame recorded.
|
||||
pub(crate) fn appears(ctx: &Context, id: Id, exiting: bool) -> bool {
|
||||
reopened(ctx, id, exiting) || with_persist(ctx, pass::current_viewport(ctx), |persist| !persist.appeared.contains_key(&id))
|
||||
}
|
||||
|
||||
/// Records that the layer `id` shows in the running viewport in this pass; returns whether it appears in it
|
||||
/// ([`appears`]). A layer shown in a popup window is recorded in its opener's viewport too, where its host runs.
|
||||
pub(crate) fn note_appeared(ctx: &Context, id: Id, exiting: bool) -> bool {
|
||||
let appears = appears(ctx, id, exiting);
|
||||
if appears {
|
||||
let viewport = pass::current_viewport(ctx);
|
||||
let first = (pass::root_frame_nr(ctx), pass::pass_nr(ctx, viewport));
|
||||
with_persist(ctx, viewport, |persist| persist.appeared.insert(id, first));
|
||||
}
|
||||
appears
|
||||
}
|
||||
|
||||
/// Whether the layer `id` first showed in the running viewport in this root frame, in any of its passes.
|
||||
pub(crate) fn appeared_this_frame(ctx: &Context, id: Id) -> bool {
|
||||
let now = pass::root_frame_nr(ctx);
|
||||
with_persist(ctx, pass::current_viewport(ctx), |persist| persist.appeared.get(&id).is_some_and(|(frame, _)| *frame == now))
|
||||
}
|
||||
|
||||
/// Marks the layer `id`'s body as running, so layers opened from inside it become its children, with the `side` of
|
||||
/// its anchor it was placed on. A layer shown again while it fades out opens anew: it appears in this frame and pass.
|
||||
pub(crate) fn begin_layer(ctx: &Context, id: Id, tier: Tier, exiting: bool, side: Option<Side>) {
|
||||
// Which layers a press opened reads the presses and releases.
|
||||
crate::runtime::replay::note_input(ctx, crate::runtime::inputs::Input::Press);
|
||||
let reopened = reopened(ctx, id, exiting);
|
||||
let new = note_appeared(ctx, id, exiting);
|
||||
with_pass(ctx, |pass| {
|
||||
pass.drawing.push((id, tier));
|
||||
pass.exiting.push(exiting);
|
||||
@@ -572,19 +591,11 @@ pub(crate) fn begin_layer(ctx: &Context, id: Id, tier: Tier, exiting: bool, side
|
||||
pass.sides.push((id, side));
|
||||
}
|
||||
});
|
||||
let viewport = pass::current_viewport(ctx);
|
||||
let first = (pass::root_frame_nr(ctx), pass::pass_nr(ctx, viewport));
|
||||
let (down, released) = pointer::with_pass_raw(ctx, |read| {
|
||||
let released = read.frame.as_ref().filter(|frame| frame.release == Some(craft_behavior::PointerButton::Primary)).map(|frame| frame.pos);
|
||||
(read.primary_down, released)
|
||||
});
|
||||
let release = with_persist(ctx, viewport, |persist| {
|
||||
let new = reopened || !persist.appeared.contains_key(&id);
|
||||
if reopened {
|
||||
persist.appeared.insert(id, first);
|
||||
} else {
|
||||
persist.appeared.entry(id).or_insert(first);
|
||||
}
|
||||
let release = with_persist(ctx, pass::current_viewport(ctx), |persist| {
|
||||
if exiting {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
use crate::runtime::cursor;
|
||||
use crate::runtime::egui::input::{self as raw_input, RawInput};
|
||||
use crate::runtime::egui::{injected, pass, viewports};
|
||||
use crate::runtime::egui::{injected, pass, repaint, viewports};
|
||||
use crate::runtime::frame::PerViewport;
|
||||
use crate::runtime::ime;
|
||||
use crate::runtime::overlay;
|
||||
@@ -56,6 +56,11 @@ pub(crate) use viewport::{PopupOpen, ViewportOpen, close_popup, place_popup, sho
|
||||
/// Seconds between writes of a changed placement store.
|
||||
const FLUSH_SECONDS: f64 = 1.0;
|
||||
|
||||
/// Seconds after an app-modal layer opens until its window takes the keyboard from a window it blocks: an OS dialog
|
||||
/// the app opens with the modal (a file dialog) takes the focus a little later, and a focus request sent before then
|
||||
/// could bring the modal's window over it.
|
||||
const MODAL_FOCUS_WAIT: f64 = 0.2;
|
||||
|
||||
/// Install-time inputs and the cross-window records of one context.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Shared {
|
||||
@@ -93,6 +98,8 @@ pub(crate) struct Shared {
|
||||
lowered: bool,
|
||||
/// Where the raise of the modal's window above the palettes it lowered stands.
|
||||
raise: Raise,
|
||||
/// The pass time at which the modal's window takes the keyboard from a window it blocks, until then.
|
||||
modal_focus: Option<f64>,
|
||||
/// Whether the root window showed an app-modal or popup layer in the last root pass: palette windows are hidden
|
||||
/// meanwhile, and one that opens meanwhile opens hidden.
|
||||
palettes_yield: bool,
|
||||
@@ -522,8 +529,8 @@ pub(crate) fn popup_room(ctx: &Context) -> Option<PopupRoom> {
|
||||
Some(PopupRoom { origin, room })
|
||||
}
|
||||
|
||||
/// Whether a primary press landed, in this root frame (or in the last one, unless the popup window `popup` just
|
||||
/// `appeared`), in a window of the app other than the running viewport (the popup's opener, whose own presses its
|
||||
/// Whether a primary press landed, in this root frame (or in the last one, unless the popup window `popup` `appeared`
|
||||
/// in this one), in a window of the app other than the running viewport (the popup's opener, whose own presses its
|
||||
/// layer stack judges) and the popup window and the popup windows opened from it.
|
||||
pub(crate) fn pressed_elsewhere(ctx: &Context, popup: ViewportId, appeared: bool) -> bool {
|
||||
let opener = pass::current_viewport(ctx);
|
||||
@@ -533,18 +540,23 @@ pub(crate) fn pressed_elsewhere(ctx: &Context, popup: ViewportId, appeared: bool
|
||||
if viewport == opener {
|
||||
return false;
|
||||
}
|
||||
// A press in a popup window opened from the popup, at any depth, is inside its family.
|
||||
let mut at = Some(viewport);
|
||||
while let Some(window) = at {
|
||||
if window == popup {
|
||||
return false;
|
||||
}
|
||||
at = PerViewport::<Record>::with_existing(ctx, window, |record| record.opener).flatten();
|
||||
}
|
||||
true
|
||||
// A press in a popup window opened from the popup is inside its family.
|
||||
!in_family(ctx, viewport, popup)
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether `viewport`'s window is `window` or a popup window opened from it, at any depth.
|
||||
fn in_family(ctx: &Context, viewport: ViewportId, window: ViewportId) -> bool {
|
||||
let mut at = Some(viewport);
|
||||
while let Some(shown) = at {
|
||||
if shown == window {
|
||||
return true;
|
||||
}
|
||||
at = PerViewport::<Record>::with_existing(ctx, shown, |record| record.opener).flatten();
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Whether no window of the app has focus, as the last frame's windows reported.
|
||||
pub(crate) fn app_away(ctx: &Context) -> bool {
|
||||
shared(ctx, |shared| shared.app.away)
|
||||
@@ -674,6 +686,8 @@ fn flush_store(ctx: &Context) {
|
||||
/// window reports focus: the batch that took focus from one window gave it to no other.
|
||||
///
|
||||
/// Once a palette has stood lowered under an app-modal layer, the modal's window is raised above it, once per modal.
|
||||
/// A window that has the keyboard when a modal comes to block it drops the keys the modal needs, so the modal's window
|
||||
/// takes the keyboard from it ([`focus_modal`]).
|
||||
fn follow_activity(ctx: &Context) {
|
||||
let windows = viewports::reported(ctx);
|
||||
let focused: Vec<ViewportId> = windows
|
||||
@@ -683,13 +697,18 @@ fn follow_activity(ctx: &Context) {
|
||||
.collect();
|
||||
let modal = overlay::app_modal_viewport(ctx);
|
||||
let minimized = viewports::current(ctx).minimized;
|
||||
let now = pass::now(ctx);
|
||||
let (repaint, raise) = shared(ctx, |shared| {
|
||||
shared.stacking.retain(|viewport| windows.iter().any(|(open, _)| open == viewport) && !focused.contains(viewport));
|
||||
shared.stacking.extend(&focused);
|
||||
let app = AppState { away: focused.is_empty(), modal, minimized };
|
||||
let lowered = std::mem::take(&mut shared.lowered);
|
||||
let modal_changed = app.modal != shared.app.modal;
|
||||
if modal_changed {
|
||||
shared.modal_focus = app.modal.map(|_| now + MODAL_FOCUS_WAIT);
|
||||
}
|
||||
let (step, raise) = match shared.raise {
|
||||
_ if app.modal != shared.app.modal => (Raise::Waiting, None),
|
||||
_ if modal_changed => (Raise::Waiting, None),
|
||||
Raise::Waiting if lowered => (Raise::Due, None),
|
||||
Raise::Due => (Raise::Done, app.modal),
|
||||
step => (step, None),
|
||||
@@ -701,11 +720,36 @@ fn follow_activity(ctx: &Context) {
|
||||
if let Some(modal) = raise {
|
||||
act(ctx, modal, WindowAction::Raise);
|
||||
}
|
||||
if let Some(modal) = modal {
|
||||
focus_modal(ctx, modal, &windows);
|
||||
}
|
||||
if repaint {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
|
||||
/// Gives the window of `modal`, the app's top modal, the OS focus when one of `windows` that it blocks still has it
|
||||
/// [`MODAL_FOCUS_WAIT`] after the modal opened; once per modal. With the focus elsewhere by then (in the modal's own
|
||||
/// window, in an OS dialog, in another app) nothing is sent.
|
||||
fn focus_modal(ctx: &Context, modal: ViewportId, windows: &[(ViewportId, viewports::Facts)]) {
|
||||
let Some(due) = shared(ctx, |shared| shared.modal_focus) else { return };
|
||||
let blocked = |viewport: ViewportId| overlay::modal_viewport(ctx, viewport) == Some(modal) && !in_family(ctx, viewport, modal);
|
||||
let wait = due - pass::now(ctx);
|
||||
if wait > 0.0 {
|
||||
if windows.iter().any(|(viewport, _)| blocked(*viewport)) {
|
||||
repaint::request_after(ctx, ViewportId::ROOT, wait);
|
||||
}
|
||||
return;
|
||||
}
|
||||
shared(ctx, |shared| shared.modal_focus = None);
|
||||
let focused = |viewport: ViewportId| {
|
||||
PerViewport::<Record>::with_existing(ctx, viewport, |record| record.facts.is_some_and(|facts| facts.focus_reported)).unwrap_or(false)
|
||||
};
|
||||
if !focused(modal) && windows.iter().any(|(viewport, _)| focused(*viewport) && blocked(*viewport)) {
|
||||
act(ctx, modal, WindowAction::Focus);
|
||||
}
|
||||
}
|
||||
|
||||
/// Records whether the root window shows an app-modal or popup layer: palette windows hide meanwhile, so a click on a
|
||||
/// palette cannot bring it over the layer, and the palettes' mounts hide and show them as they do for the app's state
|
||||
/// ([`show_viewport`]), asked for by a repaint when it changes. Runs at the end of the root pass, where the
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
//! `runtime::windows`: the input hook per viewport, window info per viewport, the press release after an OS
|
||||
//! resize (H4), the raise of a modal's window, the mount of a full-window container (in a window of its own, or in a
|
||||
//! full-screen or Wayland-maximized main window), the size of a content-sized window, the app id of child windows, a
|
||||
//! palette's level under a modal and its visibility while the main window is minimized, injected keys across a focus
|
||||
//! loss, non-finite injected points, a repeated injected press, the window that has the keys, a wheel with no known
|
||||
//! pointer, the placement of a minimized window, the root frame decided again, a held close, `act`, and a hosted
|
||||
//! window's Control-click and window-input policy.
|
||||
//! `runtime::windows`: the input hook per viewport, window info per viewport, the press release after an OS resize
|
||||
//! (H4), the raise of a modal's window and the keyboard it takes from a window it blocks, the mount of a full-window
|
||||
//! container (in a window of its own, or in a full-screen or Wayland-maximized main window), the size of a
|
||||
//! content-sized window, the app id of child windows, a palette's level under a modal and its visibility while the main
|
||||
//! window is minimized, injected keys across a focus loss, non-finite injected points, a repeated injected press, the
|
||||
//! window that has the keys, a wheel with no known pointer, what a layer in a popup window keeps while it is open, the
|
||||
//! placement of a minimized window, the root frame decided again, a held close, `act`, and a hosted window's
|
||||
//! Control-click and window-input policy.
|
||||
|
||||
use craft_behavior::{Cursor, CursorIcon, PointerButton, Sense};
|
||||
use craft_host::target::{Backend, Caps, Os, ShellInfo, WindowChrome, WindowInfo, WindowKind};
|
||||
use craft_keymap::{Key, Mods};
|
||||
use craft_ui::contract::{Common, Component, Container, ContainerProps, Cx, Mount, Overlay, Props as _, Role, Show as _, ShowContainer as _};
|
||||
use craft_ui::contract::{Common, Component, Container, ContainerProps, Cx, Mount, Overlay, Props as _, Role, Scroll, Show as _, ShowContainer as _};
|
||||
use craft_ui::runtime::InstallSpec;
|
||||
use craft_ui::runtime::focus::FocusPolicy;
|
||||
use craft_ui::runtime::overlay::CloseReason;
|
||||
@@ -328,6 +329,216 @@ fn an_app_modal_in_one_window_blocks_the_cursor_and_the_close_of_the_others() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Window facts with the focus as given, at a place the window system tells.
|
||||
fn focus(on: bool) -> ViewportInfo {
|
||||
ViewportInfo { focused: Some(on), inner_rect: Some(Rect::from_min_size(Pos2::ZERO, Vec2::splat(300.0))), ..ViewportInfo::default() }
|
||||
}
|
||||
|
||||
fn on_x11() -> Windows {
|
||||
Windows::with(InstallSpec::new(ShellInfo::default().backend(Backend::X11), Arc::new(FakeSystem::new())))
|
||||
}
|
||||
|
||||
/// How many focus requests `out` sent to `viewport`.
|
||||
fn focus_requests(out: &Out, viewport: ViewportId) -> usize {
|
||||
out.commands.iter().filter(|(id, command)| *id == viewport && *command == ViewportCommand::Focus).count()
|
||||
}
|
||||
|
||||
/// Frames that last longer than a modal's window waits before it takes the keyboard.
|
||||
const PAST_THE_WAIT: usize = 40;
|
||||
|
||||
/// The app's own modal that opens while a window it blocks has the keyboard (a command typed in a floated panel opens
|
||||
/// the save prompt in the main window) gets the keys it needs: its window takes the OS focus from the blocked one,
|
||||
/// once, and the wait before it wakes an idle app. Nothing is sent when no blocked window has the focus by then (an OS
|
||||
/// dialog that opened with the modal took it, or the modal's window has it) or the modal closed meanwhile.
|
||||
#[trial]
|
||||
fn an_app_modal_takes_the_keyboard_from_a_window_it_blocks() {
|
||||
// The frames after the modal opens in which the main window, which shows it, got a focus request, with the main
|
||||
// window and a child window focused as given and `before` run before each frame.
|
||||
let requests = |root: bool, float: bool, before: &dyn Fn(&Windows, usize)| -> Vec<usize> {
|
||||
let windows = on_x11();
|
||||
windows.root_info(focus(root));
|
||||
windows.child_info(focus(float));
|
||||
let frame = || windows.frame(vec![], vec![], |ui| ui.ctx().show_viewport_immediate(child(), ViewportBuilder::default(), |_, _| {}));
|
||||
for _ in 0..4 {
|
||||
frame();
|
||||
}
|
||||
windows.app_modal(Some(ViewportId::ROOT));
|
||||
(0..PAST_THE_WAIT)
|
||||
.flat_map(|at| {
|
||||
before(&windows, at);
|
||||
vec![at; focus_requests(&frame(), ViewportId::ROOT)]
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
let none: [usize; 0] = [];
|
||||
let sent = requests(false, true, &|_, _| {});
|
||||
let &[handed] = sent.as_slice() else { panic!("the main window takes the keyboard from the float once: {sent:?}") };
|
||||
assert!(handed > 1, "not before an OS dialog that opens with the modal could take it: frame {handed}");
|
||||
let closes = |windows: &Windows, at| {
|
||||
if at == handed {
|
||||
windows.app_modal(None);
|
||||
}
|
||||
};
|
||||
assert_eq!(requests(false, true, &closes), none, "the modal closed meanwhile");
|
||||
let os_dialog = |windows: &Windows, at| {
|
||||
if at == 1 {
|
||||
windows.child_info(focus(false));
|
||||
}
|
||||
};
|
||||
assert_eq!(requests(false, true, &os_dialog), none, "an OS dialog took the focus");
|
||||
assert_eq!(requests(false, false, &|_, _| {}), none, "no window of the app has the focus");
|
||||
assert_eq!(requests(true, false, &|_, _| {}), none, "the modal's window has the focus");
|
||||
|
||||
let woken = Arc::new(Mutex::new(false));
|
||||
let settled = |windows: &Windows, at| {
|
||||
if at == 2 {
|
||||
let woken = woken.clone();
|
||||
windows.ctx.set_request_repaint_callback(move |info| *woken.lock().unwrap() |= !info.delay.is_zero());
|
||||
}
|
||||
};
|
||||
requests(false, true, &settled);
|
||||
assert!(*woken.lock().unwrap(), "an idle app wakes for the hand-over");
|
||||
}
|
||||
|
||||
/// A framework modal in a window of its own takes the keyboard from the main window it blocks.
|
||||
#[trial]
|
||||
fn a_framework_modal_takes_the_keyboard_from_the_window_it_blocks() {
|
||||
let windows = on_x11();
|
||||
windows.root_info(focus(true));
|
||||
windows.child_info(focus(false));
|
||||
let sent: usize = (0..PAST_THE_WAIT).map(|_| focus_requests(&modal_frame(&windows), child())).sum();
|
||||
assert_eq!(sent, 1, "once");
|
||||
}
|
||||
|
||||
/// A menu's layer hung from a place near its window's corner: opened in a palette it shows in a popup window.
|
||||
fn menu_layer() -> ContainerProps {
|
||||
use craft_behavior::overlay::{Align, Side};
|
||||
use craft_ui::contract::overlay::{Anchor, Place};
|
||||
let anchor = Rect::from_min_size(Pos2::new(20.0, 20.0), Vec2::splat(10.0));
|
||||
ContainerProps::new().mount(Mount::Layer(Overlay::menu().place(Place::anchored(Anchor::Rect(anchor), Side::Below, Align::Start))))
|
||||
}
|
||||
|
||||
/// The popup window `out` shows beside the main window and `palette`.
|
||||
fn popup_window(out: &Out, palette: ViewportId) -> Option<ViewportId> {
|
||||
out.builders.iter().map(|(id, _)| *id).find(|id| ![ViewportId::ROOT, palette].contains(id))
|
||||
}
|
||||
|
||||
/// A popup window opened from the window that shows the app's modal keeps the keyboard.
|
||||
#[trial]
|
||||
fn a_popup_window_of_the_modals_window_keeps_the_keyboard() {
|
||||
let windows = on_x11();
|
||||
windows.root_info(focus(false));
|
||||
windows.child_info(focus(true));
|
||||
let open = Cell::new(false);
|
||||
let frame = || {
|
||||
windows.frame(vec![], vec![], |ui| {
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| {
|
||||
if open.get() {
|
||||
Modal { common: Common::new(), props: menu_layer() }.id_salt("popup").show(ui, |_, _| {});
|
||||
}
|
||||
});
|
||||
})
|
||||
};
|
||||
let palette = builder_titled(&frame(), "tool").0;
|
||||
windows.app_modal(Some(palette));
|
||||
open.set(true);
|
||||
frame();
|
||||
windows.child_info(focus(false));
|
||||
let outs: Vec<Out> = (0..PAST_THE_WAIT).map(|_| frame()).collect();
|
||||
let popup = outs.last().and_then(|out| popup_window(out, palette)).expect("the layer opened in the palette shows in a popup window");
|
||||
assert_eq!(windows.facts(popup).focused, Some(true), "the popup window has the keyboard");
|
||||
assert_eq!(outs.iter().map(|out| focus_requests(out, palette)).sum::<usize>(), 0, "the modal's window leaves it there");
|
||||
}
|
||||
|
||||
/// A layer in a popup window keeps the scroll that a focus move below its view gave it while it is open, and starts at
|
||||
/// the top when it opens again.
|
||||
#[trial]
|
||||
fn a_layer_in_a_popup_window_keeps_its_scroll_until_it_closes() {
|
||||
use craft_ui::runtime::focus::{FocusTarget, request};
|
||||
let windows = on_x11();
|
||||
windows.root_info(focus(true));
|
||||
windows.child_info(focus(true));
|
||||
let (open, reveal, top) = (Cell::new(false), Cell::new(false), Cell::new(0.0));
|
||||
let (tall, last) = (RefCell::new(Seen::default()), RefCell::new(Seen::default()));
|
||||
let frame = || {
|
||||
windows.frame(vec![], vec![], |ui| {
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| {
|
||||
if open.get() {
|
||||
let props = menu_layer().scroll(Scroll::vertical());
|
||||
Modal { common: Common::new(), props }.id_salt("popup").show(ui, |ui, _| {
|
||||
if !craft_ui::testing::is_measuring(ui.ctx()) {
|
||||
top.set(ui.next_widget_position().y);
|
||||
}
|
||||
Probe::new(&tall).id_salt("tall").size(Vec2::new(100.0, 2000.0)).show(ui);
|
||||
Probe::new(&last).id_salt("last").show(ui);
|
||||
if let Some(id) = last.borrow().id.filter(|_| reveal.take()) {
|
||||
request(ui.ctx(), FocusTarget::Id(id));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
};
|
||||
let settled = || {
|
||||
let mut out = frame();
|
||||
for _ in 1..PAST_THE_WAIT {
|
||||
out = frame();
|
||||
}
|
||||
out
|
||||
};
|
||||
let palette = builder_titled(&frame(), "tool").0;
|
||||
open.set(true);
|
||||
assert!(popup_window(&settled(), palette).is_some(), "the layer opened in the palette shows in a popup window");
|
||||
let start = top.get();
|
||||
reveal.set(true);
|
||||
settled();
|
||||
let scrolled = top.get();
|
||||
assert!(scrolled < start - 1.0, "the layer stays scrolled: its content starts at {scrolled}, {start} unscrolled");
|
||||
open.set(false);
|
||||
assert_eq!(popup_window(&settled(), palette), None, "the layer closed");
|
||||
open.set(true);
|
||||
settled();
|
||||
assert!((top.get() - start).abs() < 0.5, "opened again, it starts at the top: {} after {scrolled}, {start} unscrolled", top.get());
|
||||
}
|
||||
|
||||
/// A popup that a press in another window of the app opened stays open, also when its opener runs a second pass of the
|
||||
/// frame it opens in, and a later press there closes it.
|
||||
#[trial]
|
||||
fn a_popup_window_stays_after_the_press_in_another_window_that_opened_it() {
|
||||
let windows = on_x11();
|
||||
windows.root_info(focus(true));
|
||||
windows.child_info(focus(true));
|
||||
let (open, again, closed) = (Cell::new(false), Cell::new(false), RefCell::new(Vec::new()));
|
||||
let frame = |root: Vec<Event>| {
|
||||
windows.frame(root, vec![], |ui| {
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |ui, _| {
|
||||
if open.get() {
|
||||
Capture { common: Common::new(), props: menu_layer(), closed: &closed }.id_salt("popup").show(ui, |_, _| {});
|
||||
if again.take() {
|
||||
craft_ui::runtime::frame::discard_pass(ui.ctx(), "test");
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
};
|
||||
let at = Pos2::new(250.0, 250.0);
|
||||
frame(vec![]);
|
||||
let out = frame(vec![moved(at)]);
|
||||
let palette = builder_titled(&out, "tool").0;
|
||||
frame(vec![press(at), release(at)]);
|
||||
open.set(true);
|
||||
again.set(true);
|
||||
let mut out = frame(vec![]);
|
||||
for _ in 0..4 {
|
||||
out = frame(vec![]);
|
||||
}
|
||||
assert!(!again.get() && popup_window(&out, palette).is_some(), "the popup opened, its opener's pass repeated");
|
||||
assert_eq!(*closed.borrow(), [], "the press that opened it leaves it open");
|
||||
frame(vec![press(at), release(at)]);
|
||||
frame(vec![]);
|
||||
assert_eq!(closed.borrow().first(), Some(&CloseReason::Outside), "a later press in the main window closes it");
|
||||
}
|
||||
|
||||
/// A window that a modal in another window blocks takes no wheel, as it takes no press or key: what is under the
|
||||
/// pointer there does not scroll.
|
||||
#[trial]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Native dock windows: when a float gets an OS window, what the dock records when the OS moves it, the OS close, and
|
||||
//! docking the whole window by dragging its title row. A context menu opened in a palette places its popup window as
|
||||
//! it places the menu in the main window.
|
||||
//! it places the menu in the main window; the palette's own menus keep their place and take the arrow keys in theirs.
|
||||
|
||||
use craft_behavior::Intent;
|
||||
use craft_behavior::dock::{Action, Column, DockEdge, Floating, Group, Layout, Node, Permissions, Workspace};
|
||||
@@ -17,10 +17,10 @@ use craft_ui::popover::DropVeil;
|
||||
use craft_ui::runtime::InstallSpec;
|
||||
use craft_ui::runtime::env::RootEnv;
|
||||
use craft_ui::runtime::{drag, keys};
|
||||
use craft_ui::testing::access::AccessTree;
|
||||
use craft_ui::testing::access::{AccessTree, focused_key};
|
||||
use craft_ui::testing::focus::key_release;
|
||||
use craft_ui::testing::input::key_press;
|
||||
use craft_ui::testing::pointer::{moved, press, release, secondary};
|
||||
use craft_ui::testing::pointer::{gone, moved, press, release, secondary};
|
||||
use craft_ui::testing::trial;
|
||||
use craft_ui::testing::windows::{FakeSystem, HeldButtons};
|
||||
use craft_ui::text::NumberField;
|
||||
@@ -1784,3 +1784,77 @@ fn a_context_menu_from_a_native_palette_too_tall_for_either_side_covers_the_poin
|
||||
assert!(window.contains_rect(shown), "row {row} {shown:?} lies whole in the menu's window {window:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens the menu a secondary click at `at`, a point of the palette's window, asks for; returns its popup window.
|
||||
fn open_menu(dock: &mut NativeDock, rect: &mut Rect, at: Pos2) -> ViewportId {
|
||||
for events in [vec![moved(at)], vec![secondary(at, true)], vec![secondary(at, false)], vec![], vec![]] {
|
||||
collapsed_frame(dock, &mut Palettes, rect, vec![], events);
|
||||
}
|
||||
let out = collapsed_frame(dock, &mut Palettes, rect, vec![], vec![]);
|
||||
let opened = popups(dock, &out).into_iter().find(|viewport| !tree_of_viewport(&out, *viewport).with_role(Role::MENU).is_empty());
|
||||
opened.expect("the menu shows in a popup window")
|
||||
}
|
||||
|
||||
/// The arrow keys move the focus in a native palette's tab menu, and Enter runs the row they reach: Dock Panel, which
|
||||
/// is not the first row, docks the panel. Opened again after Escape, the menu starts as it opened first.
|
||||
#[trial]
|
||||
fn the_arrow_keys_reach_a_row_of_a_native_palettes_tab_menu() {
|
||||
let mut dock = NativeDock::on(Os::Windows, Arc::new(FakeSystem::new()));
|
||||
let mut at = FLOAT_AT;
|
||||
dock.windows.root_info(scaled(true, MAIN_AT, COLLAPSED_SCALE));
|
||||
dock.windows.child_info(scaled(true, at, COLLAPSED_SCALE));
|
||||
let out = collapsed_frame(&mut dock, &mut Palettes, &mut at, vec![], vec![]);
|
||||
let palette = dock.palette.expect("the palette's window opened");
|
||||
let tab = node_rect(tree_of_viewport(&out, palette), PALETTE_TITLE, Role::TAB).expect("the palette shows the panel's tab").center();
|
||||
// A key in the menu's window, and the row focused in the frame after it.
|
||||
let key = |dock: &mut NativeDock, at: &mut Rect, menu: ViewportId, key: Key| -> Option<String> {
|
||||
dock.windows.send(menu, vec![key_press(key, Modifiers::NONE)]);
|
||||
collapsed_frame(dock, &mut Palettes, at, vec![], vec![]);
|
||||
dock.windows.send(menu, vec![key_release(key, Modifiers::NONE)]);
|
||||
collapsed_frame(dock, &mut Palettes, at, vec![], vec![]);
|
||||
let out = collapsed_frame(dock, &mut Palettes, at, vec![], vec![]);
|
||||
let tree = &out.trees.iter().find(|(shown, _)| *shown == menu)?.1;
|
||||
tree.name_of(focused_key(tree)).map(str::to_owned)
|
||||
};
|
||||
let menu = open_menu(&mut dock, &mut at, tab);
|
||||
let first = key(&mut dock, &mut at, menu, Key::ArrowDown);
|
||||
let second = key(&mut dock, &mut at, menu, Key::ArrowDown);
|
||||
assert_ne!(first, second, "the second arrow moves the focus on");
|
||||
key(&mut dock, &mut at, menu, Key::Escape);
|
||||
for _ in 0..30 {
|
||||
collapsed_frame(&mut dock, &mut Palettes, &mut at, vec![], vec![]);
|
||||
}
|
||||
let out = collapsed_frame(&mut dock, &mut Palettes, &mut at, vec![], vec![]);
|
||||
assert!(!popups(&dock, &out).contains(&menu), "Escape closed the menu");
|
||||
let menu = open_menu(&mut dock, &mut at, tab);
|
||||
let mut row = key(&mut dock, &mut at, menu, Key::ArrowDown);
|
||||
assert_eq!(row, first, "the menu starts at the same row again");
|
||||
for _ in 0..4 {
|
||||
if row.as_deref() == Some("Dock Panel") {
|
||||
break;
|
||||
}
|
||||
row = key(&mut dock, &mut at, menu, Key::ArrowDown);
|
||||
}
|
||||
key(&mut dock, &mut at, menu, Key::Enter);
|
||||
let layout = dock.workspace.layout();
|
||||
assert!(layout.floating.is_empty(), "Enter ran {row:?}, which docks the panel: {layout:?}");
|
||||
}
|
||||
|
||||
/// The menu a secondary click on a native palette's title row hangs at the pointer stays there while the pointer
|
||||
/// leaves the palette for the menu's window and comes back, and hangs at the new place of a second secondary click.
|
||||
#[trial]
|
||||
fn a_native_palettes_title_row_menu_stays_where_it_opened() {
|
||||
let mut dock = NativeDock::on(Os::Windows, Arc::new(FakeSystem::new()));
|
||||
let mut at = FLOAT_AT;
|
||||
dock.windows.root_info(scaled(true, MAIN_AT, COLLAPSED_SCALE));
|
||||
dock.windows.child_info(scaled(true, at, COLLAPSED_SCALE));
|
||||
let menu = open_menu(&mut dock, &mut at, ROW_AT);
|
||||
let opened = window_rect(&dock, menu);
|
||||
for events in [vec![gone()], vec![], vec![moved(ROW_AT + Vec2::new(-60.0, 80.0))], vec![]] {
|
||||
collapsed_frame(&mut dock, &mut Palettes, &mut at, vec![], events);
|
||||
assert_eq!(window_rect(&dock, menu), opened, "the menu stays where it opened");
|
||||
}
|
||||
let menu = open_menu(&mut dock, &mut at, ROW_AT - Vec2::new(40.0, 0.0));
|
||||
let moved = window_rect(&dock, menu);
|
||||
assert!(moved.min.x < opened.min.x - 1.0, "it hangs at the second click: {moved:?}, first {opened:?}");
|
||||
}
|
||||
|
||||
@@ -22,8 +22,9 @@ const ROOT_SIZE: Vec2 = Vec2::new(800.0, 600.0);
|
||||
const CHILD_SIZE: Vec2 = Vec2::new(400.0, 300.0);
|
||||
|
||||
thread_local! {
|
||||
/// The events the next child pass receives (the renderer runs on the trial's thread).
|
||||
static CHILD_EVENTS: RefCell<Vec<Event>> = const { RefCell::new(Vec::new()) };
|
||||
/// The events of the running frame's child passes (the renderer runs on the trial's thread), each for the child it
|
||||
/// is addressed to, or else for the first child pass.
|
||||
static CHILD_EVENTS: RefCell<Vec<(Option<ViewportId>, Event)>> = const { RefCell::new(Vec::new()) };
|
||||
/// The files hovering over and dropped on the child's window in the next child pass.
|
||||
static CHILD_FILES: RefCell<(Vec<HoveredFile>, Vec<String>)> = const { RefCell::new((Vec::new(), Vec::new())) };
|
||||
/// The window facts every child opened from the root reports.
|
||||
@@ -203,7 +204,13 @@ impl egui::DroppedFile for DroppedPath {
|
||||
fn render_child(ctx: &Context, viewport: egui::ImmediateViewport<'_>) {
|
||||
patch_window(viewport.ids, viewport.builder);
|
||||
let mut callback = viewport.viewport_ui_cb;
|
||||
let events = CHILD_EVENTS.with(|events| std::mem::take(&mut *events.borrow_mut()));
|
||||
let this = viewport.ids.this;
|
||||
let events = CHILD_EVENTS.with(|events| {
|
||||
let mut events = events.borrow_mut();
|
||||
let (own, others): (Vec<_>, Vec<_>) = events.drain(..).partition(|(to, _)| to.is_none_or(|to| to == this));
|
||||
*events = others;
|
||||
own.into_iter().map(|(_, event)| event).collect()
|
||||
});
|
||||
let (hovered_files, dropped) = CHILD_FILES.with(|files| std::mem::take(&mut *files.borrow_mut()));
|
||||
let dropped_files = dropped.into_iter().map(|name| Arc::new(DroppedPath(name.into())) as egui::DroppedFileHandle).collect();
|
||||
let mut info = with_facts(viewport.ids.this, |info| info.clone());
|
||||
@@ -380,8 +387,14 @@ impl Windows {
|
||||
*self.root.borrow_mut() = root;
|
||||
}
|
||||
|
||||
/// One frame: `root` events go to the root viewport, `child` events to the child's next pass. Returns the
|
||||
/// window commands of the frame.
|
||||
/// Gives the next frame's pass of the child `viewport` these `events`, as a popup window's, which runs inside its
|
||||
/// opener's pass.
|
||||
pub fn send(&self, viewport: ViewportId, events: Vec<Event>) {
|
||||
CHILD_EVENTS.with(|kept| kept.borrow_mut().extend(events.into_iter().map(|event| (Some(viewport), event))));
|
||||
}
|
||||
|
||||
/// One frame: `root` events go to the root viewport, `child` events to the first child pass, and each other child
|
||||
/// gets the events [`send`](Self::send) gave it. Returns what the frame sent out.
|
||||
pub fn frame(&self, root: Vec<Event>, child: Vec<Event>, ui: impl FnMut(&mut Ui)) -> Out {
|
||||
self.frame_with_files(root, child, FilesOver::Root, Vec::new(), Vec::new(), ui)
|
||||
}
|
||||
@@ -397,7 +410,7 @@ impl Windows {
|
||||
dropped: Vec<String>,
|
||||
ui: impl FnMut(&mut Ui),
|
||||
) -> Out {
|
||||
CHILD_EVENTS.with(|events| *events.borrow_mut() = child);
|
||||
CHILD_EVENTS.with(|events| events.borrow_mut().extend(child.into_iter().map(|event| (None, event))));
|
||||
let ((root_hovered, root_dropped), child_files) = match over {
|
||||
FilesOver::Root => ((hovered, dropped), Default::default()),
|
||||
FilesOver::Child => (Default::default(), (hovered, dropped)),
|
||||
@@ -424,6 +437,7 @@ impl Windows {
|
||||
ROOT_INFO.with(|info| *info.borrow_mut() = self.root_info.borrow().clone());
|
||||
input.viewports = all_viewports();
|
||||
let mut output = self.ctx.run_ui(input, ui);
|
||||
CHILD_EVENTS.with(|events| events.borrow_mut().clear());
|
||||
// A child the frame no longer shows has closed: like an integration, the kit drops its window, so later inputs
|
||||
// stop listing it (and what its last pass left, such as a modal, stops counting), and a window opened again
|
||||
// opens anew.
|
||||
|
||||
@@ -166,7 +166,7 @@ An app with its own eframe `App` calls the hooks in `craft::ui::shell::embed`. `
|
||||
| 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. |
|
||||
| Close path | The runtime's window host owns the root window's close request. `embed::logic` asks the app through its closure, then hands the close to the platform quit where there is one (macOS). |
|
||||
| Wheel | `RootEnv::wheel_speed` scales each wheel delta once; a Ctrl or Cmd wheel keeps the device's distance. The install's `WheelModifiers` set egui's zoom and sideways modifiers. On Windows and Linux, a Ctrl+wheel in fractions of a notch (a point-unit one on Linux) is a touchpad pinch and arrives as `Event::Zoom`, at egui's Ctrl-scroll zoom speed: Windows hands a precision touchpad's pinch to apps only that way. Whole notches stay wheel events, except within 0.25 s of a pinch step. An app whose Ctrl+wheel does something else, or zooms at its own rate, sets `RootEnv::ctrl_wheel_pinch(false)` and reads the wheel events itself. |
|
||||
| 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). |
|
||||
| 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, they refuse to close, and the modal's window takes the keyboard if one of them has it when the modal opens). |
|
||||
| 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. 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`).
|
||||
|
||||
Reference in New Issue
Block a user