mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 16:21:11 +00:00
progress on selection memory optimization
This commit is contained in:
parent
83b4bb9be8
commit
38a6b19b0f
4 changed files with 47 additions and 33 deletions
|
@ -59,6 +59,7 @@ These are potentially inspirational resources for the editor's design.
|
||||||
- Ability to link e.g. variable name in comments to actual variable name. Comment is automatically updated when variable name is changed.
|
- Ability to link e.g. variable name in comments to actual variable name. Comment is automatically updated when variable name is changed.
|
||||||
* Automatically create all "arms" when pattern matching after entering `when var is` based on the type.
|
* Automatically create all "arms" when pattern matching after entering `when var is` based on the type.
|
||||||
- All `when ... is` should be updated if the type is changed, e.g. adding Indigo to the Color type should add an arm everywhere where `when color is` is used.
|
- All `when ... is` should be updated if the type is changed, e.g. adding Indigo to the Color type should add an arm everywhere where `when color is` is used.
|
||||||
|
* When a function is called like `foo(false)`, the name of the boolean argument should be shown automatically; `foo(`*is_active:*`false)`. This should be done for booleans and numbers.
|
||||||
|
|
||||||
|
|
||||||
### Non-Code Related Inspiration
|
### Non-Code Related Inspiration
|
||||||
|
|
|
@ -26,6 +26,10 @@ pub enum EdError {
|
||||||
},
|
},
|
||||||
#[snafu(display("MissingGlyphDims: glyph_dim_rect_opt was None for model. It needs to be set using the example_code_glyph_rect function."))]
|
#[snafu(display("MissingGlyphDims: glyph_dim_rect_opt was None for model. It needs to be set using the example_code_glyph_rect function."))]
|
||||||
MissingGlyphDims {},
|
MissingGlyphDims {},
|
||||||
|
#[snafu(display("EmptyGlyphsPerLine: glyphs_per_line was none, it is necessary for highlighting of the code."))]
|
||||||
|
EmptyGlyphsPerLine {
|
||||||
|
backtrace: Backtrace,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type EdResult<T, E = EdError> = std::result::Result<T, E>;
|
pub type EdResult<T, E = EdError> = std::result::Result<T, E>;
|
||||||
|
|
|
@ -8,6 +8,8 @@ use ab_glyph::{FontArc, Glyph, InvalidFont};
|
||||||
use cgmath::{Vector2, Vector4};
|
use cgmath::{Vector2, Vector4};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use wgpu_glyph::{ab_glyph, GlyphBrush, GlyphBrushBuilder, GlyphCruncher, Section};
|
use wgpu_glyph::{ab_glyph, GlyphBrush, GlyphBrushBuilder, GlyphCruncher, Section};
|
||||||
|
use bumpalo::collections::Vec as BumpVec;
|
||||||
|
use bumpalo::Bump;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Text {
|
pub struct Text {
|
||||||
|
@ -83,39 +85,41 @@ fn section_from_text(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns bounding boxes for every glyph
|
// returns glyphs per line
|
||||||
pub fn queue_text_draw(text: &Text, glyph_brush: &mut GlyphBrush<()>) -> Vec<Vec<Rect>> {
|
pub fn queue_text_draw<'a>(text: &Text, glyph_brush: &mut GlyphBrush<()>, arena: &'a Bump, selectable: bool) -> Option<BumpVec<'a, usize>> {
|
||||||
let layout = layout_from_text(text);
|
let layout = layout_from_text(text);
|
||||||
|
|
||||||
let section = section_from_text(text, layout);
|
let section = section_from_text(text, layout);
|
||||||
|
|
||||||
glyph_brush.queue(section.clone());
|
glyph_brush.queue(section.clone());
|
||||||
|
|
||||||
let glyph_section_iter = glyph_brush.glyphs_custom_layout(section, &layout);
|
if selectable {
|
||||||
|
let mut glyphs_per_line: BumpVec<usize> = BumpVec::new_in(arena);
|
||||||
|
|
||||||
glyph_section_iter
|
let glyph_section_iter = glyph_brush.glyphs_custom_layout(section, &layout);
|
||||||
.map(glyph_to_rect)
|
|
||||||
.group_by(|rect| rect.top_left_coords.y)
|
let first_glyph_opt = glyph_section_iter.next();
|
||||||
.into_iter()
|
|
||||||
.map(|(_y_coord, rect_group)| {
|
if let Some(first_glyph) = first_glyph_opt {
|
||||||
let mut rects_vec = rect_group.collect::<Vec<Rect>>();
|
let mut line_y_coord = first_glyph.glyph.scale.y;
|
||||||
let last_rect_opt = rects_vec.last().cloned();
|
let mut glyphs_on_line = 0;
|
||||||
// add extra rect to make it easy to highlight the newline character
|
|
||||||
if let Some(last_rect) = last_rect_opt {
|
for glyph in glyph_section_iter {
|
||||||
rects_vec.push(Rect {
|
let curr_y_coord = glyph.glyph.scale.y;
|
||||||
top_left_coords: [
|
if curr_y_coord != line_y_coord {
|
||||||
last_rect.top_left_coords.x + last_rect.width,
|
line_y_coord = curr_y_coord;
|
||||||
last_rect.top_left_coords.y,
|
glyphs_per_line.push(glyphs_on_line);
|
||||||
]
|
glyphs_on_line = 0;
|
||||||
.into(),
|
} else {
|
||||||
width: last_rect.width,
|
glyphs_on_line += 1;
|
||||||
height: last_rect.height,
|
}
|
||||||
color: last_rect.color,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
rects_vec
|
}
|
||||||
})
|
|
||||||
.collect()
|
Some(glyphs_per_line)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn glyph_to_rect(glyph: &wgpu_glyph::SectionGlyph) -> Rect {
|
fn glyph_to_rect(glyph: &wgpu_glyph::SectionGlyph) -> Rect {
|
||||||
|
|
|
@ -13,7 +13,8 @@ extern crate pest;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate pest_derive;
|
extern crate pest_derive;
|
||||||
|
|
||||||
use crate::error::EdError::MissingGlyphDims;
|
use crate::error::EdError::{MissingGlyphDims};
|
||||||
|
use crate::error::{EmptyGlyphsPerLine};
|
||||||
use crate::error::{print_err, EdResult};
|
use crate::error::{print_err, EdResult};
|
||||||
use crate::graphics::colors::{CARET_COLOR, CODE_COLOR, TXT_COLOR};
|
use crate::graphics::colors::{CARET_COLOR, CODE_COLOR, TXT_COLOR};
|
||||||
use crate::graphics::lowlevel::buffer::create_rect_buffers;
|
use crate::graphics::lowlevel::buffer::create_rect_buffers;
|
||||||
|
@ -41,6 +42,7 @@ use winit::dpi::PhysicalSize;
|
||||||
use winit::event;
|
use winit::event;
|
||||||
use winit::event::{Event, ModifiersState};
|
use winit::event::{Event, ModifiersState};
|
||||||
use winit::event_loop::ControlFlow;
|
use winit::event_loop::ControlFlow;
|
||||||
|
use snafu::ensure;
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod graphics;
|
pub mod graphics;
|
||||||
|
@ -216,7 +218,7 @@ fn run_event_loop() -> Result<(), Box<dyn Error>> {
|
||||||
.output;
|
.output;
|
||||||
|
|
||||||
let glyph_bounds_rects =
|
let glyph_bounds_rects =
|
||||||
queue_all_text(&size, &ed_model.lines, ed_model.caret_pos, &mut glyph_brush);
|
queue_all_text(&size, &ed_model.lines, ed_model.caret_pos, &mut glyph_brush, &arena);
|
||||||
|
|
||||||
match draw_all_rects(
|
match draw_all_rects(
|
||||||
&ed_model,
|
&ed_model,
|
||||||
|
@ -331,7 +333,7 @@ fn make_caret_rect(
|
||||||
let mut glyph_rect = if let Some(glyph_dim_rect) = glyph_dim_rect_opt {
|
let mut glyph_rect = if let Some(glyph_dim_rect) = glyph_dim_rect_opt {
|
||||||
glyph_dim_rect
|
glyph_dim_rect
|
||||||
} else {
|
} else {
|
||||||
return Err(MissingGlyphDims {});
|
return Err(MissingGlyphDims{});
|
||||||
};
|
};
|
||||||
|
|
||||||
let caret_y = glyph_rect.top_left_coords.y + (caret_pos.line as f32) * glyph_rect.height;
|
let caret_y = glyph_rect.top_left_coords.y + (caret_pos.line as f32) * glyph_rect.height;
|
||||||
|
@ -360,12 +362,13 @@ fn make_caret_rect(
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns bounding boxes for every glyph
|
// returns bounding boxes for every glyph
|
||||||
fn queue_all_text(
|
fn queue_all_text<'a>(
|
||||||
size: &PhysicalSize<u32>,
|
size: &PhysicalSize<u32>,
|
||||||
lines: &[String],
|
lines: &[String],
|
||||||
caret_pos: Position,
|
caret_pos: Position,
|
||||||
glyph_brush: &mut GlyphBrush<()>,
|
glyph_brush: &mut GlyphBrush<()>,
|
||||||
) -> Vec<Vec<Rect>> {
|
arena: &'a Bump
|
||||||
|
) -> EdResult<BumpVec<'a, usize>> {
|
||||||
let area_bounds = (size.width as f32, size.height as f32).into();
|
let area_bounds = (size.width as f32, size.height as f32).into();
|
||||||
|
|
||||||
let main_label = Text {
|
let main_label = Text {
|
||||||
|
@ -395,9 +398,11 @@ fn queue_all_text(
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
queue_text_draw(&main_label, glyph_brush);
|
queue_text_draw(&main_label, glyph_brush, arena, false);
|
||||||
|
|
||||||
queue_text_draw(&caret_pos_label, glyph_brush);
|
queue_text_draw(&caret_pos_label, glyph_brush, arena, false);
|
||||||
|
|
||||||
queue_text_draw(&code_text, glyph_brush)
|
let glyphs_per_line_opt = queue_text_draw(&code_text, glyph_brush, arena, true);
|
||||||
|
|
||||||
|
ensure!(glyphs_per_line_opt.is_some(), EmptyGlyphsPerLine{})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue