Skip to content

Commit

Permalink
fixup: windows, nwi
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Feb 1, 2025
1 parent 06fbd47 commit c05c59b
Showing 1 changed file with 56 additions and 63 deletions.
119 changes: 56 additions & 63 deletions installer-downloader/src/winapi_impl/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<D> = Rect{ start: PT_10, end: PT_10, top: PT_10, bottom: PT_10 };
const MARGIN: Rect<D> = 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<D> = Rect{ start: PT_10, end: PT_10, top: PT_10, bottom: PT_10 };
// const MARGIN: Rect<D> = 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")]
Expand All @@ -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<Option<nwg::Bitmap>>,

#[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();
}
}
Expand All @@ -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();
}

0 comments on commit c05c59b

Please sign in to comment.