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 TextFilter #658

Merged
merged 7 commits into from Oct 5, 2022
Merged

add TextFilter #658

merged 7 commits into from Oct 5, 2022

Conversation

tetenpapier
Copy link
Contributor

I opened the issue #649 to add TextFilter. I did it but I think it could be better. I'ven't found an example in the library so I tried something. I also added it in the test_window_impl to test.

@tetenpapier
Copy link
Contributor Author

I'm not sure about the path of the source file. I don't think it's a widget but idk where to put it.

@dbr
Copy link
Contributor

dbr commented Aug 12, 2022

Thanks for this! 🥳

I'm not sure about the path of the source file. I don't think it's a widget but idk where to put it.

I think probably just imgui/src/text_filter.rs seems best - it's similar to things like list_clipper.rs

imgui-examples/examples/test_window_impl.rs Show resolved Hide resolved
imgui/src/widget/text_filter.rs Outdated Show resolved Hide resolved
}
}

pub fn pass_filter_with_end(&self, mut start: String, mut end: String) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this method used for? It's not immediatly clear (..even looking at imgui.cpp!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't exactly know too.. I have to try it but I don't have time lately.


/// Returns true if the buffer matches the filter.
///
/// [`draw()`](Self::draw) or [`build()`](Self::build) mut be called **before** this function.
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if pass_filter is called without build? I guess imgui aborts?

If so, I wonder if it'd be worth adding some extra object so you do

fn draw(&'a mut self) -> &'a TextFilterHandle {
    ...
}
fn build(&'a mut self) -> &'a TextFilterHandle {

And since the pass_filter methods etc would be on that TextFilterHandle struct, it would be impossible to misuse (since you can't get at the pass_filter method without calling one of those methods)

Not a vital thing - there are plenty of ways to make imgui abort via the bindings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have tried to run pass_filter without build or draw in test_window_impl. It doesn't crash, just does nothing, like InputText without build. I just specify in the documentation that we have to call them before using the filter.

@dbr
Copy link
Contributor

dbr commented Aug 12, 2022

The CI failure in the Rust 1.54 checks is unrelated to PR

I think the x11-dl v2.20.0 (used by winit) now uses edition 2021 which isn't supported by Rust 1.54. We can probably just bump the MSRV to 1.56

@dbr dbr mentioned this pull request Aug 18, 2022
@dbr
Copy link
Contributor

dbr commented Oct 5, 2022

Thanks! This seems good to me, merging

There's some room for optimizing away the internally allocated String but this can be done later if someone finds it necessary!

@dbr dbr merged commit f1c87a1 into imgui-rs:main Oct 5, 2022
@dbr dbr mentioned this pull request Nov 22, 2022
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.

None yet

2 participants