diff options
author | Alexander Neumann <alexander.neumann@picos-software.com> | 2019-05-07 12:53:44 +0200 |
---|---|---|
committer | Alexander Neumann <alexander.neumann@picos-software.com> | 2019-05-07 12:53:44 +0200 |
commit | fadd1630a7bf755fd5877ad6f0596c669d6130a4 (patch) | |
tree | 46c8b606302e0c5132233a62ca8fc23b377d2344 | |
parent | More work on multi monitor HIDPI (diff) | |
download | wireguard-windows-fadd1630a7bf755fd5877ad6f0596c669d6130a4.tar.xz wireguard-windows-fadd1630a7bf755fd5877ad6f0596c669d6130a4.zip |
Widget[Base]: Add *Pixel variants of MinSize, MaxSize and SetMinMaxSize
-rw-r--r-- | boxlayout.go | 2 | ||||
-rw-r--r-- | dialog.go | 2 | ||||
-rw-r--r-- | form.go | 4 | ||||
-rw-r--r-- | gridlayout.go | 8 | ||||
-rw-r--r-- | splitterlayout.go | 2 | ||||
-rw-r--r-- | widget.go | 4 | ||||
-rw-r--r-- | window.go | 50 |
7 files changed, 61 insertions, 11 deletions
diff --git a/boxlayout.go b/boxlayout.go index 6c2f73bd..010d2024 100644 --- a/boxlayout.go +++ b/boxlayout.go @@ -339,7 +339,7 @@ func boxLayoutItems(widgets []Widget, orientation Orientation, alignment Alignme flags := widget.LayoutFlags() - max := widget.MaxSize() + max := widget.MaxSizePixels() pref := widget.SizeHint() if orientation == Horizontal { @@ -158,7 +158,7 @@ func (dlg *Dialog) Show() { var size Size if layout := dlg.Layout(); layout != nil { size = layout.MinSize() - min := dlg.MinSize() + min := dlg.MinSizePixels() size.Width = maxi(size.Width, min.Width) size.Height = maxi(size.Height, min.Height) } else { @@ -683,8 +683,8 @@ func (fb *FormBase) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) u } mmi.PtMinTrackSize = win.POINT{ - int32(fb.IntFrom96DPI(maxi(min.Width, fb.minSize.Width))), - int32(fb.IntFrom96DPI(maxi(min.Height, fb.minSize.Height))), + int32(maxi(min.Width, fb.minSize.Width)), + int32(maxi(min.Height, fb.minSize.Height)), } return 0 diff --git a/gridlayout.go b/gridlayout.go index 66f58fd7..0e52ef7e 100644 --- a/gridlayout.go +++ b/gridlayout.go @@ -300,10 +300,10 @@ func (l *GridLayout) LayoutFlags() LayoutFlags { wf := widget.LayoutFlags() - if wf&GreedyHorz != 0 && widget.MaxSize().Width > 0 { + if wf&GreedyHorz != 0 && widget.MaxSizePixels().Width > 0 { wf &^= GreedyHorz } - if wf&GreedyVert != 0 && widget.MaxSize().Height > 0 { + if wf&GreedyVert != 0 && widget.MaxSizePixels().Height > 0 { wf &^= GreedyVert } @@ -554,7 +554,7 @@ func (l *GridLayout) Update(reset bool) error { if lf := widget.LayoutFlags(); lf&GrowableHorz == 0 || lf&GrowableVert == 0 { s := widget.SizeHint() - max := widget.MaxSize() + max := widget.MaxSizePixels() if max.Width > 0 && s.Width > max.Width { s.Width = max.Width } @@ -651,7 +651,7 @@ func (l *GridLayout) sectionSizesForSpace(orientation Orientation, space int, wi info := l.widgetBase2Info[wb] flags := widget.LayoutFlags() - max := widget.MaxSize() + max := widget.MaxSizePixels() pref := widget.SizeHint() if orientation == Horizontal { diff --git a/splitterlayout.go b/splitterlayout.go index cc046d7a..68368b74 100644 --- a/splitterlayout.go +++ b/splitterlayout.go @@ -421,7 +421,7 @@ func (l *splitterLayout) Update(reset bool) error { var min, max int minSize := minSizeEffective(widget) - maxSize := widget.MaxSize() + maxSize := widget.MaxSizePixels() if l.orientation == Horizontal { min = minSize.Width @@ -533,9 +533,9 @@ func ancestor(w Widget) Form { } func minSizeEffective(w Widget) Size { - s := maxSize(w.MinSize(), w.MinSizeHint()) + s := maxSize(w.MinSizePixels(), w.MinSizeHint()) - max := w.MaxSize() + max := w.MaxSizePixels() if max.Width > 0 && s.Width > max.Width { s.Width = max.Width } @@ -154,6 +154,13 @@ type Window interface { // has a Layout. RootWidgets, like *MainWindow and *Dialog, also honor this. MaxSize() Size + // MaxSizePixels returns the maximum allowed outer Size for the Window, including + // decorations. + // + // For child windows, this is only relevant when the parent of the Window + // has a Layout. RootWidgets, like *MainWindow and *Dialog, also honor this. + MaxSizePixels() Size + // MinSize returns the minimum allowed outer Size for the Window, including // decorations. // @@ -161,6 +168,13 @@ type Window interface { // has a Layout. RootWidgets, like *MainWindow and *Dialog, also honor this. MinSize() Size + // MinSizePixels returns the minimum allowed outer Size for the Window, including + // decorations. + // + // For child windows, this is only relevant when the parent of the Window + // has a Layout. RootWidgets, like *MainWindow and *Dialog, also honor this. + MinSizePixels() Size + // MouseDown returns a *MouseEvent that you can attach to for handling // mouse down events for the Window. MouseDown() *MouseEvent @@ -240,6 +254,12 @@ type Window interface { // Use walk.Size{} to make the respective limit be ignored. SetMinMaxSize(min, max Size) error + // SetMinMaxSizePixels sets the minimum and maximum outer Size of the Window, + // including decorations. + // + // Use walk.Size{} to make the respective limit be ignored. + SetMinMaxSizePixels(min, max Size) error + // SetName sets the name of the Window. // // This is important if you want to make use of the built-in UI persistence. @@ -871,6 +891,10 @@ type ApplyDPIer interface { } func (wb *WindowBase) ApplyDPI(dpi int) { + scale := float64(dpi) / float64(wb.dpi) + wb.minSize = wb.scaleSize(wb.minSize, scale) + wb.maxSize = wb.scaleSize(wb.maxSize, scale) + wb.dpi = dpi if af, ok := wb.window.(applyFonter); ok { @@ -1291,6 +1315,15 @@ func (wb *WindowBase) SetBoundsPixels(bounds Rectangle) error { // For child windows, this is only relevant when the parent of the *WindowBase // has a Layout. RootWidgets, like *MainWindow and *Dialog, also honor this. func (wb *WindowBase) MinSize() Size { + return wb.SizeTo96DPI(wb.MinSizePixels()) +} + +// MinSizePixels returns the minimum allowed outer Size for the *WindowBase, including +// decorations. +// +// For child windows, this is only relevant when the parent of the *WindowBase +// has a Layout. RootWidgets, like *MainWindow and *Dialog, also honor this. +func (wb *WindowBase) MinSizePixels() Size { return wb.minSize } @@ -1300,6 +1333,15 @@ func (wb *WindowBase) MinSize() Size { // For child windows, this is only relevant when the parent of the *WindowBase // has a Layout. RootWidgets, like *MainWindow and *Dialog, also honor this. func (wb *WindowBase) MaxSize() Size { + return wb.SizeFrom96DPI(wb.MaxSizePixels()) +} + +// MaxSizePixels returns the maximum allowed outer Size for the *WindowBase, including +// decorations. +// +// For child windows, this is only relevant when the parent of the *WindowBase +// has a Layout. RootWidgets, like *MainWindow and *Dialog, also honor this. +func (wb *WindowBase) MaxSizePixels() Size { return wb.maxSize } @@ -1308,6 +1350,14 @@ func (wb *WindowBase) MaxSize() Size { // // Use walk.Size{} to make the respective limit be ignored. func (wb *WindowBase) SetMinMaxSize(min, max Size) error { + return wb.SetMinMaxSizePixels(wb.SizeFrom96DPI(min), wb.SizeFrom96DPI(max)) +} + +// SetMinMaxSizePixels sets the minimum and maximum outer Size of the *WindowBase, +// including decorations. +// +// Use walk.Size{} to make the respective limit be ignored. +func (wb *WindowBase) SetMinMaxSizePixels(min, max Size) error { if min.Width < 0 || min.Height < 0 { return newError("min must be positive") } |