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

ComboBox select dialog goes offscreen whenever it is opened too low #693

Closed
TheSylex opened this issue Sep 2, 2021 · 2 comments · Fixed by #2303
Closed

ComboBox select dialog goes offscreen whenever it is opened too low #693

TheSylex opened this issue Sep 2, 2021 · 2 comments · Fixed by #2303
Labels
feature New feature or request

Comments

@TheSylex
Copy link

TheSylex commented Sep 2, 2021

Whenever you position a combobox too low on the screen, its select window goes out of the window, like this:
unknown
Instead it should move upwards to fit.

@emilk emilk added the feature New feature or request label Sep 28, 2021
@DrOptix
Copy link
Contributor

DrOptix commented Sep 29, 2021

For this one I think me need that layout size pre-process mentioned here in #606.

I'm facing the same issue while trying to use popup::popup_below_widget to show a popup when I click a button.
Seeing that ComboBox uses popup internally I tried to fix it.

The idea that I have is to compare ui.input().screen_rect() to the rect generated by the Area from here:

pub fn popup_below_widget<R>(
ui: &Ui,
popup_id: Id,
widget_response: &Response,
add_contents: impl FnOnce(&mut Ui) -> R,
) -> Option<R> {
if ui.memory().is_popup_open(popup_id) {
let parent_clip_rect = ui.clip_rect();
let inner = Area::new(popup_id)
.order(Order::Foreground)
.fixed_pos(widget_response.rect.left_bottom())
.show(ui.ctx(), |ui| {
ui.set_clip_rect(parent_clip_rect); // for when the combo-box is in a scroll area.
let frame = Frame::popup(ui.style());
let frame_margin = frame.margin;
frame
.show(ui, |ui| {
ui.with_layout(Layout::top_down_justified(Align::LEFT), |ui| {
ui.set_width(widget_response.rect.width() - 2.0 * frame_margin.x);
add_contents(ui)
})
.inner
})
.inner
})
.inner;
if ui.input().key_pressed(Key::Escape) || widget_response.clicked_elsewhere() {
ui.memory().close_popup();
}
Some(inner)
} else {
None
}
}

@bonsairobo
Copy link

This seems possible without #606. One option is to choose the popup direction based on the y coordinates of box. Upper half of the window means open downwards, lower half means open upwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants