From 9f3b0e01e72630acf7f2a3c1508b4087a6e15d9d Mon Sep 17 00:00:00 2001 From: korin Date: Sun, 9 Apr 2023 00:34:08 -0400 Subject: [PATCH] resizable window; refresh rate lowered to 50Hz instead of highest possible to avoid railing a CPU core --- src/editor_render.rs | 4 ++-- src/main.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/editor_render.rs b/src/editor_render.rs index 3724da2..e85613b 100644 --- a/src/editor_render.rs +++ b/src/editor_render.rs @@ -8,8 +8,8 @@ use std::{fs::File, path::Path, io::Read}; use sdl2::rect::Point; pub struct GlyphMetrics { - width: usize, - height: usize, + pub width: usize, + pub height: usize, } impl GlyphMetrics { diff --git a/src/main.rs b/src/main.rs index 3511a32..e7df3ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ extern crate sdl2; use clipboard::{ClipboardProvider, ClipboardContext}; -use sdl2::event::Event; +use sdl2::event::{Event, WindowEvent}; use sdl2::keyboard::Keycode; use sdl2::pixels::Color; use sdl2::rect::Point; @@ -27,6 +27,7 @@ pub fn main() -> Result<(), String> { let window = video_subsys .window("Rude", SCREEN_WIDTH, SCREEN_HEIGHT) .position_centered() + .resizable() .opengl() .build() .map_err(|e| e.to_string())?; @@ -77,6 +78,11 @@ pub fn main() -> Result<(), String> { // TODO: Make this completely user-configurable instead of hardcoded for event in sdl_context.event_pump()?.poll_iter() { match event { + Event::Window { win_event, .. } => { + if let WindowEvent::Resized(_w, _h) = win_event { + draw_text(&buffer, cursor_position)? + } + } // ESC or SIGKILL Event::KeyDown { keycode: Some(Keycode::Escape), .. } | Event::Quit { .. } => break 'mainloop, @@ -234,6 +240,8 @@ pub fn main() -> Result<(), String> { _ => {} } } + + ::std::thread::sleep(std::time::Duration::new(0, 50_000_000)); } format!("{selection_anchor:?}"); println!("{buffer}");