mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 02:54:25 +00:00
A child of a wrapping row measures in a whole line, as a body there already did: one too wide for the rest of the line goes on the next line at its own width instead of being cut to the rest, the same in either direction
This commit is contained in:
@@ -245,11 +245,7 @@ impl<'b> BodyHooks<'b> {
|
||||
Some(crate::layout::Shrink::Apply(row)) if !fills => crate::layout::shrink_cap(ui.ctx(), row, id),
|
||||
_ => None,
|
||||
};
|
||||
let room = Vec2::new(cap.map_or(room.x, |cap| room.x.min(cap)), props.room_height.unwrap_or(room.y));
|
||||
// In a row that wraps, a body too wide for the rest of the line moves to the next one: it measures
|
||||
// in the whole line, so its allocation carries its width and the row can wrap it.
|
||||
let layout = ui.layout();
|
||||
if layout.main_wrap && layout.is_horizontal() { Vec2::new(room.x.max(ui.available_size().x), room.y) } else { room }
|
||||
Vec2::new(cap.map_or(room.x, |cap| room.x.min(cap)), props.room_height.unwrap_or(room.y))
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -551,11 +551,17 @@ pub(crate) fn flow_room(ui: &Ui) -> Vec2 {
|
||||
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); unbounded along the axes of the scrolling body that encloses it, whose region is only
|
||||
/// as large as egui can make it.
|
||||
/// 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.
|
||||
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.
|
||||
let layout = ui.layout();
|
||||
if layout.main_wrap && layout.is_horizontal() {
|
||||
room.x = ui.max_rect().width();
|
||||
}
|
||||
// A body sized from its content offers its children the width it was offered, and a row body that placed its
|
||||
// block behind a lead the width of its band; either less what they took.
|
||||
let env = Env::of(ui);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! The row-room rule: a container offers its children the room it was offered, and a child that fills an axis
|
||||
//! takes that room only where the container is given the axis; on an axis the container sizes from its content,
|
||||
//! the child takes its measured size.
|
||||
//! the child takes its measured size. A child of a wrapping row measures in a whole line.
|
||||
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{Bind, Show as _, ShowContainer as _};
|
||||
@@ -42,6 +42,37 @@ fn a_row_too_wide_for_the_rest_of_a_wrapping_row_moves_to_the_next_line_whole()
|
||||
assert!(nested.right() <= width + SLACK, "the wrapped row stays in the room {width}: {nested:?}");
|
||||
}
|
||||
|
||||
/// The rects of a wrapping row's buttons in a room `width` wide, in `direction`.
|
||||
fn wrapped_buttons(width: f32, direction: craft_i18n::Direction) -> Vec<Rect> {
|
||||
const LABELS: [&str; 5] = ["Promote", "Delete", "Slice Options…", "Divide…", "Hide Auto Slices"];
|
||||
let mut fixture = Fixture::new(|ui| {
|
||||
Row::new().fill_width().wrap(true).show(ui, |ui, _| {
|
||||
for label in LABELS {
|
||||
Button::new(label).show(ui);
|
||||
}
|
||||
});
|
||||
});
|
||||
fixture.direction(direction).room(Vec2::new(width, ROOM.y)).settle();
|
||||
LABELS.iter().map(|label| fixture.by_label(label).map_or(Rect::NOTHING, |target| target.rect)).collect()
|
||||
}
|
||||
|
||||
/// A child too wide for the rest of a wrapping row's line goes on the next line at its own width, not cut to the
|
||||
/// rest, and under right-to-left every child lies at the reflection of its left-to-right place.
|
||||
#[trial]
|
||||
fn a_button_too_wide_for_the_rest_of_a_wrapping_row_wraps_whole_in_either_direction() {
|
||||
use craft_i18n::Direction;
|
||||
let wide = wrapped_buttons(ROOM.x, Direction::Ltr);
|
||||
let width = wide[4].right() - 1.0;
|
||||
let ltr = wrapped_buttons(width, Direction::Ltr);
|
||||
assert!(ltr[4].top() >= ltr[3].bottom() - SLACK, "the last button wraps: {ltr:?}");
|
||||
assert!((ltr[4].width() - wide[4].width()).abs() <= SLACK, "the wrapped button keeps its width: {:?}, not {:?}", wide[4], ltr[4]);
|
||||
let rtl = wrapped_buttons(width, Direction::Rtl);
|
||||
for (a, b) in ltr.iter().zip(&rtl) {
|
||||
let reflected = Rect::from_min_max(egui::pos2(width - a.max.x, a.min.y), egui::pos2(width - a.min.x, a.max.y));
|
||||
assert!((reflected.min - b.min).length() <= SLACK && (reflected.max - b.max).length() <= SLACK, "{a:?} is at {b:?} under RTL");
|
||||
}
|
||||
}
|
||||
|
||||
/// The rects of a side-labelled field whose row holds a text field and two buttons, in a room of `width`: the
|
||||
/// field's, then its children's.
|
||||
fn labelled_row(width: f32) -> [Rect; 4] {
|
||||
|
||||
Reference in New Issue
Block a user