-
Notifications
You must be signed in to change notification settings - Fork 567
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
Add the LifeCycle::Size event. #953
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.
Looks good, there seems to be a leftover typo in the docs you've edited.
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.
Just some observations, no change necessary
pub fn set_layout_rect(&mut self, ctx: &mut LayoutCtx, data: &T, env: &Env, layout_rect: Rect) { | ||
let mut needs_merge = false; | ||
|
||
let old_size = self.state.layout_rect.map(|r| r.size()); |
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.
surprised clippy didn't want .map(Rect::size)
.
|
||
let old_size = self.state.layout_rect.map(|r| r.size()); | ||
let new_size = layout_rect.size(); | ||
|
||
self.state.layout_rect = Some(layout_rect); |
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.
this feels like an opportunity for Option::replace
, maybe.
self.state.layout_rect = Some(layout_rect); | ||
|
||
if old_size.is_none() || old_size.unwrap() != new_size { |
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.
and I'd have written this as if old_size != Some(new_size)
, probably
There have been several occurrences now where a widget would like to know when its size changes and do some non-layout work. This was disccused in zulip and this would also help solve an animation issue with the
Scroll
widget as explained in #834.Thus this PR adds the
LifeCycle::Size
event which gets sent every time the size of the widget changes.