Track retained layout validity explicitly

This commit is contained in:
iris-ai committed 2026-09-15 16:03:53 -04:00
1 parent 691e3eb23c
commit 29c7881c8a
25 files changed
+836 -795

No files matched your search

-4
View File
@@ -93,10 +93,6 @@ impl Widget for TextEdit {
);
size
}
fn on_resize(&self, axis: Axis) -> OnResize {
self.view.on_resize(axis)
}
}
const CARET_WIDTH: f32 = 1.0;
+10 -26
View File
@@ -47,12 +47,16 @@ impl TextView {
/// answers under the attrs too, so changing those asks a new question
/// rather than invalidating anything.
fn render(&mut self, painter: &mut Painter) -> &RenderedText {
let width = if self.attrs.wrap {
Some(painter.px_len(Axis::X))
} else {
None
};
painter.render_text(&mut self.buf, &self.attrs, width)
let width = self.attrs.wrap.then(|| painter.px_len(Axis::X));
let text = painter.render_text(&mut self.buf, &self.attrs, width);
// A greedy break is the same break at every width from its longest
// line up to the one it was made at: each line still fits, and none
// could take a word that did not fit in the wider box. A line too
// long to fit at all says nothing about narrower boxes.
if let Some(width) = width {
painter.holds(Axis::X, text.size.x.min(width)..=width);
}
text
}
pub fn tex(&self) -> Option<&RenderedText> {
@@ -78,22 +82,6 @@ impl TextView {
(region, size)
}
/// Wrapping reads the width it is offered, so a wider box reshapes it and
/// a taller one does not. Alignment matters too, and separately: glyphs
/// anchored to the start of an axis stay put when that extent changes,
/// but centred or end-aligned ones move even though the shaping stands.
pub fn on_resize(&self, axis: Axis) -> OnResize {
let reshapes = axis == Axis::X && self.attrs.wrap;
let anchored = match axis {
Axis::X => self.align.x,
Axis::Y => self.align.y,
} == AxisAlign::Neg;
match reshapes || !anchored {
true => OnResize::Redraw,
false => OnResize::Translate,
}
}
pub fn content(&self) -> String {
self.buf.text().to_string()
}
@@ -120,10 +108,6 @@ impl Widget for Text {
self.update_buf();
self.view.draw(painter).1
}
fn on_resize(&self, axis: Axis) -> OnResize {
self.view.on_resize(axis)
}
}
impl Deref for Text {