Skip to content
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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

norrchr
Copy link

@norrchr norrchr commented Jul 10, 2024

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.

@marc2332 marc2332 added the enhancement New feature or request label Jul 11, 2024
@marc2332 marc2332 marked this pull request as draft July 11, 2024 21:16
@norrchr norrchr marked this pull request as ready for review July 15, 2024 04:18
Copy link
Member

@marc2332 marc2332 left a 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() };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let width = if props.width == 0 { props.icon.width() } else { &props.width.to_string() };
let width = props.icon.width().unwrap_or(props.width);

Comment on lines +32 to 33
#[props(default = 0)]
pub width: u32,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#[props(default = 0)]
pub width: u32,
pub width: Option<u32>,

Copy link
Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String sounds better IMO

packages/lib/src/icon_component.rs Outdated Show resolved Hide resolved
@@ -18,18 +15,33 @@ impl IconShape for {ICON_NAME} {
fn view_box(&self) -> &str {
"{VIEW_BOX}"
}
fn width(&self) -> &str {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn width(&self) -> &str {
fn width(&self) -> u32{

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants