Update to current winapi, split project

This commit is contained in:
Your Name
2024-08-25 22:24:06 -04:00
parent a647fc5186
commit 82153d31c9
18 changed files with 593 additions and 145 deletions

View File

@@ -0,0 +1,70 @@
extern crate native_windows_gui as nwg;
extern crate native_windows_derive as nwd;
use nwd::NwgUi;
use nwg::NativeUi;
#[derive(Default, NwgUi)]
pub struct BasicApp {
#[nwg_control(size: (300, 515), position: (300, 300), title: "Basic example", flags: "WINDOW")]
window: nwg::Window,
#[nwg_resource(source_file: Some("./res/muted.ico"))]
muted_icon: nwg::Icon,
#[nwg_resource(source_file: Some("./res/unmuted.ico"))]
unmuted_icon: nwg::Icon,
#[nwg_layout(parent: window, spacing: 1)]
grid: nwg::GridLayout,
#[nwg_control()]
#[nwg_layout_item(layout: grid, row: 0, col: 0)]
listbox: nwg::ListBox<String>,
#[nwg_control(text: "Test", size: (50, 50))]
#[nwg_layout_item(layout: grid, col: 0, row: 1, row_span: 2)]
hello_button: nwg::Button,
#[nwg_control(parent: window, popup: true)]
tray_menu: nwg::Menu,
#[nwg_control(parent: tray_menu, text: "Show")]
#[nwg_events(OnMenuItemSelected: [BasicApp::on_show])]
tray_show: nwg::MenuItem,
#[nwg_control(parent: tray_menu)]
tray_sep: nwg::MenuSeparator,
#[nwg_control(parent: tray_menu, text: "Exit")]
#[nwg_events(OnMenuItemSelected: [BasicApp::on_close])]
tray_exit: nwg::MenuItem,
#[nwg_control(icon: Some(&data.muted_icon))]
#[nwg_events( OnContextMenu: [BasicApp::on_menu] )]
tray: nwg::TrayNotification,
}
impl BasicApp {
fn on_close(&self) {
nwg::stop_thread_dispatch();
}
fn on_show(&self) {
self.window.set_visible(true);
self.listbox.set_collection(vec!["potato".to_string(), "good".to_string()]);
}
fn on_menu(&self) {
let (x, y) = nwg::GlobalCursor::position();
self.tray_menu.popup(x, y);
}
}
fn main() {
nwg::init().expect("Failed to init Native Windows GUI");
nwg::Font::set_global_family("Segoe UI").expect("Failed to set default font");
let _app = BasicApp::build_ui(Default::default()).expect("Failed to build UI");
nwg::dispatch_thread_events();
}