cursor finally working properly and removed from render_text
This commit is contained in:
@@ -39,16 +39,6 @@ impl TextAttrs {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Copy, Clone)]
|
||||
pub enum VisualCursor {
|
||||
#[default]
|
||||
None,
|
||||
Select {
|
||||
line: isize,
|
||||
col: isize,
|
||||
},
|
||||
}
|
||||
|
||||
pub type TextBuffer = Buffer;
|
||||
|
||||
impl Default for TextAttrs {
|
||||
@@ -68,7 +58,6 @@ impl TextData {
|
||||
&mut self,
|
||||
buffer: &mut TextBuffer,
|
||||
attrs: &TextAttrs,
|
||||
cursor: &VisualCursor,
|
||||
textures: &mut Textures,
|
||||
) -> (TextureHandle, TextOffset) {
|
||||
let mut pixels = HashMap::new();
|
||||
@@ -76,30 +65,20 @@ impl TextData {
|
||||
let mut min_y = 0;
|
||||
let mut max_x = 0;
|
||||
let mut max_y = 0;
|
||||
let c = attrs.color;
|
||||
let cosmic_color = {
|
||||
let c = attrs.color;
|
||||
cosmic_text::Color::rgba(c.r, c.g, c.b, c.a)
|
||||
};
|
||||
let mut max_width = 0.0f32;
|
||||
let mut cursor_x = 0;
|
||||
for (run_i, run) in buffer.layout_runs().enumerate() {
|
||||
if let VisualCursor::Select { line, .. } = cursor
|
||||
&& *line == run_i as isize
|
||||
{
|
||||
cursor_x = run.line_w as i32;
|
||||
}
|
||||
for (i, glyph) in run.glyphs.iter().enumerate() {
|
||||
for run in buffer.layout_runs() {
|
||||
for glyph in run.glyphs.iter() {
|
||||
let physical_glyph = glyph.physical((0., 0.), 1.0);
|
||||
|
||||
let glyph_color = match glyph.color_opt {
|
||||
Some(some) => some,
|
||||
None => cosmic_text::Color::rgba(c.r, c.g, c.b, c.a),
|
||||
None => cosmic_color,
|
||||
};
|
||||
|
||||
if let VisualCursor::Select { col: idx, line } = cursor
|
||||
&& *line == run_i as isize
|
||||
&& *idx == i as isize
|
||||
{
|
||||
cursor_x = physical_glyph.x;
|
||||
}
|
||||
|
||||
self.swash_cache.with_pixels(
|
||||
&mut self.font_system,
|
||||
physical_glyph.cache_key,
|
||||
@@ -117,11 +96,6 @@ impl TextData {
|
||||
}
|
||||
max_width = max_width.max(run.line_w);
|
||||
}
|
||||
if let &VisualCursor::Select { line, .. } = cursor {
|
||||
let y = (attrs.line_height * (line + 1) as f32) as i32 - 1;
|
||||
max_y = max_y.max(y);
|
||||
max_x = max_x.max(cursor_x);
|
||||
}
|
||||
let width = (max_x - min_x + 1) as u32;
|
||||
let height = (max_y - min_y + 1) as u32;
|
||||
let mut image = RgbaImage::new(width, height);
|
||||
@@ -130,15 +104,6 @@ impl TextData {
|
||||
let y = (y - min_y) as u32;
|
||||
image.put_pixel(x, y, color);
|
||||
}
|
||||
if let &VisualCursor::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 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 lines = buffer.lines.len();
|
||||
let offset = TextOffset {
|
||||
top_left: Vec2::new(min_x as f32, min_y as f32),
|
||||
|
||||
Reference in New Issue
Block a user