Use layout for the splash image

This commit is contained in:
Vladimir Borisov 2025-01-23 17:36:22 +02:00
parent 9902c37aa2
commit d9fbabbf62
No known key found for this signature in database
GPG key ID: F9A584BE4FCB6603
2 changed files with 27 additions and 35 deletions

View file

@ -311,9 +311,7 @@ impl MainWindow {
data.set_min_size(WINDOW_MIN_WIDTH, WINDOW_MIN_HEIGHT); data.set_min_size(WINDOW_MIN_WIDTH, WINDOW_MIN_HEIGHT);
} }
fn on_paint(&self) { fn on_paint(&self) {
if self.splash_screen.visible() { if !self.splash_screen.visible() {
self.splash_screen.resize(self.window.size());
} else {
self.webview.fit_to_window(self.window.handle.hwnd()); self.webview.fit_to_window(self.window.handle.hwnd());
} }
} }

View file

@ -1,6 +1,6 @@
use crate::stremio_app::constants::{WINDOW_MIN_HEIGHT, WINDOW_MIN_WIDTH};
use native_windows_derive::NwgPartial; use native_windows_derive::NwgPartial;
use native_windows_gui as nwg; use native_windows_gui as nwg;
use std::cmp;
#[derive(Default, NwgPartial)] #[derive(Default, NwgPartial)]
pub struct SplashImage { pub struct SplashImage {
@ -8,25 +8,19 @@ pub struct SplashImage {
embed: nwg::EmbedResource, embed: nwg::EmbedResource,
#[nwg_resource(size: Some((300,300)), source_embed: Some(&data.embed), source_embed_str: Some("SPLASHIMAGE"))] #[nwg_resource(size: Some((300,300)), source_embed: Some(&data.embed), source_embed_str: Some("SPLASHIMAGE"))]
splash_image: nwg::Bitmap, splash_image: nwg::Bitmap,
#[nwg_control(background_color: Some(Self::BG_COLOR))] #[nwg_layout(spacing: 0, min_size: [WINDOW_MIN_WIDTH as u32, WINDOW_MIN_HEIGHT as u32])]
splash_frame: nwg::ImageFrame, grid: nwg::GridLayout,
#[nwg_control(parent: splash_frame, background_color: Some(Self::BG_COLOR), bitmap: Some(&data.splash_image))] #[nwg_control(background_color: Some(Self::BG_COLOR), bitmap: Some(&data.splash_image))]
#[nwg_layout_item(layout: grid, col: 0, row: 0)]
splash: nwg::ImageFrame, splash: nwg::ImageFrame,
} }
impl SplashImage { impl SplashImage {
const BG_COLOR: [u8; 3] = [27, 17, 38]; const BG_COLOR: [u8; 3] = [27, 17, 38];
pub fn resize(&self, size: (u32, u32)) {
let (w, h) = size;
let s = cmp::min(w, h);
self.splash_frame.set_size(w, h);
self.splash.set_size(s, s);
self.splash.set_position(w as i32 / 2 - s as i32 / 2, 0);
}
pub fn visible(&self) -> bool { pub fn visible(&self) -> bool {
self.splash_frame.visible() self.splash.visible()
} }
pub fn hide(&self) { pub fn hide(&self) {
self.splash_frame.set_visible(false); self.splash.set_visible(false);
} }
} }