mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 02:36:54 +01:00
ribbon-w1: net change of 3 commits
- ribbon-w1: written by an agent - ribbon-w1: review fixes (review-1) - ribbon-w1: resolve the More label through the env view (lead fix)
This commit is contained in:
1 parent
1a8d771ea0
commit
af9d0b795f
8 files changed
+263
-40
No files matched your search
@@ -148,9 +148,8 @@ impl<'a> ArtboardBar<'a> {
|
||||
cells = Some(background_cells(ui, &words, background));
|
||||
});
|
||||
Divider::vertical().show(ui);
|
||||
let response = BarItems::new(vec![BarItem::new(ArtboardCommand::AddNew).display(ItemDisplay::Text)]).label(words.commands.clone()).show(ui);
|
||||
// P3(ribbon-w1): rb.F5
|
||||
let response = response.response;
|
||||
let response =
|
||||
BarItems::new(vec![BarItem::new(ArtboardCommand::AddNew).display(ItemDisplay::Text)]).label(words.commands.clone()).show(ui).response;
|
||||
Divider::vertical().show(ui);
|
||||
let button = IconButton::new(IconId::new("align_edge_left")).label(words.align.clone()).popup(PopupKind::Menu).show(ui);
|
||||
Menu::new(words.align.clone()).opened_by(&button.response, Trigger::Press).show(ui, |ui, _| {
|
||||
|
||||
@@ -99,7 +99,7 @@ impl<'a> SliceBar<'a> {
|
||||
unit_picked = shown.unit_picked;
|
||||
settings.style = style;
|
||||
Divider::vertical().show(ui);
|
||||
text(&[SliceCommand::FromGuides]).show(ui)
|
||||
text(&[SliceCommand::FromGuides]).show(ui).response
|
||||
}
|
||||
SliceMode::Select => {
|
||||
text(&[SliceCommand::Promote, SliceCommand::Divide, SliceCommand::Delete]).show(ui);
|
||||
@@ -107,11 +107,9 @@ impl<'a> SliceBar<'a> {
|
||||
let hide = Checkbox::new(Bind::bound(&mut settings.hide_auto)).label(words.hide_auto.clone()).show(ui);
|
||||
settings_changed = hide.value().is_some();
|
||||
Divider::vertical().show(ui);
|
||||
text(&[SliceCommand::Options]).show(ui)
|
||||
text(&[SliceCommand::Options]).show(ui).response
|
||||
}
|
||||
};
|
||||
// P3(ribbon-w1): rb.F5
|
||||
let response = response.response;
|
||||
if locked {
|
||||
let notice = Env::of(ui).words::<SliceToolWords>().locked.clone();
|
||||
Text::new(notice).shade(Shade::Muted).role(TypeRole::Caption).elide(Elide::End).show(ui);
|
||||
|
||||
@@ -131,7 +131,6 @@ impl AlignBar {
|
||||
.enumerate()
|
||||
.flat_map(|(section, row)| row.into_iter().map(move |action| BarItem::new(action).section(section as _)));
|
||||
let menu_only = AlignAction::DISTRIBUTE[..6].iter().copied().map(|action| BarItem::new(action).section(2).keep(FitKeep::Menu));
|
||||
// P3(ribbon-w1): rb.F5
|
||||
let response = BarItems::new(buttons.chain(menu_only).collect()).label(name).more(MoreMenu::Every).glyphs(GlyphRole::Tool).show(ui).response;
|
||||
AlignBarOutput { response }
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
use super::words::BarWords;
|
||||
use crate::buttons::{Button, IconButton, ToggleButton};
|
||||
use crate::contract::{
|
||||
Access, Common, Component, Cx, MeasureCx, Name, OverlayUi, Overlays as _, PaintUi, PartsCx, Props as _, Role, Show as _, ShowContainer as _,
|
||||
WordSetCx as _,
|
||||
Access, Common, Component, ContextMenuRequest, Cx, MeasureCx, Name, OverlayUi, Overlays as _, PaintUi, PartsCx, Props as _, Remember as _,
|
||||
Role, Show as _, ShowContainer as _, WordSetCx as _,
|
||||
};
|
||||
use crate::display::Divider;
|
||||
use crate::menu::{Menu, MenuItem};
|
||||
@@ -50,6 +50,10 @@ pub enum MoreMenu {
|
||||
pub struct BarItem {
|
||||
/// The command the item shows and runs.
|
||||
pub command: CommandRef,
|
||||
/// The item's name in place of its command's label.
|
||||
pub label: Option<Label>,
|
||||
/// The item's icon in place of its command's icon.
|
||||
pub icon: Option<IconId>,
|
||||
/// The section: neighbouring items of one section are a group, which the strip shows or moves into "More" whole.
|
||||
/// A rule separates the groups of a horizontal strip, extra space those of a vertical one.
|
||||
pub section: u16,
|
||||
@@ -62,19 +66,19 @@ pub struct BarItem {
|
||||
impl BarItem {
|
||||
/// Uses the item's own name in place of its command's.
|
||||
pub fn label(mut self, label: impl Into<Label>) -> Self {
|
||||
let _ = (&mut self, label);
|
||||
todo!("rb.F3")
|
||||
self.label = Some(label.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Uses the item's own icon in place of its command's.
|
||||
pub fn icon(mut self, icon: IconId) -> Self {
|
||||
let _ = (&mut self, icon);
|
||||
todo!("rb.F3")
|
||||
self.icon = Some(icon);
|
||||
self
|
||||
}
|
||||
|
||||
/// An item for `command` in section 0, shown as its icon.
|
||||
pub fn new(command: impl Into<CommandRef>) -> Self {
|
||||
BarItem { command: command.into(), section: 0, display: ItemDisplay::Icon, keep: FitKeep::Free }
|
||||
BarItem { command: command.into(), label: None, icon: None, section: 0, display: ItemDisplay::Icon, keep: FitKeep::Free }
|
||||
}
|
||||
|
||||
/// Puts the item in `section`.
|
||||
@@ -177,18 +181,26 @@ fn icon_of(resolved: &ResolvedCommand) -> Option<IconSpec<'static>> {
|
||||
resolved.icon.clone().map(|name| IconSpec::svg(IconId::from(name)))
|
||||
}
|
||||
|
||||
fn item_icon(present: &Present) -> Option<IconSpec<'static>> {
|
||||
present.item.icon.clone().map(IconSpec::svg).or_else(|| icon_of(&present.resolved))
|
||||
}
|
||||
|
||||
fn item_label(present: &Present) -> Label {
|
||||
present.item.label.clone().unwrap_or_else(|| Label::Shared(present.resolved.label.clone()))
|
||||
}
|
||||
|
||||
/// What the item shows: its display, or its label when the command has no icon for it.
|
||||
fn display_of(present: &Present) -> ItemDisplay {
|
||||
if present.item.display != ItemDisplay::Text && icon_of(&present.resolved).is_none() { ItemDisplay::Text } else { present.item.display }
|
||||
if present.item.display != ItemDisplay::Text && item_icon(present).is_none() { ItemDisplay::Text } else { present.item.display }
|
||||
}
|
||||
|
||||
/// The face of an item: an icon button, a toggle for a command with a checked state, or a text button. Icon-only faces
|
||||
/// take the strip's glyph role.
|
||||
fn face_of(present: &Present, glyphs: GlyphRole) -> Face {
|
||||
let (item, resolved) = (&present.item, &present.resolved);
|
||||
let icon = icon_of(resolved);
|
||||
let icon = item_icon(present);
|
||||
let toggle = resolved.checked.is_some();
|
||||
match (display_of(present), icon) {
|
||||
let face = match (display_of(present), icon) {
|
||||
(ItemDisplay::Icon, Some(icon)) if toggle => {
|
||||
Face::Toggle(Box::new(ToggleButton::command(item.command.clone()).icon(icon).icon_only().glyphs(glyphs)))
|
||||
}
|
||||
@@ -197,6 +209,12 @@ fn face_of(present: &Present, glyphs: GlyphRole) -> Face {
|
||||
(ItemDisplay::IconText, Some(icon)) => Face::Text(Box::new(Button::command(item.command.clone()).variant(Variant::GHOST).icon(icon))),
|
||||
(_, _) if toggle => Face::Toggle(Box::new(ToggleButton::command(item.command.clone()))),
|
||||
(_, _) => Face::Text(Box::new(Button::command(item.command.clone()).variant(Variant::GHOST))),
|
||||
};
|
||||
let Some(label) = &item.label else { return face };
|
||||
match face {
|
||||
Face::Action(face) => Face::Action(Box::new((*face).label(label.clone()))),
|
||||
Face::Toggle(face) => Face::Toggle(Box::new((*face).label(label.clone()))),
|
||||
Face::Text(face) => Face::Text(Box::new((*face).label(label.clone()))),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,8 +374,7 @@ impl Component for BarItems {
|
||||
}
|
||||
|
||||
fn sense(&self) -> Sense {
|
||||
// P3(ribbon-w1): rb.F5
|
||||
Sense::HOVER | Sense::CONTEXT_CLICK
|
||||
Sense::HOVER
|
||||
}
|
||||
|
||||
/// Fits the items into the rect, places the shown items, the rules between sections and the "More" part, and
|
||||
@@ -400,14 +417,21 @@ impl Component for BarItems {
|
||||
});
|
||||
for &(index, cell) in &shown {
|
||||
// An edit command's item keeps the focus where it is, so the edit reaches the focused component.
|
||||
let sense = if present[index].resolved.edit { Sense::CLICK | Sense::FOCUS | Sense::KEEP_FOCUS } else { Sense::CLICK | Sense::FOCUS };
|
||||
let part = cx.part(ITEM.at(index as u64), cell).sense(sense).focusable();
|
||||
if display_of(&present[index]) == ItemDisplay::Icon {
|
||||
let sense = Sense::CLICK | Sense::FOCUS | Sense::CONTEXT_CLICK;
|
||||
let sense = if present[index].resolved.edit { sense | Sense::KEEP_FOCUS } else { sense };
|
||||
let tooltip = if display_of(&present[index]) == ItemDisplay::Icon {
|
||||
let resolved = &present[index].resolved;
|
||||
part.tooltip(match &resolved.chord {
|
||||
Some(chord) => Label::from(crate::contract::tooltip::with_chord(&resolved.label, chord, os)),
|
||||
None => Label::Shared(resolved.label.clone()),
|
||||
});
|
||||
let label = cx.env.resolve(&item_label(&present[index]));
|
||||
Some(match &resolved.chord {
|
||||
Some(chord) => Label::from(crate::contract::tooltip::with_chord(label.as_str(), chord, os)),
|
||||
None => label,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let part = cx.part(ITEM.at(index as u64), cell).sense(sense).focusable();
|
||||
if let Some(tooltip) = tooltip {
|
||||
part.tooltip(tooltip);
|
||||
}
|
||||
}
|
||||
if let Some(more) = more {
|
||||
@@ -442,7 +466,14 @@ impl Component for BarItems {
|
||||
if previous.is_some_and(|section| section != item.section) {
|
||||
Divider::horizontal().show(ui);
|
||||
}
|
||||
MenuItem::command(item.command.clone()).show(ui);
|
||||
let mut row = MenuItem::command(item.command.clone());
|
||||
if let Some(label) = &item.label {
|
||||
row = row.label(label.clone());
|
||||
}
|
||||
if let Some(icon) = &item.icon {
|
||||
row = row.icon(IconSpec::svg(icon.clone()));
|
||||
}
|
||||
row.show(ui);
|
||||
previous = Some(item.section);
|
||||
}
|
||||
});
|
||||
@@ -473,9 +504,25 @@ impl Component for BarItems {
|
||||
}
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> BarItemsOutput {
|
||||
// P3(ribbon-w1): rb.F5
|
||||
BarItemsOutput { response: cx.response.clone(), menu: Default::default() }
|
||||
fn finish(self, mut cx: Cx<'_, Self>) -> BarItemsOutput {
|
||||
let request = cx.context_part().and_then(|part| {
|
||||
let laid = self.laid.as_ref()?;
|
||||
let &(index, rect) = laid.shown.iter().find(|&&(index, _)| ITEM.at(index as u64) == part)?;
|
||||
Some(ContextMenuRequest::new(laid.present[index].item.command.clone(), rect.left_bottom()))
|
||||
});
|
||||
let open = crate::contract::overlay::opened_from(&cx.ctx, cx.response.id);
|
||||
let held = cx.memory::<Option<ContextMenuRequest<CommandRef>>>();
|
||||
// A pass reports only its own request; an open menu keeps its request between passes.
|
||||
if request.is_some() || !open {
|
||||
*held = request;
|
||||
}
|
||||
if held.as_ref().is_some_and(|request| {
|
||||
!self.laid.as_ref().is_some_and(|laid| laid.present.iter().any(|present| present.item.command == request.key))
|
||||
}) {
|
||||
*held = None;
|
||||
}
|
||||
let menu = held.clone();
|
||||
BarItemsOutput { response: cx.response.clone(), menu }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,13 +532,13 @@ pub struct BarItemsOutput {
|
||||
/// The strip's response.
|
||||
pub response: Response,
|
||||
/// The item whose context menu is open, held while its menu stays open.
|
||||
pub menu: Option<crate::contract::ContextMenuRequest<CommandRef>>,
|
||||
pub menu: Option<ContextMenuRequest<CommandRef>>,
|
||||
}
|
||||
|
||||
impl crate::contract::Outcome for BarItemsOutput {
|
||||
type Value = crate::contract::NoValue;
|
||||
|
||||
fn response(&self) -> &Response {
|
||||
todo!("rb.F4")
|
||||
&self.response
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,6 @@ fn floating_bar(ui: &mut Ui) -> bool {
|
||||
let items =
|
||||
BarItems::new(vec![BarItem::new(EditCommands::Undo), BarItem::new(EditCommands::Redo), BarItem::new(EditCommands::Cut).section(1)])
|
||||
.show(ui);
|
||||
// P3(ribbon-w1): rb.F5
|
||||
crate::contract::clicked(&items.response)
|
||||
})
|
||||
.inner
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
//! `BarItems`: a strip too short for its items moves whole groups into "More"; the every-item menu lists them all.
|
||||
|
||||
use craft_ui::bars::{BarItem, BarItems, MoreMenu};
|
||||
use craft_ui::contract::{Role, Show as _};
|
||||
use craft_ui::runtime::commands::EditCommands;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::Vec2;
|
||||
use craft_behavior::{IconId, PartKey};
|
||||
use craft_ui::bars::{BarItem, BarItems, BarWords, ItemDisplay, MoreMenu};
|
||||
use craft_ui::contract::tooltip::DELAY;
|
||||
use craft_ui::contract::{ContextMenuRequest, Role, Show as _, ShowContainer as _};
|
||||
use craft_ui::menu::{Menu, MenuItem};
|
||||
use craft_ui::runtime::commands::{CommandRef, CommandSet as _, EditCommands};
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use craft_ui::runtime::focus::{FocusTarget, request};
|
||||
use craft_ui::testing::{Fixture, pointer, trial};
|
||||
use egui::{Id, Key, Modifiers, Rect, Shape, TextureId, Vec2};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
|
||||
fn strip(width: f32, more: MoreMenu) -> Fixture {
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
@@ -52,3 +59,123 @@ fn the_every_item_menu_lists_the_items_on_the_strip_too() {
|
||||
fixture.settle();
|
||||
assert_eq!(fixture.by_role(Role::MENU_ITEM).len(), 5, "the menu lists every item");
|
||||
}
|
||||
|
||||
/// A context request identifies the part, survives input-free passes while its menu is open, and expires on close.
|
||||
#[trial]
|
||||
fn a_secondary_click_on_an_item_reports_its_command_until_the_menu_closes() {
|
||||
let menu = Rc::new(RefCell::new(None::<ContextMenuRequest<CommandRef>>));
|
||||
let owner = Rc::new(Cell::new(None::<Id>));
|
||||
let twice = Rc::new(Cell::new(false));
|
||||
let (seen, id, discard) = (menu.clone(), owner.clone(), twice.clone());
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let output = BarItems::new(vec![BarItem::new(EditCommands::Undo), BarItem::new(EditCommands::Redo)]).show(ui);
|
||||
id.set(Some(output.response.id));
|
||||
*seen.borrow_mut() = output.menu.clone();
|
||||
Menu::context("Item options", &output.response).show(ui, |ui, _| {
|
||||
if let Some(request) = &output.menu {
|
||||
MenuItem::command(request.key.clone()).show(ui);
|
||||
}
|
||||
});
|
||||
if discard.get() && ui.ctx().current_pass_index() == 0 {
|
||||
ui.ctx().request_discard("context menus must survive a second pass without repeating input");
|
||||
}
|
||||
});
|
||||
fixture.settle();
|
||||
let strip = owner.get().expect("the strip is shown");
|
||||
let second = fixture.part(strip, PartKey::new("item").at(1)).expect("the second item is shown");
|
||||
fixture.frame(vec![pointer::moved(second.center()), pointer::secondary(second.center(), true)]);
|
||||
twice.set(true);
|
||||
fixture.frame(vec![pointer::secondary(second.center(), false)]);
|
||||
twice.set(false);
|
||||
let asked = menu.borrow().clone().expect("a secondary click asks for the item's menu");
|
||||
assert_eq!(asked.key, CommandRef::from(EditCommands::Redo), "the request belongs to the second item");
|
||||
assert_eq!(asked.at, second.rect.left_bottom(), "the menu hangs from the requested part");
|
||||
fixture.settle();
|
||||
assert_eq!(*menu.borrow(), Some(asked.clone()), "the open menu keeps its item without another input event");
|
||||
assert!(!fixture.by_role(Role::MENU_ITEM).is_empty(), "the request opens a real context menu");
|
||||
fixture.key(Key::Escape, Modifiers::NONE).settle();
|
||||
assert!(menu.borrow().is_none(), "the request expires after Escape closes the menu");
|
||||
assert!(fixture.by_role(Role::MENU_ITEM).is_empty(), "Escape closes the menu");
|
||||
|
||||
request(fixture.ctx(), FocusTarget::Part(strip, PartKey::new("item").at(1)));
|
||||
fixture.settle();
|
||||
twice.set(true);
|
||||
fixture.key(Key::F10, Modifiers::SHIFT);
|
||||
twice.set(false);
|
||||
fixture.settle();
|
||||
assert_eq!(*menu.borrow(), Some(asked), "Shift+F10 asks for the focused item's menu and keeps it on the second pass");
|
||||
assert!(!fixture.by_role(Role::MENU_ITEM).is_empty(), "the keyboard request opens the menu");
|
||||
fixture.key(Key::Escape, Modifiers::NONE).settle();
|
||||
assert!(menu.borrow().is_none(), "the keyboard request expires when its menu closes");
|
||||
}
|
||||
|
||||
/// The textures a control paints let the trial compare its icon before and after an override without pixel constants.
|
||||
fn icon_textures(shapes: &[Shape], rect: Rect) -> Vec<TextureId> {
|
||||
shapes
|
||||
.iter()
|
||||
.filter_map(|shape| match shape {
|
||||
Shape::Mesh(mesh) if rect.contains(mesh.calc_bounds().center()) => Some(mesh.texture_id),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// An item's own label reaches the strip, its tooltip and the separately built overflow row; its icon reaches both faces.
|
||||
#[trial]
|
||||
fn an_items_own_label_and_icon_replace_its_commands_in_the_strip_and_in_more() {
|
||||
// Paste has no registry icon; Undo has one. Both must honour the item's icon.
|
||||
for command in [EditCommands::Undo, EditCommands::Paste] {
|
||||
let own = Label::from("Table");
|
||||
let original = EditCommands::defs()
|
||||
.expect("edit commands have definitions")
|
||||
.into_iter()
|
||||
.find(|def| def.command == CommandRef::from(command))
|
||||
.expect("the item's command has a definition")
|
||||
.label;
|
||||
let icon = Rc::new(RefCell::new(IconId::new("grid")));
|
||||
let more_name = Rc::new(RefCell::new(String::new()));
|
||||
let (current, label, word) = (icon.clone(), own.clone(), more_name.clone());
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let env = Env::of(ui);
|
||||
*word.borrow_mut() = env.view().resolve(&env.words::<BarWords>().items_more).as_str().to_owned();
|
||||
BarItems::new(vec![
|
||||
BarItem::new(EditCommands::Redo).display(ItemDisplay::Text),
|
||||
BarItem::new(command).section(1).label(label.clone()).icon(current.borrow().clone()),
|
||||
])
|
||||
.show(ui);
|
||||
});
|
||||
fixture.room(Vec2::new(600.0, 300.0)).settle();
|
||||
let item = fixture.by_label(own.as_str()).expect("the item's label is its accessible name");
|
||||
assert!(fixture.by_label(&original).is_none(), "the command's name is replaced");
|
||||
assert!(!fixture.texts().iter().any(|run| run.text == own.as_str()), "the item's icon keeps its name out of the face");
|
||||
let before = icon_textures(&fixture.frame_shapes(), item.rect);
|
||||
assert!(!before.is_empty(), "the item's icon is painted even without a registry icon");
|
||||
*icon.borrow_mut() = IconId::new("file");
|
||||
fixture.settle();
|
||||
let after = icon_textures(&fixture.frame_shapes(), item.rect);
|
||||
assert_ne!(before, after, "the strip paints the item's chosen icon");
|
||||
|
||||
fixture.frame(vec![pointer::moved(item.center())]);
|
||||
assert!(fixture.by_role(Role::TOOLTIP).is_empty(), "the tooltip waits for the pointer to rest");
|
||||
fixture.advance(DELAY).settle();
|
||||
let tooltip = fixture.by_role(Role::TOOLTIP).into_iter().next().expect("the resting pointer shows the tooltip");
|
||||
assert!(
|
||||
fixture.texts().iter().any(|run| tooltip.rect.contains(run.rect.center()) && run.text.starts_with(own.as_str())),
|
||||
"the tooltip uses the item's name before its chord"
|
||||
);
|
||||
fixture.frame(vec![pointer::gone()]);
|
||||
fixture.room(Vec2::new(40.0, 300.0)).settle();
|
||||
assert!(fixture.by_label(own.as_str()).is_none(), "the narrow strip moves the item into More");
|
||||
let more = fixture.by_label(more_name.borrow().as_str()).expect("the narrow strip has an overflow menu");
|
||||
fixture.click(&more).settle();
|
||||
let row = fixture.by_label(own.as_str()).expect("the overflow row uses the item's name");
|
||||
assert!(fixture.by_role(Role::MENU_ITEM).iter().any(|item| item.node == row.node), "the item's label names a menu row");
|
||||
assert!(fixture.by_label(&original).is_none(), "the overflow row replaces the command's label too");
|
||||
let before = icon_textures(&fixture.frame_shapes(), row.rect);
|
||||
assert!(!before.is_empty(), "the overflow row paints the item's icon");
|
||||
*icon.borrow_mut() = IconId::new("grid");
|
||||
fixture.settle();
|
||||
let after = icon_textures(&fixture.frame_shapes(), row.rect);
|
||||
assert_ne!(before, after, "the separately built overflow row follows the item's chosen icon");
|
||||
}
|
||||
}
|
||||
@@ -412,3 +412,57 @@ fn a_page_card_wraps_its_name_and_sets_the_detail_under_it() {
|
||||
assert!(tile.contains_rect(detail), "the detail is inside the card: {detail:?} in {tile:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Rich item content stays out of the grid until the pointer rests long enough to open its tooltip layer.
|
||||
#[trial]
|
||||
fn an_items_painted_tip_shows_after_the_pointer_rests_on_it() {
|
||||
use craft_behavior::keyed;
|
||||
use craft_ui::contract::tooltip::DELAY;
|
||||
use craft_ui::contract::ShowCollection as _;
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::runtime::env::Label;
|
||||
use craft_ui::runtime::overlay::{self, OpenFilter};
|
||||
use craft_ui::testing::{Fixture, pointer};
|
||||
use craft_ui::tile_grid::TileGrid;
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
|
||||
let detail = Label::from("A painted preview with document details");
|
||||
let content = detail.clone();
|
||||
let layer = Rc::new(Cell::new(None::<egui::LayerId>));
|
||||
let painted_on = layer.clone();
|
||||
let twice = Rc::new(Cell::new(false));
|
||||
let discard = twice.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let keys = [0u64];
|
||||
let source = keyed(&keys, |key: &u64| *key);
|
||||
TileGrid::new("Documents").show_items(ui, &source, &mut |_, cx| {
|
||||
let detail = content.clone();
|
||||
let painted_on = painted_on.clone();
|
||||
cx.tip(move |ui| {
|
||||
painted_on.set(Some(ui.layer_id()));
|
||||
Text::new(detail).show(ui);
|
||||
});
|
||||
Tile::new("Preview")
|
||||
});
|
||||
if discard.get() && ui.ctx().current_pass_index() == 0 {
|
||||
ui.ctx().request_discard("a rich item tooltip must also paint on the input-free second pass");
|
||||
}
|
||||
});
|
||||
fixture.settle();
|
||||
let tile = fixture.by_label("Preview").expect("the grid shows its tile");
|
||||
fixture.frame(vec![pointer::moved(tile.center())]);
|
||||
assert!(!overlay::any_open(fixture.ctx(), OpenFilter::Any), "moving onto the tile does not open its tooltip");
|
||||
assert!(!fixture.texts().iter().any(|run| run.text == detail.as_str()), "the rich content is hidden before the delay");
|
||||
// Each frame advances 1/60 s; half the delay leaves room for the settling frames too.
|
||||
fixture.advance(DELAY / 2.0).settle();
|
||||
assert!(!overlay::any_open(fixture.ctx(), OpenFilter::Any), "the tooltip stays hidden while the rest is too short");
|
||||
assert!(!fixture.texts().iter().any(|run| run.text == detail.as_str()), "the rich content does not paint early");
|
||||
twice.set(true);
|
||||
fixture.advance(DELAY).settle();
|
||||
twice.set(false);
|
||||
assert!(overlay::any_open(fixture.ctx(), OpenFilter::Any), "the rest opens the rich content's layer");
|
||||
let painted = fixture.texts().iter().find(|run| run.text == detail.as_str()).expect("the tooltip paints the ItemCx::tip content");
|
||||
assert_eq!(layer.get().map(|layer| layer.order), Some(egui::Order::Tooltip), "the rich content paints on the tooltip layer");
|
||||
assert!(!tile.rect.contains(painted.rect.center()), "the rich content is outside the tile's face");
|
||||
}
|
||||
@@ -89,7 +89,7 @@ name = "ToolbarResponse"
|
||||
old = "craft_ui::patterns::toolbar::ToolbarResponse"
|
||||
new = ""
|
||||
status = "removed"
|
||||
note = "`BarItems` returns a `Response` and fires the item's command; the app takes the command. `items` (per-item responses) has no replacement."
|
||||
note = "`BarItems` returns `BarItemsOutput { response, menu }` and fires the item's command; the app takes the command. `items` (per-item responses) has no replacement."
|
||||
|
||||
[[type]]
|
||||
name = "CommitCancel"
|
||||
|
||||
Reference in new issue
Block a user