summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2018-12-05 16:48:44 +0100
committerAlexander Neumann <alexander.neumann@picos-software.com>2018-12-05 16:48:44 +0100
commit37f054161da72f08d89c3ac27aecc18872066adb (patch)
tree66ee30c82453d474a966968a51032f7a4e967ab0
parentAdd support for widgets that trade height for width to layouts and do some refactoring (diff)
downloadwireguard-windows-37f054161da72f08d89c3ac27aecc18872066adb.tar.xz
wireguard-windows-37f054161da72f08d89c3ac27aecc18872066adb.zip
Label reform
-rw-r--r--datelabel.go114
-rw-r--r--declarative/datelabel.go77
-rw-r--r--declarative/label.go11
-rw-r--r--declarative/numberlabel.go78
-rw-r--r--declarative/tableviewcolumn.go7
-rw-r--r--declarative/textlabel.go90
-rw-r--r--label.go70
-rw-r--r--numberlabel.go156
-rw-r--r--simpletypes.go6
-rw-r--r--static.go190
-rw-r--r--tableviewcolumn.go4
-rw-r--r--textedit.go4
-rw-r--r--textlabel.go86
13 files changed, 835 insertions, 58 deletions
diff --git a/datelabel.go b/datelabel.go
new file mode 100644
index 00000000..b7c046ea
--- /dev/null
+++ b/datelabel.go
@@ -0,0 +1,114 @@
+// Copyright 2018 The Walk Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build windows
+
+package walk
+
+import (
+ "time"
+)
+
+type DateLabel struct {
+ static
+ date time.Time
+ dateChangedPublisher EventPublisher
+ format string
+ formatChangedPublisher EventPublisher
+}
+
+func NewDateLabel(parent Container) (*DateLabel, error) {
+ dl := new(DateLabel)
+
+ if err := dl.init(dl, parent); err != nil {
+ return nil, err
+ }
+
+ dl.SetTextAlignment(AlignFar)
+ if _, err := dl.updateText(); err != nil {
+ return nil, err
+ }
+
+ dl.MustRegisterProperty("Date", NewProperty(
+ func() interface{} {
+ return dl.Date()
+ },
+ func(v interface{}) error {
+ return dl.SetDate(assertTimeOr(v, time.Time{}))
+ },
+ dl.dateChangedPublisher.Event()))
+
+ dl.MustRegisterProperty("Format", NewProperty(
+ func() interface{} {
+ return dl.Format()
+ },
+ func(v interface{}) error {
+ return dl.SetFormat(assertStringOr(v, ""))
+ },
+ dl.formatChangedPublisher.Event()))
+
+ return dl, nil
+}
+
+func (dl *DateLabel) TextAlignment() Alignment1D {
+ return dl.textAlignment1D()
+}
+
+func (dl *DateLabel) SetTextAlignment(alignment Alignment1D) error {
+ if alignment == AlignDefault {
+ alignment = AlignNear
+ }
+
+ return dl.setTextAlignment1D(alignment)
+}
+
+func (dl *DateLabel) Date() time.Time {
+ return dl.date
+}
+
+func (dl *DateLabel) SetDate(date time.Time) error {
+ if date == dl.date {
+ return nil
+ }
+
+ old := dl.date
+
+ dl.date = date
+
+ if _, err := dl.updateText(); err != nil {
+ dl.date = old
+ return err
+ }
+
+ dl.dateChangedPublisher.Publish()
+
+ return nil
+}
+
+func (dl *DateLabel) Format() string {
+ return dl.format
+}
+
+func (dl *DateLabel) SetFormat(format string) error {
+ if format == dl.format {
+ return nil
+ }
+
+ old := dl.format
+
+ dl.format = format
+
+ if _, err := dl.updateText(); err != nil {
+ dl.format = old
+ return err
+ }
+
+ dl.formatChangedPublisher.Publish()
+
+ return nil
+}
+
+func (dl *DateLabel) updateText() (changed bool, err error) {
+ return dl.setText(dl.date.Format(dl.format))
+}
diff --git a/declarative/datelabel.go b/declarative/datelabel.go
new file mode 100644
index 00000000..98ecb70d
--- /dev/null
+++ b/declarative/datelabel.go
@@ -0,0 +1,77 @@
+// Copyright 2018 The Walk Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build windows
+
+package declarative
+
+import (
+ "github.com/lxn/walk"
+)
+
+type DateLabel struct {
+ // Window
+
+ Background Brush
+ ContextMenuItems []MenuItem
+ Enabled Property
+ Font Font
+ MaxSize Size
+ MinSize Size
+ Name string
+ OnBoundsChanged walk.EventHandler
+ OnKeyDown walk.KeyEventHandler
+ OnKeyPress walk.KeyEventHandler
+ OnKeyUp walk.KeyEventHandler
+ OnMouseDown walk.MouseEventHandler
+ OnMouseMove walk.MouseEventHandler
+ OnMouseUp walk.MouseEventHandler
+ OnSizeChanged walk.EventHandler
+ Persistent bool
+ RightToLeftReading bool
+ ToolTipText Property
+ Visible Property
+
+ // Widget
+
+ AlwaysConsumeSpace bool
+ Column int
+ ColumnSpan int
+ GraphicsEffects []walk.WidgetGraphicsEffect
+ Row int
+ RowSpan int
+ StretchFactor int
+
+ // static
+
+ TextColor walk.Color
+
+ // DateLabel
+
+ AssignTo **walk.DateLabel
+ Date Property
+ Format Property
+ TextAlignment Alignment1D
+}
+
+func (dl DateLabel) Create(builder *Builder) error {
+ w, err := walk.NewDateLabel(builder.Parent())
+ if err != nil {
+ return err
+ }
+
+ if dl.AssignTo != nil {
+ *dl.AssignTo = w
+ }
+
+ return builder.InitWidget(dl, w, func() error {
+ if err := w.SetTextAlignment(walk.Alignment1D(dl.TextAlignment)); err != nil {
+ return err
+ }
+
+ w.SetTextColor(dl.TextColor)
+
+ return nil
+ })
+}
diff --git a/declarative/label.go b/declarative/label.go
index cf566872..44a8140c 100644
--- a/declarative/label.go
+++ b/declarative/label.go
@@ -45,9 +45,10 @@ type Label struct {
// Label
- AssignTo **walk.Label
- Text Property
- TextColor walk.Color
+ AssignTo **walk.Label
+ Text Property
+ TextAlignment Alignment1D
+ TextColor walk.Color
}
func (l Label) Create(builder *Builder) error {
@@ -61,6 +62,10 @@ func (l Label) Create(builder *Builder) error {
}
return builder.InitWidget(l, w, func() error {
+ if err := w.SetTextAlignment(walk.Alignment1D(l.TextAlignment)); err != nil {
+ return err
+ }
+
w.SetTextColor(l.TextColor)
return nil
diff --git a/declarative/numberlabel.go b/declarative/numberlabel.go
new file mode 100644
index 00000000..ed656764
--- /dev/null
+++ b/declarative/numberlabel.go
@@ -0,0 +1,78 @@
+// Copyright 2018 The Walk Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build windows
+
+package declarative
+
+import (
+ "github.com/lxn/walk"
+)
+
+type NumberLabel struct {
+ // Window
+
+ Background Brush
+ ContextMenuItems []MenuItem
+ Enabled Property
+ Font Font
+ MaxSize Size
+ MinSize Size
+ Name string
+ OnBoundsChanged walk.EventHandler
+ OnKeyDown walk.KeyEventHandler
+ OnKeyPress walk.KeyEventHandler
+ OnKeyUp walk.KeyEventHandler
+ OnMouseDown walk.MouseEventHandler
+ OnMouseMove walk.MouseEventHandler
+ OnMouseUp walk.MouseEventHandler
+ OnSizeChanged walk.EventHandler
+ Persistent bool
+ RightToLeftReading bool
+ ToolTipText Property
+ Visible Property
+
+ // Widget
+
+ AlwaysConsumeSpace bool
+ Column int
+ ColumnSpan int
+ GraphicsEffects []walk.WidgetGraphicsEffect
+ Row int
+ RowSpan int
+ StretchFactor int
+
+ // static
+
+ TextColor walk.Color
+
+ // NumberLabel
+
+ AssignTo **walk.NumberLabel
+ Decimals Property
+ Suffix Property
+ TextAlignment Alignment1D
+ Value Property
+}
+
+func (nl NumberLabel) Create(builder *Builder) error {
+ w, err := walk.NewNumberLabel(builder.Parent())
+ if err != nil {
+ return err
+ }
+
+ if nl.AssignTo != nil {
+ *nl.AssignTo = w
+ }
+
+ return builder.InitWidget(nl, w, func() error {
+ if err := w.SetTextAlignment(walk.Alignment1D(nl.TextAlignment)); err != nil {
+ return err
+ }
+
+ w.SetTextColor(nl.TextColor)
+
+ return nil
+ })
+}
diff --git a/declarative/tableviewcolumn.go b/declarative/tableviewcolumn.go
index 61eea882..12f5e1e4 100644
--- a/declarative/tableviewcolumn.go
+++ b/declarative/tableviewcolumn.go
@@ -13,9 +13,10 @@ import (
type Alignment1D uint
const (
- AlignNear Alignment1D = iota
- AlignCenter
- AlignFar
+ AlignDefault = Alignment1D(walk.AlignDefault)
+ AlignNear = Alignment1D(walk.AlignNear)
+ AlignCenter = Alignment1D(walk.AlignCenter)
+ AlignFar = Alignment1D(walk.AlignFar)
)
type TableViewColumn struct {
diff --git a/declarative/textlabel.go b/declarative/textlabel.go
new file mode 100644
index 00000000..0eef43f7
--- /dev/null
+++ b/declarative/textlabel.go
@@ -0,0 +1,90 @@
+// Copyright 2018 The Walk Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build windows
+
+package declarative
+
+import (
+ "github.com/lxn/walk"
+)
+
+type Alignment2D uint
+
+const (
+ AlignHNearVNear = Alignment2D(walk.AlignHNearVNear)
+ AlignHCenterVNear = Alignment2D(walk.AlignHCenterVNear)
+ AlignHFarVNear = Alignment2D(walk.AlignHFarVNear)
+ AlignHNearVCenter = Alignment2D(walk.AlignHNearVCenter)
+ AlignHCenterVCenter = Alignment2D(walk.AlignHCenterVCenter)
+ AlignHFarVCenter = Alignment2D(walk.AlignHFarVCenter)
+ AlignHNearVFar = Alignment2D(walk.AlignHNearVFar)
+ AlignHCenterVFar = Alignment2D(walk.AlignHCenterVFar)
+ AlignHFarVFar = Alignment2D(walk.AlignHFarVFar)
+)
+
+type TextLabel struct {
+ // Window
+
+ Background Brush
+ ContextMenuItems []MenuItem
+ Enabled Property
+ Font Font
+ MaxSize Size
+ MinSize Size
+ Name string
+ OnBoundsChanged walk.EventHandler
+ OnKeyDown walk.KeyEventHandler
+ OnKeyPress walk.KeyEventHandler
+ OnKeyUp walk.KeyEventHandler
+ OnMouseDown walk.MouseEventHandler
+ OnMouseMove walk.MouseEventHandler
+ OnMouseUp walk.MouseEventHandler
+ OnSizeChanged walk.EventHandler
+ Persistent bool
+ RightToLeftReading bool
+ ToolTipText Property
+ Visible Property
+
+ // Widget
+
+ AlwaysConsumeSpace bool
+ Column int
+ ColumnSpan int
+ GraphicsEffects []walk.WidgetGraphicsEffect
+ Row int
+ RowSpan int
+ StretchFactor int
+
+ // static
+
+ TextColor walk.Color
+
+ // Text
+
+ AssignTo **walk.TextLabel
+ TextAlignment Alignment2D
+ Text Property
+}
+
+func (tl TextLabel) Create(builder *Builder) error {
+ w, err := walk.NewTextLabel(builder.Parent())
+ if err != nil {
+ return err
+ }
+
+ if tl.AssignTo != nil {
+ *tl.AssignTo = w
+ }
+
+ return builder.InitWidget(tl, w, func() error {
+ w.SetTextColor(tl.TextColor)
+
+ if err := w.SetTextAlignment(walk.Alignment2D(tl.TextAlignment)); err != nil {
+ return err
+ }
+
+ return nil
+ })
+}
diff --git a/label.go b/label.go
index 00de0f4a..13f541d6 100644
--- a/label.go
+++ b/label.go
@@ -6,14 +6,9 @@
package walk
-import (
- "github.com/lxn/win"
-)
-
type Label struct {
- WidgetBase
+ static
textChangedPublisher EventPublisher
- textColor Color
}
func NewLabel(parent Container) (*Label, error) {
@@ -23,23 +18,19 @@ func NewLabel(parent Container) (*Label, error) {
func NewLabelWithStyle(parent Container, style uint32) (*Label, error) {
l := new(Label)
- if err := InitWidget(
- l,
- parent,
- "STATIC",
- win.WS_VISIBLE|win.SS_CENTERIMAGE|style,
- 0); err != nil {
+ if err := l.init(l, parent); err != nil {
return nil, err
}
- l.SetBackground(nullBrushSingleton)
+ l.SetTextAlignment(AlignNear)
l.MustRegisterProperty("Text", NewProperty(
func() interface{} {
return l.Text()
},
func(v interface{}) error {
- return l.setText(assertStringOr(v, ""))
+ _, err := l.setText(assertStringOr(v, ""))
+ return err
},
l.textChangedPublisher.Event()))
@@ -47,54 +38,33 @@ func NewLabelWithStyle(parent Container, style uint32) (*Label, error) {
}
func (*Label) LayoutFlags() LayoutFlags {
- return GrowableVert | GrowableHorz
+ return ShrinkableHorz | ShrinkableVert | GrowableHorz | GrowableVert
}
-func (l *Label) MinSizeHint() Size {
- return l.calculateTextSize()
+func (l *Label) TextAlignment() Alignment1D {
+ return l.textAlignment1D()
}
-func (l *Label) SizeHint() Size {
- return l.MinSizeHint()
+func (l *Label) SetTextAlignment(alignment Alignment1D) error {
+ if alignment == AlignDefault {
+ alignment = AlignNear
+ }
+
+ return l.setTextAlignment1D(alignment)
}
func (l *Label) Text() string {
return l.text()
}
-func (l *Label) SetText(value string) error {
- if value == l.Text() {
- return nil
- }
-
- if err := l.setText(value); err != nil {
+func (l *Label) SetText(text string) error {
+ if changed, err := l.setText(text); err != nil {
return err
+ } else if !changed {
+ return nil
}
- return l.updateParentLayout()
-}
-
-func (l *Label) TextColor() Color {
- return l.textColor
-}
-
-func (l *Label) SetTextColor(c Color) {
- l.textColor = c
-
- l.Invalidate()
-}
-
-func (l *Label) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) uintptr {
- switch msg {
- case win.WM_NCHITTEST:
- return win.HTCLIENT
-
- case win.WM_SETTEXT:
- l.textChangedPublisher.Publish()
-
- case win.WM_SIZE, win.WM_SIZING:
- l.Invalidate()
- }
+ l.textChangedPublisher.Publish()
- return l.WidgetBase.WndProc(hwnd, msg, wParam, lParam)
+ return nil
}
diff --git a/numberlabel.go b/numberlabel.go
new file mode 100644
index 00000000..964c9e45
--- /dev/null
+++ b/numberlabel.go
@@ -0,0 +1,156 @@
+// Copyright 2018 The Walk Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build windows
+
+package walk
+
+import (
+ "strings"
+)
+
+type NumberLabel struct {
+ static
+ decimals int
+ decimalsChangedPublisher EventPublisher
+ suffix string
+ suffixChangedPublisher EventPublisher
+ value float64
+ valueChangedPublisher EventPublisher
+}
+
+func NewNumberLabel(parent Container) (*NumberLabel, error) {
+ nl := new(NumberLabel)
+
+ if err := nl.init(nl, parent); err != nil {
+ return nil, err
+ }
+
+ nl.SetTextAlignment(AlignFar)
+ if _, err := nl.updateText(); err != nil {
+ return nil, err
+ }
+
+ nl.MustRegisterProperty("Decimals", NewProperty(
+ func() interface{} {
+ return nl.Decimals()
+ },
+ func(v interface{}) error {
+ return nl.SetDecimals(assertIntOr(v, 0))
+ },
+ nl.decimalsChangedPublisher.Event()))
+
+ nl.MustRegisterProperty("Suffix", NewProperty(
+ func() interface{} {
+ return nl.Suffix()
+ },
+ func(v interface{}) error {
+ return nl.SetSuffix(assertStringOr(v, ""))
+ },
+ nl.suffixChangedPublisher.Event()))
+
+ nl.MustRegisterProperty("Value", NewProperty(
+ func() interface{} {
+ return nl.Value()
+ },
+ func(v interface{}) error {
+ return nl.SetValue(assertFloat64Or(v, 0.0))
+ },
+ nl.valueChangedPublisher.Event()))
+
+ return nl, nil
+}
+
+func (nl *NumberLabel) TextAlignment() Alignment1D {
+ return nl.textAlignment1D()
+}
+
+func (nl *NumberLabel) SetTextAlignment(alignment Alignment1D) error {
+ if alignment == AlignDefault {
+ alignment = AlignFar
+ }
+
+ return nl.setTextAlignment1D(alignment)
+}
+
+func (nl *NumberLabel) Decimals() int {
+ return nl.decimals
+}
+
+func (nl *NumberLabel) SetDecimals(decimals int) error {
+ if decimals == nl.decimals {
+ return nil
+ }
+
+ old := nl.decimals
+
+ nl.decimals = decimals
+
+ if _, err := nl.updateText(); err != nil {
+ nl.decimals = old
+ return err
+ }
+
+ nl.decimalsChangedPublisher.Publish()
+
+ return nil
+}
+
+func (nl *NumberLabel) Suffix() string {
+ return nl.suffix
+}
+
+func (nl *NumberLabel) SetSuffix(suffix string) error {
+ if suffix == nl.suffix {
+ return nil
+ }
+
+ old := nl.suffix
+
+ nl.suffix = suffix
+
+ if _, err := nl.updateText(); err != nil {
+ nl.suffix = old
+ return err
+ }
+
+ nl.suffixChangedPublisher.Publish()
+
+ return nil
+}
+
+func (nl *NumberLabel) Value() float64 {
+ return nl.value
+}
+
+func (nl *NumberLabel) SetValue(value float64) error {
+ if value == nl.value {
+ return nil
+ }
+
+ old := nl.value
+
+ nl.value = value
+
+ if _, err := nl.updateText(); err != nil {
+ nl.value = old
+ return err
+ }
+
+ nl.valueChangedPublisher.Publish()
+
+ return nil
+}
+
+func (nl *NumberLabel) updateText() (changed bool, err error) {
+ var sb strings.Builder
+
+ sb.WriteString(FormatFloatGrouped(nl.value, nl.decimals))
+
+ if nl.suffix != "" {
+ sb.WriteString(nl.suffix)
+ }
+
+ return nl.setText(sb.String())
+}
diff --git a/simpletypes.go b/simpletypes.go
index af7c0353..78db6c28 100644
--- a/simpletypes.go
+++ b/simpletypes.go
@@ -9,7 +9,8 @@ package walk
type Alignment1D uint
const (
- AlignNear Alignment1D = iota
+ AlignDefault Alignment1D = iota
+ AlignNear
AlignCenter
AlignFar
)
@@ -17,7 +18,8 @@ const (
type Alignment2D uint
const (
- AlignHNearVNear Alignment2D = iota
+ AlignHVDefault Alignment2D = iota
+ AlignHNearVNear
AlignHCenterVNear
AlignHFarVNear
AlignHNearVCenter
diff --git a/static.go b/static.go
new file mode 100644
index 00000000..92347ff9
--- /dev/null
+++ b/static.go
@@ -0,0 +1,190 @@
+// Copyright 2018 The Walk Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build windows
+
+package walk
+
+import (
+ "unsafe"
+
+ "github.com/lxn/win"
+)
+
+type static struct {
+ WidgetBase
+ textAlignment Alignment2D
+ textColor Color
+}
+
+func (s *static) init(widget Widget, parent Container) error {
+ if err := InitWidget(
+ widget,
+ parent,
+ "STATIC",
+ win.WS_VISIBLE|win.SS_OWNERDRAW,
+ 0); err != nil {
+ return err
+ }
+
+ s.SetBackground(nullBrushSingleton)
+
+ return nil
+}
+
+func (*static) LayoutFlags() LayoutFlags {
+ return GrowableHorz | GrowableVert
+}
+
+func (s *static) MinSizeHint() Size {
+ return s.calculateTextSizeForWidth(0)
+}
+
+func (s *static) SizeHint() Size {
+ return s.MinSizeHint()
+}
+
+func (s *static) HeightForWidth(width int) int {
+ return s.MinSizeHint().Height
+}
+
+func (s *static) textAlignment1D() Alignment1D {
+ switch s.textAlignment {
+ case AlignHCenterVCenter:
+ return AlignCenter
+
+ case AlignHFarVCenter:
+ return AlignFar
+
+ default:
+ return AlignNear
+ }
+}
+
+func (s *static) setTextAlignment1D(alignment Alignment1D) error {
+ var align Alignment2D
+
+ switch alignment {
+ case AlignCenter:
+ align = AlignHCenterVCenter
+
+ case AlignFar:
+ align = AlignHFarVCenter
+
+ default:
+ align = AlignHNearVCenter
+ }
+
+ return s.setTextAlignment(align)
+}
+
+func (s *static) setTextAlignment(alignment Alignment2D) error {
+ if alignment == s.textAlignment {
+ return nil
+ }
+
+ s.textAlignment = alignment
+
+ s.Invalidate()
+
+ return nil
+}
+
+func (s *static) setText(value string) (changed bool, err error) {
+ if value == s.text() {
+ return false, nil
+ }
+
+ if err := s.WidgetBase.setText(value); err != nil {
+ return false, err
+ }
+
+ return true, s.updateParentLayout()
+}
+
+func (s *static) TextColor() Color {
+ return s.textColor
+}
+
+func (s *static) SetTextColor(c Color) {
+ s.textColor = c
+
+ s.Invalidate()
+}
+
+func (s *static) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) uintptr {
+ switch msg {
+ case win.WM_NCHITTEST:
+ return win.HTCLIENT
+
+ case win.WM_SIZE, win.WM_SIZING:
+ s.Invalidate()
+
+ case win.WM_DRAWITEM:
+ dis := (*win.DRAWITEMSTRUCT)(unsafe.Pointer(lParam))
+
+ canvas, err := newCanvasFromHDC(dis.HDC)
+ if err != nil {
+ break
+ }
+ canvas.Dispose()
+
+ format := TextWordbreak
+
+ switch s.textAlignment {
+ case AlignHNearVNear, AlignHNearVCenter, AlignHNearVFar:
+ format |= TextLeft
+
+ case AlignHCenterVNear, AlignHCenterVCenter, AlignHCenterVFar:
+ format |= TextCenter
+
+ case AlignHFarVNear, AlignHFarVCenter, AlignHFarVFar:
+ format |= TextRight
+ }
+
+ switch s.textAlignment {
+ case AlignHNearVNear, AlignHCenterVNear, AlignHFarVNear:
+ format |= TextTop
+
+ case AlignHNearVCenter, AlignHCenterVCenter, AlignHFarVCenter:
+ format |= TextVCenter
+
+ case AlignHNearVFar, AlignHCenterVFar, AlignHFarVFar:
+ format |= TextBottom
+ }
+
+ bounds := rectangleFromRECT(dis.RcItem)
+
+ if format&TextVCenter != 0 || format&TextBottom != 0 {
+ size := s.calculateTextSizeForWidth(bounds.Width)
+
+ if format&TextVCenter != 0 {
+ bounds.Y += (bounds.Height - size.Height) / 2
+ } else {
+ bounds.Y += bounds.Height - size.Height
+ }
+
+ bounds.Height = size.Height
+ }
+
+ bg, wnd := s.backgroundEffective()
+ if bg == nil {
+ break
+ }
+
+ s.prepareDCForBackground(dis.HDC, s.hWnd, wnd)
+
+ if err := canvas.FillRectangle(bg, s.ClientBounds()); err != nil {
+ break
+ }
+
+ if err := canvas.DrawText(s.text(), s.Font(), s.textColor, bounds, format); err != nil {
+ break
+ }
+
+ return 1
+ }
+
+ return s.WidgetBase.WndProc(hwnd, msg, wParam, lParam)
+}
diff --git a/tableviewcolumn.go b/tableviewcolumn.go
index b482ac2a..e66c59ac 100644
--- a/tableviewcolumn.go
+++ b/tableviewcolumn.go
@@ -45,6 +45,10 @@ func (tvc *TableViewColumn) Alignment() Alignment1D {
// SetAlignment sets the alignment of the TableViewColumn.
func (tvc *TableViewColumn) SetAlignment(alignment Alignment1D) (err error) {
+ if alignment == AlignDefault {
+ alignment = AlignNear
+ }
+
if alignment == tvc.alignment {
return nil
}
diff --git a/textedit.go b/textedit.go
index 3bf4cec2..6897666c 100644
--- a/textedit.go
+++ b/textedit.go
@@ -105,6 +105,10 @@ func (te *TextEdit) Alignment() Alignment1D {
}
func (te *TextEdit) SetAlignment(alignment Alignment1D) error {
+ if alignment == AlignDefault {
+ alignment = AlignNear
+ }
+
var bit uint32
switch alignment {
diff --git a/textlabel.go b/textlabel.go
new file mode 100644
index 00000000..299590a7
--- /dev/null
+++ b/textlabel.go
@@ -0,0 +1,86 @@
+// // Copyright 2018 The Walk Authors. All rights reserved.
+// // Use of this source code is governed by a BSD-style
+// // license that can be found in the LICENSE file.
+
+// // +build windows
+
+package walk
+
+type TextLabel struct {
+ static
+ textChangedPublisher EventPublisher
+}
+
+func NewTextLabel(parent Container) (*TextLabel, error) {
+ return NewTextLabelWithStyle(parent, 0)
+}
+
+func NewTextLabelWithStyle(parent Container, style uint32) (*TextLabel, error) {
+ tl := new(TextLabel)
+
+ if err := tl.init(tl, parent); err != nil {
+ return nil, err
+ }
+
+ tl.textAlignment = AlignHNearVNear
+
+ tl.MustRegisterProperty("Text", NewProperty(
+ func() interface{} {
+ return tl.Text()
+ },
+ func(v interface{}) error {
+ _, err := tl.setText(assertStringOr(v, ""))
+ return err
+ },
+ tl.textChangedPublisher.Event()))
+
+ return tl, nil
+}
+
+func (*TextLabel) LayoutFlags() LayoutFlags {
+ return ShrinkableHorz | ShrinkableVert | GrowableHorz | GrowableVert
+}
+
+func (tl *TextLabel) MinSizeHint() Size {
+ if tl.minSize.Width > 0 {
+ return tl.calculateTextSizeForWidth(tl.minSize.Width)
+ }
+
+ return tl.calculateTextSizeForWidth(0)
+}
+
+func (tl *TextLabel) SizeHint() Size {
+ return tl.calculateTextSizeForWidth(tl.Width())
+}
+
+func (tl *TextLabel) HeightForWidth(width int) int {
+ return tl.calculateTextSizeForWidth(width).Height
+}
+
+func (tl *TextLabel) TextAlignment() Alignment2D {
+ return tl.textAlignment
+}
+
+func (tl *TextLabel) SetTextAlignment(alignment Alignment2D) error {
+ if alignment == AlignHVDefault {
+ alignment = AlignHNearVNear
+ }
+
+ return tl.setTextAlignment(alignment)
+}
+
+func (tl *TextLabel) Text() string {
+ return tl.text()
+}
+
+func (tl *TextLabel) SetText(text string) error {
+ if changed, err := tl.setText(text); err != nil {
+ return err
+ } else if !changed {
+ return nil
+ }
+
+ tl.textChangedPublisher.Publish()
+
+ return nil
+}