Odd for someone that worked with C++ for a while at least.
use winsafe::co::BS;
use winsafe::{self as w, gui, msg, prelude::*};
fn main() {
let main_window = Window::new();
if let Err(e) = main_window.wnd.run_main(None) {
eprintln!("main_window.run_main() error: {}", e);
}
}
#[derive(Clone)]
pub struct Window {
wnd: gui::WindowMain,
btn_install: gui::Button,
}
struct Common {
left: i32,
top: i32,
center_width: u32,
center_height: u32,
}
impl Window {
pub fn new() -> Self {
let mut common = Common {
left: 0,
top: 0,
center_width: 0,
center_height: 0,
};
let wnd = gui::WindowMain::new(gui::WindowMainOpts {
title: "Example".to_owned(),
size: (800, 600),
..Default::default()
});
wnd.on().wm_create(move |p: msg::wm::Create| -> w::AnyResult<i32> {
println!("Created window");
common.left = p.createstruct.x;
common.top = p.createstruct.y;
common.center_width = (common.left / 2) as u32;
common.center_height = (common.top / 2) as u32;
println!("Left: {} Top: {}", common.left, common.top);
Ok(0)
});
let btn_install = gui::Button::new(&wnd, gui::ButtonOpts {
text: "&Install".to_owned(),
position: (common.left, common.top),
button_style: BS::FLAT,
width: common.center_width,
height: common.center_height,
..Default::default()
});
let window_self = Self { wnd, btn_install };
window_self.events();
window_self
}
fn events(&self) {
let wnd = self.wnd.clone();
self.btn_install.on().bn_clicked(move || {
wnd.hwnd().SetWindowText("It registered a click!")?;
Ok(())
});
}
}