summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2019-02-25 17:54:25 +0100
committerAlexander Neumann <alexander.neumann@picos-software.com>2019-02-25 17:54:25 +0100
commit3ad7eecee2ab43445130938d65b1297ae7ef6f37 (patch)
tree2e43400dfcf222a280c0ddb781a823a74294db46
parentRemove experimental run.dll performance improvement code (diff)
downloadwireguard-windows-3ad7eecee2ab43445130938d65b1297ae7ef6f37.tar.xz
wireguard-windows-3ad7eecee2ab43445130938d65b1297ae7ef6f37.zip
Some more static fixes
-rw-r--r--static.go98
1 files changed, 56 insertions, 42 deletions
diff --git a/static.go b/static.go
index e91d8e2a..d9a2d093 100644
--- a/static.go
+++ b/static.go
@@ -52,7 +52,7 @@ func (s *static) init(widget Widget, parent Container) error {
0,
nil,
); s.hwndStatic == 0 {
- return newErr("creating static failed")
+ return newError("creating static failed")
}
s.origStaticWndProcPtr = win.SetWindowLongPtr(s.hwndStatic, win.GWLP_WNDPROC, staticWndProcPtr)
@@ -176,7 +176,17 @@ func (s *static) setText(text string) (changed bool, err error) {
return false, err
}
- return true, s.updateParentLayout()
+ size := s.Bounds().Size()
+
+ if err := s.updateParentLayout(); err != nil {
+ return false, err
+ }
+
+ if s.Bounds().Size() == size && size != (Size{}) {
+ s.updateStaticBounds()
+ }
+
+ return true, nil
}
func (s *static) TextColor() Color {
@@ -189,60 +199,64 @@ func (s *static) SetTextColor(c Color) {
s.Invalidate()
}
-func (s *static) WndProc(hwnd win.HWND, msg uint32, wp, lp uintptr) uintptr {
- switch msg {
- case win.WM_CTLCOLORSTATIC:
- if hBrush := s.handleWMCTLCOLOR(wp, uintptr(s.hWnd)); hBrush != 0 {
- return hBrush
- }
+func (s *static) updateStaticBounds() {
+ var format DrawTextFormat
+
+ switch s.textAlignment {
+ case AlignHNearVNear, AlignHNearVCenter, AlignHNearVFar:
+ format |= TextLeft
+
+ case AlignHCenterVNear, AlignHCenterVCenter, AlignHCenterVFar:
+ format |= TextCenter
- case win.WM_SIZE, win.WM_SIZING:
- var format DrawTextFormat
+ case AlignHFarVNear, AlignHFarVCenter, AlignHFarVFar:
+ format |= TextRight
+ }
- switch s.textAlignment {
- case AlignHNearVNear, AlignHNearVCenter, AlignHNearVFar:
- format |= TextLeft
+ switch s.textAlignment {
+ case AlignHNearVNear, AlignHCenterVNear, AlignHFarVNear:
+ format |= TextTop
- case AlignHCenterVNear, AlignHCenterVCenter, AlignHCenterVFar:
- format |= TextCenter
+ case AlignHNearVCenter, AlignHCenterVCenter, AlignHFarVCenter:
+ format |= TextVCenter
- case AlignHFarVNear, AlignHFarVCenter, AlignHFarVFar:
- format |= TextRight
- }
+ case AlignHNearVFar, AlignHCenterVFar, AlignHFarVFar:
+ format |= TextBottom
+ }
- switch s.textAlignment {
- case AlignHNearVNear, AlignHCenterVNear, AlignHFarVNear:
- format |= TextTop
+ cb := s.ClientBounds()
- case AlignHNearVCenter, AlignHCenterVCenter, AlignHFarVCenter:
- format |= TextVCenter
+ if format&TextVCenter != 0 || format&TextBottom != 0 {
+ var size Size
+ if _, ok := s.window.(HeightForWidther); ok {
+ size = s.calculateTextSizeForWidth(cb.Width)
+ } else {
+ size = s.calculateTextSize()
+ }
- case AlignHNearVFar, AlignHCenterVFar, AlignHFarVFar:
- format |= TextBottom
+ if format&TextVCenter != 0 {
+ cb.Y += (cb.Height - size.Height) / 2
+ } else {
+ cb.Y += cb.Height - size.Height
}
- cb := s.ClientBounds()
+ cb.Height = size.Height
+ }
- if format&TextVCenter != 0 || format&TextBottom != 0 {
- var size Size
- if _, ok := s.window.(HeightForWidther); ok {
- size = s.calculateTextSizeForWidth(cb.Width)
- } else {
- size = s.calculateTextSize()
- }
+ win.MoveWindow(s.hwndStatic, int32(cb.X), int32(cb.Y), int32(cb.Width), int32(cb.Height), true)
- if format&TextVCenter != 0 {
- cb.Y += (cb.Height - size.Height) / 2
- } else {
- cb.Y += cb.Height - size.Height
- }
+ s.Invalidate()
+}
- cb.Height = size.Height
+func (s *static) WndProc(hwnd win.HWND, msg uint32, wp, lp uintptr) uintptr {
+ switch msg {
+ case win.WM_CTLCOLORSTATIC:
+ if hBrush := s.handleWMCTLCOLOR(wp, uintptr(s.hWnd)); hBrush != 0 {
+ return hBrush
}
- win.MoveWindow(s.hwndStatic, int32(cb.X), int32(cb.Y), int32(cb.Width), int32(cb.Height), true)
-
- s.Invalidate()
+ case win.WM_SIZE:
+ s.updateStaticBounds()
}
return s.WidgetBase.WndProc(hwnd, msg, wp, lp)