|
|
@ -17,18 +17,17 @@ use crate::keybindings::construct_keybinding_string;
|
|
|
|
|
|
|
|
|
|
|
|
const FONT_NAME: &str = "Delugia Nerd Font";
|
|
|
|
const FONT_NAME: &str = "Delugia Nerd Font";
|
|
|
|
const FONT_SIZE: f32 = 14.0;
|
|
|
|
const FONT_SIZE: f32 = 14.0;
|
|
|
|
const FONT_WIDTH: f32 = 8.2;
|
|
|
|
|
|
|
|
const FONT_HEIGHT: f32 = 16.4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fn process_draw_commands(draw_commands: &Vec<DrawCommand>, default_colors: &Colors, piet: &mut Piet, font: &PietFont) {
|
|
|
|
// fn process_draw_commands(draw_commands: &Vec<DrawCommand>, default_colors: &Colors, piet: &mut Piet, font: &PietFont) {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
fn draw(
|
|
|
|
fn draw(
|
|
|
|
editor: &Arc<Mutex<Editor>>,
|
|
|
|
editor: &Arc<Mutex<Editor>>,
|
|
|
|
canvas: &mut Canvas
|
|
|
|
canvas: &mut Canvas,
|
|
|
|
|
|
|
|
font: &Font,
|
|
|
|
|
|
|
|
font_width: f32,
|
|
|
|
|
|
|
|
font_height: f32
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let typeface = Typeface::new(FONT_NAME, FontStyle::default()).expect("Could not load font file.");
|
|
|
|
|
|
|
|
let font = Font::from_typeface(typeface, FONT_SIZE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// let shaper = Shaper::new(None);
|
|
|
|
// let shaper = Shaper::new(None);
|
|
|
|
// if let Some((blob, _)) = shaper.shape_text_blob("This is a test ~==", font, false, 10000.0, Point::default()) {
|
|
|
|
// if let Some((blob, _)) = shaper.shape_text_blob("This is a test ~==", font, false, 10000.0, Point::default()) {
|
|
|
@ -43,11 +42,11 @@ fn draw(
|
|
|
|
canvas.clear(default_colors.background.clone().unwrap().to_color());
|
|
|
|
canvas.clear(default_colors.background.clone().unwrap().to_color());
|
|
|
|
|
|
|
|
|
|
|
|
for command in draw_commands {
|
|
|
|
for command in draw_commands {
|
|
|
|
let x = command.col_start as f32 * FONT_WIDTH;
|
|
|
|
let x = command.col_start as f32 * font_width;
|
|
|
|
let y = command.row as f32 * FONT_HEIGHT + FONT_HEIGHT;
|
|
|
|
let y = command.row as f32 * font_height + font_height - font_height * 0.2;
|
|
|
|
let top = y - FONT_HEIGHT * 0.8;
|
|
|
|
let top = y - font_height * 0.8;
|
|
|
|
let width = command.text.chars().count() as f32 * FONT_WIDTH;
|
|
|
|
let width = command.text.chars().count() as f32 * font_width;
|
|
|
|
let height = FONT_HEIGHT;
|
|
|
|
let height = font_height;
|
|
|
|
let region = Rect::new(x, top, x + width, top + height);
|
|
|
|
let region = Rect::new(x, top, x + width, top + height);
|
|
|
|
let background_paint = Paint::new(command.style.colors.background.unwrap_or(default_colors.background.clone().unwrap()), None);
|
|
|
|
let background_paint = Paint::new(command.style.colors.background.unwrap_or(default_colors.background.clone().unwrap()), None);
|
|
|
|
canvas.draw_rect(region, &background_paint);
|
|
|
|
canvas.draw_rect(region, &background_paint);
|
|
|
@ -57,18 +56,25 @@ fn draw(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let (cursor_grid_x, cursor_grid_y) = cursor_pos;
|
|
|
|
let (cursor_grid_x, cursor_grid_y) = cursor_pos;
|
|
|
|
let cursor_x = cursor_grid_x as f32 * FONT_WIDTH;
|
|
|
|
let cursor_x = cursor_grid_x as f32 * font_width;
|
|
|
|
let cursor_width = FONT_WIDTH / 8.0;
|
|
|
|
let cursor_width = font_width / 8.0;
|
|
|
|
let cursor_y = cursor_grid_y as f32 * FONT_HEIGHT + FONT_HEIGHT * 0.2;
|
|
|
|
let cursor_y = cursor_grid_y as f32 * font_height;
|
|
|
|
let cursor_height = FONT_HEIGHT;
|
|
|
|
let cursor_height = font_height;
|
|
|
|
let cursor = Rect::new(cursor_x, cursor_y, cursor_x + cursor_width, cursor_y + cursor_height);
|
|
|
|
let cursor = Rect::new(cursor_x, cursor_y, cursor_x + cursor_width, cursor_y + cursor_height);
|
|
|
|
let cursor_paint = Paint::new(default_colors.foreground.unwrap(), None);
|
|
|
|
let cursor_paint = Paint::new(default_colors.foreground.unwrap(), None);
|
|
|
|
canvas.draw_rect(cursor, &cursor_paint);
|
|
|
|
canvas.draw_rect(cursor, &cursor_paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn ui_loop(editor: Arc<Mutex<Editor>>) {
|
|
|
|
pub fn ui_loop(editor: Arc<Mutex<Editor>>) {
|
|
|
|
|
|
|
|
let typeface = Typeface::new(FONT_NAME, FontStyle::default()).expect("Could not load font file.");
|
|
|
|
|
|
|
|
let font = Font::from_typeface(typeface, FONT_SIZE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let (width, bounds) = font.measure_str("0", None);
|
|
|
|
|
|
|
|
let font_width = width;
|
|
|
|
|
|
|
|
let font_height = bounds.height() * 1.68;
|
|
|
|
|
|
|
|
|
|
|
|
let event_loop = EventLoop::<()>::with_user_event();
|
|
|
|
let event_loop = EventLoop::<()>::with_user_event();
|
|
|
|
let logical_size = LogicalSize::new((100.0 * FONT_WIDTH) as f64, (50.0 * FONT_HEIGHT) as f64);
|
|
|
|
let logical_size = LogicalSize::new((100.0 * font_width) as f64, (50.0 * font_height) as f64);
|
|
|
|
let visible_range = Rect {
|
|
|
|
let visible_range = Rect {
|
|
|
|
left: 0.0,
|
|
|
|
left: 0.0,
|
|
|
|
right: logical_size.width as f32,
|
|
|
|
right: logical_size.width as f32,
|
|
|
@ -84,8 +90,8 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>) {
|
|
|
|
.expect("Failed to create window");
|
|
|
|
.expect("Failed to create window");
|
|
|
|
|
|
|
|
|
|
|
|
let mut renderer = RendererBuilder::new()
|
|
|
|
let mut renderer = RendererBuilder::new()
|
|
|
|
.use_vulkan_debug_layer(true)
|
|
|
|
|
|
|
|
.coordinate_system(CoordinateSystem::Logical)
|
|
|
|
.coordinate_system(CoordinateSystem::Logical)
|
|
|
|
|
|
|
|
.prefer_mailbox_present_mode()
|
|
|
|
.build(&window)
|
|
|
|
.build(&window)
|
|
|
|
.expect("Failed to create renderer");
|
|
|
|
.expect("Failed to create renderer");
|
|
|
|
|
|
|
|
|
|
|
@ -102,10 +108,12 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>) {
|
|
|
|
event: WindowEvent::Resized(new_size),
|
|
|
|
event: WindowEvent::Resized(new_size),
|
|
|
|
..
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
} => {
|
|
|
|
editor.lock().unwrap().resize(
|
|
|
|
if new_size.width > 0.0 && new_size.height > 0.0 {
|
|
|
|
(new_size.width as f32 / FONT_WIDTH) as u16,
|
|
|
|
editor.lock().unwrap().resize(
|
|
|
|
(new_size.height as f32 / FONT_HEIGHT) as u16
|
|
|
|
(new_size.width as f32 / font_width) as u16,
|
|
|
|
)
|
|
|
|
(new_size.height as f32 / font_height) as u16
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
Event:: WindowEvent {
|
|
|
|
Event:: WindowEvent {
|
|
|
@ -130,7 +138,7 @@ pub fn ui_loop(editor: Arc<Mutex<Editor>>) {
|
|
|
|
..
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
} => {
|
|
|
|
if let Err(e) = renderer.draw(&window, |canvas, _coordinate_system_helper| {
|
|
|
|
if let Err(e) = renderer.draw(&window, |canvas, _coordinate_system_helper| {
|
|
|
|
draw(&editor, canvas);
|
|
|
|
draw(&editor, canvas, &font, font_width, font_height);
|
|
|
|
}) {
|
|
|
|
}) {
|
|
|
|
println!("Error during draw: {:?}", e);
|
|
|
|
println!("Error during draw: {:?}", e);
|
|
|
|
*control_flow = ControlFlow::Exit
|
|
|
|
*control_flow = ControlFlow::Exit
|
|
|
|