Skip to content

Commit

Permalink
merge 1.0 with master
Browse files Browse the repository at this point in the history
  • Loading branch information
gabdube committed Jul 19, 2020
2 parents c6c9c62 + 96ce5c9 commit fa9166f
Show file tree
Hide file tree
Showing 207 changed files with 37,175 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: gabdube
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
**/target
**/*.rs.bk
**/examples/test.rs
Cargo.lock
code
native-windows-docs/tmp.*
.vs
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[workspace]

members = [
"native-windows-gui",
"native-windows-derive",
"native-windows-gui\\examples\\opengl_canvas",
"native-windows-gui\\examples\\embed_resources",
"native-windows-gui\\examples\\sync-draw",
]

[profile.dev]
panic = 'abort'

[profile.release]
panic = 'abort'
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Gabriel Dube

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions native-windows-derive/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target
**/*.rs.bk
Cargo.lock
13 changes: 13 additions & 0 deletions native-windows-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "native-windows-derive"
version = "0.1.0"
authors = ["gdube <[email protected]>"]
edition = "2018"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = "1.0"
syn = { version = "1.0", features = ["extra-traits", "full"]}
quote = "1.0"
71 changes: 71 additions & 0 deletions native-windows-derive/src/controls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use crate::shared::Parameters;

pub fn parameters(field: &syn::Field, attr_id: &'static str) -> (Vec<syn::Ident>, Vec<syn::Expr>) {
let member = match field.ident.as_ref() {
Some(m) => m,
None => unreachable!()
};

let nwg_control = |attr: &&syn::Attribute| {
attr.path.get_ident()
.map(|id| id == attr_id )
.unwrap_or(false)
};

let attr = match field.attrs.iter().find(nwg_control) {
Some(attr) => attr,
None => unreachable!()
};

let ctrl: Parameters = match syn::parse2(attr.tokens.clone()) {
Ok(a) => a,
Err(e) => panic!("Failed to parse field #{}: {}", member, e)
};

let params = ctrl.params;
let mut names = Vec::with_capacity(params.len());
let mut exprs = Vec::with_capacity(params.len());

for p in params {
if p.ident == "ty" {
continue;
}

names.push(p.ident);
exprs.push(p.e);
}

(names, exprs)
}

pub fn expand_flags(member_name: &syn::Ident, ty: &syn::Ident, flags: syn::Expr) -> syn::Expr {
let flags_type = format!("{}Flags", ty);

let flags_value = match &flags {
syn::Expr::Lit(expr_lit) => match &expr_lit.lit {
syn::Lit::Str(value) => value,
other => panic!("Compressed flags must str, got {:?} for control {}", other, member_name)
},
other => panic!("Compressed flags must str, got {:?} for control {}", other, member_name)
};

let flags = flags_value.value();
let splitted: Vec<&str> = flags.split('|').collect();

let flags_count = splitted.len() - 1;
let mut final_flags: String = String::with_capacity(100);
for (i, value) in splitted.into_iter().enumerate() {
final_flags.push_str(&flags_type);
final_flags.push_str("::");
final_flags.push_str(value);

if i != flags_count {
final_flags.push('|');
}
}

match syn::parse_str(&final_flags) {
Ok(e) => e,
Err(e) => panic!("Failed to parse flags value for control {}: {}", member_name, e)
}
}
Loading

0 comments on commit fa9166f

Please sign in to comment.