From 9327dcf204ee4782430beec215afa9d12d223c81 Mon Sep 17 00:00:00 2001 From: snuk182 Date: Wed, 29 Nov 2017 23:31:57 +0100 Subject: [PATCH] Initial commit --- Cargo.toml | 22 +++ build.rs | 5 + plygui.manifest | 33 ++++ plygui.rc | 2 + rustfmt.toml | 1 + src/application.rs | 65 ++++++ src/button.rs | 267 +++++++++++++++++++++++++ src/common.rs | 408 ++++++++++++++++++++++++++++++++++++++ src/layout_linear.rs | 435 +++++++++++++++++++++++++++++++++++++++++ src/layout_relative.rs | 5 + src/lib.rs | 31 +++ src/window.rs | 282 ++++++++++++++++++++++++++ 12 files changed, 1556 insertions(+) create mode 100644 Cargo.toml create mode 100644 build.rs create mode 100644 plygui.manifest create mode 100644 plygui.rc create mode 100644 rustfmt.toml create mode 100644 src/application.rs create mode 100644 src/button.rs create mode 100644 src/common.rs create mode 100644 src/layout_linear.rs create mode 100644 src/layout_relative.rs create mode 100644 src/lib.rs create mode 100644 src/window.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..7bd9433 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "plygui-win32" +version = "0.0.1" +authors = ["Serhii Plyhun "] + +[lib] +name = "plygui_win32" +path = "src/lib.rs" + +[dependencies] +plygui = {version = "0.0.1", path = "../plygui"} +user32-sys = "~0.2" +gdi32-sys = "~0.2" +kernel32-sys = "~0.2" +comctl32-sys = "~0.2" +comdlg32-sys = "~0.2" +winapi = "~0.2" +lazy_static = "~0.2" +derive_builder = "~0.5" + +[build-dependencies] +embed-resource = "~1.1" \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..9674400 --- /dev/null +++ b/build.rs @@ -0,0 +1,5 @@ +extern crate embed_resource; + +fn main() { + embed_resource::compile("plygui.rc"); +} \ No newline at end of file diff --git a/plygui.manifest b/plygui.manifest new file mode 100644 index 0000000..b0ee38f --- /dev/null +++ b/plygui.manifest @@ -0,0 +1,33 @@ + + + + Plygui + + + + + + + + + + + + + + + + + + + true + + + + diff --git a/plygui.rc b/plygui.rc new file mode 100644 index 0000000..19b4adc --- /dev/null +++ b/plygui.rc @@ -0,0 +1,2 @@ +#define RT_MANIFEST 24 +1 RT_MANIFEST "plygui.manifest" \ No newline at end of file diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..61d8e96 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +max_width = 250 diff --git a/src/application.rs b/src/application.rs new file mode 100644 index 0000000..1b21cbd --- /dev/null +++ b/src/application.rs @@ -0,0 +1,65 @@ +use super::*; +use super::common::WindowsContainer; + +use std::{mem, thread}; + +use plygui::{Id, UiApplication, UiWindow}; + +pub struct Application { + name: String, + windows: Vec, +} + +impl UiApplication for Application { + fn new_window(&mut self, title: &str, width: u16, height: u16, has_menu: bool) -> Box { + let w = Window::new(title, width, height, has_menu); + unsafe { + self.windows.push(w.hwnd()); + } + w + } + fn name(&self) -> &str { + self.name.as_str() + } + fn start(&mut self) { + for i in (0..self.windows.len()).rev() { + if i > 0 { + thread::spawn(move || {}); + } else { + start_window(self.windows[i]); + } + } + } +} + +impl Application { + pub fn with_name(name: &str) -> Box { + init_comctl(); + Id::next(); + Box::new(Application { + name: name.into(), + windows: Vec::with_capacity(1), + }) + } +} + +fn start_window(hwnd: winapi::HWND) { + let w: &mut Window = unsafe { mem::transmute(user32::GetWindowLongPtrW(hwnd, winapi::GWLP_USERDATA)) }; + w.start(); +} + +fn init_comctl() { + unsafe { + let mut icc: winapi::INITCOMMONCONTROLSEX = mem::zeroed(); + icc.dwSize = mem::size_of::() as u32; + icc.dwICC = winapi::ICC_STANDARD_CLASSES + | winapi::ICC_LISTVIEW_CLASSES + | winapi::ICC_TAB_CLASSES + | winapi::ICC_PROGRESS_CLASS + | winapi::ICC_UPDOWN_CLASS + | winapi::ICC_BAR_CLASSES; + if comctl32::InitCommonControlsEx(&icc) == 0 { + common::log_error(); + } + } +} \ No newline at end of file diff --git a/src/button.rs b/src/button.rs new file mode 100644 index 0000000..317684c --- /dev/null +++ b/src/button.rs @@ -0,0 +1,267 @@ +use super::*; + +use plygui::{layout, Id, UiRole, UiRoleMut, Visibility, UiControl, UiButton, UiMember, UiContainer}; + +use std::{ptr, mem, str}; +use std::os::raw::c_void; +use std::os::windows::ffi::OsStrExt; +use std::ffi::OsStr; + +pub const CLASS_ID: &str = "Button"; + +lazy_static! { + pub static ref WINDOW_CLASS: Vec = OsStr::new(CLASS_ID) + .encode_wide() + .chain(Some(0).into_iter()) + .collect::>(); +} + +#[repr(C)] +pub struct Button { + base: common::WindowsControlBase, + label: String, + h_left_clicked: Option>, +} + +impl Button { + pub fn new(label: &str) -> Box