|
@@ -44,6 +44,7 @@ type descLayoutParams struct {
|
|
|
ColSpan int // Grid layout colspan
|
|
ColSpan int // Grid layout colspan
|
|
|
AlignH string // horizontal alignment
|
|
AlignH string // horizontal alignment
|
|
|
AlignV string // vertical alignment
|
|
AlignV string // vertical alignment
|
|
|
|
|
+ Edge string // Dock layout edge: top,right,bottom,left,center
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// descPanel describes all panel types
|
|
// descPanel describes all panel types
|
|
@@ -83,6 +84,8 @@ type descPanel struct {
|
|
|
Shortcut string // Menu
|
|
Shortcut string // Menu
|
|
|
Value *float32 // Slider
|
|
Value *float32 // Slider
|
|
|
ScaleFactor *float32 // Slider
|
|
ScaleFactor *float32 // Slider
|
|
|
|
|
+ Title string // Window
|
|
|
|
|
+ Resizable string // Window resizable borders
|
|
|
parent *descPanel // used internally
|
|
parent *descPanel // used internally
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -106,9 +109,11 @@ const (
|
|
|
descTypeTreeNode = "node"
|
|
descTypeTreeNode = "node"
|
|
|
descTypeMenuBar = "menubar"
|
|
descTypeMenuBar = "menubar"
|
|
|
descTypeMenu = "menu"
|
|
descTypeMenu = "menu"
|
|
|
|
|
+ descTypeWindow = "window"
|
|
|
descTypeHBoxLayout = "hbox"
|
|
descTypeHBoxLayout = "hbox"
|
|
|
descTypeVBoxLayout = "vbox"
|
|
descTypeVBoxLayout = "vbox"
|
|
|
descTypeGridLayout = "grid"
|
|
descTypeGridLayout = "grid"
|
|
|
|
|
+ descTypeDockLayout = "dock"
|
|
|
fieldMargins = "margins"
|
|
fieldMargins = "margins"
|
|
|
fieldBorders = "borders"
|
|
fieldBorders = "borders"
|
|
|
fieldBorderColor = "bordercolor"
|
|
fieldBorderColor = "bordercolor"
|
|
@@ -146,6 +151,24 @@ var mapAlignName = map[string]Align{
|
|
|
"center": AlignCenter,
|
|
"center": AlignCenter,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// maps edge name (dock layout) with edge parameter
|
|
|
|
|
+var mapEdgeName = map[string]int{
|
|
|
|
|
+ "top": DockTop,
|
|
|
|
|
+ "right": DockRight,
|
|
|
|
|
+ "bottom": DockBottom,
|
|
|
|
|
+ "left": DockLeft,
|
|
|
|
|
+ "center": DockCenter,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// maps resize border name (window) with parameter value
|
|
|
|
|
+var mapResizable = map[string]Resizable{
|
|
|
|
|
+ "top": ResizeTop,
|
|
|
|
|
+ "right": ResizeRight,
|
|
|
|
|
+ "bottom": ResizeBottom,
|
|
|
|
|
+ "left": ResizeLeft,
|
|
|
|
|
+ "all": ResizeAll,
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// NewBuilder creates and returns a pointer to a new gui Builder object
|
|
// NewBuilder creates and returns a pointer to a new gui Builder object
|
|
|
func NewBuilder() *Builder {
|
|
func NewBuilder() *Builder {
|
|
|
|
|
|
|
@@ -286,6 +309,8 @@ func (b *Builder) build(pd *descPanel, iparent IPanel) (IPanel, error) {
|
|
|
pan, err = b.buildMenu(pd, false, true)
|
|
pan, err = b.buildMenu(pd, false, true)
|
|
|
case descTypeMenu:
|
|
case descTypeMenu:
|
|
|
pan, err = b.buildMenu(pd, false, false)
|
|
pan, err = b.buildMenu(pd, false, false)
|
|
|
|
|
+ case descTypeWindow:
|
|
|
|
|
+ pan, err = b.buildWindow(pd)
|
|
|
default:
|
|
default:
|
|
|
err = fmt.Errorf("Invalid panel type:%s", pd.Type)
|
|
err = fmt.Errorf("Invalid panel type:%s", pd.Type)
|
|
|
}
|
|
}
|
|
@@ -773,6 +798,49 @@ func (b *Builder) buildMenu(pd *descPanel, child, bar bool) (IPanel, error) {
|
|
|
return menu, nil
|
|
return menu, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// buildWindow builds a gui object of type: Window from the
|
|
|
|
|
+// specified panel descriptor.
|
|
|
|
|
+func (b *Builder) buildWindow(dp *descPanel) (IPanel, error) {
|
|
|
|
|
+
|
|
|
|
|
+ // Builds window and sets its common attributes
|
|
|
|
|
+ width, height := b.size(dp)
|
|
|
|
|
+ win := NewWindow(width, height)
|
|
|
|
|
+ err := b.setAttribs(dp, win, asWIDGET)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Title attribute
|
|
|
|
|
+ win.SetTitle(dp.Title)
|
|
|
|
|
+
|
|
|
|
|
+ // Parse resizable borders
|
|
|
|
|
+ if dp.Resizable != "" {
|
|
|
|
|
+ parts := strings.Fields(dp.Resizable)
|
|
|
|
|
+ var res Resizable
|
|
|
|
|
+ for _, name := range parts {
|
|
|
|
|
+ v, ok := mapResizable[name]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ return nil, b.err("resizable", "Invalid resizable name:"+name)
|
|
|
|
|
+ }
|
|
|
|
|
+ res |= v
|
|
|
|
|
+ }
|
|
|
|
|
+ win.SetResizable(res)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Builds window client panel children recursively
|
|
|
|
|
+ for i := 0; i < len(dp.Items); i++ {
|
|
|
|
|
+ item := dp.Items[i]
|
|
|
|
|
+ b.objpath.push(item.Name)
|
|
|
|
|
+ child, err := b.build(item, win)
|
|
|
|
|
+ b.objpath.pop()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+ win.Add(child)
|
|
|
|
|
+ }
|
|
|
|
|
+ return win, nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// setAttribs sets common attributes from the description to the specified panel
|
|
// setAttribs sets common attributes from the description to the specified panel
|
|
|
// The attributes which are set can be specified by the specified bitmask.
|
|
// The attributes which are set can be specified by the specified bitmask.
|
|
|
func (b *Builder) setAttribs(pd *descPanel, ipan IPanel, attr uint) error {
|
|
func (b *Builder) setAttribs(pd *descPanel, ipan IPanel, attr uint) error {
|
|
@@ -960,6 +1028,19 @@ func (b *Builder) setLayoutParams(dp *descPanel, ipan IPanel) error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // DockLayout parameters
|
|
|
|
|
+ if playout.Type == descTypeDockLayout {
|
|
|
|
|
+ if dlp.Edge != "" {
|
|
|
|
|
+ edge, ok := mapEdgeName[dlp.Edge]
|
|
|
|
|
+ if !ok {
|
|
|
|
|
+ return b.err("edge", "Invalid edge name:"+dlp.Edge)
|
|
|
|
|
+ }
|
|
|
|
|
+ params := DockLayoutParams{Edge: edge}
|
|
|
|
|
+ panel.SetLayoutParams(¶ms)
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return b.err("layoutparams", "Invalid parent layout:"+playout.Type)
|
|
return b.err("layoutparams", "Invalid parent layout:"+playout.Type)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1037,6 +1118,13 @@ func (b *Builder) setLayout(dp *descPanel, ipan IPanel) error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // Dock layout
|
|
|
|
|
+ if dl.Type == descTypeDockLayout {
|
|
|
|
|
+ dockl := NewDockLayout()
|
|
|
|
|
+ panel.SetLayout(dockl)
|
|
|
|
|
+ return nil
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return b.err("layout", "Invalid layout type:"+dl.Type)
|
|
return b.err("layout", "Invalid layout type:"+dl.Type)
|
|
|
}
|
|
}
|
|
|
|
|
|