mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 05:37:04 +00:00
Merge branch 'red/rr-ribbon-w3' into area/ribbon-fw
This commit is contained in:
@@ -163,6 +163,11 @@ fn show_row<T: Clone + Eq + Hash + Send + Sync + Debug + 'static>(
|
||||
let side = if cx.env.direction().is_rtl() { -1.0 } else { 1.0 };
|
||||
let distance = cx.style::<Region>().map_or(0.0, |style| style.slide);
|
||||
let lead = gap.clamp(-1.0, 1.0) * side * distance;
|
||||
if gap != 0.0 {
|
||||
eprintln!(
|
||||
"DIAG a_tab_change_slides_the_row_in_from_the_new_tabs_side_and_shows_at_rest_under_reduced_motion: place {place} gap {gap} distance {distance} lead {lead}"
|
||||
);
|
||||
}
|
||||
let chevron = cx.style::<Region>().map_or(0.0, |style| style.chevron);
|
||||
// The row moves through the slide container's own offset, which places its body on a layer of its own.
|
||||
let shown = Region::slide(lead)
|
||||
|
||||
@@ -70,7 +70,16 @@ impl<'a> RibbonGroup<'a> {
|
||||
/// popup the content opens does not close the popover: the overlay family keeps it open.
|
||||
fn collapsed(&self, ui: &mut Ui, add: &mut dyn FnMut(&mut Ui)) {
|
||||
let button = Button::new(self.title.clone()).icon(self.icon.clone()).arrangement(Arrangement::Stacked).show(ui);
|
||||
if craft_ui::contract::clicked(&button.response) {
|
||||
eprintln!(
|
||||
"DIAG a_collapsed_groups_popover_stays_open_while_a_child_popup_is_used: collapsed button {:?} clicked at {:?}, sizing {}",
|
||||
button.response.id,
|
||||
button.response.rect,
|
||||
ui.is_sizing_pass()
|
||||
);
|
||||
}
|
||||
Popover::new(self.title.clone(), Bind::kept()).overlay(|overlay| overlay.opened_by(&button.response, Trigger::Click)).show(ui, |ui, _| {
|
||||
eprintln!("DIAG a_collapsed_groups_popover_stays_open_while_a_child_popup_is_used: popover body of {:?} runs", self.title.as_str());
|
||||
with_env(
|
||||
ui,
|
||||
|overrides| {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::HashMap;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft_behavior::{IconId, MotionMode};
|
||||
use craft_keymap::CommandRef;
|
||||
@@ -10,6 +11,7 @@ use craft_menu::{GroupLevel, GroupWidths, Ribbon, RibbonGroup, RibbonRow, Ribbon
|
||||
use craft_ui::buttons::{Arrangement, Button, SplitButton};
|
||||
use craft_ui::contract::{Bind, Entry, Props as _, Show as _};
|
||||
use craft_ui::runtime::env::{Direction, Env};
|
||||
use craft_ui::runtime::inspect::{Element, Recorded};
|
||||
use craft_ui::testing::{Fixture, is_measuring, last_pass_measuring_runs, trial};
|
||||
use egui::{Event, Key, Modifiers, PointerButton, Pos2, vec2};
|
||||
|
||||
@@ -142,6 +144,13 @@ fn a_collapsed_groups_popover_stays_open_while_a_child_popup_is_used() {
|
||||
assert!(fixture.by_label("Paste").is_none(), "the group is collapsed");
|
||||
let button = fixture.by_label("Clipboard").expect("the collapsed group's button");
|
||||
fixture.click(&button).idle(3);
|
||||
eprintln!(
|
||||
"DIAG a_collapsed_groups_popover_stays_open_while_a_child_popup_is_used: clicked {:?}; after: Clipboard {:?} Paste {:?} Wide {:?}",
|
||||
button.rect,
|
||||
fixture.by_label("Clipboard").map(|target| target.rect),
|
||||
fixture.by_label("Paste").map(|target| target.rect),
|
||||
fixture.by_label("Wide").map(|target| target.rect)
|
||||
);
|
||||
assert!(fixture.by_label("Paste").is_some(), "the button opens the group's popover");
|
||||
fixture.key(Key::ArrowDown, Modifiers::ALT).idle(3);
|
||||
fixture.key(Key::Enter, Modifiers::NONE).idle(3);
|
||||
@@ -151,14 +160,22 @@ fn a_collapsed_groups_popover_stays_open_while_a_child_popup_is_used() {
|
||||
assert!(fixture.by_label("Paste").is_none(), "a press outside closes the popover");
|
||||
}
|
||||
|
||||
/// The painted x of the group titled `title`, once the fixture has run a frame.
|
||||
fn group_x(fixture: &Fixture, title: &str) -> f32 {
|
||||
fixture.by_label(title).map_or(f32::NAN, |target| target.rect.left())
|
||||
/// The ribbon's inspected record of the latest real run.
|
||||
type Controls = Rc<RefCell<Option<Arc<Recorded>>>>;
|
||||
|
||||
/// The x at which the latest frame painted the group titled `title`: its rect in the ribbon's record, which maps each
|
||||
/// element through the layer it shows on (the slide's), unlike its access bounds, which stay in that layer's points.
|
||||
fn group_x(controls: &Controls, title: &str) -> f32 {
|
||||
let recorded = controls.borrow();
|
||||
let named = |element: &&Element| element.part.is_none() && element.facts.as_ref().and_then(|facts| facts.name.as_deref()) == Some(title);
|
||||
let elements: &[Element] = recorded.as_deref().map_or(&[], |recorded| recorded.elements.as_slice());
|
||||
elements.iter().filter(named).min_by_key(|element| element.depth).map_or(f32::NAN, |element| element.rect.left())
|
||||
}
|
||||
|
||||
/// A ribbon of three tabs with one group each, showing the tab `shown` holds.
|
||||
fn slide_rig(shown: &Rc<Cell<usize>>, direction: Direction, motion: MotionMode) -> Fixture {
|
||||
/// A ribbon of three tabs with one group each, showing the tab `shown` holds; `controls` takes its record.
|
||||
fn slide_rig(shown: &Rc<Cell<usize>>, controls: &Controls, direction: Direction, motion: MotionMode) -> Fixture {
|
||||
let state = shown.clone();
|
||||
let record = controls.clone();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let tabs = [RibbonTab::new(0_usize, "One"), RibbonTab::new(1, "Two"), RibbonTab::new(2, "Three")];
|
||||
let out = Ribbon::new("Ribbon", &tabs, Bind::given(state.get())).show(ui, |row, tab| match tab {
|
||||
@@ -169,6 +186,9 @@ fn slide_rig(shown: &Rc<Cell<usize>>, direction: Direction, motion: MotionMode)
|
||||
if let Some(next) = out.shown {
|
||||
state.set(next);
|
||||
}
|
||||
if let Some(controls) = out.controls {
|
||||
*record.borrow_mut() = Some(controls);
|
||||
}
|
||||
});
|
||||
fixture.direction(direction).motion(motion).room(vec2(600.0, 300.0));
|
||||
fixture.settle();
|
||||
@@ -180,14 +200,21 @@ fn slide_rig(shown: &Rc<Cell<usize>>, direction: Direction, motion: MotionMode)
|
||||
/// the release (the click's idle frame) is the first that shows the new row.
|
||||
fn slide(direction: Direction, motion: MotionMode, from: usize, to: usize) -> (f32, f32) {
|
||||
let shown = Rc::new(Cell::new(from));
|
||||
let mut fixture = slide_rig(&shown, direction, motion);
|
||||
let controls: Controls = Rc::new(RefCell::new(None));
|
||||
let mut fixture = slide_rig(&shown, &controls, direction, motion);
|
||||
let tab = fixture.by_label(["One", "Two", "Three"][to]).expect("the tab to change to");
|
||||
fixture.click(&tab);
|
||||
assert_eq!(shown.get(), to, "the click on the tab showed it");
|
||||
let title = ["Alpha", "Beta", "Gamma"][to];
|
||||
let first = group_x(&fixture, title);
|
||||
let first = group_x(&controls, title);
|
||||
fixture.idle(120);
|
||||
(first, group_x(&fixture, title))
|
||||
let rest = group_x(&controls, title);
|
||||
eprintln!(
|
||||
"DIAG a_tab_change_slides_the_row_in_from_the_new_tabs_side_and_shows_at_rest_under_reduced_motion: {from}->{to} rtl {} first {first} rest {rest} access {:?}",
|
||||
direction.is_rtl(),
|
||||
fixture.by_label(title).map(|target| target.rect)
|
||||
);
|
||||
(first, rest)
|
||||
}
|
||||
|
||||
/// A tab change slides the new group row in from the side of the new tab (mirrored in right-to-left) and reaches
|
||||
@@ -269,6 +296,11 @@ fn a_settled_ribbon_runs_no_group_body_again_and_a_level_change_runs_only_that_g
|
||||
assert!(KEYS.iter().all(|key| level(&runs, key) == GroupLevel::Full), "every group shows in full in a wide room");
|
||||
clear(&runs);
|
||||
fixture.idle(1);
|
||||
eprintln!(
|
||||
"DIAG a_settled_ribbon_runs_no_group_body_again_and_a_level_change_runs_only_that_group: idle pass runs {:?}, measuring bodies {:?}",
|
||||
runs.borrow(),
|
||||
last_pass_measuring_runs(fixture.ctx())
|
||||
);
|
||||
assert!(KEYS.iter().all(|key| measured(&runs, key) == 0), "a pass with unchanged inputs measures no group: {:?}", runs.borrow());
|
||||
assert!(last_pass_measuring_runs(fixture.ctx()).is_empty(), "a pass with unchanged inputs runs no measuring run");
|
||||
|
||||
|
||||
@@ -364,9 +364,17 @@ pub fn levelled_unit(ui: &mut Ui, key: Id, levels: usize, mut show: impl FnMut(&
|
||||
let rtl = Env::of(ui).direction.is_rtl();
|
||||
let mut widths = Vec::with_capacity(levels);
|
||||
let mut widest = Vec2::ZERO;
|
||||
// Each level measures at what it takes in no room: unbounded along x, in a region as wide as the row's.
|
||||
// An infinite egui region would put right-to-left content's start edge at infinity.
|
||||
let no_room = own_room.derive_local(|scoped| scoped.unbounded.0 = true);
|
||||
let width = ui.max_rect().width();
|
||||
for level in 0..levels.max(1) {
|
||||
let installed = Env::install_for(ui, own_room.clone());
|
||||
let (_, took) = crate::runtime::egui::sizing::run_sized(ui, f32::INFINITY, child::column_layout(rtl), |ui| show(ui, level));
|
||||
let installed = Env::install_for(ui, no_room.clone());
|
||||
// Every level shows the same bodies under the same ids: each measures as a probe, so no level reuses a
|
||||
// record another level left, and none serves the sweep at the levels given, which records its own.
|
||||
let (_, took) = layout_memory::probing(&ctx, || {
|
||||
crate::runtime::egui::sizing::run_sized(ui, width, child::column_layout(rtl), |ui| show(ui, level))
|
||||
});
|
||||
Env::restore(&ctx, installed);
|
||||
if level == 0 {
|
||||
widest = took;
|
||||
@@ -605,6 +613,9 @@ fn run_shrinking<R>(ui: &mut Ui, id: Id, mut body: impl FnMut(&mut Ui) -> R) ->
|
||||
} else {
|
||||
vec![0; levelled.len()]
|
||||
};
|
||||
if !levelled.is_empty() {
|
||||
eprintln!("DIAG groups_with_the_same_title_keep_their_own_level: row {id:?} room {room} fixed {fixed} level widths {level_widths:?} levels {levels:?}");
|
||||
}
|
||||
let width_at = |leaf: &Reported, level: usize| leaf.levels.get(level).copied().unwrap_or_default();
|
||||
let held: f32 = levelled.iter().zip(&levels).map(|(leaf, level)| width_at(*leaf, *level)).sum();
|
||||
let widths = if room.is_finite() {
|
||||
|
||||
@@ -83,10 +83,12 @@ pub(crate) fn discardable(ctx: &Context) -> bool {
|
||||
ctx.current_pass_index() + 1 < ctx.options(|options| options.max_passes.get())
|
||||
}
|
||||
|
||||
/// Runs `f` in an invisible sizing pass `width` wide, from the parent's cursor, and returns what it took.
|
||||
/// Runs `f` in an invisible sizing pass `width` wide, at the start of the rest of the parent's region, and returns
|
||||
/// what it took.
|
||||
/// The parent allocates nothing.
|
||||
pub(crate) fn run_sized<R>(ui: &mut Ui, width: f32, layout: Layout, f: impl FnOnce(&mut Ui) -> R) -> (R, Vec2) {
|
||||
let room = Rect::from_min_size(ui.cursor().min, Vec2::new(width, f32::INFINITY));
|
||||
// The rest of the parent's region, not its cursor: a right-to-left cursor starts at negative infinity.
|
||||
let room = Rect::from_min_size(ui.available_rect_before_wrap().min, Vec2::new(width, f32::INFINITY));
|
||||
let mut child = ui.new_child(UiBuilder::new().max_rect(room).layout(layout).sizing_pass().invisible());
|
||||
let inner = f(&mut child);
|
||||
(inner, child.min_rect().size())
|
||||
|
||||
Reference in New Issue
Block a user