]> git.seodisparate.com - mpd_info_screen/commitdiff
WIP allow resizing, better handling of resizing
authorStephen Seo <seo.disparate@gmail.com>
Tue, 14 Dec 2021 09:59:27 +0000 (18:59 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 14 Dec 2021 09:59:27 +0000 (18:59 +0900)
src/display.rs
src/main.rs

index 32568d7144f7861a6da1bb965fcf1ce5b3164ea5..bdacd2d76d3de59d3d3aafb98c641ca1f4eaf69e 100644 (file)
@@ -1,7 +1,7 @@
 use crate::mpd_handler::MPDHandler;
 use crate::Opt;
 use ggez::event::{self, EventHandler};
-use ggez::graphics::{self, Color, DrawParam, Drawable, Text, TextFragment};
+use ggez::graphics::{self, Color, DrawParam, Drawable, Rect, Text, TextFragment};
 use ggez::timer::{check_update_time, fps, yield_now};
 use ggez::Context;
 use ggez::GameError;
@@ -47,4 +47,17 @@ impl EventHandler for MPDDisplay {
 
         graphics::present(ctx)
     }
+
+    fn resize_event(&mut self, ctx: &mut Context, width: f32, height: f32) {
+        graphics::set_screen_coordinates(
+            ctx,
+            Rect {
+                x: 0.0,
+                y: 0.0,
+                w: width,
+                h: height,
+            },
+        )
+        .expect("Failed to handle resizing window");
+    }
 }
index b2d2a2b5a2129aee9d38d30d871cb62cbddebacf..1312ee543835d88584a3b36b0868eab98e88b81e 100644 (file)
@@ -1,7 +1,7 @@
 mod display;
 mod mpd_handler;
 
-use ggez::conf::WindowSetup;
+use ggez::conf::{WindowMode, WindowSetup};
 use ggez::event;
 use ggez::ContextBuilder;
 use std::net::Ipv4Addr;
@@ -34,6 +34,10 @@ fn main() -> Result<(), String> {
             title: "mpd info screen".into(),
             ..Default::default()
         })
+        .window_mode(WindowMode {
+            resizable: true,
+            ..Default::default()
+        })
         .build()
         .expect("Failed to create ggez context");