mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 04:04:25 +00:00
Layer content runs outside its opener's label scopes
A tooltip shown from a field's control recorded its text line in the field's label scope, so the side label lined up with the tooltip and dropped under the next row. The overlay host now runs a layer's body outside the open label and merge scopes.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
//! `BlendRows`: a percent field keeps its side label while the field's tooltip shows.
|
||||
|
||||
use craft_layers::ui::mock::FakeLayers;
|
||||
use craft_layers::ui::rows::BlendRows;
|
||||
use craft_layers::ui::tree::{LayerProperties, LayerTree as _};
|
||||
use craft_ui::contract::tooltip::DELAY;
|
||||
use craft_ui::testing::pointer::moved;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::Rect;
|
||||
|
||||
/// The rect of the run whose text starts with `start`, if the last frame painted one.
|
||||
fn run(fixture: &Fixture, start: &str) -> Option<Rect> {
|
||||
fixture.texts().iter().find(|run| run.text.starts_with(start)).map(|run| run.rect)
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_field_keeps_its_side_label_while_its_tooltip_shows() {
|
||||
let modes = FakeLayers::sample().blend_modes(false, "normal");
|
||||
let mut properties = LayerProperties::new("normal");
|
||||
properties.opacity = 80.0;
|
||||
properties.editable = true;
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
ui.set_width(320.0);
|
||||
let _ = BlendRows::new(Some(&properties), &modes).show(ui);
|
||||
});
|
||||
fixture.settle();
|
||||
let label = run(&fixture, "Opacity").expect("the Opacity label shows");
|
||||
let value = run(&fixture, "80").expect("the Opacity value shows");
|
||||
fixture.frame(vec![moved(value.center())]);
|
||||
fixture.advance(DELAY);
|
||||
fixture.settle();
|
||||
let texts: Vec<_> = fixture.texts().iter().map(|run| (run.text.clone(), run.rect)).collect();
|
||||
let shown: Vec<Rect> = fixture.texts().iter().filter(|run| run.text.starts_with("Opacity")).map(|run| run.rect).collect();
|
||||
assert!(shown.len() >= 2, "the tooltip shows beside the label: {texts:?}");
|
||||
assert!(shown.contains(&label), "the label stays where it was while the tooltip shows: {label:?} in {texts:?}");
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
//! The integration binary of craft-layers: every test is a registered trial.
|
||||
|
||||
mod blend_rows;
|
||||
mod panel_drag_menu;
|
||||
mod panel_filter;
|
||||
mod panel_input;
|
||||
|
||||
@@ -187,8 +187,8 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U
|
||||
ui.set_clip_rect(ui.clip_rect().intersect(region));
|
||||
}
|
||||
areas::fade(ui, layer.fade * overlay.opacity);
|
||||
// The layer is not inside its opener's arena, roving group, scroll or row: its content starts from the
|
||||
// opener's inherited env with the layer-local fields fresh.
|
||||
// The layer is not inside its opener's arena, roving group, scroll, row or label scope: its content starts
|
||||
// from the opener's inherited env with the layer-local fields fresh, and outside the opener's scopes.
|
||||
let installed = Env::install_for(ui, layer.env.capture().env());
|
||||
let real = !ui.is_sizing_pass();
|
||||
if real && (layer.exiting || matches!(overlay.rank, Rank::Popup | Rank::Modal { .. })) {
|
||||
@@ -202,7 +202,7 @@ pub(crate) fn host(ctx: &Context, layer: &Layer<'_>, body: &mut dyn FnMut(&mut U
|
||||
if overlay.fit == OverlayFit::Resizable {
|
||||
ui.set_min_size(overlay.size_limits.min.min(placed.room));
|
||||
}
|
||||
body(ui);
|
||||
access::scope::outside(ctx, || body(ui));
|
||||
if scope.is_some() && real {
|
||||
focus::pop_scope(ctx);
|
||||
}
|
||||
|
||||
@@ -187,6 +187,15 @@ pub(crate) fn depth(ctx: &Context) -> usize {
|
||||
pass_state::with::<Stack, _>(ctx, |stack| stack.0.len())
|
||||
}
|
||||
|
||||
/// Runs `body` outside every open label and merge scope, as a layer's content runs: a tooltip or popup shown from a
|
||||
/// control is not part of the field the control sits in, so it neither names, lines up nor sizes that field's label.
|
||||
pub(crate) fn outside<R>(ctx: &Context, body: impl FnOnce() -> R) -> R {
|
||||
let open = pass_state::with::<Stack, _>(ctx, |stack| std::mem::take(&mut stack.0));
|
||||
let out = body();
|
||||
pass_state::with::<Stack, _>(ctx, |stack| stack.0 = open);
|
||||
out
|
||||
}
|
||||
|
||||
/// Opens the scope of `container`; its body shows inside it.
|
||||
pub(crate) fn begin(ctx: &Context, container: Id, owner: Id, kind: Kind) {
|
||||
pass_state::with::<Stack, _>(ctx, |stack| {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The tooltip of a control that paints no label: its own label shows there, inside a field or not; a control named
|
||||
//! only by its field label shows none.
|
||||
//! only by its field label shows none, and the field's label stays where it was.
|
||||
|
||||
use super::kit::PlainStyle;
|
||||
use craft_behavior::Sense;
|
||||
@@ -52,9 +52,19 @@ fn texts_added_by_hover(show: impl Fn(&mut Ui) -> Rect + 'static) -> Vec<String>
|
||||
fixture.settle();
|
||||
// A cut run carries its full text too: runs are told apart by whether they are cut.
|
||||
let before: Vec<(String, bool)> = fixture.texts().iter().map(|run| (run.text.clone(), run.elided)).collect();
|
||||
let placed: Vec<(String, Rect)> = fixture.texts().iter().map(|run| (run.text.clone(), run.rect)).collect();
|
||||
fixture.frame(vec![moved(at.get().center())]);
|
||||
fixture.advance(DELAY);
|
||||
fixture.settle();
|
||||
// The tooltip shows on its own layer: every text shown before stays where it was, a field's label included.
|
||||
for shown in &placed {
|
||||
assert!(
|
||||
fixture.texts().iter().any(|run| run.text == shown.0 && run.rect == shown.1),
|
||||
"{:?} stays at {:?} under the tooltip",
|
||||
shown.0,
|
||||
shown.1
|
||||
);
|
||||
}
|
||||
let after = fixture.texts().iter().map(|run| (run.text.clone(), run.elided));
|
||||
after.filter(|run| !before.contains(run)).map(|(text, _)| text).collect()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user