uic: support colspan/rowspan in grid layouts

This commit is contained in:
mappu 2024-10-05 17:49:10 +13:00
parent 1a4d34185f
commit b64d48a974
2 changed files with 25 additions and 6 deletions

View File

@ -5,8 +5,10 @@ import (
)
type UiLayoutItem struct {
Row *int `xml:"row,attr"`
Column *int `xml:"column,attr"`
Row *int `xml:"row,attr"`
Column *int `xml:"column,attr"`
RowSpan *int `xml:"rowspan,attr"`
ColSpan *int `xml:"colspan,attr"`
// A layout item either has a widget, or a spacer
Widget *UiWidget `xml:"widget"`

View File

@ -298,12 +298,29 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string,
`)
case `QGridLayout`:
// For QGridLayout it's AddWidget2
// FIXME in Miqt this function has optionals, needs to be called with the correct arity
// TODO support rowSpan, columnSpan
ret.WriteString(`
if child.ColSpan != nil || child.RowSpan != nil {
// If either are present, use full four-value AddWidget3
rowSpan := 1
if child.RowSpan != nil {
rowSpan = *child.RowSpan
}
colSpan := 1
if child.ColSpan != nil {
colSpan = *child.ColSpan
}
ret.WriteString(`
ui.` + w.Layout.Name + `.AddWidget3(` + qwidgetName(`ui.`+child.Widget.Name, child.Widget.Class) + `, ` + fmt.Sprintf("%d, %d, %d, %d", *child.Row, *child.Column, rowSpan, colSpan) + `)
`)
} else {
// Row and Column are always present in the .ui file
// For row/column it's AddWidget2
ret.WriteString(`
ui.` + w.Layout.Name + `.AddWidget2(` + qwidgetName(`ui.`+child.Widget.Name, child.Widget.Class) + `, ` + fmt.Sprintf("%d, %d", *child.Row, *child.Column) + `)
`)
}
case "QVBoxLayout", "QHBoxLayout":
// For box layout it's AddWidget