Fix conflicts and implement window centering

This commit is contained in:
Vladimir Borisov 2021-07-13 18:07:35 +03:00
commit 26bd7cb955
No known key found for this signature in database
GPG key ID: F9A584BE4FCB6603

View file

@ -1,3 +1,4 @@
use std::cmp;
use native_windows_derive::NwgUi;
use native_windows_gui as nwg;
@ -7,7 +8,7 @@ use crate::stremio_app::stremio_player::Player;
#[derive(Default, NwgUi)]
pub struct StremioApp {
#[nwg_control(title: "Stremio", flags: "MAIN_WINDOW|VISIBLE")]
#[nwg_events( OnWindowClose: [StremioApp::quit] )]
#[nwg_events( OnWindowClose: [StremioApp::on_quit], OnInit: [StremioApp::on_init] )]
window: nwg::Window,
#[nwg_partial(parent: window)]
webview: WebView,
@ -16,7 +17,16 @@ pub struct StremioApp {
}
impl StremioApp {
fn quit(&self) {
fn on_init(&self) {
let small_side = cmp::min(nwg::Monitor::width(), nwg::Monitor::height()) * 70 / 100;
let dimensions = (small_side * 16 / 9, small_side);
let [total_width, total_height] = [nwg::Monitor::width(), nwg::Monitor::height()];
let x = (total_width-dimensions.0)/2;
let y = (total_height-dimensions.1)/2;
self.window.set_size(dimensions.0 as u32, dimensions.1 as u32);
self.window.set_position(x, y);
}
fn on_quit(&self) {
nwg::stop_thread_dispatch();
}
}