-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Fix up codegen #52
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some general thoughts
let (fill, stroke, stroke_width) = props.icon.fill_and_stroke(&props.fill); | ||
|
||
let id = props.id.unwrap_or_default(); | ||
let width = if props.width == 0 { props.icon.width() } else { &props.width.to_string() }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let width = if props.width == 0 { props.icon.width() } else { &props.width.to_string() }; | |
let width = props.icon.width().unwrap_or(props.width); |
#[props(default = 0)] | ||
pub width: u32, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[props(default = 0)] | |
pub width: u32, | |
pub width: Option<u32>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth changing width and height input to String to allow for unit identifiers? Or even implement it as an Enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String
sounds better IMO
@@ -18,18 +15,33 @@ impl IconShape for {ICON_NAME} { | |||
fn view_box(&self) -> &str { | |||
"{VIEW_BOX}" | |||
} | |||
fn width(&self) -> &str { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn width(&self) -> &str { | |
fn width(&self) -> u32{ |
I decided to have a crack at fixing up the codegen a bit, getting rid of hard-coded values.
Values like width, height, fill, stroke, stroke-width, stroke-linecap, stroke-linejoin etc are now fetched from attributes instead of essentially being hard-coded values.
Also made some changes to the Icon struct to take options for some values instead of hard-coded string defaults so we can dynamically choose between user-input and icon defaults.
The svg parsing could do with being reworked to support svg's which have more than one parent element. Maybe in the future could add support for new features/attributes.