rename z offset to layer offset

This commit is contained in:
2025-11-22 18:45:01 -05:00
parent 9deba3d9d7
commit d757e805e8
3 changed files with 22 additions and 14 deletions

View File

@@ -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(&region),
@@ -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(&region),
);
}
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<Item = (Vec2, f32)> {
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<f32> {
}
/// returns top of line segment where cursor should visually select
fn cursor_pos(cursor: &Cursor, buf: &TextBuffer) -> Option<Vec2> {
fn cursor_pos(cursor: Cursor, buf: &TextBuffer) -> Option<Vec2> {
let mut prev = None;
for run in buf
.layout_runs()