Skip to content

Commit 4ad3fd8

Browse files
committed
Refactoring column tag
1 parent 82b40eb commit 4ad3fd8

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

efx/src/tags/column.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use proc_macro2::TokenStream;
21
use efx_core::Element;
2+
use proc_macro2::TokenStream;
33
use quote::{ToTokens, quote};
44

55
use crate::render::render_nodes_as_stmts;
6-
use crate::tags::{TagAttributes, Tagged};
76
use crate::tags::util::{attr_map, f32_opt};
7+
use crate::tags::{TagAttributes, Tagged};
88

99
pub struct Column;
1010

@@ -33,11 +33,25 @@ impl Tagged for Column {
3333
epilog.extend(quote! { #ui.add_space(#p as f32); });
3434
}
3535

36+
let content = Column::content(ui, el, attributes);
37+
38+
quote! {
39+
{
40+
#prolog
41+
#content
42+
#epilog
43+
}
44+
}
45+
}
46+
}
47+
48+
impl Column {
49+
fn content<UI: ToTokens>(ui: &UI, el: &Element, attributes: Attributes) -> TokenStream {
3650
let body = render_nodes_as_stmts(&quote!(ui), &el.children);
3751

3852
// align: left|center|right → egui::Align::{Min,Center,Max} in Layout::top_down(...)
39-
let content = if let Some(al) = attributes.align {
40-
let align_expr = match al.as_str() {
53+
if let Some(align) = attributes.align {
54+
let align_expr = match align.as_str() {
4155
"left" => quote!(::egui::Align::Min),
4256
"right" => quote!(::egui::Align::Max),
4357
"center" => quote!(::egui::Align::Center),
@@ -59,14 +73,6 @@ impl Tagged for Column {
5973
#body
6074
});
6175
}
62-
};
63-
64-
quote! {
65-
{
66-
#prolog
67-
#content
68-
#epilog
69-
}
7076
}
7177
}
7278
}

0 commit comments

Comments
 (0)