partially working externalized command

macos-click-through
keith 5 years ago
parent 22ddb545a9
commit 2dfe4c1a7f

@ -3,6 +3,8 @@ use std::collections::HashMap;
use crate::events::{RedrawEvent, StyledContent};
use crate::editor::{DrawCommand, Style};
const COMMAND_SCALE: u16 = 2;
pub struct CommandLine {
visible: bool,
prefix: String,
@ -30,14 +32,18 @@ impl CommandLine {
let (width, height) = window_size;
let text_length: usize = self.content.iter().map(|(_, text)| text.len()).sum();
let x = (width / 2) - (text_length as u64 / 2);
let y = height / 2;
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();
let command_width = text.len() * 2;
let style = defined_styles.get(style_id).map(|style| style.clone());
let command = DrawCommand::new(text.clone(), (start_x, y), style);
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>>();
@ -74,7 +80,7 @@ impl CommandLine {
self.block = Vec::new();
}
fn set_position(&mut self, position: u64, level: u64) {
fn set_position(&mut self, position: u64, _level: u64) {
self.cursor_position = position;
}

@ -60,7 +60,7 @@ struct FontLookup {
impl FontLookup {
pub fn new(name: &str, base_size: f32) -> FontLookup {
let lookup = FontLookup {
let mut lookup = FontLookup {
name: name.to_string(),
base_size,
loaded_fonts: HashMap::new()
@ -74,16 +74,11 @@ impl FontLookup {
}
fn size(&mut self, size_multiplier: u16) -> &Fonts {
match self.loaded_fonts.get(&size_multiplier) {
Some(fonts) => fonts,
None => {
let fonts = Fonts::new(
&self.name,
self.base_size * size_multiplier as f32);
self.loaded_fonts.insert(size_multiplier, fonts);
self.loaded_fonts.get(&size_multiplier).unwrap()
}
}
let name = self.name.clone();
let base_size = self.base_size;
self.loaded_fonts.entry(size_multiplier).or_insert_with(|| {
Fonts::new(&name, base_size * size_multiplier as f32)
})
}
}
@ -105,7 +100,7 @@ impl Renderer {
let surface = None;
let mut paint = Paint::new(colors::WHITE, None);
paint.set_anti_alias(false);
let fonts_lookup = FontLookup::new(FONT_NAME, FONT_SIZE);
let mut fonts_lookup = FontLookup::new(FONT_NAME, FONT_SIZE);
let shaper = CachingShaper::new();
let base_fonts = fonts_lookup.size(1);
@ -122,8 +117,8 @@ impl Renderer {
let (grid_x, grid_y) = grid_pos;
let x = grid_x as f32 * self.font_width;
let y = grid_y as f32 * self.font_height;
let width = text.chars().count() as f32 * self.font_width;
let height = self.font_height;
let width = text.chars().count() as f32 * self.font_width * size as f32;
let height = self.font_height * size as f32;
let region = Rect::new(x, y, x + width, y + height);
let style = style.clone().unwrap_or(Style::new(default_colors.clone()));
@ -141,7 +136,7 @@ impl Renderer {
let style = style.clone().unwrap_or(Style::new(default_colors.clone()));
if style.underline || style.undercurl {
let (_, metrics) = self.fonts_lookup.size(scale).get(&style).metrics();
let (_, metrics) = self.fonts_lookup.size(size).get(&style).metrics();
let line_position = metrics.underline_position().unwrap();
self.paint.set_color(style.special(&default_colors).to_color());
@ -151,7 +146,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.get(&style));
let blob = self.shaper.shape_cached(text.to_string(), self.fonts_lookup.size(size).get(&style));
canvas.draw_text_blob(blob, (x, y), &self.paint);
}
}
@ -185,10 +180,10 @@ impl Renderer {
coordinate_system_helper.use_logical_coordinates(&mut canvas);
for command in draw_commands.iter() {
self.draw_background(&mut canvas, &command.text, command.grid_position.clone(), &command.style, &default_colors);
self.draw_background(&mut canvas, &command.text, command.grid_position.clone(), command.scale, &command.style, &default_colors);
}
for command in draw_commands.iter() {
self.draw_foreground(&mut canvas, &command.text, command.grid_position.clone(), &command.style, &default_colors);
self.draw_foreground(&mut canvas, &command.text, command.grid_position.clone(), command.scale, &command.style, &default_colors);
}
let image = surface.image_snapshot();
@ -229,7 +224,7 @@ impl Renderer {
.map(|(character, _)| character)
.unwrap_or(' ');
gpu_canvas.draw_text_blob(
self.shaper.shape_cached(character.to_string(), &self.fonts.normal),
self.shaper.shape_cached(character.to_string(), &self.fonts_lookup.size(1).normal),
(cursor_x, cursor_y), &self.paint);
}
}

@ -52,7 +52,10 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>, nvim: Neovim, initial_size: (u64, u64
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
} => {
nvim.quit_no_save().ok();
*control_flow = ControlFlow::Exit
},
Event::WindowEvent {
event: WindowEvent::Resized(new_size),

Loading…
Cancel
Save