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 hot glow option to multiwin example. #845

Merged
merged 1 commit into from
Apr 16, 2020

Conversation

xStrom
Copy link
Member

@xStrom xStrom commented Apr 14, 2020

This PR adds an option to the context menu of the multiwin example. When enabled the background turns red when the window is hot.

I've used it successfully to test the workings of hot state and I think it can be interesting to others as well. Also it will be useful for demonstrating various hot state issues that I plan to tackle in upcoming PRs.

@xStrom xStrom added examples concerns examples S-needs-review waits for review labels Apr 14, 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.

Now I've got another GTK issue to work on, the MouseLeave event seems to work only when leaving very slowly 🤔 I've two nit picks tho.
Thanks for the example!

Comment on lines 104 to 107
if matches!(event, LifeCycle::HotChanged(_)) {
ctx.request_paint();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consistency with other examples

Suggested change
if matches!(event, LifeCycle::HotChanged(_)) {
ctx.request_paint();
}
if let LifeCycle::HotChanged(_) = event {
ctx.request_paint();
}

) -> Size {
let size = self.inner.layout(ctx, bc, data, env);
self.inner.set_layout_rect(size.to_rect());
bc.max()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Returning size would make this container 'neutral' regarding layout, which seems more idiomatic to me

Suggested change
bc.max()
size

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably better with size indeed.

@xStrom xStrom merged commit fb0e8b8 into linebender:master Apr 16, 2020
@xStrom xStrom deleted the multiwin-hot branch April 16, 2020 12:37
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 notes that occur to me while looking over this, no changes needed

inner: WidgetPod<State, W>,
}

impl<W: Widget<State>> Glow<W> {
Copy link
Member

Choose a reason for hiding this comment

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

just a note: I think you could have achieved this using a Painter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps in some way, but it wasn't super obvious. Like the Painter docs state: If you would like it to repaint at other times (such as when hot or active state changes) you will need to call request_paint further up the tree. There's nothing further up the tree, so it wouldn't just be a Painter at least.

Copy link
Member

Choose a reason for hiding this comment

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

oh huh for some reason I thought it did repaint on hot. My mistake!

I wonder if it makes sense to just make 'paint on hot' be an option for painter? but that's a small thing.

}

struct Glow<W> {
inner: WidgetPod<State, W>,
Copy link
Member

Choose a reason for hiding this comment

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

if a widget is entirely transparent for the purposes of event handling and layout (it is just passing things through) then WidgetPod is unnecessary. It doesn't hurt in any meaningful way, but it is unnecessary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This really needs to be written down 😅

) -> Size {
let size = self.inner.layout(ctx, bc, data, env);
self.inner.set_layout_rect(ctx, data, env, size.to_rect());
size
Copy link
Member

Choose a reason for hiding this comment

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

a general note; I think it's good to call bc.constrain(size) anytime you return from layout, as a way of ensuring all returned sizes are appropriate for the constraints.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, my inspiration came from ControllerHost which does not do that, maybe open an Issue to make this consistent for all container?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples concerns examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants