richardwilkes / unison

A unified graphical user experience toolkit for Go desktop applications
Mozilla Public License 2.0
202 stars 10 forks source link

Dock's divider position #25

Closed pekim closed 1 year ago

pekim commented 1 year ago

If I create a Dock and immediately set its divider position, the position ends up at 0 (rather than the default of a 50/50 split).

dock := unison.NewDock()
dock.DockTo(..., nil, unison.LeftSide)
dock.DockTo(..., nil, unison.RightSide)

dock.RootDockLayout().SetDividerPosition(300)

However if I defer the call to SetDividerPostition, it is honoured.

dock := unison.NewDock()
dock.DockTo(...)
dock.DockTo(...)

unison.InvokeTask(func() {
    dock.RootDockLayout().SetDividerPosition(300)
})

Is this expected? Is there a better way to achieve this?

On a related note, is there a means of observing changes to a dock layout's divider position? I ask because I'd like to persist the divider position when it changes, and set the persisted position on window creation. I could poll the divider position and persist when it changes, but I'd much prefer an event driven approach.

richardwilkes commented 1 year ago

This is a problem if the dock hasn't been laid out yet, since it then has a size of zero, which causes the divider position to be clamped to that lower value. By deferring the call to later, you ensure you call it when the dock has a valid size.

You can attempt to avoid this by forcing layout prior to the call... however, on some platforms, window sizing is also delayed, which means the dock won't have a real size until some indeterminate amount of time after the window is created, which also causes problems.

As for observing the divider's change, no, there currently is no such notification. One could be added... however, the way I make this work in my projects is I only read and save its state when the window is closed. No need to poll that way.

pekim commented 1 year ago

I think that I'll stick to deferring setting the divider position if there's nothing wrong with that.

And I'll probably go with your approach of persisting the position only when the window is closed.

I only started using unison yesterday, but so far I really like it. I'd previously dabbled with using skia (with the help of your https://github.com/richardwilkes/cskia), but unison is way better.