From c05c59bffdac825d9f0ad33546eec4d1c5ff2130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=B6nnhager?= Date: Sat, 1 Feb 2025 16:08:36 +0100 Subject: [PATCH] fixup: windows, nwi --- installer-downloader/src/winapi_impl/mod.rs | 119 +++++++++----------- 1 file changed, 56 insertions(+), 63 deletions(-) diff --git a/installer-downloader/src/winapi_impl/mod.rs b/installer-downloader/src/winapi_impl/mod.rs index 81adb08287b5..faeda04b66ae 100644 --- a/installer-downloader/src/winapi_impl/mod.rs +++ b/installer-downloader/src/winapi_impl/mod.rs @@ -1,7 +1,7 @@ use std::cell::RefCell; -use native_windows_gui as nwg; use native_windows_derive as nwd; +use native_windows_gui as nwg; use nwd::NwgUi; use nwg::NativeUi; @@ -10,22 +10,18 @@ const WINDOW_TITLE: &str = "Mullvad VPN installer"; const WINDOW_WIDTH: i32 = 676; const WINDOW_HEIGHT: i32 = 390; -static BANNER_IMAGE_DATA: &[u8] = include_bytes!("../logo-icon.svg"); +static BANNER_IMAGE_DATA: &[u8] = include_bytes!("../logo.png"); -/* // Stretch style -use nwg::stretch::{geometry::{Size, Rect}, style::{Dimension as D, FlexDirection, AlignSelf}}; -const FIFTY_PC: D = D::Percent(0.5); -const PT_10: D = D::Points(10.0); -const PT_5: D = D::Points(5.0); -const PADDING: Rect = Rect{ start: PT_10, end: PT_10, top: PT_10, bottom: PT_10 }; -const MARGIN: Rect = Rect{ start: PT_5, end: PT_5, top: PT_5, bottom: PT_5 }; -*/ - +// use nwg::stretch::{geometry::{Size, Rect}, style::{Dimension as D, FlexDirection, AlignSelf}}; +// const FIFTY_PC: D = D::Percent(0.5); +// const PT_10: D = D::Points(10.0); +// const PT_5: D = D::Points(5.0); +// const PADDING: Rect = Rect{ start: PT_10, end: PT_10, top: PT_10, bottom: PT_10 }; +// const MARGIN: Rect = Rect{ start: PT_5, end: PT_5, top: PT_5, bottom: PT_5 }; const BACKGROUND_COLOR: [u8; 3] = [0x19, 0x2e, 0x45]; - #[derive(Default, NwgUi)] pub struct AppUi { #[nwg_control(size: (WINDOW_WIDTH, WINDOW_HEIGHT), position: (-1, -1), title: WINDOW_TITLE, flags: "WINDOW|VISIBLE")] @@ -37,73 +33,70 @@ pub struct AppUi { #[nwg_control(parent: window, flags: "VISIBLE", background_color: Some(BACKGROUND_COLOR))] #[nwg_layout_item(layout: grid, col: 0, row: 0, row_span: 2)] - banner: nwg::ImageFrame, - - // TODO: + banner: nwg::ImageFrame, + // TODO: #[nwg_resource] decoder: nwg::ImageDecoder, - // ^ TODO: from stream, include_bytes!() - + // ^ TODO: from stream, include_bytes!() + // Logo image banner_image_bitmap: RefCell>, - + #[nwg_control(parent: banner, flags: "VISIBLE", background_color: Some(BACKGROUND_COLOR))] banner_image: nwg::ImageFrame, - - // TODO: add image - // TODO: add progress bar - - /* - #[nwg_layout(parent: window, flex_direction: FlexDirection::Row, padding: PADDING)] - layout: nwg::FlexboxLayout, - - #[nwg_control(text: "Btn 1")] - #[nwg_layout_item(layout: layout, margin: MARGIN, - max_size: Size { width: D::Points(200.0), height: D::Undefined }, - size: Size { width: FIFTY_PC, height: D::Auto } - )] - button1: nwg::Button, - - #[nwg_control(text: "Btn 2")] - #[nwg_layout_item(layout: layout, - margin: MARGIN, - align_self: AlignSelf::FlexEnd, - size: Size { width: D::Percent(0.25), height: FIFTY_PC } - )] - button2: nwg::Button, - - #[nwg_control(text: "Btn 3")] - #[nwg_layout_item(layout: layout, - margin: MARGIN, - flex_grow: 2.0, - size: Size { width: D::Auto, height: D::Auto } - )] - button3: nwg::Button - */ + // TODO: add image + // TODO: add progress bar + + // #[nwg_layout(parent: window, flex_direction: FlexDirection::Row, padding: PADDING)] + // layout: nwg::FlexboxLayout, + // + // #[nwg_control(text: "Btn 1")] + // #[nwg_layout_item(layout: layout, margin: MARGIN, + // max_size: Size { width: D::Points(200.0), height: D::Undefined }, + // size: Size { width: FIFTY_PC, height: D::Auto } + // )] + // button1: nwg::Button, + // + // #[nwg_control(text: "Btn 2")] + // #[nwg_layout_item(layout: layout, + // margin: MARGIN, + // align_self: AlignSelf::FlexEnd, + // size: Size { width: D::Percent(0.25), height: FIFTY_PC } + // )] + // button2: nwg::Button, + // + // #[nwg_control(text: "Btn 3")] + // #[nwg_layout_item(layout: layout, + // margin: MARGIN, + // flex_grow: 2.0, + // size: Size { width: D::Auto, height: D::Auto } + // )] + // button3: nwg::Button } impl AppUi { - fn on_init(&self) { - // TODO: rasterize via nsvg - // FIXME - let decoded = self.decoder.from_stream(BANNER_IMAGE_DATA).unwrap(); - let image_data = decoded.frame(0).unwrap(); - let mut bitmap = self.banner_image_bitmap.borrow_mut(); + fn on_init(&self) { + // TODO: rasterize via nsvg + // FIXME + let decoded = self.decoder.from_stream(BANNER_IMAGE_DATA).unwrap(); + let image_data = decoded.frame(0).unwrap(); if let Ok(bitmap) = decoded.frame(0).and_then(|frame| frame.as_bitmap()) { - let mut img = self.banner_image_bitmap.borrow_mut(); - img.replace(bitmap); - self.banner_image.set_bitmap(img.as_ref()); + let mut img = self.banner_image_bitmap.borrow_mut(); + img.replace(bitmap); + self.banner_image.set_bitmap(img.as_ref()); } - } + } fn say_hello(&self) { - //nwg::modal_info_message(&self.window, "Hello", &format!("Hello {}", self.name_edit.text())); + // nwg::modal_info_message(&self.window, "Hello", &format!("Hello {}", + // self.name_edit.text())); } - + fn on_close(&self) { - //nwg::modal_info_message(&self.window, "Goodbye", &format!("Goodbye {}", self.name_edit.text())); + // nwg::modal_info_message(&self.window, "Goodbye", &format!("Goodbye {}", + // self.name_edit.text())); nwg::stop_thread_dispatch(); } } @@ -113,6 +106,6 @@ pub fn main() { nwg::Font::set_global_family("Segoe UI").expect("Failed to set default font"); let _ui = AppUi::build_ui(Default::default()).expect("Failed to build UI"); - + nwg::dispatch_thread_events(); }