summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2019-02-27 17:16:54 +0100
committerAlexander Neumann <alexander.neumann@picos-software.com>2019-02-27 17:16:54 +0100
commitb74661ddf606566b2cea7476d68e92768afa0c75 (patch)
tree8ce941fe5ddcf36d99180d96f1edfded3c6efc16
parent[Line|Text]Edit: Rename [Set]Alignment to [Set]TextAlignment (diff)
downloadwireguard-windows-b74661ddf606566b2cea7476d68e92768afa0c75.tar.xz
wireguard-windows-b74661ddf606566b2cea7476d68e92768afa0c75.zip
Add support for alignment specified per widget
-rw-r--r--boxlayout.go17
-rw-r--r--declarative/builder.go14
-rw-r--r--declarative/checkbox.go1
-rw-r--r--declarative/combobox.go1
-rw-r--r--declarative/composite.go1
-rw-r--r--declarative/customwidget.go1
-rw-r--r--declarative/dateedit.go1
-rw-r--r--declarative/datelabel.go1
-rw-r--r--declarative/gradientcomposite.go1
-rw-r--r--declarative/groupbox.go1
-rw-r--r--declarative/imageview.go1
-rw-r--r--declarative/label.go1
-rw-r--r--declarative/lineedit.go1
-rw-r--r--declarative/lineerrorpresenter.go1
-rw-r--r--declarative/linklabel.go1
-rw-r--r--declarative/listbox.go1
-rw-r--r--declarative/numberedit.go1
-rw-r--r--declarative/numberlabel.go1
-rw-r--r--declarative/progressbar.go1
-rw-r--r--declarative/pushbutton.go1
-rw-r--r--declarative/radiobutton.go1
-rw-r--r--declarative/radiobuttongroupbox.go1
-rw-r--r--declarative/scrollview.go1
-rw-r--r--declarative/separator.go1
-rw-r--r--declarative/slider.go1
-rw-r--r--declarative/splitbutton.go1
-rw-r--r--declarative/splitter.go1
-rw-r--r--declarative/tableview.go1
-rw-r--r--declarative/tabwidget.go1
-rw-r--r--declarative/textedit.go1
-rw-r--r--declarative/textlabel.go2
-rw-r--r--declarative/toolbar.go1
-rw-r--r--declarative/toolbutton.go1
-rw-r--r--declarative/treeview.go1
-rw-r--r--declarative/webview.go1
-rw-r--r--gridlayout.go9
-rw-r--r--widget.go27
37 files changed, 93 insertions, 8 deletions
diff --git a/boxlayout.go b/boxlayout.go
index a8b7dfdb..0c261726 100644
--- a/boxlayout.go
+++ b/boxlayout.go
@@ -534,9 +534,14 @@ func boxLayoutItems(widgets []Widget, orientation Orientation, alignment Alignme
s2 = prefSizes2[i]
}
+ align := widget.Alignment()
+ if align == AlignHVDefault {
+ align = alignment
+ }
+
var x, y, w, h, p2 int
if orientation == Horizontal {
- switch alignment {
+ switch align {
case AlignHNearVNear, AlignHNearVCenter, AlignHNearVFar:
// nop
@@ -547,7 +552,7 @@ func boxLayoutItems(widgets []Widget, orientation Orientation, alignment Alignme
p1 += halfExcessShare
}
- switch alignment {
+ switch align {
case AlignHNearVNear, AlignHCenterVNear, AlignHFarVNear:
p2 = start2
@@ -560,7 +565,7 @@ func boxLayoutItems(widgets []Widget, orientation Orientation, alignment Alignme
x, y, w, h = p1, p2, s1, s2
} else {
- switch alignment {
+ switch align {
case AlignHNearVNear, AlignHCenterVNear, AlignHFarVNear:
// nop
@@ -571,7 +576,7 @@ func boxLayoutItems(widgets []Widget, orientation Orientation, alignment Alignme
p1 += halfExcessShare
}
- switch alignment {
+ switch align {
case AlignHNearVNear, AlignHNearVCenter, AlignHNearVFar:
p2 = start2
@@ -586,7 +591,7 @@ func boxLayoutItems(widgets []Widget, orientation Orientation, alignment Alignme
}
if orientation == Horizontal {
- switch alignment {
+ switch align {
case AlignHNearVNear, AlignHNearVCenter, AlignHNearVFar:
p1 += excessShare
@@ -598,7 +603,7 @@ func boxLayoutItems(widgets []Widget, orientation Orientation, alignment Alignme
}
} else {
- switch alignment {
+ switch align {
case AlignHNearVNear, AlignHCenterVNear, AlignHFarVNear:
p1 += excessShare
diff --git a/declarative/builder.go b/declarative/builder.go
index 307cc9f4..6954b24a 100644
--- a/declarative/builder.go
+++ b/declarative/builder.go
@@ -215,6 +215,10 @@ func (b *Builder) InitWidget(d Widget, w walk.Window, customInit func() error) e
columnBackup := column
if widget, ok := w.(walk.Widget); ok {
+ if err := widget.SetAlignment(walk.Alignment2D(b.alignment())); err != nil {
+ return err
+ }
+
if err := widget.SetAlwaysConsumeSpace(b.bool("AlwaysConsumeSpace")); err != nil {
return err
}
@@ -423,6 +427,16 @@ func (b *Builder) InitWidget(d Widget, w walk.Window, customInit func() error) e
return nil
}
+func (b *Builder) alignment() Alignment2D {
+ fieldValue := b.widgetValue.FieldByName("Alignment")
+
+ if fieldValue.IsValid() {
+ return fieldValue.Interface().(Alignment2D)
+ }
+
+ return AlignHVDefault
+}
+
func (b *Builder) bool(fieldName string) bool {
fieldValue := b.widgetValue.FieldByName(fieldName)
diff --git a/declarative/checkbox.go b/declarative/checkbox.go
index 714ef9b0..40c40f6b 100644
--- a/declarative/checkbox.go
+++ b/declarative/checkbox.go
@@ -35,6 +35,7 @@ type CheckBox struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/combobox.go b/declarative/combobox.go
index 8dea7635..473446ef 100644
--- a/declarative/combobox.go
+++ b/declarative/combobox.go
@@ -39,6 +39,7 @@ type ComboBox struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/composite.go b/declarative/composite.go
index ff27c162..065f501a 100644
--- a/declarative/composite.go
+++ b/declarative/composite.go
@@ -36,6 +36,7 @@ type Composite struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/customwidget.go b/declarative/customwidget.go
index 1dcc281b..44dbb84b 100644
--- a/declarative/customwidget.go
+++ b/declarative/customwidget.go
@@ -43,6 +43,7 @@ type CustomWidget struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/dateedit.go b/declarative/dateedit.go
index 744c84f6..41eb3683 100644
--- a/declarative/dateedit.go
+++ b/declarative/dateedit.go
@@ -39,6 +39,7 @@ type DateEdit struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/datelabel.go b/declarative/datelabel.go
index 98ecb70d..d2c63ab1 100644
--- a/declarative/datelabel.go
+++ b/declarative/datelabel.go
@@ -35,6 +35,7 @@ type DateLabel struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/gradientcomposite.go b/declarative/gradientcomposite.go
index 67106707..70746d7b 100644
--- a/declarative/gradientcomposite.go
+++ b/declarative/gradientcomposite.go
@@ -36,6 +36,7 @@ type GradientComposite struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/groupbox.go b/declarative/groupbox.go
index 04aaf015..9b23ed87 100644
--- a/declarative/groupbox.go
+++ b/declarative/groupbox.go
@@ -35,6 +35,7 @@ type GroupBox struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/imageview.go b/declarative/imageview.go
index a429768e..392f2698 100644
--- a/declarative/imageview.go
+++ b/declarative/imageview.go
@@ -46,6 +46,7 @@ type ImageView struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/label.go b/declarative/label.go
index 44a8140c..afb219f5 100644
--- a/declarative/label.go
+++ b/declarative/label.go
@@ -35,6 +35,7 @@ type Label struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/lineedit.go b/declarative/lineedit.go
index 10b3a64b..2c59ff6c 100644
--- a/declarative/lineedit.go
+++ b/declarative/lineedit.go
@@ -43,6 +43,7 @@ type LineEdit struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/lineerrorpresenter.go b/declarative/lineerrorpresenter.go
index f481fa54..4f4bc8de 100644
--- a/declarative/lineerrorpresenter.go
+++ b/declarative/lineerrorpresenter.go
@@ -35,6 +35,7 @@ type LineErrorPresenter struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/linklabel.go b/declarative/linklabel.go
index af3dcbb2..7ba20991 100644
--- a/declarative/linklabel.go
+++ b/declarative/linklabel.go
@@ -35,6 +35,7 @@ type LinkLabel struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/listbox.go b/declarative/listbox.go
index e537b00f..6e97d8b7 100644
--- a/declarative/listbox.go
+++ b/declarative/listbox.go
@@ -40,6 +40,7 @@ type ListBox struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/numberedit.go b/declarative/numberedit.go
index 125455a4..46c6519d 100644
--- a/declarative/numberedit.go
+++ b/declarative/numberedit.go
@@ -35,6 +35,7 @@ type NumberEdit struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/numberlabel.go b/declarative/numberlabel.go
index ed656764..db5477e9 100644
--- a/declarative/numberlabel.go
+++ b/declarative/numberlabel.go
@@ -35,6 +35,7 @@ type NumberLabel struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/progressbar.go b/declarative/progressbar.go
index 54a9bc87..933ca149 100644
--- a/declarative/progressbar.go
+++ b/declarative/progressbar.go
@@ -35,6 +35,7 @@ type ProgressBar struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/pushbutton.go b/declarative/pushbutton.go
index b5bc2f88..2b86c446 100644
--- a/declarative/pushbutton.go
+++ b/declarative/pushbutton.go
@@ -35,6 +35,7 @@ type PushButton struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/radiobutton.go b/declarative/radiobutton.go
index 52ed8b85..5e35a58b 100644
--- a/declarative/radiobutton.go
+++ b/declarative/radiobutton.go
@@ -35,6 +35,7 @@ type RadioButton struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/radiobuttongroupbox.go b/declarative/radiobuttongroupbox.go
index 89c86f11..1df041cf 100644
--- a/declarative/radiobuttongroupbox.go
+++ b/declarative/radiobuttongroupbox.go
@@ -35,6 +35,7 @@ type RadioButtonGroupBox struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/scrollview.go b/declarative/scrollview.go
index 2aaee972..ffb5aa5f 100644
--- a/declarative/scrollview.go
+++ b/declarative/scrollview.go
@@ -35,6 +35,7 @@ type ScrollView struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/separator.go b/declarative/separator.go
index 32e5811a..976fadc4 100644
--- a/declarative/separator.go
+++ b/declarative/separator.go
@@ -35,6 +35,7 @@ type HSeparator struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/slider.go b/declarative/slider.go
index 865aaa16..35378ef7 100644
--- a/declarative/slider.go
+++ b/declarative/slider.go
@@ -35,6 +35,7 @@ type Slider struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/splitbutton.go b/declarative/splitbutton.go
index 768b76b4..ca9c07a5 100644
--- a/declarative/splitbutton.go
+++ b/declarative/splitbutton.go
@@ -35,6 +35,7 @@ type SplitButton struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/splitter.go b/declarative/splitter.go
index d9031b1c..01b28000 100644
--- a/declarative/splitter.go
+++ b/declarative/splitter.go
@@ -35,6 +35,7 @@ type HSplitter struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/tableview.go b/declarative/tableview.go
index 28a9d91b..23c836be 100644
--- a/declarative/tableview.go
+++ b/declarative/tableview.go
@@ -36,6 +36,7 @@ type TableView struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/tabwidget.go b/declarative/tabwidget.go
index 2a42a22e..ac9d89a5 100644
--- a/declarative/tabwidget.go
+++ b/declarative/tabwidget.go
@@ -35,6 +35,7 @@ type TabWidget struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/textedit.go b/declarative/textedit.go
index 26510900..5cdc2989 100644
--- a/declarative/textedit.go
+++ b/declarative/textedit.go
@@ -36,6 +36,7 @@ type TextEdit struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/textlabel.go b/declarative/textlabel.go
index 430c85fc..ec0b2064 100644
--- a/declarative/textlabel.go
+++ b/declarative/textlabel.go
@@ -13,6 +13,7 @@ import (
type Alignment2D uint
const (
+ AlignHVDefault = Alignment2D(walk.AlignHVDefault)
AlignHNearVNear = Alignment2D(walk.AlignHNearVNear)
AlignHCenterVNear = Alignment2D(walk.AlignHCenterVNear)
AlignHFarVNear = Alignment2D(walk.AlignHFarVNear)
@@ -49,6 +50,7 @@ type TextLabel struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/toolbar.go b/declarative/toolbar.go
index 930f205b..93547626 100644
--- a/declarative/toolbar.go
+++ b/declarative/toolbar.go
@@ -44,6 +44,7 @@ type ToolBar struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/toolbutton.go b/declarative/toolbutton.go
index 944b2602..df1ed915 100644
--- a/declarative/toolbutton.go
+++ b/declarative/toolbutton.go
@@ -35,6 +35,7 @@ type ToolButton struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/treeview.go b/declarative/treeview.go
index f1e53001..d0b3bc97 100644
--- a/declarative/treeview.go
+++ b/declarative/treeview.go
@@ -35,6 +35,7 @@ type TreeView struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/declarative/webview.go b/declarative/webview.go
index d86e8c9f..c9c3b12f 100644
--- a/declarative/webview.go
+++ b/declarative/webview.go
@@ -35,6 +35,7 @@ type WebView struct {
// Widget
+ Alignment Alignment2D
AlwaysConsumeSpace bool
Column int
ColumnSpan int
diff --git a/gridlayout.go b/gridlayout.go
index 5a3032b9..a4e1a826 100644
--- a/gridlayout.go
+++ b/gridlayout.go
@@ -638,8 +638,13 @@ func (l *GridLayout) Update(reset bool) error {
}
}
+ alignment := widget.Alignment()
+ if alignment == AlignHVDefault {
+ alignment = l.alignment
+ }
+
if w != width {
- switch l.alignment {
+ switch alignment {
case AlignHCenterVNear, AlignHCenterVCenter, AlignHCenterVFar:
x += (width - w) / 2
@@ -649,7 +654,7 @@ func (l *GridLayout) Update(reset bool) error {
}
if h != height {
- switch l.alignment {
+ switch alignment {
case AlignHNearVCenter, AlignHCenterVCenter, AlignHFarVCenter:
y += (height - h) / 2
diff --git a/widget.go b/widget.go
index e121d8ad..9af218c9 100644
--- a/widget.go
+++ b/widget.go
@@ -40,6 +40,9 @@ const (
type Widget interface {
Window
+ // Alignment returns the alignment of the Widget.
+ Alignment() Alignment2D
+
// AlwaysConsumeSpace returns if the Widget should consume space even if it
// is not visible.
AlwaysConsumeSpace() bool
@@ -64,6 +67,9 @@ type Widget interface {
// Parent returns the Container of the Widget.
Parent() Container
+ // SetAlignment sets the alignment of the widget.
+ SetAlignment(alignment Alignment2D) error
+
// SetAlwaysConsumeSpace sets if the Widget should consume space even if it
// is not visible.
SetAlwaysConsumeSpace(b bool) error
@@ -88,6 +94,7 @@ type WidgetBase struct {
toolTipTextProperty Property
toolTipTextChangedPublisher EventPublisher
graphicsEffects *WidgetGraphicsEffectList
+ alignment Alignment2D
alwaysConsumeSpace bool
}
@@ -208,6 +215,26 @@ func (wb *WidgetBase) Form() Form {
return ancestor(wb)
}
+// Alignment return the alignment ot the *WidgetBase.
+func (wb *WidgetBase) Alignment() Alignment2D {
+ return wb.alignment
+}
+
+// SetAlignment sets the alignment of the *WidgetBase.
+func (wb *WidgetBase) SetAlignment(alignment Alignment2D) error {
+ if alignment != wb.alignment {
+ if alignment < AlignHVDefault || alignment > AlignHFarVFar {
+ return newError("invalid Alignment value")
+ }
+
+ wb.alignment = alignment
+
+ wb.updateParentLayout()
+ }
+
+ return nil
+}
+
// LayoutFlags returns a combination of LayoutFlags that specify how the
// WidgetBase wants to be treated by Layout implementations.
func (wb *WidgetBase) LayoutFlags() LayoutFlags {