WIP allow resizing, better handling of resizing

This commit is contained in:
Stephen Seo 2021-12-14 18:59:27 +09:00
parent 946eed5a69
commit e9d8e23cc3
2 changed files with 19 additions and 2 deletions

View 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");
}
}

View 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");