A bar judges each member in flow with its label; a fill in a scrolling bar is a leaf's

Only a member in flow is judged: a part shown at a rect and a control in a label scope belong to the member around
them, and a labelled leaf is hidden together with its label. Containers that fill keep their content width in a
bar (a Field fills by default), so only a leaf that fills takes the room the view leaves.
This commit is contained in:
aiongg
2026-11-12 14:32:49 +00:00
parent 5d6e75e768
commit 20decd82d5
7 changed files with 47 additions and 49 deletions
@@ -336,7 +336,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
// it takes its own room, not a share.
let flows = matches!(at.at, ShowAt::Flow) && self.in_flow(comp);
// Along an axis the flow does not bound it fills nothing (`sized`): it measures its content there.
let bounded = crate::layout::flow_room_filling(at.ui);
let bounded = crate::layout::flow_room(at.ui);
let (fills_x, fills_y) = (self.given.0 && bounded.x.is_finite(), self.given.1 && bounded.y.is_finite());
if flows
&& at.ui.is_sizing_pass()
@@ -448,7 +448,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
let props = comp.props(Internal::new());
match self.sizing(props) {
Sizing::Fill => {
let room = crate::layout::flow_room_filling(ui);
let room = crate::layout::flow_room(ui);
// The available rect, not at least it: a fill child that took the whole room in an earlier pass (a
// content-sized layer offers its whole room before the footer is known) must not keep its remembered
// size once the room is less. Along an axis it is not given it takes its measured size. Along the main
@@ -477,8 +477,6 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
let width = if room.is_finite() && across {
match crate::layout::main_fill(ui, id, craft_behavior::Axis::X) {
crate::layout::MainFill::Measuring => 0.0,
// In a body that scrolls along x its share never cuts its content: what is past the view scrolls.
crate::layout::MainFill::Share(share) if Env::of(ui).unbounded.0 => size.x.max(share),
crate::layout::MainFill::Share(share) => share,
crate::layout::MainFill::Room => size.x.max(room),
}
+2 -3
View File
@@ -252,11 +252,10 @@ impl<'b> BodyHooks<'b> {
(Mount::Pane(ShellPane { at: Some(rect), content_height: true, .. }), _) => rect.size(),
(_, ShowAt::Rect(rect)) => rect.size(),
(_, ShowAt::Flow) => {
let content = self.sizing(props) == Sizing::Content;
let room = if content { crate::layout::flow_room(ui) } else { crate::layout::flow_room_filling(ui) };
let room = crate::layout::flow_room(ui);
// A row that shrinks its children to fit gives a body among them a width: it measures and shows
// in that room. A body that fills a bounded row takes the rest of it instead.
let fills = !content && room.x.is_finite();
let fills = self.sizing(props) != Sizing::Content && room.x.is_finite();
let cap = match Env::of(ui).shrink {
Some(crate::layout::Shrink::Apply(row)) if !fills => crate::layout::shrink_cap(ui.ctx(), row, id),
_ => None,
@@ -192,6 +192,10 @@ pub(crate) fn run(ui: &mut Ui, env: &Env, input: &LabelIn<'_>, trailing: Option<
placed.trailing = Rect::from_min_size(egui::pos2(cell.min.x, middle - input.trailing.y / 2.0), input.trailing);
}
let label_id_for_scope = sub(input.scope, "label");
// A label shows with the control it names: where a bar's view shows the two only in part, neither shows.
if crate::contract::run::cut_by_bar_view(env, placed.label.union(placed.control)) {
kids.set_clip_rect(Rect::NOTHING);
}
let shown = Props::id(leaf, label_id_for_scope).show_at(&mut kids, placed.label);
Env::restore(&ctx, installed);
if let Some(fact) = reset.filter(|_| shown.double_click || shown.dot_click) {
@@ -259,7 +263,16 @@ pub(crate) fn flow_leaf<C: Show>(
}
// The child runs under the inside label its measures saw.
let installed = under.inside.clone().map(|inside| Env::install_for(ui, env.derive_local(|scoped| scoped.inside_label = Some(inside))));
// The control and its label are one member of a bar's line: hidden together, as the label step hid the label.
let shown_clip = ui.clip_rect();
let cut = !ui.is_sizing_pass() && crate::contract::run::cut_by_bar_view(&env, placed.label.union(placed.control));
if cut {
ui.set_clip_rect(Rect::NOTHING);
}
let output = crate::contract::run::show_leaf(crate::contract::Props::id(child, id), ui, crate::contract::run::ShowAt::Rect(control), None);
if cut {
ui.set_clip_rect(shown_clip);
}
if let Some(installed) = installed {
Env::restore(ui.ctx(), installed);
}
+11 -10
View File
@@ -299,7 +299,7 @@ impl<C: Component> ShapeHooks<C> for LeafHooks {
}
fn sized(&self, comp: &C, ui: &Ui, id: Id, size: Vec2) -> Vec2 {
let room = crate::layout::flow_fill_room(ui);
let room = crate::layout::leaf_fill_room(ui);
// Along an axis the enclosing body sizes from its content, a child that fills keeps its measured size, so it
// never sets that size. Across an unwrapped row's line it is shown across the line the row settled on in its
// measuring run, where the child measured at its own size.
@@ -849,13 +849,6 @@ fn run_in_host(p: &mut Pass<'_, '_, '_>, ui: &mut Ui, host_at: Option<ShowAt>, h
return;
}
p.real = true;
// A member of a bar's line that its view shows only in part is not shown until a scroll brings it in whole: it
// keeps its stop, so Tab reaches it and the reveal scrolls it in.
let shown_clip = ui.clip_rect();
let cut = p.p.member() && cut_by_bar_view(env, rect);
if cut {
ui.set_clip_rect(Rect::NOTHING);
}
let inspected = p.trace.recording() && inspect::open_element(ui, id, facts.name);
let e = &mut *p.p;
// 7 parts
@@ -904,6 +897,14 @@ fn run_in_host(p: &mut Pass<'_, '_, '_>, ui: &mut Ui, host_at: Option<ShowAt>, h
// A control that draws only its mark senses over its own label too: indicator, gap and label are one target.
let label = if facts.labelled_after && !inert { scope::claim(&ctx) } else { None };
let hit = label.map_or(rect, |label| rect.union(label));
// A member of a bar's line, with the label it claims, that its view shows only in part is not shown until a
// scroll brings it in whole: it keeps its stop, so Tab reaches it and the reveal scrolls it in. Only a member in
// flow is judged: a part shown at a rect, and a control in a label scope, belong to the member around them.
let shown_clip = ui.clip_rect();
let cut = e.member() && matches!(at, ShowAt::Flow) && !scope::in_label(&ctx) && cut_by_bar_view(env, hit);
if cut {
ui.set_clip_rect(Rect::NOTHING);
}
let sensing::RootResult { mut response, parts: results, press, activation, activated_member, sense: root_sense } =
sense_root(ui, member, RootSpec { id, rect: hit, own_sense: own, own: decls, enabled }, arena);
if label.is_some() {
@@ -1154,7 +1155,7 @@ fn run_in_host(p: &mut Pass<'_, '_, '_>, ui: &mut Ui, host_at: Option<ShowAt>, h
/// Whether `rect`, in the scrolling body of a bar, lies partly outside the body's view along x. A member wider than the
/// view shows in part, since no scroll shows it whole.
fn cut_by_bar_view(env: &Env, rect: Rect) -> bool {
pub(crate) fn cut_by_bar_view(env: &Env, rect: Rect) -> bool {
if !env.values.get::<crate::contract::InBar>().0 {
return false;
}
@@ -1222,7 +1223,7 @@ pub(super) fn run(t: &mut dyn Erased, ui: &mut Ui, at: ShowAt, mut tip: Option<T
// room (`mount_room`). A body that fills the width of a bounded room takes the room or its share of it (`sized`),
// so it is no unit.
let in_flow = matches!(at, ShowAt::Flow) && t.fills().is_none();
let fill_body = shape == ShapeKind::Body && in_flow && t.in_flow() && t.fills_width() && crate::layout::flow_room_filling(ui).x.is_finite();
let fill_body = shape == ShapeKind::Body && in_flow && t.in_flow() && t.fills_width() && crate::layout::flow_room(ui).x.is_finite();
let shrink = env.shrink.filter(|_| in_flow && (shape == ShapeKind::Leaf || (shape == ShapeKind::Body && t.in_flow() && !fill_body)));
let cap = match shrink {
Some(crate::layout::Shrink::Apply(row)) if shape == ShapeKind::Leaf => crate::layout::shrink_cap(&ctx, row, id),
+13 -11
View File
@@ -581,13 +581,13 @@ pub(crate) fn flow_region(ui: &Ui) -> Rect {
/// `Row` body that encloses `ui` directly, else the rest of `ui`'s layout.
pub(crate) fn flow_room(ui: &Ui) -> Vec2 {
let cell = Env::of(ui).grid.and_then(|body| pass_state::with::<Cursors, _>(ui.ctx(), |cursors| cursors.0.get(&body).map(Cursor::room)));
cell.unwrap_or_else(|| open_room(ui, false))
cell.unwrap_or_else(|| open_room(ui))
}
/// The rest of `ui`'s layout (the room offered to the container, less the earlier siblings and gaps; a whole line in a row
/// that wraps); unbounded along the axes of the scrolling body that encloses it, whose region is only as large as egui
/// can make it, except along x for a child that `fills`, which there fills what the view shows (`view_room`).
fn open_room(ui: &Ui, fills: bool) -> Vec2 {
/// can make it.
fn open_room(ui: &Ui) -> Vec2 {
let (x, y) = Env::of(ui).unbounded;
let mut room = ui.available_size_before_wrap();
// In a row that wraps, a child that does not fit the rest of the line goes on the next one: its room is a line.
@@ -601,22 +601,24 @@ fn open_room(ui: &Ui, fills: bool) -> Vec2 {
if let Some(offered) = env.offered.or(env.row_room) {
room.x += offered - ui.max_rect().width();
}
let unbounded_x = if fills { view_room(ui).unwrap_or(f32::INFINITY) } else { f32::INFINITY };
Vec2::new(if x { unbounded_x } else { room.x }, if y { f32::INFINITY } else { room.y })
Vec2::new(if x { f32::INFINITY } else { room.x }, if y { f32::INFINITY } else { room.y })
}
/// The room a child that fills its width fills in `ui`: `flow_room`, except that in a `Content` column of a `Grid` it
/// is the column's width, so the child never measures as the room and pushes the next column out of it.
pub(crate) fn flow_fill_room(ui: &Ui) -> Vec2 {
let cell = Env::of(ui).grid.and_then(|body| pass_state::with::<Cursors, _>(ui.ctx(), |cursors| cursors.0.get(&body).map(Cursor::fill_room)));
cell.unwrap_or_else(|| open_room(ui, true))
cell.unwrap_or_else(|| open_room(ui))
}
/// `flow_room` for a container that fills its width: along x in a body that scrolls along x it is what the view shows
/// from the container's start, so the container fills the view and what it holds past that scrolls.
pub(crate) fn flow_room_filling(ui: &Ui) -> Vec2 {
let cell = Env::of(ui).grid.and_then(|body| pass_state::with::<Cursors, _>(ui.ctx(), |cursors| cursors.0.get(&body).map(Cursor::room)));
cell.unwrap_or_else(|| open_room(ui, true))
/// `flow_fill_room` for a leaf that fills its width: along x in a body that scrolls along x it is what the view shows
/// from the leaf's start, so the leaf fills the view and what is past it scrolls.
pub(crate) fn leaf_fill_room(ui: &Ui) -> Vec2 {
let room = flow_fill_room(ui);
match view_room(ui).filter(|_| room.x.is_infinite()) {
Some(view) => Vec2::new(view, room.y),
None => room,
}
}
/// Whether the next child shown in flow in `ui` goes in a `Content` column of the `Grid` body that encloses `ui`
+1 -1
View File
@@ -22,6 +22,6 @@ pub(crate) use crate::runtime::env::Shrink;
#[doc(hidden)]
pub use body::place_in_flow;
pub(crate) use body::{
InFlow, MainFill, counting_fills, fill_share, flow_fill_room, flow_region, flow_room, flow_room_filling, in_grid_content_column, main_fill,
InFlow, MainFill, counting_fills, fill_share, flow_fill_room, flow_region, flow_room, in_grid_content_column, leaf_fill_room, main_fill,
place_in_cell, report_least, report_shrink, run_body, run_body_measured, shrink_cap, take_in_flow,
};
+5 -20
View File
@@ -9,15 +9,12 @@ use craft_ui::buttons::{Button, IconButton};
use craft_ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _};
use craft_ui::display::{Divider, Text};
use craft_ui::form::Field;
use craft_ui::layout_components::Row;
use craft_ui::pickers::Select;
use craft_ui::runtime::commands::EditCommands;
use craft_ui::testing::{Fixture, trial};
use craft_ui::text::TextField;
use craft_ui::value_drag::Slider;
use egui::{Rect, Vec2};
use std::cell::Cell;
use std::num::NonZeroU8;
use std::rc::Rc;
const SLACK: f32 = 0.5;
@@ -81,29 +78,18 @@ fn the_end_region_shares_the_line_of_the_members_whether_the_bar_overflows_or_no
}
}
/// The rects of a seek slider that fills and of the readout after it in a tool bar `width` wide, and of a search
/// field that fills a fill-width row in the second row of a two-row bar.
fn filled(width: f32) -> (Rect, Rect, Rect) {
let seen = Rc::new(Cell::new((Rect::NOTHING, Rect::NOTHING, Rect::NOTHING)));
/// The rects of a seek slider that fills and of the readout after it in a tool bar `width` wide.
fn filled(width: f32) -> (Rect, Rect) {
let seen = Rc::new(Cell::new((Rect::NOTHING, Rect::NOTHING)));
let out = Rc::clone(&seen);
let mut fixture = Fixture::new(move |ui| {
let mut search = String::new();
let (mut slider, mut readout, mut field) = (Rect::NOTHING, Rect::NOTHING, Rect::NOTHING);
let (mut slider, mut readout) = (Rect::NOTHING, Rect::NOTHING);
Bar::new("Media", BarKind::Tool).show(ui, |ui, _| {
IconButton::new(IconId::new("play")).label("Play").show(ui);
slider = Slider::new(Bind::given(2.0), 0.0..=10.0).fill_width(true).label("Seek").show(ui).response.rect;
readout = Text::new("0:12.50").show(ui).rect;
});
Bar::new("Bin", BarKind::Tool).rows(NonZeroU8::new(2).expect("two")).show(ui, |ui, _| {
Row::new().show(ui, |ui, _| {
IconButton::new(IconId::new("arrow_up")).label("Up").show(ui);
});
Row::new().fill_width().show(ui, |ui, _| {
field = TextField::search("Search", Bind::bound(&mut search)).fill_width(true).show(ui).response.rect;
Text::new("12 items").show(ui);
});
});
out.set((slider, readout, field));
out.set((slider, readout));
});
fixture.room(Vec2::new(width, 160.0)).settle();
seen.get()
@@ -120,7 +106,6 @@ fn a_member_that_fills_takes_the_room_its_bar_leaves() {
narrow.1,
wide.1
);
assert!(wide.2.width() - narrow.2.width() >= grown, "the search field grew from {:?} to {:?} in a 300 pt wider bar", narrow.2, wide.2);
}
/// An options bar `width` wide with eight buttons, and the clicks each button reported.