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 ability to override collapsing icons #1147

Merged
merged 4 commits into from
Jan 22, 2022

Conversation

juancampa
Copy link
Contributor

@juancampa juancampa commented Jan 21, 2022

I wanted custom icons for my tree so I added the ability to override's CollapsingHeader's icon by passing a function that gets called instead of paint_icon.

I personally like the pointy triangles but not the fact that they get thicker on hover.

Let's discuss if this is the best approach or if there's something better (e.g. implementing an Icon trait or something). I can add a demo if we decide to move forward.

2022-01-21.17-54-29.mp4

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Very nice, simple idea. I love it!

Only some minor nits and a clippy error to fix.

@@ -141,6 +141,7 @@ pub struct CollapsingHeader {
selectable: bool,
selected: bool,
show_background: bool,
icon: Option<Box<dyn FnOnce(&mut Ui, f32, &Response)>>,
Copy link
Owner

Choose a reason for hiding this comment

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

pub type IconPainter = Box<dyn FnOnce(&mut Ui, f32, &Response)>; with a nice docstring would make this type simpler, and silence clippy

Copy link
Contributor Author

@juancampa juancampa Jan 22, 2022

Choose a reason for hiding this comment

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

I added the type alias and used it here.

I didn't use it in the icon function to keep the API simple (that way caller doesn't have to use Box::new). If trait aliases ever get stabilized we could use that, but who knows if that will ever happen.

egui/src/containers/collapsing_header.rs Outdated Show resolved Hide resolved
egui/src/containers/collapsing_header.rs Outdated Show resolved Hide resolved
egui/src/containers/collapsing_header.rs Outdated Show resolved Hide resolved
@juancampa juancampa requested a review from emilk January 22, 2022 09:19
@emilk emilk merged commit 343f7da into emilk:master Jan 22, 2022
@juancampa juancampa deleted the custom-collapsing-icons branch January 22, 2022 09:39
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