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

Support percent in config values for height and width #51

Closed
wants to merge 1 commit into from

Conversation

Arcadio-Buendia
Copy link

@Arcadio-Buendia Arcadio-Buendia commented Jun 28, 2021

I was unsure about where to put the function. config/params.rs seemed like the right place.

Resolves #25

};
if input.contains('%') {
return match input.trim().strip_suffix('%').unwrap().parse::<u32>() {
Ok(a) => (a * default) / 100,
Copy link
Owner

Choose a reason for hiding this comment

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

Unfortunately that won't work, current value is interpreted as pixels. Thus 80% will be converted to 80px (instead of expected 0.8 * screen_side).

Instead I'll suggest to create a separate type for width/height, like this:

enum SideSize {
    Absolute { pixels: u32 },
    Relative { ratio: f32 },
}

Then at the surface.rs SideSize::Relative should be converted into the absolute value.

Copy link
Author

Choose a reason for hiding this comment

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

I was thinking relative to the default values, So 80% would be converted to 320px for height.
I seem to have missed the intent.
I will try this new way.

Copy link
Owner

Choose a reason for hiding this comment

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

Indeed, some of issues are vaguely described, mostly because these are written for myself. Sorry for inconvenience, feel free to ask any question, if anything else is ambiguous.

None => return default,
};
if input.contains('%') {
return match input.trim().strip_suffix('%').unwrap().parse::<u32>() {
Copy link
Owner

Choose a reason for hiding this comment

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

  1. No need in trim there and below
  2. strip_prefix returns Option<&str> without specified suffix, so you don't need contains call above

fn parse_cent(input: Option<&String>, default: u32) -> u32 {
let input: String = match input {
Some(a) => a.split_whitespace().collect(),
None => return default,
Copy link
Owner

Choose a reason for hiding this comment

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

You still may return Option-s everywhere and at SurfaceParams call unwrap_or as before.

@l4l
Copy link
Owner

l4l commented Oct 11, 2022

There's no activity there for more than a year so I'm closing this. Feel free to open a new PR or update this one

@l4l l4l closed this Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support percent in config values
2 participants