Skip to content

Define available_rect per Area #551

@mankinskin

Description

@mankinskin

I recently ran into an issue when implementing context menus #543 . The context menu is an Area rendered in a Foreground layer, and it can generally be placed anywhere on the screen, even on top of panels.

The problem was that egui treats all Areas as Windows and all windows are constrained to an available_rect, which is the screen space minus the panels (except for the CentralPanel, which effectively takes up the available_rect). This caused the context menu to not recognize hovers or clicks on anything except the central panel, because it had been constrained to the available_rect:

if let Some(bounds) = drag_bounds {
state.pos = ctx.constrain_window_rect_to_area(state.rect(), bounds).min;
} else {
state.pos = ctx.constrain_window_rect(state.rect()).min;
}

In this part of the code the position of the context menu Area was constrained out of the panel that had been clicked on, so that the rect used to detect hovers was off-placed.

To circumvent this I turned this code off for immovable Areas, but in general it should be possible to drag windows over panels if that is desired. This seems to be what the drag bounds are for already, but they seem to default to the available_rect. Maybe this should be changed to default to the whole screen area, and there should be a shortcut for the bounds of the background rect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions