Skip to content

Commit 9c5af56

Browse files
committed
Added AttrNames to Column & Row
1 parent 24eb2e6 commit 9c5af56

6 files changed

Lines changed: 15 additions & 23 deletions

File tree

efx-attrnames/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ proc-macro = true
1111

1212
[dependencies]
1313
quote = "1.0"
14-
proc-macro2 = "1.0"
1514
syn = { version = "2.0", features = ["full"] }

efx-attrnames/src/lib.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use proc_macro::TokenStream;
44
use quote::quote;
5-
use syn::{parse_macro_input, DeriveInput, Data, Fields, Meta, Lit, LitStr};
5+
use syn::{Data, DeriveInput, Fields, LitStr, parse_macro_input};
66

77
/// Derive for generating `ATTR_NAMES` constant for attribute structure.
88
/// Supports field renaming via `#[attr(name = "align")]`.
@@ -20,17 +20,14 @@ pub fn derive_attr_names(input: TokenStream) -> TokenStream {
2020
&st.fields,
2121
"AttrNames supports only structs with named fields",
2222
)
23-
.to_compile_error()
24-
.into()
23+
.to_compile_error()
24+
.into();
2525
}
2626
},
2727
_ => {
28-
return syn::Error::new_spanned(
29-
&input.ident,
30-
"AttrNames supports only structs",
31-
)
28+
return syn::Error::new_spanned(&input.ident, "AttrNames supports only structs")
3229
.to_compile_error()
33-
.into()
30+
.into();
3431
}
3532
};
3633

@@ -41,12 +38,9 @@ pub fn derive_attr_names(input: TokenStream) -> TokenStream {
4138
let ident = match &f.ident {
4239
Some(id) => id,
4340
None => {
44-
return syn::Error::new_spanned(
45-
f,
46-
"expected named field",
47-
)
41+
return syn::Error::new_spanned(f, "expected named field")
4842
.to_compile_error()
49-
.into()
43+
.into();
5044
}
5145
};
5246

efx/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::buffer::build_buffer_from_children;
1818
use crate::input::EfxInput;
1919
use crate::render::render_nodes_as_stmts;
2020
use crate::tags::button::render_button;
21-
use efx_core::{parse_str, Node};
21+
use efx_core::{Node, parse_str};
2222

2323
/// Functional procedural macro `efx!` - parses compact XML-like markup
2424
/// and executes it against the passed UI context.

efx/src/render.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use proc_macro2::TokenStream;
21
use crate::tags::*;
32
use efx_core::{Element, Node};
3+
use proc_macro2::TokenStream;
44
use quote::{ToTokens, quote};
55

66
pub(crate) fn render_nodes_as_stmts<UI: ToTokens>(
@@ -64,7 +64,7 @@ fn render_element_stmt<UI: ToTokens>(ui: &UI, el: &Element) -> proc_macro2::Toke
6464

6565
fn render_tag<T: Tag>(ui: &impl ToTokens, el: &Element) -> TokenStream {
6666
match T::from_element(el) {
67-
Ok(tag) => tag.render(ui),
67+
Ok(tag) => tag.render(ui),
6868
Err(err) => err,
6969
}
7070
}

efx/src/tags/column.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use efx_core::Element;
22
use proc_macro2::TokenStream;
3-
use quote::{quote, ToTokens};
3+
use quote::{ToTokens, quote};
44

55
use crate::render::render_nodes_as_stmts;
66
use crate::tags::util::{attr_map, f32_opt};

efx/src/tags/row.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use efx_core::Element;
22
use proc_macro2::TokenStream;
3-
use quote::{quote, ToTokens};
4-
3+
use quote::{ToTokens, quote};
4+
use efx_attrnames::AttrNames;
55
use crate::render::render_nodes_as_stmts;
66
use crate::tags::util::{attr_map, bool_or, f32_opt};
77
use crate::tags::{Tag, TagAttributes};
@@ -90,7 +90,7 @@ impl Row {
9090
}
9191
}
9292

93-
#[derive(Clone, Debug)]
93+
#[derive(Clone, Debug, AttrNames)]
9494
struct Attributes {
9595
gap: Option<f32>,
9696
padding: Option<f32>,
@@ -100,8 +100,7 @@ struct Attributes {
100100

101101
impl TagAttributes for Attributes {
102102
fn new(el: &Element) -> Result<Self, TokenStream> {
103-
const KNOWN: &[&str] = &["gap", "padding", "align", "wrap"];
104-
let map = match attr_map(el, KNOWN, "Row") {
103+
let map = match attr_map(el, Attributes::ATTR_NAMES, "Row") {
105104
Ok(m) => m,
106105
Err(err) => return Err(err),
107106
};

0 commit comments

Comments
 (0)