fix: Trigger grid resize after font change

macos-click-through
Serg Tereshchenko 3 years ago committed by Keith Simmons
parent d5404299ee
commit 71e107d649

@ -230,7 +230,7 @@ impl Renderer {
canvas.restore(); canvas.restore();
} }
pub fn handle_draw_command(&mut self, root_canvas: &mut Canvas, draw_command: DrawCommand) { fn handle_draw_command(&mut self, root_canvas: &mut Canvas, draw_command: DrawCommand) {
match draw_command { match draw_command {
DrawCommand::Window { DrawCommand::Window {
grid_id, grid_id,
@ -276,16 +276,19 @@ impl Renderer {
} }
} }
/// Draws frame
///
/// # Returns
/// `bool` indicating whether or not font was changed during this frame.
#[allow(clippy::needless_collect)] #[allow(clippy::needless_collect)]
pub fn draw_frame(&mut self, root_canvas: &mut Canvas, dt: f32) -> bool { pub fn draw_frame(&mut self, root_canvas: &mut Canvas, dt: f32) -> bool {
let mut font_changed = false;
let draw_commands: Vec<_> = self let draw_commands: Vec<_> = self
.batched_draw_command_receiver .batched_draw_command_receiver
.try_iter() // Iterator of Vec of DrawCommand .try_iter() // Iterator of Vec of DrawCommand
.map(|batch| batch.into_iter()) // Iterator of Iterator of DrawCommand .map(|batch| batch.into_iter()) // Iterator of Iterator of DrawCommand
.flatten() // Iterator of DrawCommand .flatten() // Iterator of DrawCommand
.collect(); .collect();
let mut font_changed = false;
for draw_command in draw_commands.into_iter() { for draw_command in draw_commands.into_iter() {
if let DrawCommand::FontChanged(_) = draw_command { if let DrawCommand::FontChanged(_) = draw_command {

@ -164,9 +164,10 @@ impl GlutinWindowWrapper {
pub fn draw_frame(&mut self, dt: f32) { pub fn draw_frame(&mut self, dt: f32) {
let window = self.windowed_context.window(); let window = self.windowed_context.window();
let mut font_changed = false;
if REDRAW_SCHEDULER.should_draw() || SETTINGS.get::<WindowSettings>().no_idle { if REDRAW_SCHEDULER.should_draw() || SETTINGS.get::<WindowSettings>().no_idle {
self.renderer.draw_frame(self.skia_renderer.canvas(), dt); font_changed = self.renderer.draw_frame(self.skia_renderer.canvas(), dt);
self.skia_renderer.gr_context.flush(None); self.skia_renderer.gr_context.flush(None);
self.windowed_context.swap_buffers().unwrap(); self.windowed_context.swap_buffers().unwrap();
} }
@ -180,11 +181,13 @@ impl GlutinWindowWrapper {
let size = SETTINGS.get::<CmdLineSettings>().geometry; let size = SETTINGS.get::<CmdLineSettings>().geometry;
window.set_inner_size(self.renderer.convert_grid_to_physical(size)); window.set_inner_size(self.renderer.convert_grid_to_physical(size));
self.saved_grid_size = Some(size); self.saved_grid_size = Some(size);
// Font change at startup is ignored, so grid size (and startup screen) could be preserved.
font_changed = false;
} }
let new_size = window.inner_size(); let new_size = window.inner_size();
if self.saved_inner_size != new_size { if self.saved_inner_size != new_size || font_changed {
self.saved_inner_size = new_size; self.saved_inner_size = new_size;
self.handle_new_grid_size(new_size); self.handle_new_grid_size(new_size);
self.skia_renderer.resize(&self.windowed_context); self.skia_renderer.resize(&self.windowed_context);

Loading…
Cancel
Save