mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
Merge branch 'sync/delta11' into sync/next2
This commit is contained in:
commit
bf62d509fb
12 files changed
+221
-38
No files matched your search
@@ -75,7 +75,8 @@ impl BodyCx<'_> {
|
||||
|
||||
impl BodyHooks<'_> {
|
||||
/// Records for the container's hooks whether this pass's primary press went down on its own surface
|
||||
/// (`BodyCx::surface_pressed`): no shape of last pass under the press takes it, and the press lies in the
|
||||
/// (`BodyCx::surface_pressed`): no shape of last pass under the press takes it, nor a component's text widget
|
||||
/// egui gives it to (a focused field's), and the press lies in the
|
||||
/// container's rect on its layer; and whether that press is the second of a double click
|
||||
/// (`BodyCx::surface_double_pressed`), read from the same press's click count; and whether this pass's primary
|
||||
/// release ends a press that went down there (`BodyCx::surface_clicked`). The press origin waits in the press slot
|
||||
@@ -90,11 +91,11 @@ impl BodyHooks<'_> {
|
||||
areas::layer_at(&ctx, pos) == Some(layer) && rect.contains(at)
|
||||
};
|
||||
let surface = if sensed {
|
||||
pass.frame
|
||||
.as_ref()
|
||||
.and_then(|frame| frame.press)
|
||||
.filter(|press| press.button == PointerButton::Primary)
|
||||
.filter(|press| inside(press.origin) && pointer::press_winner(&ctx, press.origin, pass.press_targets).is_none())
|
||||
pass.frame.as_ref().and_then(|frame| frame.press).filter(|press| press.button == PointerButton::Primary).filter(|press| {
|
||||
inside(press.origin)
|
||||
&& pointer::press_winner(&ctx, press.origin, pass.press_targets).is_none()
|
||||
&& !pointer::text_takes_press(&ctx, pass.press_targets)
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
@@ -285,7 +285,7 @@ struct View {
|
||||
gens: ViewGens,
|
||||
}
|
||||
/// A press's double-press matcher, its time, and whether a binding's command accepts the press where it lands.
|
||||
type ChordMatch<'a> = (&'a mut Matcher, f64, &'a dyn Fn(&CommandRef) -> bool);
|
||||
type ChordMatch<'a> = (&'a mut Matcher, f64, bool, &'a dyn Fn(&CommandRef) -> bool);
|
||||
|
||||
/// What a resolution read besides the board's own generation and the gate.
|
||||
#[derive(Default)]
|
||||
@@ -867,12 +867,12 @@ impl KeyScopes {
|
||||
f(&Active { panel, contexts: &contexts, typing }, outer)
|
||||
}
|
||||
|
||||
/// What a press of `input` runs, read through `layout`. With `matcher` and the press's time the press counts toward
|
||||
/// a double press; without, it is matched on its own. With a matcher, a binding of a command `accept` refuses
|
||||
/// (disabled where the press lands) is passed over for the press's next binding.
|
||||
/// What a press of `input` runs, read through `layout`. With `matcher`, the press's time and whether it is a held
|
||||
/// key's repeat, a press counts toward a double press; without, it is matched on its own. With a matcher, a binding
|
||||
/// of a command `accept` refuses (disabled where the press lands) is passed over for the press's next binding.
|
||||
fn press(&self, layout: &Layout, input: &KeyInput, typing: bool, matcher: Option<ChordMatch<'_>>) -> Option<Hit> {
|
||||
self.matching(typing, |active, outer| match matcher {
|
||||
Some((matcher, now, accept)) => matcher.press_where(layout, &self.keymap, &Press { input, repeat: false, now, active, outer }, accept),
|
||||
Some((matcher, now, repeat, accept)) => matcher.press_where(layout, &self.keymap, &Press { input, repeat, now, active, outer }, accept),
|
||||
None => Matcher::single(layout, &self.keymap, input, active, outer),
|
||||
})
|
||||
}
|
||||
@@ -2052,6 +2052,24 @@ pub(crate) fn begin(ctx: &Context) {
|
||||
let hit = if time - wait.since >= wait.delay { Some(wait.hold) } else { wait.tap }?;
|
||||
press(hit, Some(wait.key), time, place)
|
||||
};
|
||||
// A binding whose command is disabled where the press lands (a window command with no floating window, a canvas's
|
||||
// view command it does not offer) is passed over: the press runs the next binding of its chord, in an outer scope,
|
||||
// or of its next chord candidate, as if the disabled one were unbound.
|
||||
let enabled = |command: &CommandRef| {
|
||||
let (_, instance) = with(ctx, |board| board.target_of(ctx, command, &board.here));
|
||||
resolve_in(ctx, command, instance, Reach::Focus, None, Reads::default()).0.enabled
|
||||
};
|
||||
// Whether a text component has the keys for `shortcut`'s press; one that lets command keys through leaves their
|
||||
// presses to the app's commands.
|
||||
let typing_at = |shortcut: &keys::Shortcut| {
|
||||
let command_key = shortcuts.command_keys
|
||||
&& shortcuts
|
||||
.layout
|
||||
.candidates(&shortcut.input)
|
||||
.first()
|
||||
.is_some_and(|chord| TypingRule::CommandKeysOnly.fires(chord, keys.keymap.platform()));
|
||||
shortcuts.typing && !shortcut.canvas && !command_key
|
||||
};
|
||||
let (mut fired, mut dimmed) = (Vec::new(), Vec::new());
|
||||
let mut changes = shortcuts.mods.iter().map(|(index, _)| *index).peekable();
|
||||
for (index, shortcut) in shortcuts.keys.iter().enumerate() {
|
||||
@@ -2070,28 +2088,26 @@ pub(crate) fn begin(ctx: &Context) {
|
||||
let held = with(ctx, |board| key.and_then(|key| board.held.iter().position(|held| held.key == key)).map(|at| board.held.remove(at)));
|
||||
fired.extend(held.map(|held| release_fired(held, shortcut.input.mods, time, Some(shortcut.place))));
|
||||
}
|
||||
_ => {
|
||||
FirePhase::Repeat => {
|
||||
// A held key's repeat (`RootEnv::shortcuts_repeat`) runs its chord's command again, on its own: it
|
||||
// completes no double press and settles no wait, and the key a momentary or tool command holds stays
|
||||
// held by its press. The key of a wait or of a hold binding repeats nothing.
|
||||
let typing = typing_at(shortcut);
|
||||
if wait.as_ref().is_some_and(|wait| Some(wait.key) == key) || keys.hold(&shortcuts.layout, &shortcut.input, typing).is_some() {
|
||||
continue;
|
||||
}
|
||||
let tap = keys.press(&shortcuts.layout, &shortcut.input, typing, Some((&mut matcher, time, true, &enabled)));
|
||||
let repeated = tap.and_then(|tap| press(tap, None, time, Some(shortcut.place)));
|
||||
fired.extend(repeated.map(|fired| Fired { phase: FirePhase::Repeat, ..fired }));
|
||||
}
|
||||
FirePhase::Press => {
|
||||
// Another key's press settles the wait first: keys act in the order they went down.
|
||||
fired.extend(settle(wait.take(), time, Some(shortcut.place)));
|
||||
// A binding whose command is disabled where the press lands (a window command with no floating
|
||||
// window, a canvas's view command it does not offer) is passed over: the press runs the next binding
|
||||
// of its chord, in an outer scope, or of its next chord candidate, as if the disabled one were unbound.
|
||||
let enabled = |command: &CommandRef| {
|
||||
let (_, instance) = with(ctx, |board| board.target_of(ctx, command, &board.here));
|
||||
resolve_in(ctx, command, instance, Reach::Focus, None, Reads::default()).0.enabled
|
||||
};
|
||||
// A text component that lets command keys through leaves their presses to the app's commands.
|
||||
let command_key = shortcuts.command_keys
|
||||
&& shortcuts
|
||||
.layout
|
||||
.candidates(&shortcut.input)
|
||||
.first()
|
||||
.is_some_and(|chord| TypingRule::CommandKeysOnly.fires(chord, keys.keymap.platform()));
|
||||
let typing = shortcuts.typing && !shortcut.canvas && !command_key;
|
||||
let typing = typing_at(shortcut);
|
||||
let hold = key
|
||||
.filter(|_| !typing && !modal_at_start)
|
||||
.and_then(|key| keys.hold(&shortcuts.layout, &shortcut.input, typing).map(|hold| (key, hold)));
|
||||
let tap = keys.press(&shortcuts.layout, &shortcut.input, typing, Some((&mut matcher, time, &enabled)));
|
||||
let tap = keys.press(&shortcuts.layout, &shortcut.input, typing, Some((&mut matcher, time, false, &enabled)));
|
||||
match (hold, tap) {
|
||||
(Some((key, hold)), tap) => wait = Some(HoldWait { key, hold, since: time, delay, tap, viewport }),
|
||||
(None, Some(tap)) => fired.extend(press(tap, key, time, Some(shortcut.place))),
|
||||
|
||||
@@ -239,7 +239,7 @@ pub enum FireSource {
|
||||
pub enum FirePhase {
|
||||
/// The press.
|
||||
Press,
|
||||
/// A repeat of a held key.
|
||||
/// A repeat of a held key, with `RootEnv::shortcuts_repeat` on.
|
||||
Repeat,
|
||||
/// The release of a momentary command's or a tool's key: a momentary command ends here, and a spring-loaded tool
|
||||
/// gives back the previous one.
|
||||
|
||||
@@ -261,6 +261,8 @@ pub struct Inherited {
|
||||
pub(crate) tab_toggles_chrome: bool,
|
||||
/// `RootEnv::escape_leaves_fields`.
|
||||
pub(crate) escape_leaves_fields: bool,
|
||||
/// `RootEnv::shortcuts_repeat`: the key stage reads only it, so no view's key covers it.
|
||||
pub(crate) shortcuts_repeat: bool,
|
||||
/// `RootEnv::cursor_follows_zoom`: painted cursor images follow the interface zoom.
|
||||
pub(crate) cursor_follows_zoom: bool,
|
||||
/// `RootEnv::tooltips`: tooltips show.
|
||||
@@ -658,6 +660,7 @@ impl Env {
|
||||
today: root.today,
|
||||
tab_toggles_chrome: root.tab_toggles_chrome,
|
||||
escape_leaves_fields: root.escape_leaves_fields,
|
||||
shortcuts_repeat: root.shortcuts_repeat,
|
||||
cursor_follows_zoom: root.cursor_follows_zoom,
|
||||
tooltips: root.tooltips,
|
||||
canvas_pattern: root.canvas_pattern,
|
||||
|
||||
+4
@@ -40,6 +40,9 @@ pub struct RootEnv {
|
||||
/// Whether Escape in a focused text field also takes the focus from it, with or without typing to revert, so the
|
||||
/// next keys go to the window. A clearing field (a search box) still clears its text first.
|
||||
pub escape_leaves_fields: bool,
|
||||
/// Whether a held key's repeats run the command its chord binds again (`FirePhase::Repeat`), as a held Cmd+= keeps
|
||||
/// zooming in. A key with a hold binding, and a key held down while a modal layer opened or closed, repeat nothing.
|
||||
pub shortcuts_repeat: bool,
|
||||
/// Which Tab stops a dialog's Tab order visits.
|
||||
pub dialog_tab: TabReach,
|
||||
/// Whether the canvas surround shows the theme's pattern.
|
||||
@@ -80,6 +83,7 @@ impl Default for RootEnv {
|
||||
tab_all_controls: true,
|
||||
tab_toggles_chrome: false,
|
||||
escape_leaves_fields: false,
|
||||
shortcuts_repeat: false,
|
||||
dialog_tab: TabReach::Root,
|
||||
canvas_pattern: true,
|
||||
cursor_follows_zoom: true,
|
||||
|
||||
@@ -61,6 +61,8 @@ struct Strip<'a> {
|
||||
alt_code_ended: bool,
|
||||
/// Whether the window's keymap binds a chord to a command that is enabled now (`commands::runs_now`).
|
||||
bound: &'a dyn Fn(&Chord) -> bool,
|
||||
/// A held key's repeats are shortcuts too (`RootEnv::shortcuts_repeat`).
|
||||
repeats: bool,
|
||||
}
|
||||
|
||||
/// How the strip reads one raw event beside its key reading: when it arrived, and what its neighbours say of it.
|
||||
@@ -470,10 +472,10 @@ impl Strip<'_> {
|
||||
held: Vec::new(),
|
||||
ime: false,
|
||||
});
|
||||
if !repeat {
|
||||
if !repeat || self.repeats {
|
||||
batch.shortcuts.push(Shortcut {
|
||||
input: *input,
|
||||
phase: FirePhase::Press,
|
||||
phase: if repeat { FirePhase::Repeat } else { FirePhase::Press },
|
||||
press: Some(batch.presses.len() - 1),
|
||||
canvas: false,
|
||||
at,
|
||||
@@ -631,6 +633,7 @@ pub(crate) fn input_hook(ctx: &Context, input: &RawInput, events: &mut Vec<Arriv
|
||||
// disabled (Word's Alt+Shift+- Collapse outside Outline) leaves the text typed (Option+Shift+- is an em dash).
|
||||
let bound = |chord: &Chord| commands::runs_now(ctx, viewport, chord);
|
||||
let press_captured = crate::runtime::pointer::press_captured_in(ctx, viewport) || crate::runtime::drag::running(ctx);
|
||||
let repeats = Env::root_for(ctx, viewport).is_some_and(|env| env.shortcuts_repeat);
|
||||
let (batch, visible, later) = with(ctx, viewport, |stage| {
|
||||
let claims = stage_claims(&record, stage);
|
||||
let edits = |command| keys.is_some_and(|keys| keys.edits.contains(command));
|
||||
@@ -658,6 +661,7 @@ pub(crate) fn input_hook(ctx: &Context, input: &RawInput, events: &mut Vec<Arriv
|
||||
alt_claimed: !stage.alt_claims.is_empty(),
|
||||
alt_code_ended,
|
||||
bound: &bound,
|
||||
repeats,
|
||||
};
|
||||
let mut batch = Batch::default();
|
||||
let mut visible = None;
|
||||
|
||||
@@ -132,7 +132,8 @@ pub(crate) fn begin(ctx: &Context, press_captured: bool) -> EscapeRouting {
|
||||
for command in queued {
|
||||
push(&mut routed, focused, Intent::Edit(command), false);
|
||||
}
|
||||
let (shortcuts, held) = owned_shortcuts(ctx, target.as_ref(), &batch, &consumed, &taken_texts);
|
||||
let over: Vec<bool> = batch.presses.iter().map(held_press).collect();
|
||||
let (shortcuts, held) = owned_shortcuts(ctx, target.as_ref(), &batch, &consumed, &taken_texts, &over);
|
||||
withdraw_taken(ctx, target.as_ref(), &batch, &held, &withdrawn_texts);
|
||||
let pasted = batch.paste.as_deref().zip(focused).map(|(text, id)| (id, Arc::<str>::from(text)));
|
||||
// PLAN: a repeat Tab of a held-over key is not gated; `take_nav` reads `batch.tabs` before this hook runs (owner: focus).
|
||||
@@ -244,8 +245,16 @@ pub(crate) fn owner_at(ctx: &Context, target: Option<&StopRec>, scopes: &[Id], b
|
||||
/// (`holds_press`). The owner is the focused component's class, or `Blocked` while a modal layer is stacked above the
|
||||
/// focus; inside a layer its `Overlay.keys` class ranks with the component's. A `Recorder` keeps every key and a `Menu`
|
||||
/// its navigation keys (`keeps_key`); a text field keeps the text its presses typed. `consumed` is what
|
||||
/// routing did with each press and `taken_texts` whether a component took each text of the pass.
|
||||
fn owned_shortcuts(ctx: &Context, target: Option<&StopRec>, batch: &Batch, consumed: &[Taken], taken_texts: &[bool]) -> (Shortcuts, Vec<bool>) {
|
||||
/// routing did with each press, `taken_texts` whether a component took each text of the pass, and `over` whether each
|
||||
/// press is a repeat of a key held over a modal layer's opening or closing, which runs no shortcut either.
|
||||
fn owned_shortcuts(
|
||||
ctx: &Context,
|
||||
target: Option<&StopRec>,
|
||||
batch: &Batch,
|
||||
consumed: &[Taken],
|
||||
taken_texts: &[bool],
|
||||
over: &[bool],
|
||||
) -> (Shortcuts, Vec<bool>) {
|
||||
let scopes = target.map(|rec| focus::scope_chain(ctx, rec)).unwrap_or_default();
|
||||
let owner = owner_at(ctx, target, &scopes, None);
|
||||
let own = target.map(|rec| rec.stop.keys.owner);
|
||||
@@ -271,7 +280,7 @@ fn owned_shortcuts(ctx: &Context, target: Option<&StopRec>, batch: &Batch, consu
|
||||
.iter()
|
||||
.map(|shortcut| {
|
||||
let key = shortcut.input.typed.or(shortcut.input.physical);
|
||||
!keeps_key(owner, key, shortcut.input.mods) && !shortcut.press.is_some_and(|at| held[at])
|
||||
!keeps_key(owner, key, shortcut.input.mods) && !shortcut.press.is_some_and(|at| held[at] || over[at])
|
||||
})
|
||||
.collect();
|
||||
let keys = batch.shortcuts.iter().zip(&kept).filter(|(_, stays)| **stays).map(|(shortcut, _)| *shortcut).collect();
|
||||
|
||||
@@ -1100,6 +1100,14 @@ fn registered_in(layers: &LayerRecord, widget: Id) -> bool {
|
||||
layers.values().any(|roots| roots.values().any(|root| root.widgets.contains(&widget)))
|
||||
}
|
||||
|
||||
/// Whether egui gives the latest press to a component's text widget (a focused field's), as `targets` name its
|
||||
/// widgets: the press is that text's, though it goes to no root and has no winner (`find_under`).
|
||||
pub(crate) fn text_takes_press(ctx: &Context, targets: PressTargets) -> bool {
|
||||
PerViewport::<Shapes>::with(ctx, pass::current_viewport(ctx), |record| {
|
||||
targets.click.is_some_and(|widget| !record.last_grounds.contains(&widget) && record.last_texts.contains_key(&widget))
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether the egui widget `widget`, one of the latest press's targets, is one no component registered or made for its
|
||||
/// text, and no layer shows beneath everything on it, in the pass the press was hit-tested against: a raw egui widget.
|
||||
pub(crate) fn foreign_target(ctx: &Context, widget: Id) -> bool {
|
||||
|
||||
@@ -14,6 +14,7 @@ pub(crate) mod latch;
|
||||
pub(crate) mod memory;
|
||||
pub(crate) mod pen;
|
||||
pub(crate) mod pointer;
|
||||
pub(crate) mod repeats;
|
||||
pub(crate) mod theme_app;
|
||||
pub(crate) mod typed_keys;
|
||||
pub(crate) mod wheel;
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//! A held key's repeats (`RootEnv::shortcuts_repeat`): an app that turns them on runs a bound command again on each
|
||||
//! repeat, as a held Cmd+= keeps zooming in; a momentary command's repeats leave its key held, so the release ends it.
|
||||
|
||||
use craft_ui::runtime::commands::{AppCatalog, Binding, CommandDef, CommandInput, CommandKind, FirePhase, Scope};
|
||||
use craft_ui::runtime::env::RootEnv;
|
||||
use craft_ui::runtime::frame::take_output;
|
||||
use craft_ui::testing::focus::key_release;
|
||||
use craft_ui::testing::input::{key_press, key_repeat};
|
||||
use craft_ui::testing::{Frames, trial};
|
||||
use egui::{Key, Modifiers, Ui};
|
||||
|
||||
const ZOOM: &str = "repeatTrial.zoom";
|
||||
const PAN: &str = "repeatTrial.pan";
|
||||
|
||||
/// The phases `key` fired its command in over a press, two repeats and the release, with nothing focused, under
|
||||
/// `shortcuts_repeat` set to `repeats`.
|
||||
fn fired_over_a_hold(key: Key, repeats: bool) -> Vec<FirePhase> {
|
||||
let defs = [(ZOOM, "F9", CommandKind::Command), (PAN, "F8", CommandKind::Momentary)].map(|(id, chord, kind)| {
|
||||
let binding = Binding::parse(chord).expect("the trial's chord parses");
|
||||
CommandDef::new(id, id, Scope::app()).with_default(binding).with_kind(kind)
|
||||
});
|
||||
let catalog = AppCatalog::new(defs.to_vec(), 1).expect("the trial's catalog is taken");
|
||||
let mut frames = Frames::new();
|
||||
let mut root = RootEnv::new();
|
||||
root.shortcuts_repeat = repeats;
|
||||
frames.root(root);
|
||||
frames.commands(CommandInput::new().catalog(catalog));
|
||||
let mut show = |_: &mut Ui| {};
|
||||
frames.idle(2, &mut show);
|
||||
take_output(&frames.ctx);
|
||||
let mut phases = Vec::new();
|
||||
for event in
|
||||
[key_press(key, Modifiers::NONE), key_repeat(key, Modifiers::NONE), key_repeat(key, Modifiers::NONE), key_release(key, Modifiers::NONE)]
|
||||
{
|
||||
frames.frame(vec![event], &mut show);
|
||||
frames.idle(1, &mut show);
|
||||
phases.extend(take_output(&frames.ctx).fired.into_iter().map(|fired| fired.phase));
|
||||
}
|
||||
phases
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_held_keys_repeats_run_its_command_again_only_when_the_app_says_so() {
|
||||
assert_eq!(fired_over_a_hold(Key::F9, false), vec![FirePhase::Press], "by default the press runs the command once");
|
||||
assert_eq!(
|
||||
fired_over_a_hold(Key::F9, true),
|
||||
vec![FirePhase::Press, FirePhase::Repeat, FirePhase::Repeat],
|
||||
"with repeats on, each repeat runs it again"
|
||||
);
|
||||
assert_eq!(
|
||||
fired_over_a_hold(Key::F8, true),
|
||||
vec![FirePhase::Press, FirePhase::Repeat, FirePhase::Repeat, FirePhase::Release],
|
||||
"a momentary command repeats and still ends at the release"
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
//! 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.
|
||||
|
||||
use craft_behavior::Intent;
|
||||
use craft_behavior::dock::{Action, Column, DockEdge, Floating, Group, Layout, Node, Permissions, Workspace};
|
||||
use craft_behavior::placement::Placement;
|
||||
use craft_host::target::{Backend, Caps, Os, ShellInfo};
|
||||
@@ -14,12 +15,15 @@ use craft_ui::menu::{Menu, MenuItem};
|
||||
use craft_ui::patterns::dock::DockArea;
|
||||
use craft_ui::popover::DropVeil;
|
||||
use craft_ui::runtime::InstallSpec;
|
||||
use craft_ui::runtime::drag;
|
||||
use craft_ui::runtime::env::RootEnv;
|
||||
use craft_ui::runtime::{drag, keys};
|
||||
use craft_ui::testing::access::AccessTree;
|
||||
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::trial;
|
||||
use craft_ui::testing::windows::{FakeSystem, HeldButtons};
|
||||
use craft_ui::text::NumberField;
|
||||
use craft_ui_test_kit::windows::{AppKitWindow, FilesOver, Out, Windows};
|
||||
use egui::{Event, HoveredFile, Key, Modifiers, Pos2, Rect, Ui, Vec2, ViewportBuilder, ViewportCommand, ViewportEvent, ViewportId, ViewportInfo};
|
||||
use std::sync::Arc;
|
||||
@@ -1382,6 +1386,78 @@ fn a_file_dropped_on_a_native_float_reaches_window_files_once() {
|
||||
assert_eq!(reached(true), 0, "a file a target in the window took does not");
|
||||
}
|
||||
|
||||
/// A palette whose panel holds an Opacity field, then reads the keys its OS window's pass left, as an app passes a
|
||||
/// panel window's leftover Enter and Escape on to its main window: how many of each it read.
|
||||
#[derive(Default)]
|
||||
struct FieldPalette {
|
||||
opacity: Option<f64>,
|
||||
submits: usize,
|
||||
cancels: usize,
|
||||
}
|
||||
|
||||
impl DockPanels<u32> for FieldPalette {
|
||||
fn body(&mut self, _: &u32, ui: &mut Ui, _: &mut BodyCx<'_>) {
|
||||
NumberField::new("Opacity", Bind::bound(&mut self.opacity)).show(ui);
|
||||
if ui.ctx().viewport_id() != ViewportId::ROOT {
|
||||
self.submits += usize::from(keys::with_window_intents(ui.ctx(), false, |window| window.take(Intent::Submit)));
|
||||
self.cancels += usize::from(keys::with_window_intents(ui.ctx(), false, |window| window.take(Intent::Cancel)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Enter and Escape in a field of a native palette are the field's, with `RootEnv::escape_leaves_fields` off or on:
|
||||
/// neither reaches the palette window's leftover keys. A press on the field once it has the focus, which egui gives the
|
||||
/// field's text widget, is no press on the group's empty body, which would hand the focus to the panel's tab. Once
|
||||
/// Escape has taken the focus from the field, Enter is the window's.
|
||||
#[trial]
|
||||
fn enter_and_escape_in_a_native_palettes_field_stay_the_fields() {
|
||||
for leaves in [false, true] {
|
||||
let windows = Windows::new();
|
||||
windows.root_info(info(true, ROOT_AT));
|
||||
windows.child_info(info(true, PALETTE_AT));
|
||||
let mut root = RootEnv::new();
|
||||
root.escape_leaves_fields = leaves;
|
||||
windows.root_env(root);
|
||||
let mut workspace = Arc::new(Workspace::new(Layout::new(None, vec![float()])));
|
||||
let mut palette = FieldPalette { opacity: Some(50.0), ..FieldPalette::default() };
|
||||
let mut frame = |palette: &mut FieldPalette, child: Vec<Event>| {
|
||||
windows.frame(vec![], child, |ui| {
|
||||
let _ =
|
||||
DockArea::new("Native dock", Bind::bound(&mut workspace), &Specs::with(Permissions::ALL), &mut *palette, DockConfig::default())
|
||||
.show(ui);
|
||||
})
|
||||
};
|
||||
let mut out = frame(&mut palette, vec![]);
|
||||
for _ in 0..3 {
|
||||
out = frame(&mut palette, vec![]);
|
||||
}
|
||||
let child = out.trees.iter().find(|(viewport, _)| *viewport != ViewportId::ROOT).expect("the palette has an OS window");
|
||||
let tree = &child.1;
|
||||
let field = tree
|
||||
.keys()
|
||||
.into_iter()
|
||||
.find(|key| tree.name_of(*key) == Some("Opacity") && tree.role_of(*key) != Some(Role::LABEL))
|
||||
.and_then(|key| tree.bounds_of(key))
|
||||
.expect("the palette shows the field")
|
||||
.center();
|
||||
for key in [Key::Enter, Key::Escape] {
|
||||
for events in [vec![moved(field), press(field)], vec![release(field)], vec![], vec![]] {
|
||||
frame(&mut palette, events);
|
||||
}
|
||||
for events in [vec![key_press(key, Modifiers::NONE)], vec![key_release(key, Modifiers::NONE)], vec![], vec![]] {
|
||||
frame(&mut palette, events);
|
||||
}
|
||||
assert_eq!((palette.submits, palette.cancels), (0, 0), "leaves {leaves}: {key:?} in the field is the field's");
|
||||
}
|
||||
if leaves {
|
||||
for events in [vec![key_press(Key::Enter, Modifiers::NONE)], vec![key_release(Key::Enter, Modifiers::NONE)], vec![]] {
|
||||
frame(&mut palette, events);
|
||||
}
|
||||
assert_eq!(palette.submits, 1, "an Enter after Escape left the field is the window's");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 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)))
|
||||
|
||||
@@ -264,6 +264,7 @@ pub struct Windows {
|
||||
/// The installed context.
|
||||
pub ctx: Context,
|
||||
root_info: RefCell<ViewportInfo>,
|
||||
root: RefCell<RootEnv>,
|
||||
}
|
||||
|
||||
impl Default for Windows {
|
||||
@@ -292,7 +293,7 @@ impl Windows {
|
||||
COMMANDS.with(|kept| kept.borrow_mut().clear());
|
||||
BUILDERS.with(|kept| kept.borrow_mut().clear());
|
||||
NOW.with(|now| now.set(0.0));
|
||||
Windows { ctx, root_info: RefCell::new(ViewportInfo::default()) }
|
||||
Windows { ctx, root_info: RefCell::new(ViewportInfo::default()), root: RefCell::new(RootEnv::default()) }
|
||||
}
|
||||
|
||||
/// The window facts child passes report from now on.
|
||||
@@ -311,6 +312,11 @@ impl Windows {
|
||||
*self.root_info.borrow_mut() = info;
|
||||
}
|
||||
|
||||
/// The app's root values every frame gives from now on, the defaults until then.
|
||||
pub fn root_env(&self, root: RootEnv) {
|
||||
*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.
|
||||
pub fn frame(&self, root: Vec<Event>, child: Vec<Event>, ui: impl FnMut(&mut Ui)) -> Out {
|
||||
@@ -337,7 +343,7 @@ impl Windows {
|
||||
root_dropped.into_iter().map(|name| Arc::new(DroppedPath(name.into())) as egui::DroppedFileHandle).collect();
|
||||
CHILD_FILES.with(|files| *files.borrow_mut() = child_files);
|
||||
TREES.with(|kept| kept.borrow_mut().clear());
|
||||
set_input(&self.ctx, FrameInput::new(RootEnv::default()));
|
||||
set_input(&self.ctx, FrameInput::new(self.root.borrow().clone()));
|
||||
let mut input = RawInput {
|
||||
screen_rect: Some(Rect::from_min_size(Pos2::ZERO, ROOT_SIZE)),
|
||||
events: root,
|
||||
|
||||
Reference in new issue
Block a user