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

Add the LifeCycle::Size event. #953

Merged
merged 1 commit into from
May 17, 2020
Merged

Conversation

xStrom
Copy link
Member

@xStrom xStrom commented May 17, 2020

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.

@xStrom xStrom added the S-needs-review waits for review label May 17, 2020
Copy link
Collaborator

@luleyleo luleyleo left a 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.

druid/src/core.rs Outdated Show resolved Hide resolved
@luleyleo luleyleo added S-waiting-on-author waits for changes from the submitter and removed S-needs-review waits for review labels May 17, 2020
@xStrom xStrom removed the S-waiting-on-author waits for changes from the submitter label May 17, 2020
@xStrom xStrom merged commit 7955f76 into linebender:master May 17, 2020
@xStrom xStrom deleted the size-changed branch May 17, 2020 13:43
Copy link
Member

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

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);
Copy link
Member

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 {
Copy link
Member

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

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.

3 participants