From d757e805e8f356aa8c4ac30066288830cfcce4ab Mon Sep 17 00:00:00 2001 From: shadow cat Date: Sat, 22 Nov 2025 18:45:01 -0500 Subject: [PATCH] rename z offset to layer offset --- src/core/text/edit.rs | 22 ++++++++++------------ src/core/trait_fns.rs | 4 ++-- src/layout/vec2.rs | 10 ++++++++++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/core/text/edit.rs b/src/core/text/edit.rs index 25dc26b..dc43712 100644 --- a/src/core/text/edit.rs +++ b/src/core/text/edit.rs @@ -39,11 +39,11 @@ impl Widget for TextEdit { let region = self.view.draw(painter); painter.layer = base; - match &self.selection { + let size = vec2(1, self.attrs.line_height); + match self.selection { TextSelection::None => (), TextSelection::Pos(cursor) => { if let Some(offset) = cursor_pos(cursor, &self.buf) { - let size = vec2(1, self.attrs.line_height); painter.primitive_within( RectPrimitive::color(Color::WHITE), size.align(Align::TOP_LEFT).offset(offset).within(®ion), @@ -51,19 +51,17 @@ impl Widget for TextEdit { } } TextSelection::Span { start, end } => { - let (start, end) = sort_cursors(*start, *end); - let line_height = self.attrs.line_height; - for (top_left, width) in iter_layout_lines(&self.buf, &start, &end) { + let (start, end) = sort_cursors(start, end); + for (top_left, width) in iter_layout_lines(start, end, &self.buf) { painter.primitive_within( RectPrimitive::color(Color::SKY), - vec2(width, line_height) + size.with_x(width) .align(Align::TOP_LEFT) .offset(top_left) .within(®ion), ); } - if let Some(end_offset) = cursor_pos(&end, &self.buf) { - let size = vec2(1, self.attrs.line_height); + if let Some(end_offset) = cursor_pos(end, &self.buf) { painter.primitive_within( RectPrimitive::color(Color::WHITE), size.align(Align::TOP_LEFT) @@ -86,11 +84,11 @@ impl Widget for TextEdit { /// provides top left + width fn iter_layout_lines( + start: Cursor, + end: Cursor, buf: &TextBuffer, - start: &Cursor, - end: &Cursor, ) -> impl Iterator { - gen { + gen move { let mut iter = buf.layout_runs(); for line in iter.by_ref() { if line.line_i == start.line @@ -145,7 +143,7 @@ fn index_x(run: &LayoutRun, index: usize) -> Option { } /// returns top of line segment where cursor should visually select -fn cursor_pos(cursor: &Cursor, buf: &TextBuffer) -> Option { +fn cursor_pos(cursor: Cursor, buf: &TextBuffer) -> Option { let mut prev = None; for run in buf .layout_runs() diff --git a/src/core/trait_fns.rs b/src/core/trait_fns.rs index d5b771b..24dca87 100644 --- a/src/core/trait_fns.rs +++ b/src/core/trait_fns.rs @@ -15,7 +15,7 @@ pub trait CoreWidget { fn scroll(self) -> impl WidgetIdFn; fn masked(self) -> impl WidgetFn; fn background(self, w: impl WidgetLike) -> impl WidgetFn; - fn z_offset(self, offset: usize) -> impl WidgetFn; + fn layer_offset(self, offset: usize) -> impl WidgetFn; } impl, Tag> CoreWidget for W { @@ -121,7 +121,7 @@ impl, Tag> CoreWidget for W { } } - fn z_offset(self, offset: usize) -> impl WidgetFn { + fn layer_offset(self, offset: usize) -> impl WidgetFn { move |ui| Stack { children: vec![self.add(ui).any()], size: StackSize::Child(0), diff --git a/src/layout/vec2.rs b/src/layout/vec2.rs index 593095f..47e8785 100644 --- a/src/layout/vec2.rs +++ b/src/layout/vec2.rs @@ -56,6 +56,16 @@ impl Vec2 { pub const fn tuple(&self) -> (f32, f32) { (self.x, self.y) } + + pub const fn with_x(mut self, x: f32) -> Self { + self.x = x; + self + } + + pub const fn with_y(mut self, y: f32) -> Self { + self.y = y; + self + } } impl const From for Vec2 {