mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
B15 phase 3 fixes: the picker caption row is ListRow::caption (ListRow already has a heading prop); a click on a row a collection does not take keeps the layers open; a new right-click moves an open context menu to the pointer; an open menu blocks only the tooltips outside it; Menu runs the row Enter names on its own key activation; trials adjusted (submenu rect, bar shortcut and Help search on a scoped command)
This commit is contained in:
@@ -53,6 +53,17 @@ impl<C: Collection> ItemsHooks<'_, '_, C> {
|
||||
if layout.mirrors() && rtl { flow.to_physical(Rect::from_min_size(at, Vec2::ZERO)).min } else { at }
|
||||
};
|
||||
let mods_now = crate::runtime::pointer::frame(&ctx).mods;
|
||||
// A click on a row the collection does not take (a caption, a disabled row) is no pick: the layers around the
|
||||
// collection (a dropdown's list) stay open.
|
||||
if cx.core.activation.as_ref().is_some_and(|activation| !activation.by_key)
|
||||
&& let Some(pos) = crate::runtime::pointer::frame(&ctx).pos
|
||||
&& local(pos).y >= 0.0
|
||||
&& layout
|
||||
.hit(local(pos), offset)
|
||||
.is_some_and(|at| !self.source.enabled(at) || (self.source.is_section(at) && !self.source.section_stop(at)))
|
||||
{
|
||||
cx.keep_open();
|
||||
}
|
||||
self.pressed = match cx.core.press.phase {
|
||||
PressPhase::Down { start, .. } | PressPhase::Held { start, .. }
|
||||
if start.button == craft_behavior::PointerButton::Primary && local(start.origin).y >= 0.0 =>
|
||||
|
||||
@@ -30,7 +30,8 @@ pub(crate) fn opener_open(stage: &mut MemoryStage, first: &Opener) -> bool {
|
||||
let slot = stage.session::<OpenerOpen>(sub(first.id, "opens"));
|
||||
if let Some(opener) = first.all().find(|opener| opener.fired) {
|
||||
if slot.applied != frame {
|
||||
slot.open = !slot.open;
|
||||
// A context request opens, also over the open layer: a new right-click moves it to the pointer.
|
||||
slot.open = opener.trigger == Trigger::Context || !slot.open;
|
||||
slot.by = Some((opener.id, opener.trigger, opener.opening));
|
||||
}
|
||||
slot.applied = frame;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The overlay host: shows a layer on an egui layer, remembers it while shown and closes its family.
|
||||
|
||||
use super::dismissal::dismissal;
|
||||
use super::opener::Opening;
|
||||
use super::opener::{Opening, Trigger};
|
||||
use super::place::{OverlayFit, Place};
|
||||
use super::placement::{anchor_rect, opened_overlay, placement};
|
||||
use super::props::{Outside, Overlay};
|
||||
@@ -117,6 +117,16 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U
|
||||
// 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 mut memory = if overlay::appears(ctx, layer.id, layer.exiting) { 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 opened = opened_overlay(ctx, layer.overlay, memory.opening);
|
||||
if let Some((_, opening)) = &opened {
|
||||
memory.opening.get_or_insert(*opening);
|
||||
|
||||
@@ -238,7 +238,8 @@ fn show_tip(call: TipCall<'_>) {
|
||||
}
|
||||
let when_now = spec.as_ref().is_some_and(|spec| spec.when == TooltipWhen::Now);
|
||||
let wants = has_content && wants_input;
|
||||
let suppressed = pressed || overlay_blocks(ctx) || pointer::press_captured(ctx) || drag::running(ctx);
|
||||
let screen = areas::layer_to_screen(ctx, rect_layer) * rect;
|
||||
let suppressed = pressed || overlay_blocks(ctx, screen.center()) || pointer::press_captured(ctx) || drag::running(ctx);
|
||||
if wants {
|
||||
state.since.get_or_insert(now);
|
||||
} else {
|
||||
@@ -305,8 +306,9 @@ fn overlay_motion() -> motion::MotionSpec {
|
||||
}
|
||||
|
||||
/// Whether a menu owns the keys: tooltips stay hidden then.
|
||||
fn overlay_blocks(ctx: &egui::Context) -> bool {
|
||||
crate::runtime::overlay::class_open(ctx, OwnerClass::Menu)
|
||||
/// An open menu blocks the tooltips of what lies outside it; its own rows keep theirs.
|
||||
fn overlay_blocks(ctx: &egui::Context, at: egui::Pos2) -> bool {
|
||||
crate::runtime::overlay::class_open_away_from(ctx, OwnerClass::Menu, at)
|
||||
}
|
||||
|
||||
/// The look of a tooltip card.
|
||||
|
||||
@@ -722,9 +722,13 @@ pub(crate) fn modal_viewport(ctx: &Context, viewport: ViewportId) -> Option<View
|
||||
pass::live_viewports(ctx).into_iter().filter(|other| *other != viewport).find(|other| with_persist(ctx, *other, |persist| persist.modal))
|
||||
}
|
||||
|
||||
/// Whether a layer of key class `class` that is not fading out was shown last frame.
|
||||
pub(crate) fn class_open(ctx: &Context, class: OwnerClass) -> bool {
|
||||
with_pass(ctx, |pass| pass.last.iter().any(|entry| !entry.exiting && entry.keys == class))
|
||||
/// Whether a layer of key class `class` that is not fading out was shown last frame and the screen point `at` lies in
|
||||
/// none of those layers.
|
||||
pub(crate) fn class_open_away_from(ctx: &Context, class: OwnerClass, at: Pos2) -> bool {
|
||||
with_pass(ctx, |pass| {
|
||||
let mut open = pass.last.iter().filter(|entry| !entry.exiting && entry.keys == class).peekable();
|
||||
open.peek().is_some() && open.all(|entry| !entry.rect.contains(at))
|
||||
})
|
||||
}
|
||||
|
||||
// The facts the canvas reach under a modal reads (`runtime::sampler`).
|
||||
|
||||
@@ -178,7 +178,7 @@ pub struct ListRow<'a> {
|
||||
#[prop(into)]
|
||||
pub(super) accessible_name: Option<String>,
|
||||
pub(super) spacer: bool,
|
||||
pub(super) heading: bool,
|
||||
pub(super) caption: bool,
|
||||
pub(super) cells: Vec<(ColumnKey, Rect)>,
|
||||
/// Each column's alignment and whether its figures are tabular, from `columns(..)`.
|
||||
pub(super) aligns: Vec<(ColumnKey, HAlign, bool)>,
|
||||
@@ -271,7 +271,7 @@ impl<'a> ListRow<'a> {
|
||||
progress: None,
|
||||
accessible_name: None,
|
||||
spacer: false,
|
||||
heading: false,
|
||||
caption: false,
|
||||
cells: Vec::new(),
|
||||
aligns: Vec::new(),
|
||||
muted: Vec::new(),
|
||||
@@ -315,9 +315,9 @@ impl<'a> ListRow<'a> {
|
||||
/// A caption over the rows after it (a group's name in a picker's list): `label` in the caption role and
|
||||
/// `text.muted` at the row's start, a row high. Like a spacer it senses nothing and takes no lead; its AccessKit
|
||||
/// node is a heading. Mark its position `ItemSource::is_section` so keys and clicks skip it.
|
||||
pub fn heading(label: impl Into<Label>) -> Self {
|
||||
pub fn caption(label: impl Into<Label>) -> Self {
|
||||
let mut row = Self::new(label);
|
||||
row.heading = true;
|
||||
row.caption = true;
|
||||
row
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ impl Component for ListRow<'_> {
|
||||
if self.spacer {
|
||||
return Vec2::ZERO;
|
||||
}
|
||||
if self.heading {
|
||||
if self.caption {
|
||||
let caption = cx.layout_at(&TextRun::new(cx.resolved.label).role(cx.style.detail.role), f32::INFINITY).size();
|
||||
return Vec2::new(caption.x + 2.0 * sizes.pad, sizes.row.max(caption.y));
|
||||
}
|
||||
@@ -166,12 +166,12 @@ impl Component for ListRow<'_> {
|
||||
}
|
||||
|
||||
fn sense(&self) -> Sense {
|
||||
if self.spacer || self.heading { Sense::empty() } else { Sense::CLICK | Sense::FOCUS }
|
||||
if self.spacer || self.caption { Sense::empty() } else { Sense::CLICK | Sense::FOCUS }
|
||||
}
|
||||
|
||||
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
|
||||
self.record_toggle_names(cx);
|
||||
if self.spacer || self.heading {
|
||||
if self.spacer || self.caption {
|
||||
return;
|
||||
}
|
||||
self.adopt_toggle_columns(&cx.env, cx.resolved.id);
|
||||
@@ -287,7 +287,7 @@ impl Component for ListRow<'_> {
|
||||
}
|
||||
|
||||
fn update(&mut self, cx: &mut Cx<'_, Self>) {
|
||||
if self.spacer || self.heading {
|
||||
if self.spacer || self.caption {
|
||||
return;
|
||||
}
|
||||
if let Some(open) = self.group
|
||||
@@ -352,7 +352,7 @@ impl Component for ListRow<'_> {
|
||||
access.name(Name::Decorative);
|
||||
return;
|
||||
}
|
||||
if self.heading {
|
||||
if self.caption {
|
||||
access.role(Role::HEADING);
|
||||
return;
|
||||
}
|
||||
@@ -452,7 +452,7 @@ impl Component for ListRow<'_> {
|
||||
let sizes = &style.sizes;
|
||||
let rtl = cx.env.direction().is_rtl();
|
||||
let rect = cx.rect;
|
||||
if self.heading {
|
||||
if self.caption {
|
||||
let draw = ui.draw();
|
||||
let content = rect.shrink2(Vec2::new(sizes.pad, 0.0));
|
||||
let run = TextRun::new(cx.resolved.label).role(style.detail.role).color(cx.resolve(&style.detail.color)).elide();
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::level::{LevelMemory, MenuLevel, level_env};
|
||||
use crate::contract::overlay::{Anchor, Dismiss, Outside, Popup};
|
||||
use crate::contract::{
|
||||
Bind, BindMut, BodyCx, Common, Component, Container, ContainerProps, Cx, Entry, Focus as _, Gap, InMenu, LeastWidth, Mount, NoValue, Outcome,
|
||||
Overlay, POPUP_PAD, Props as _, Remember as _, Role, Show as _, ShowContainer as _, TooltipSpec, Trigger,
|
||||
Overlay, POPUP_PAD, Pointer as _, Props as _, Remember as _, Role, Show as _, ShowContainer as _, TooltipSpec, Trigger,
|
||||
};
|
||||
use crate::display::Divider;
|
||||
use crate::runtime::env::{Env, Label};
|
||||
@@ -13,7 +13,7 @@ use crate::runtime::focus::{FocusPolicy, Initial};
|
||||
use crate::runtime::frame;
|
||||
use crate::runtime::overlay::CloseReason;
|
||||
use crate::style::{ComponentStyle, StyleCx, SurfaceKind};
|
||||
use craft_behavior::{Arrows, Intent, Metrics, NavShape, Roving, Sense, Value};
|
||||
use craft_behavior::{Arrows, Metrics, NavShape, Roving, Sense, Value};
|
||||
use egui::{Response, Ui};
|
||||
|
||||
/// The style of a menu: the surface comes from the container.
|
||||
@@ -309,9 +309,12 @@ impl Component for Menu<'_> {
|
||||
frame::request_repaint(&cx.core.ctx);
|
||||
}
|
||||
}
|
||||
if cx.intents().take(Intent::Activate)
|
||||
// Enter routed from the field arrives as the menu's own activation by key: the row it names runs, and the run
|
||||
// closes the menus, not the activation.
|
||||
if cx.activation().is_some_and(|activation| activation.by_key)
|
||||
&& let Some(row) = level.active_or_first()
|
||||
{
|
||||
cx.keep_open();
|
||||
level.run(row);
|
||||
frame::request_repaint(&cx.core.ctx);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ impl<'e, 'l, T> EntryRows<'e, 'l, T> {
|
||||
let entries: &'e [Entry<T>] = self.entries;
|
||||
let entry = &entries[at];
|
||||
let Some(value) = entry.value() else {
|
||||
return if entry.is_heading() { ListRow::heading(self.labels[at].clone()) } else { ListRow::spacer() };
|
||||
return if entry.is_heading() { ListRow::caption(self.labels[at].clone()) } else { ListRow::spacer() };
|
||||
};
|
||||
let row = ListRow::new(self.labels[at].clone()).option().check(chosen == Some(at)).enabled(entry.is_enabled());
|
||||
let row = match entry.icon_spec() {
|
||||
|
||||
@@ -35,7 +35,7 @@ impl<'a, V: NumberValue + 'static> NumberField<'a, V> {
|
||||
if rows[*at].is_separator() {
|
||||
ListRow::spacer()
|
||||
} else if rows[*at].is_heading() {
|
||||
ListRow::heading(labels[*at].clone())
|
||||
ListRow::caption(labels[*at].clone())
|
||||
} else {
|
||||
ListRow::new(labels[*at].clone()).enabled(rows[*at].is_enabled()).option().check(marked == Some(*at))
|
||||
}
|
||||
|
||||
@@ -75,26 +75,87 @@ fn undo_picked_from_the_edit_menu_undoes_in_the_field_that_held_focus() {
|
||||
rig.assert_undone_in_the_field("Edit › Undo");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn opening_help_focuses_its_search_and_down_then_enter_runs_the_first_match() {
|
||||
let mut rig = rig();
|
||||
rig.click("Help");
|
||||
rig.fixture.type_text("und");
|
||||
rig.fixture.settle();
|
||||
assert_eq!(*rig.text.borrow(), "helloabc", "the typed text lands in the search field, not the text field");
|
||||
rig.fixture.key(egui::Key::ArrowDown, egui::Modifiers::NONE);
|
||||
rig.fixture.key(egui::Key::Enter, egui::Modifiers::NONE);
|
||||
rig.fixture.settle();
|
||||
rig.assert_undone_in_the_field("Help › und, Down, Enter");
|
||||
/// The command of the scope around the target button in the bar-keys trial.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, craft_ui::contract::CommandSet)]
|
||||
#[command(prefix = "barKeys", scope = "trial.barKeys")]
|
||||
#[non_exhaustive]
|
||||
pub enum BarKeysCommand {
|
||||
#[command(label = "Toggle", default = "Cmd+Alt+P")]
|
||||
Toggle,
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_shortcut_pressed_on_the_focused_bar_runs_once_where_focus_was_and_gives_focus_back() {
|
||||
let mut rig = rig();
|
||||
rig.fixture.key(egui::Key::F10, egui::Modifiers::NONE);
|
||||
rig.fixture.settle();
|
||||
assert_ne!(rig.fixture.focused_stop().map(|(id, _)| id), rig.field.get(), "F10 takes the focus to the bar");
|
||||
rig.fixture.key(egui::Key::Z, egui::Modifiers::COMMAND);
|
||||
rig.fixture.settle();
|
||||
rig.assert_undone_in_the_field("F10, then the Undo shortcut");
|
||||
use craft_ui::contract::ShowContainer as _;
|
||||
use craft_ui::runtime::commands::Commands as _;
|
||||
let count = Rc::new(Cell::new(0));
|
||||
let target = Rc::new(Cell::new(None));
|
||||
let (seen, stop) = (count.clone(), target.clone());
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let titles = vec![MenuTitle::new("&Edit", |ui| {
|
||||
MenuItem::command(EditCommands::Undo).show(ui);
|
||||
})];
|
||||
MenuBar::new("Main menu", titles).show(ui);
|
||||
craft_ui::layout_components::Stack::new().command_scope(<BarKeysCommand as craft_ui::contract::CommandSet>::SCOPE).show(ui, |ui, cx| {
|
||||
while cx.take_command::<BarKeysCommand>().is_some() {
|
||||
seen.set(seen.get() + 1);
|
||||
}
|
||||
stop.set(Some(craft_ui::buttons::Button::new("Target").show(ui).id));
|
||||
});
|
||||
});
|
||||
fixture.settle();
|
||||
craft_ui::runtime::focus::request(fixture.ctx(), craft_ui::runtime::focus::FocusTarget::Id(target.get().expect("the button ran")));
|
||||
fixture.settle();
|
||||
fixture.key(egui::Key::F10, egui::Modifiers::NONE);
|
||||
fixture.settle();
|
||||
assert_ne!(fixture.focused_stop().map(|(id, _)| id), target.get(), "F10 takes the focus to the bar");
|
||||
fixture.key(egui::Key::P, egui::Modifiers::COMMAND | egui::Modifiers::ALT);
|
||||
fixture.settle();
|
||||
assert_eq!(count.get(), 1, "the shortcut runs once, in the scope of the stop the bar took the focus from");
|
||||
assert_eq!(fixture.focused_stop().map(|(id, _)| id), target.get(), "and the focus is back on that stop");
|
||||
}
|
||||
|
||||
/// A bar whose Help searches the target scope's Toggle, then the Target button inside that scope; returns the count
|
||||
/// of Toggle runs and the button's id.
|
||||
fn scoped_rig() -> (Fixture, Rc<Cell<u32>>, Rc<Cell<Option<Id>>>) {
|
||||
use craft_ui::contract::ShowContainer as _;
|
||||
use craft_ui::runtime::commands::Commands as _;
|
||||
let count = Rc::new(Cell::new(0));
|
||||
let target = Rc::new(Cell::new(None));
|
||||
let (seen, stop) = (count.clone(), target.clone());
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let titles = vec![MenuTitle::new("&Help", |ui| {
|
||||
MenuItem::new("&About").show(ui);
|
||||
})];
|
||||
let help = vec![HelpEntry::new(BarKeysCommand::Toggle, "Toggle")];
|
||||
MenuBar::new("Main menu", titles).help(MenuHelp::new(0, &help)).show(ui);
|
||||
craft_ui::layout_components::Stack::new().command_scope(<BarKeysCommand as craft_ui::contract::CommandSet>::SCOPE).show(ui, |ui, cx| {
|
||||
while cx.take_command::<BarKeysCommand>().is_some() {
|
||||
seen.set(seen.get() + 1);
|
||||
}
|
||||
stop.set(Some(craft_ui::buttons::Button::new("Target").show(ui).id));
|
||||
});
|
||||
});
|
||||
fixture.settle();
|
||||
craft_ui::runtime::focus::request(fixture.ctx(), craft_ui::runtime::focus::FocusTarget::Id(target.get().expect("the button ran")));
|
||||
fixture.settle();
|
||||
(fixture, count, target)
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn opening_help_focuses_its_search_and_down_then_enter_runs_the_first_match() {
|
||||
let (mut fixture, count, target) = scoped_rig();
|
||||
let help = fixture.by_label("Help").expect("the Help title");
|
||||
fixture.click(&help);
|
||||
fixture.settle();
|
||||
fixture.type_text("tog");
|
||||
fixture.settle();
|
||||
assert!(fixture.by_label("Toggle").is_some(), "the typed text lands in the search field and finds Toggle");
|
||||
fixture.key(egui::Key::ArrowDown, egui::Modifiers::NONE);
|
||||
fixture.settle();
|
||||
fixture.key(egui::Key::Enter, egui::Modifiers::NONE);
|
||||
fixture.settle();
|
||||
assert_eq!(count.get(), 1, "Down then Enter runs the first match once");
|
||||
assert!(fixture.by_label("About").is_none(), "and the menu closes");
|
||||
assert_eq!(fixture.focused_stop().map(|(id, _)| id), target.get(), "with the focus back on the stop that held it");
|
||||
}
|
||||
|
||||
@@ -42,7 +42,8 @@ fn an_open_submenu_stays_open_while_the_pointer_heads_for_it_across_another_row(
|
||||
let mut fixture = open_menu();
|
||||
let recent = fixture.by_label("Recent").expect("the menu is open").center();
|
||||
fixture.frame(vec![pointer::moved(recent)]).idle(1);
|
||||
let submenu = fixture.by_label("Report.txt").expect("the submenu is open").rect;
|
||||
let first = fixture.by_label("Report.txt").expect("the submenu is open").rect;
|
||||
let submenu = first.union(fixture.by_label("Draft.txt").expect("the submenu's last row").rect);
|
||||
let templates = fixture.by_label("Templates").expect("the second submenu row").rect;
|
||||
// A point on Templates, near the submenu's edge and level with its rows: the pointer heads for the submenu.
|
||||
let crossing = egui::pos2(templates.max.x - 2.0, templates.center().y);
|
||||
|
||||
Reference in New Issue
Block a user