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 clipped by window #825

Closed
BenBooth1344 opened this issue Oct 20, 2021 · 4 comments · Fixed by #885
Closed

ComboBox clipped by window #825

BenBooth1344 opened this issue Oct 20, 2021 · 4 comments · Fixed by #885
Labels
bug Something is broken

Comments

@BenBooth1344
Copy link

Describe the bug

When a Window has a ComboBox near the bottom some items in the list can be cut off.

To Reproduce
Steps to reproduce the behavior (Bottom clip - 1st screenshot):

  • Create a window
  • add ui elements using up ~ 300pts of height
  • add a ComboBox with a large number of elements
  • build & run and click on ComboBox
  • bottom of dropdown list is clipped

Steps to reproduce the behavior (Bottom & Side clip 2nd screenshot):

  • Create a window with .scroll(true)
  • add ui elements using up ~ 600pts of height
  • add a ComboBox with a large number of elements (it needs to be located near right edge of window)
  • build & run and click on ComboBox
  • bottom and right of dropdown list is clipped

Expected behavior
dropdown lists should not be clipped

Cause of issue
clip_rect of parent ui (window or scroll area) is being used to clip the dropdown list

Screenshots
image
image

Proposed solution
If the clip_rect of the ui is expanded immediately prior to drawing the dropdown popup and shrunk back afterwards, the problem can be fixed.

The vertical height of the clip_rect needs to be temporally expanded by "ui.spacing().combo_height"
I don't the required width expansion is easily determined

I believe the code change needs to be done in src\containers\popop.popup_below_widget

It might be best to make clip_rect expansion optional

functions to expand/shrink clip_rect:

pub fn expand_ui_clip_rect_y(ui: &mut Ui) {
    let rect = ui.clip_rect();
    ui.set_clip_rect(Rect::from_two_pos(
        rect.min,
        pos2(rect.max.x, rect.max.y + ui.spacing().combo_height),
    ));
}

pub fn shrink_ui_clip_rect_y(ui: &mut Ui) {
    let rect = ui.clip_rect();
    ui.set_clip_rect(Rect::from_two_pos(
        rect.min,
        pos2(rect.max.x, rect.max.y + ui.spacing().combo_height),
    ));
}

Desktop (please complete the following information):

  • OS: Windows 10
  • eframe : 0.14.0
  • Native app
@BenBooth1344 BenBooth1344 added the bug Something is broken label Oct 20, 2021
@emilk
Copy link
Owner

emilk commented Oct 20, 2021

Good find!

The reason that the parent clip rect is respected at all is for the case when the combobox is in a scroll-area. However, maybe it is just easier to always ignore the parent clip rect, and let popups (including comboboxes) "escape" the parent.

See https://github.com/emilk/egui/blob/master/egui/src/containers/popup.rs#L288

@emilk
Copy link
Owner

emilk commented Oct 20, 2021

Another option is to move the popup to be within the parent clip rect, which would also solve #693

@BenBooth1344
Copy link
Author

In my case the window is procedurally generated and based on parsed user input. So it's not really an option to move the combo box.

The other issue is I would like to allow the ComboBox to be in a scroll Area since the user can input any number of input blocks which can cause the window to need a scroll bar.

If the ComboBox dropdown being clipped is always bad (at least in y) then you can add a call to "expand_ui_clip_rect_y"
right after line 288
https://github.com/emilk/egui/blob/master/egui/src/containers/popup.rs#L288
and a call to "shrink_ui_clip_rect_y" right after line 299 https://github.com/emilk/egui/blob/master/egui/src/containers/popup.rs#L299

and that should allow the dropdown to still work with a scroll area

@BenBooth1344
Copy link
Author

BenBooth1344 commented Oct 20, 2021

I misread your comment about moving the ComboBox, if the popup can be automatically moved to within the clip_rect that would solve my issue.

It would also solve the issue with clipping when in a ScrollArea (second screenshot above)

But wouldn't that require knowing how big the popup will be prior to drawing it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants