event_loop, text_edit, layout: focus-time cursor as an end-of-value sentinel, caret height tied to the text line, row align_top/fill_height modes
Some checks failed
CI / build + test (push) Has been cancelled
CI / cargo audit (push) Has been cancelled

Focus-time cursor (event_loop/focus.rs): focusing a text input pinned the cursor to a concrete `value.len()` snapshot. When the value keeps growing after focus without the widget seeing keystrokes — crustace's launcher search field is fed over IPC while forge routes the type-to-search keys around Wayland — that snapshot goes stale, and the first key delivered normally afterwards inserts mid-string. The cursor is now seeded with the `usize::MAX` sentinel ("end of whatever value is rendered"), the same convention `select_on_focus` fields already rely on; every consumer (insert/delete, arrow keys, draw, hit-test, context-menu paste offset, a11y tree) clamps via `cursor.min( value.len() )`, so the cursor tracks external growth and collapses to a concrete position on the first real keystroke or click. Click placement is untouched — the pointer path writes its own hit-tested offset.
Caret height (widget/text_edit/draw.rs): the single-line caret spanned `rect.height - 16`, so a field taller than its text line (the launcher's borderless search pill) grew a caret about twice the glyph height. It now measures `font_size + 4`, vertically centered like the text — matching what the multiline caret already did.
Row alignment modes (layout/row.rs): `Row` gains `align_top()` (children pinned to the top edge instead of the default vertical centering) and `fill_height()` (every non-spacer child stretched to the row's inner height, the row itself still sized by its tallest child). Both exist for siblings whose natural heights differ by a few font-metric pixels — like the QS media card next to the wifi/bluetooth chip column — where equal-height layouts cannot be achieved by estimating text heights: `new_line_size` is font-dependent, so px arithmetic in the app always drifts. Containers paint their chrome over the full rect they receive and columns absorb the extra in weighted spacers, so a stretched card keeps its content anchored where its internal spacers put it.
This commit is contained in:
2026-07-30 01:02:30 +02:00
parent 1234943e86
commit 16c04f4159
3 changed files with 56 additions and 17 deletions

View File

@@ -47,6 +47,8 @@ pub struct Row<Msg: Clone>
/// Padding on all sides. [`Length`]; default `0.0` px.
pub( crate ) padding: Length,
pub( crate ) align_right: bool,
pub( crate ) align_top: bool,
pub( crate ) fill_height: bool,
}
impl<Msg: Clone> Row<Msg>
@@ -59,6 +61,8 @@ impl<Msg: Clone> Row<Msg>
spacing: Length::px( 8.0 ),
padding: Length::px( 0.0 ),
align_right: false,
align_top: false,
fill_height: false,
}
}
@@ -104,6 +108,26 @@ impl<Msg: Clone> Row<Msg>
self
}
/// Pin children to the top edge instead of the default vertical
/// centering, so siblings of slightly different heights (e.g. two
/// cards whose text metrics differ) share the same top line.
pub fn align_top( mut self ) -> Self
{
self.align_top = true;
self
}
/// Stretch every child to the row's inner height, so siblings share
/// both the top and the bottom line regardless of their natural
/// heights. The row's own height still comes from the tallest
/// child's preferred size; children whose content should track the
/// stretch need internal flexible spacers.
pub fn fill_height( mut self ) -> Self
{
self.fill_height = true;
self
}
/// Return the preferred `(width, height)` given available `max_width`.
pub fn preferred_size( &self, max_width: f32, canvas: &Canvas ) -> (f32, f32)
{
@@ -240,8 +264,15 @@ impl<Msg: Clone> Row<Msg>
Element::Flex( f ) => flex_unit * f.weight as f32,
_ => w,
};
let y = rect.y + pad + ( inner_h - h ) / 2.0;
result.push( ( Rect { x, y, width, height: h }, i ) );
let ( y, height ) = if self.fill_height && !matches!( child, Element::Spacer( _ ) )
{
( rect.y + pad, inner_h )
} else if self.align_top {
( rect.y + pad, h )
} else {
( rect.y + pad + ( inner_h - h ) / 2.0, h )
};
result.push( ( Rect { x, y, width, height }, i ) );
x += width + spacing;
}
result
@@ -258,6 +289,8 @@ impl<Msg: Clone> Row<Msg>
spacing: self.spacing,
padding: self.padding,
align_right: self.align_right,
align_top: self.align_top,
fill_height: self.fill_height,
}
}
}