richardwilkes / unison

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

Get structure of a Dock's containers and layouts #30

Closed pekim closed 1 year ago

pekim commented 1 year ago

I want to persist a Dock's content, and restore it on application start. I want layouts' horizontal/vertical, divider position, and nested layouts and containers. While it might be possible to infer the structure from creative use of existing functions, it doesn't appear to be straightforward or intuitive.

This DockLayout method would allow me to walk the hierarchy of a Dock's layouts and containers.

// ForEachNode calls the given function for each of the layout's nodes that is a DockContainer or DockLayout.
// Each call of the function will provide either a non-nil DockContainer OR a non-nil DockLayout.
func (d *DockLayout) ForEachNode(f func(*DockContainer, *DockLayout)) {
    for _, node := range d.nodes {
        switch c := node.(type) {
        case *DockContainer:
            f(c, nil)
        case *DockLayout:
            f(nil, c)
        }
    }
}

Before I open a pull request, is there a straightforward means of achieving something similar with the existing API?

richardwilkes commented 1 year ago

I don't think there is. I've had a task on my list for a while now to create a way to save & restore an existing dock's arrangement of content, but obviously haven't gotten around to it. If you can come up with a nice way to make that a possibility, that would be very worthwhile.

What you have above should work fine for walking the basic structure.