egui icon indicating copy to clipboard operation
egui copied to clipboard

Unable to change window pivot after creation

Open zdimension opened this issue 1 year ago • 1 comments

Is your feature request related to a problem? Please describe.

I'm able to open a Window centered on the screen by doing

let center = (ctx.input(|i| i.screen_rect.size()) / 2.0).to_pos2();
wnd.pivot(Align2::CENTER_CENTER).default_pos(center).[etc etc].show(...)

This works well, but it has the effect of permanently setting the pivot of the Window's Area to CENTER_CENTER. The consequence of that is that if the Window is automatically resized (e.g. because its contents change size, because a widget is added, an expander is opened, ...) it grows outward from its center, instead of southeastward from its top-left corner. Obviously, because the pivot is CENTER_CENTER.

This is pretty much the expected behavior, the problem is that... there doesn't seem to be a way to change the Area's pivot to LEFT_TOP after the Window has been created.

Describe the solution you'd like

Either:

  • allow changing the pivot afterwards
    • but this still requires changing it after the window has been shown, so it might look weird for a frame or two
  • allow using a "temporary" pivot (e.g. start the window with a position relative to a pivot, but still store the position relative to LEFT_TOP)
  • something else?

zdimension avatar Jul 13 '23 22:07 zdimension

Having a similar issue here, the .pivot acts more like .default_pivot rather than immediate mode pivot. So whatever pivot I had on first opening the window gets stuck, even if I've re-created the window.

egui=0.21.0

This is for a tooltip that needs to flow left or right of the cursor so that it doesn't get cut off by the screen.

As a workaround I've put in two different window Ids for the left and right version.

dimvoly avatar Nov 30 '23 03:11 dimvoly