IDC FINALLY OH MY GOD (I think like ctx + resize propagation + some other stuff)

This commit is contained in:
2025-09-11 00:59:26 -04:00
parent 709a2d0e17
commit 242c3b992e
15 changed files with 476 additions and 281 deletions

View File

@@ -33,8 +33,8 @@ pub enum Cursor {
#[default]
None,
Select {
line: usize,
idx: usize,
line: isize,
col: isize,
},
}
@@ -78,15 +78,14 @@ impl TextData {
let mut max_y = 0;
let c = attrs.color;
let mut max_width = 0.0f32;
let mut i = 0;
let mut cursor_x = 0;
for (run_i, run) in buffer.layout_runs().enumerate() {
if let Cursor::Select { line, .. } = cursor
&& *line == run_i
&& *line == run_i as isize
{
cursor_x = run.line_w as i32;
}
for glyph in run.glyphs.iter() {
for (i, glyph) in run.glyphs.iter().enumerate() {
let physical_glyph = glyph.physical((0., 0.), 1.0);
let glyph_color = match glyph.color_opt {
@@ -94,13 +93,12 @@ impl TextData {
None => cosmic_text::Color::rgba(c.r, c.g, c.b, c.a),
};
if let Cursor::Select { idx, line } = cursor
&& *line == run_i
&& *idx == i
if let Cursor::Select { col: idx, line } = cursor
&& *line == run_i as isize
&& *idx == i as isize
{
cursor_x = physical_glyph.x;
}
i += 1;
self.swash_cache.with_pixels(
&mut self.font_system,
@@ -133,19 +131,23 @@ impl TextData {
image.put_pixel(x, y, color);
}
if let &Cursor::Select { line, .. } = cursor {
let x = (cursor_x - min_x) as u32;
for y in 0..attrs.line_height as u32 {
// no clue if this is good or bad for non integer values
// depends on how the layouting is actually done
let x = (cursor_x - min_x) as u32;
let y = (y as f32 + attrs.line_height * line as f32 - min_y as f32) as u32;
image.put_pixel(x, y, Rgba(c.as_arr()));
}
}
let mut lines = buffer.lines.len();
if content.ends_with('\n') {
lines += 1;
}
let offset = TextOffset {
top_left: Vec2::new(min_x as f32, min_y as f32),
bot_right: Vec2::new(
max_width - max_x as f32,
attrs.line_height * buffer.lines.len() as f32 - max_y as f32,
attrs.line_height * lines as f32 - max_y as f32,
),
};
(textures.add(image), offset)