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

Programmatically open / closing windows #3517

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft

Conversation

Norlock
Copy link

@Norlock Norlock commented Nov 1, 2023

This is an API redesign for events. You can open/close/hide/show the window programmatically keeping the borrow checker unlocked. I updated the demo application with two new buttons to showcase. Everything is still backwards compatible. I do favor to deprecate the .open() function.

Closes 358

Fixes: emilk#358

You can open / close windows programmatically to events. See demo about.

The good thing about the new API, is that it won't lock the
borrowchecker (unlike open). It's maybe a good idea to considering open
as deprecated.
e.g: display_event.set(DisplayEvent::ToggleCollapse);

To use so rust analyzer won't complain about not handling the return like in insert / replace
@Norlock Norlock changed the title Manually open / closing windows Programmatically open / closing windows Nov 1, 2023
Comment on lines 69 to 79
pub fn is_hidden(&self) -> bool {
self.state.hidden
}

pub fn toggle_hidden(&mut self) {
self.state.hidden = !self.state.hidden;
}

pub fn set_hidden(&mut self, hidden: bool) {
self.state.hidden = hidden;
}
Copy link
Owner

Choose a reason for hiding this comment

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

What does it mean for a CollapsingHeader to be hidden?

Copy link
Author

Choose a reason for hiding this comment

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

Well windows can become hidden, collapsing headers won't do anything but I will update the PR, so this code won't be accessible when not using a window. I also have made the same event option for normal widgets to expand/collapse which I will include in this PR as well.

Copy link
Author

@Norlock Norlock Nov 11, 2023

Choose a reason for hiding this comment

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

I added some comments to notify the dev that its only for window components. The API is not open to end users, I have made another branch where I split the two structs (see comments below).

Copy link
Author

@Norlock Norlock Nov 12, 2023

Choose a reason for hiding this comment

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

I build a split between the two states on this branch (draft): Norlock@40b1fb7#diff-817170c50650af7962ada22bb6459b20eeb54ce921043e4db8522368ccf8933e. I don't know if its a real improvement but you can check it out. If you prefer that version I can clean up the code a bit

@Norlock Norlock marked this pull request as draft November 11, 2023 18:35
@Norlock Norlock marked this pull request as ready for review November 11, 2023 20:43
Comment on lines +49 to +53
Expand,
Collapse,
Hide,
ToggleCollapse,
ToggleHidden,
Copy link
Owner

Choose a reason for hiding this comment

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

These need docstrings.

What does it mean to hide a window? Does it mean "Close"? If so, please name it that because "Close" is the antonym of "Open".

Comment on lines +56 to +57
// Helper function for user space
pub trait SetEvent {
Copy link
Owner

Choose a reason for hiding this comment

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

SetWindowEvent is probably a better name.

What would this be used for?

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.

Add methods to collapse a window
3 participants