horizontal scrolling and progress toward command line

macos-click-through
keith 5 years ago
parent bf574cc876
commit 1d620acc5a

@ -28,26 +28,28 @@ impl CommandLine {
pub fn draw(&self, window_size: (u64, u64), defined_styles: &HashMap<u64, Style>) -> Vec<DrawCommand> {
let mut draw_commands = Vec::new();
if self.content.len() > 0 {
let (width, height) = window_size;
let text_length: usize = self.content.iter().map(|(_, text)| text.len()).sum();
let text_width = text_length * COMMAND_SCALE as usize;
let text_height = COMMAND_SCALE;
let x = (width / 2) - (text_width as u64 / 2);
let y = (height / 2) - (text_height as u64 / 2);
let mut start_x = x;
let mut commands = self.content.iter().map(|(style_id, text)| {
let command_width = text.len() * 2;
let style = defined_styles.get(style_id).map(|style| style.clone());
let mut command = DrawCommand::new(text.clone(), (start_x, y), style);
command.scale = COMMAND_SCALE;
start_x = start_x + command_width as u64;
command
}).collect::<Vec<DrawCommand>>();
draw_commands.append(&mut commands);
if self.visible {
if self.content.len() > 0 {
let (width, height) = window_size;
let text_length: usize = self.content.iter().map(|(_, text)| text.len()).sum();
let text_width = text_length * COMMAND_SCALE as usize;
let text_height = COMMAND_SCALE;
let x = (width / 2) - (text_width as u64 / 2);
let y = (height / 2) - (text_height as u64 / 2);
let mut start_x = x;
let mut commands = self.content.iter().map(|(style_id, text)| {
let command_width = text.len() * 2;
let style = defined_styles.get(style_id).map(|style| style.clone());
let mut command = DrawCommand::new(text.clone(), (start_x, y), style);
command.scale = COMMAND_SCALE;
start_x = start_x + command_width as u64;
command
}).collect::<Vec<DrawCommand>>();
draw_commands.append(&mut commands);
}
}
draw_commands
}

@ -23,6 +23,20 @@ pub struct DrawCommand {
pub scale: u16
}
impl DrawCommand {
pub fn set_coverage(&self, dirty: &mut Vec<Vec<bool>>) {
let (left, top) = self.grid_position;
let text_width = self.text.chars().count() * self.scale as usize;
for y in top..(top + self.scale as u64 - 1) {
let row = &mut dirty[y as usize];
for x in left..(left + text_width as u64 - 1) {
row[x as usize] = true;
}
}
}
}
pub struct Editor {
pub grid: Vec<Vec<GridCell>>,
pub dirty: Vec<Vec<bool>>,
@ -136,6 +150,9 @@ impl Editor {
}).collect::<Vec<DrawCommand>>();
let mut command_line_draw_commands = self.command_line.draw(self.size, &self.defined_styles);
for command_line_draw_command in command_line_draw_commands.iter() {
command_line_draw_command.set_coverage(&mut self.dirty);
}
draw_commands.append(&mut command_line_draw_commands);
let (width, height) = self.size;

@ -3,7 +3,7 @@ use skulpin::skia_safe::{Shaper, TextBlob, Font, Point};
pub struct CachingShaper {
shaper: Shaper,
cache: LruCache<String, TextBlob>
cache: LruCache<(String, u16), TextBlob>
}
impl CachingShaper {
@ -19,11 +19,16 @@ impl CachingShaper {
blob
}
pub fn shape_cached(&mut self, text: String, font: &Font) -> &TextBlob {
if !self.cache.contains(&text) {
self.cache.put(text.clone(), self.shape(&text, &font));
pub fn shape_cached(&mut self, text: String, scale: u16, font: &Font) -> &TextBlob {
let key = (text.clone(), scale);
if !self.cache.contains(&key) {
self.cache.put(key.clone(), self.shape(&text, &font));
}
self.cache.get(&text).unwrap()
self.cache.get(&key).unwrap()
}
pub fn clear(&mut self) {
self.cache.clear();
}
}

@ -5,7 +5,7 @@ use skulpin::skia_safe::{Canvas, Paint, Path, Point};
use crate::renderer::{CachingShaper, FontLookup};
use crate::editor::{Colors, Cursor, CursorShape, Editor};
const AVERAGE_MOTION_PERCENTAGE: f32 = 0.8;
const AVERAGE_MOTION_PERCENTAGE: f32 = 0.6;
const MOTION_PERCENTAGE_SPREAD: f32 = 0.5;
const BAR_WIDTH: f32 = 1.0 / 8.0;
@ -142,7 +142,7 @@ impl CursorRenderer {
.map(|(character, _)| character)
.unwrap_or(' ');
canvas.draw_text_blob(
shaper.shape_cached(character.to_string(), &fonts_lookup.size(1).normal),
shaper.shape_cached(character.to_string(), 1, &fonts_lookup.size(1).normal),
(cursor_x, cursor_y), &paint);
}
}

@ -149,7 +149,7 @@ impl Renderer {
self.paint.set_color(style.foreground(&default_colors).to_color());
let text = text.trim_end();
if text.len() > 0 {
let blob = self.shaper.shape_cached(text.to_string(), self.fonts_lookup.size(size).get(&style));
let blob = self.shaper.shape_cached(text.to_string(), size, self.fonts_lookup.size(size).get(&style));
canvas.draw_text_blob(blob, (x, y), &self.paint);
}
}

@ -124,20 +124,33 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, nvim: Neovim, initial_size: (u64, u64
Event::WindowEvent {
event: WindowEvent::MouseWheel {
delta: MouseScrollDelta::LineDelta(_, delta),
delta: MouseScrollDelta::LineDelta(horizontal, vertical),
..
},
..
} => {
let input_type = if delta > 0.0 {
let vertical_input_type = if vertical > 0.0 {
Some("up")
} else if delta < 0.0 {
} else if vertical < 0.0 {
Some("down")
} else {
None
};
if let Some(input_type) = input_type {
if let Some(input_type) = vertical_input_type {
let (grid_x, grid_y) = mouse_pos;
nvim.input_mouse("wheel", input_type, "", 0, grid_y, grid_x).expect("Could not send mouse input");
}
let horizontal_input_type = if horizontal > 0.0 {
Some("right")
} else if horizontal < 0.0 {
Some("left")
} else {
None
};
if let Some(input_type) = horizontal_input_type {
let (grid_x, grid_y) = mouse_pos;
nvim.input_mouse("wheel", input_type, "", 0, grid_y, grid_x).expect("Could not send mouse input");
}

Loading…
Cancel
Save