mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 04:27:49 +00:00
look-rest-3: a wrapping row wraps at its container's paragraph line length (a dialog's wrap width) instead of widening a content-sized dialog; Page Setup's grid kinds take two lines as WordCraft's; trial
This commit is contained in:
@@ -1523,6 +1523,14 @@ pub(crate) fn run_body_measured<R>(
|
||||
BodyLayout::Row { wrap, align } => {
|
||||
let room = ui.available_rect_before_wrap();
|
||||
let rect = match *align {
|
||||
// A wrapping row wraps at the line length its container sets for paragraphs (a dialog's), as the
|
||||
// paragraphs beside it do: a dialog sized from its content stays as wide as its text, and a row of
|
||||
// radios that would not fit there takes a second line instead of widening the dialog.
|
||||
// A room unbounded at its end edge (a measuring run's) is cut from its start edge.
|
||||
RowAlign::Start | RowAlign::SpaceBetween if *wrap => env
|
||||
.measure()
|
||||
.filter(|measure| *measure < room.width() && (!rtl || room.right().is_finite()))
|
||||
.map(|measure| Flow::new(room, rtl).span(0.0, measure)),
|
||||
RowAlign::Start | RowAlign::SpaceBetween => None,
|
||||
RowAlign::Center | RowAlign::End => {
|
||||
let last = this_pass(&ctx, sizing, id);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
//! A content-sized `Stack`'s width roles: `least_width` keeps it at least the role's width with narrow content (a
|
||||
//! File page's side menu, `LeastWidth::SideMenu`), and `wrap_width` breaks a long paragraph at the role's line length
|
||||
//! instead of letting it widen the stack (a Print page's settings column, `WrapWidth::Column`).
|
||||
//! instead of letting it widen the stack (a Print page's settings column, `WrapWidth::Column`), and breaks a wrapping
|
||||
//! row there too.
|
||||
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{LeastWidth, Show as _, ShowContainer as _, WrapWidth};
|
||||
use craft_ui::contract::{LeastWidth, Props as _, Show as _, ShowContainer as _, WrapWidth};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Rect, Vec2};
|
||||
use std::cell::Cell;
|
||||
@@ -50,3 +51,44 @@ fn a_stacks_wrap_width_breaks_a_long_paragraph_at_the_column() {
|
||||
assert!(column.width() < plain.width() / 2.0, "the column's wrap width keeps the stack narrow: {column:?} against {plain:?}");
|
||||
assert!(wrapped.height() > one_line.height() * 2.0, "the paragraph breaks into lines: {wrapped:?} against {one_line:?}");
|
||||
}
|
||||
|
||||
/// Labels whose row is far wider than a column.
|
||||
const KINDS: [&str; 6] = ["No grid", "Lines only", "Lines and characters", "Text snaps to characters", "Left-to-right", "Right-to-left"];
|
||||
|
||||
/// A wrapping row in a stack with a wrap width breaks at the stack's line length, as its paragraphs do (a dialog's
|
||||
/// row of radios takes a second line), instead of widening the stack to keep its children on one line.
|
||||
#[trial]
|
||||
fn a_wrapping_row_breaks_at_the_stacks_wrap_width() {
|
||||
let shown = |wrap: Option<WrapWidth>| {
|
||||
let seen = Rc::new(Cell::new((Rect::NOTHING, Rect::NOTHING, Rect::NOTHING)));
|
||||
let out = Rc::clone(&seen);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let (first, last) = (Cell::new(Rect::NOTHING), Cell::new(Rect::NOTHING));
|
||||
let stack = match wrap {
|
||||
Some(wrap) => Stack::new().wrap_width(wrap),
|
||||
None => Stack::new(),
|
||||
};
|
||||
let shown = stack.show(ui, |ui, _| {
|
||||
Row::new().wrap(true).show(ui, |ui, _| {
|
||||
for (at, kind) in KINDS.into_iter().enumerate() {
|
||||
let rect = Button::new(kind).id_salt(kind).show(ui).rect;
|
||||
if at == 0 {
|
||||
first.set(rect);
|
||||
}
|
||||
last.set(rect);
|
||||
}
|
||||
});
|
||||
});
|
||||
if !ui.is_sizing_pass() {
|
||||
out.set((shown.output.rect, first.get(), last.get()));
|
||||
}
|
||||
});
|
||||
fixture.room(Vec2::new(1600.0, 600.0)).settle();
|
||||
seen.get()
|
||||
};
|
||||
let (plain, plain_first, plain_last) = shown(None);
|
||||
let (column, first, last) = shown(Some(WrapWidth::Column));
|
||||
assert!((plain_first.center().y - plain_last.center().y).abs() < 1.0, "without a wrap width the row keeps one line: {plain:?}");
|
||||
assert!(last.top() >= first.bottom(), "the row breaks onto a second line: {first:?} then {last:?}");
|
||||
assert!(column.width() < plain.width() * 0.75, "the wrap width keeps the stack narrow: {column:?} against {plain:?}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user