-
Notifications
You must be signed in to change notification settings - Fork 1.7k
added splitter #1028
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
base: main
Are you sure you want to change the base?
added splitter #1028
Conversation
This is awesome. Just tried the demo and I have a few suggestions:
Splitter::with_orientation(self.splitter_orientation)
.ratio(self.splitter_ratio)
.show(
ui,
|ui| {
ui.label("Left/Top");
ui.label("Left/Top");
ui.label("Left/Top");
},
|ui| {
ui.label("Right/Bottom");
ui.label("Right/Bottom");
ui.label("Right/Bottom");
},
);
|
Thanks! I'm glad you like it!
Well, the reason I originally went with 2 closures is that emilk suggested it as an API in the original issue where this was discussed. I also personally prefer it, as there's no question about which order the closures will be called in and so on.
Sounds like a useful feature, but to be honest I'm kind of scared at the math needed for this. Also I'm not sure how I'd fit it in alongside the current ratio implementation.
That sounds like a great idea! Although I'm not quite sure if the intended way of doing this kinda thing Isn't just to place the widget inside one that restricts its available space. Also this would make the API a bit less flexible for users who "just want a splitter" and don't really care all that much about precise layout and figuring out dimensions.
That sounds like it would be a good way to go about fixing the clipping issue. I think that's worth doing, although I should probably add a way for the caller to disable this so they can figure out their own layouts and have more freedom. BTW if you feel like working on this, you'd be more than welcome! Feel free to just open a PR on my fork on the |
This will create borrowing issues, so I don't think it is a good idea. |
That is a great point! It can be resolved by providing two Splitter::with_orientation(self.splitter_orientation)
.ratio(self.splitter_ratio)
.show_left(ui, |ui| {
ui.label("Left/Top");
ui.label("Left/Top");
ui.label("Left/Top");
})
.show_right(ui, |ui| {
ui.label("Right/Bottom");
ui.label("Right/Bottom");
ui.label("Right/Bottom");
}); It also resolves the other issue about ordering. In this case, |
This sounds completely reasonable. I would want the demo to include such a wrapper (and of course, documentation) so that it is obvious that the expectation is for the user to allocate space in some way. Adding a spitter to some container is a fine way to allocate space without really caring to define dimensions. (This is what the demo currently does in this PR; |
Well, a big part of the reason I'm using only 1 closure is the response type that /// The response of showing a Splitter
pub struct SplitterResponse<R> {
/// The return value of the closure passed into show.
pub body_returned: R,
/// The response of the top or left UI depending on the splitter's orientation.
pub top_left_response: Response,
/// The response of the bottom or right UI depending on the splitter's orientation.
pub bottom_right_response: Response,
/// The response of the whole splitter widget.
pub splitter_response: Response,
} With a show method that takes 2 closures, we'd need 2 fields (and 2 generic parameters) for the return type of both the closures. If we had 2 show functions, I'm not sure how we could make them chainable like you suggested, since that would make this response handling pretty much impossible. |
Here's a prototype: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7b292915dc28bd21554bbc7457317545 It only adds minor complexity. But I think the improvement to ergonomics are worth it. |
I don't really like this. I think this is just more complex than it needs to be. Also this requires calling |
I don't think any of those are
8000
showstoppers. You can reverse the call order with another intermediate struct. If you want to set a variable in one side and use it in the other, you can just capture it in both closures (like |
I like that suggestion! Also, that way you can handle scrollables in a graceful way: impl Splitter {
// Only content, without wrapping into a scrollable area
fn show_first<R>(...) -> R { ... }
fn show_second<R>(...) -> R { ... }
// Wraps content into a scrollable area
fn show_scrollable_first<R>(...) -> R { ... }
fn show_scrollable_second<R>(...) -> R { ... }
} Also, I think it is better to use neutral words |
Closes #944.
The splitter currently still has some issues, which I'm not quite sure how to fix:
Guidance would be much appreciated!