Skip to content

Conversation

@acul009
Copy link

@acul009 acul009 commented Sep 27, 2025

This just adds the FromScreensize option to the window settings size.

I used the positioning option as a base.

I use this for my drowdown terminal, so the window size is automatically set.

@pml68
Copy link
Contributor

pml68 commented Sep 27, 2025

I think you could use fn(Size) -> Size in the added variant to avoid the Arc, since Position::SpecificWith also just uses a function pointer (which is Send, Sync and Copy)

@acul009
Copy link
Author

acul009 commented Sep 27, 2025

I think you could use fn(Size) -> Size in the added variant to avoid the Arc, since Position::SpecificWith also just uses a function pointer (which is Send, Sync and Copy)

I did in the original PR, but for the tester I need to support closures, since I need to make the window wider than it would otherwise be:

iced/tester/src/lib.rs

Lines 67 to 72 in 0a34496

fn window(&self) -> Option<window::Settings> {
self.program.window().map(|window| window::Settings {
size: window.size + Size::new(300.0, 80.0),
..window
})
}

impl Add<crate::Size> for Size {
type Output = Self;
fn add(self, other: crate::Size) -> Self {
match self {
Self::Fixed(size) => Self::Fixed(size + other),
Self::FromScreensize(func) => {
Self::from_screen_size(move |size| func(size) + other)
}
}
}
}

The only other solution I could think of, would be to ignore the variable window size when the tester is used.
Maybe you have a better idea?

@pml68
Copy link
Contributor

pml68 commented Sep 27, 2025

Hmm

You could add an extra field to the variant which contains extra size, but that could make it a bit confusing to use, or just plain ugly.

@acul009
Copy link
Author

acul009 commented Oct 9, 2025

Hmm

You could add an extra field to the variant which contains extra size, but that could make it a bit confusing to use, or just plain ugly.

The current API isn't really all user friendly either.
I added a helper function, but the enum variant is still there and requires a manual Arc.
It's not obvious you should use the helper.

@pml68 What do you think about creating a wrapper struct to hide the enum variants?
Then I'd just expose helper functions and nothing else.
That way I wouldn't expose any weird enum variants.

pub struct Size( pub(crate) SizeVariant)

Not sure these enum in struct types fir with the iced style.

@pml68
Copy link
Contributor

pml68 commented Oct 10, 2025

@pml68 What do you think about creating a wrapper struct to hide the enum variants? Then I'd just expose helper functions and nothing else. That way I wouldn't expose any weird enum variants.

pub struct Size( pub(crate) SizeVariant)

Hmm not sure honestly. I can't really think of a better way, but I wonder what Héctor would think about the proposed solutions (user has to Arc / hidden enum / some other solution to the test recorder-size adding problem)

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.

2 participants