mirror of
https://github.com/storytold/craft-libs.git
synced 2026-12-01 10:48:15 +01:00
Merge pull request #4239 from dotCooCoo/fix/paragraph-controls-measure-host-rows
text: the Paragraph controls' host rows count in their measured height
This commit is contained in:
2 files changed
+41
-9
No files matched your search
@@ -229,9 +229,9 @@ impl<'a> ParagraphControls<'a> {
|
||||
}
|
||||
|
||||
/// As [`show`](Self::show), with the host's rows drawn by `between` after the alignment and direction rows and
|
||||
/// before the indents.
|
||||
pub fn show_with(self, ui: &mut Ui, between: impl FnOnce(&mut Ui)) -> ParagraphControlsOutput {
|
||||
let mut between = Some(between);
|
||||
/// before the indents. `between` runs in every run of the controls' body, its measuring runs included, so its rows
|
||||
/// count in the height the controls measure.
|
||||
pub fn show_with(self, ui: &mut Ui, mut between: impl FnMut(&mut Ui)) -> ParagraphControlsOutput {
|
||||
let direction_row = self.direction_row;
|
||||
let values = self.values;
|
||||
let point_text = self.point_text;
|
||||
@@ -256,9 +256,7 @@ impl<'a> ParagraphControls<'a> {
|
||||
if direction_row != DirectionRow::Hidden {
|
||||
edits.extend(toggle_row(ui, Some(&words.direction), &directions));
|
||||
}
|
||||
if let Some(between) = between.take() {
|
||||
between(ui);
|
||||
}
|
||||
between(ui);
|
||||
|
||||
Grid::new(&TWO_COLUMNS).fill_width().show(ui, |ui, _| {
|
||||
let start = LengthRow {
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
//! The Word Paragraph dialog's pages: a check box whose paragraphs differ stays mixed across page switches until clicked;
|
||||
//! the contextual spacing box.
|
||||
|
||||
use craft_behavior::Mixed;
|
||||
use craft_text::ui::character::{AsianTypography, LineBreakOptions, ParagraphDialog, ParagraphFormat, ParagraphTab};
|
||||
use craft_behavior::{Mixed, Proposal};
|
||||
use craft_text::ui::character::{
|
||||
AsianTypography, LineBreakOptions, ParagraphControls, ParagraphDialog, ParagraphFormat, ParagraphTab, ParagraphValues,
|
||||
};
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{Props as _, Show as _, ShowContainer as _};
|
||||
use craft_ui::dialog::{DialogStack, StackDialog as _};
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use std::cell::RefCell;
|
||||
use egui::{Rect, Ui, Vec2};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
|
||||
fn toggled(fixture: &Fixture, label: &str) -> Option<Mixed<bool>> {
|
||||
@@ -66,3 +72,31 @@ fn a_mixed_contextual_spacing_box_clicked_is_on_in_the_answer() {
|
||||
let answer = dialog.borrow_mut().take_ok().expect("OK filed its answer");
|
||||
assert_eq!(answer.format.contextual_spacing, Some(Some(true)), "the answer carries the box");
|
||||
}
|
||||
|
||||
/// The host's rows between the alignment rows and the indents count in the controls' measured height: a container
|
||||
/// measured around the controls is as tall as it shows, so a flyout sized by that measure reaches Hyphenate.
|
||||
#[trial]
|
||||
fn the_rows_between_count_in_the_measured_height_of_the_paragraph_controls() {
|
||||
const WIDTH: f32 = 290.0;
|
||||
let values = ParagraphValues::default();
|
||||
let seen = Rc::new(Cell::new((Vec2::ZERO, Rect::NOTHING)));
|
||||
let out = Rc::clone(&seen);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let controls = |ui: &mut Ui| {
|
||||
ParagraphControls::new("Paragraph", &values).show_with(ui, |ui| {
|
||||
Button::new("Host row").show(ui);
|
||||
});
|
||||
};
|
||||
let measured = Stack::new().id_salt("measured").measure_in(ui, Proposal::Width(WIDTH), |ui, _| controls(ui));
|
||||
let room = Rect::from_min_size(ui.max_rect().min, Vec2::new(WIDTH, 2000.0));
|
||||
let shown = Stack::new().id_salt("measured").show_at(ui, room, |ui, _| controls(ui));
|
||||
out.set((measured, shown.output.rect));
|
||||
});
|
||||
fixture.room(Vec2::new(800.0, 2000.0)).settle();
|
||||
let (measured, shown) = seen.get();
|
||||
let host = fixture.by_label("Host row").expect("the host's row is shown");
|
||||
let hyphenate = fixture.by_label("Hyphenate").expect("Hyphenate is shown");
|
||||
assert!(host.rect.bottom() < hyphenate.rect.top(), "the host's row is above Hyphenate: {host:?}, {hyphenate:?}");
|
||||
let reach = hyphenate.rect.bottom() - shown.top();
|
||||
assert!(measured.y >= reach - 0.5, "the measure ({}) reaches Hyphenate's foot ({reach}) in {shown:?}", measured.y);
|
||||
}
|
||||
Reference in new issue
Block a user