Skip to content
Snippets Groups Projects
Unverified Commit e013fb9e authored by Ygg01's avatar Ygg01
Browse files

Fix proc macro

parent 2571f642
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ const PROPS_HELPER_IDENT: &str = "prop_field"; ...@@ -13,6 +13,7 @@ const PROPS_HELPER_IDENT: &str = "prop_field";
const PROP_CHILDREN: &str = "Children"; const PROP_CHILDREN: &str = "Children";
const PROP_STYLE: &str = "Styles"; const PROP_STYLE: &str = "Styles";
const PROP_ON_EVENT: &str = "OnEvent"; const PROP_ON_EVENT: &str = "OnEvent";
const PROP_ON_LAYOUT: &str = "OnLayout";
const PROP_FOCUSABLE: &str = "Focusable"; const PROP_FOCUSABLE: &str = "Focusable";
#[derive(Default)] #[derive(Default)]
...@@ -20,6 +21,7 @@ struct PropsHelpers { ...@@ -20,6 +21,7 @@ struct PropsHelpers {
children_ident: Option<Ident>, children_ident: Option<Ident>,
styles_ident: Option<Ident>, styles_ident: Option<Ident>,
on_event_ident: Option<Ident>, on_event_ident: Option<Ident>,
on_layout_ident: Option<Ident>,
focusable_ident: Option<Ident>, focusable_ident: Option<Ident>,
} }
...@@ -43,6 +45,7 @@ pub(crate) fn impl_widget_props(input: TokenStream) -> TokenStream { ...@@ -43,6 +45,7 @@ pub(crate) fn impl_widget_props(input: TokenStream) -> TokenStream {
let children_return = quote_clone_field(helpers.children_ident); let children_return = quote_clone_field(helpers.children_ident);
let styles_return = quote_clone_field(helpers.styles_ident); let styles_return = quote_clone_field(helpers.styles_ident);
let on_event_return = quote_clone_field(helpers.on_event_ident); let on_event_return = quote_clone_field(helpers.on_event_ident);
let on_layout_return = quote_clone_field(helpers.on_layout_ident);
let focusable_return = quote_clone_field(helpers.focusable_ident); let focusable_return = quote_clone_field(helpers.focusable_ident);
let kayak_core = get_core_crate(); let kayak_core = get_core_crate();
...@@ -65,6 +68,10 @@ pub(crate) fn impl_widget_props(input: TokenStream) -> TokenStream { ...@@ -65,6 +68,10 @@ pub(crate) fn impl_widget_props(input: TokenStream) -> TokenStream {
#on_event_return #on_event_return
} }
fn get_on_layout(&self) -> Option<#kayak_core::OnLayout> {
#on_layout_return
}
fn get_focusable(&self) -> Option<bool> { fn get_focusable(&self) -> Option<bool> {
#focusable_return #focusable_return
} }
...@@ -125,6 +132,7 @@ fn process_field(field: Field, props: &mut PropsHelpers) { ...@@ -125,6 +132,7 @@ fn process_field(field: Field, props: &mut PropsHelpers) {
PROP_CHILDREN => props.children_ident = field.ident.clone(), PROP_CHILDREN => props.children_ident = field.ident.clone(),
PROP_STYLE => props.styles_ident = field.ident.clone(), PROP_STYLE => props.styles_ident = field.ident.clone(),
PROP_ON_EVENT => props.on_event_ident = field.ident.clone(), PROP_ON_EVENT => props.on_event_ident = field.ident.clone(),
PROP_ON_LAYOUT => props.on_layout_ident = field.ident.clone(),
PROP_FOCUSABLE => props.focusable_ident = field.ident.clone(), PROP_FOCUSABLE => props.focusable_ident = field.ident.clone(),
err => emit_error!(err.span(), "Invalid attribute: {}", err), err => emit_error!(err.span(), "Invalid attribute: {}", err),
} }
......
...@@ -2,7 +2,7 @@ use crate::core::{ ...@@ -2,7 +2,7 @@ use crate::core::{
render_command::RenderCommand, render_command::RenderCommand,
rsx, rsx,
styles::{Corner, Style, StyleProp, Units}, styles::{Corner, Style, StyleProp, Units},
widget, Children, Color, Fragment, OnEvent, WidgetProps, widget, Children, Color, Fragment, OnEvent, OnLayout, WidgetProps,
}; };
use kayak_core::CursorIcon; use kayak_core::CursorIcon;
...@@ -17,6 +17,7 @@ pub struct ButtonProps { ...@@ -17,6 +17,7 @@ pub struct ButtonProps {
pub styles: Option<Style>, pub styles: Option<Style>,
pub children: Option<Children>, pub children: Option<Children>,
pub on_event: Option<OnEvent>, pub on_event: Option<OnEvent>,
pub on_layout: Option<OnLayout>,
pub focusable: Option<bool>, pub focusable: Option<bool>,
} }
...@@ -37,6 +38,10 @@ impl WidgetProps for ButtonProps { ...@@ -37,6 +38,10 @@ impl WidgetProps for ButtonProps {
self.on_event.clone() self.on_event.clone()
} }
fn get_on_layout(&self) -> Option<OnLayout> {
self.on_layout.clone()
}
fn get_focusable(&self) -> Option<bool> { fn get_focusable(&self) -> Option<bool> {
Some(!self.disabled) Some(!self.disabled)
} }
......
...@@ -4,7 +4,7 @@ use crate::core::{ ...@@ -4,7 +4,7 @@ use crate::core::{
styles::{Corner, Style, Units}, styles::{Corner, Style, Units},
widget, Bound, Children, Color, EventType, MutableBound, OnEvent, WidgetProps, widget, Bound, Children, Color, EventType, MutableBound, OnEvent, WidgetProps,
}; };
use kayak_core::CursorIcon; use kayak_core::{CursorIcon, OnLayout};
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use crate::widgets::{Background, Clip, Text}; use crate::widgets::{Background, Clip, Text};
...@@ -26,6 +26,7 @@ pub struct TextBoxProps { ...@@ -26,6 +26,7 @@ pub struct TextBoxProps {
pub styles: Option<Style>, pub styles: Option<Style>,
pub children: Option<Children>, pub children: Option<Children>,
pub on_event: Option<OnEvent>, pub on_event: Option<OnEvent>,
pub on_layout: Option<OnLayout>,
pub focusable: Option<bool>, pub focusable: Option<bool>,
} }
...@@ -46,6 +47,10 @@ impl WidgetProps for TextBoxProps { ...@@ -46,6 +47,10 @@ impl WidgetProps for TextBoxProps {
self.on_event.clone() self.on_event.clone()
} }
fn get_on_layout(&self) -> Option<OnLayout> {
self.on_layout.clone()
}
fn get_focusable(&self) -> Option<bool> { fn get_focusable(&self) -> Option<bool> {
Some(!self.disabled) Some(!self.disabled)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment