Permalink
Browse files

Some Splitter and layout improvements

  • Loading branch information...
1 parent 79beaa9 commit 86f375ee9e3ef291babd88e75c051c40d673dd34 @lxn committed Jun 7, 2012
Showing with 223 additions and 138 deletions.
  1. +14 −37 boxlayout.go
  2. +5 −1 checkbox.go
  3. +5 −1 combobox.go
  4. +5 −1 dateedit.go
  5. +5 −17 gridlayout.go
  6. +1 −1 label.go
  7. +4 −0 lineedit.go
  8. +3 −4 listbox.go
  9. +4 −0 numberedit.go
  10. +4 −0 progressbar.go
  11. +5 −6 pushbutton.go
  12. +5 −1 radiobutton.go
  13. +9 −0 rectangle.go
  14. +36 −0 size.go
  15. +74 −64 splitter.go
  16. +15 −1 splitterlayout.go
  17. +4 −0 textedit.go
  18. +4 −0 toolbar.go
  19. +4 −0 toolbutton.go
  20. +9 −2 toplevelwindow.go
  21. +8 −2 widget.go
View
@@ -266,55 +266,32 @@ func (l *BoxLayout) MinSize() Size {
return Size{}
}
- // Begin by finding out which widgets we care about.
widgets := l.widgets()
+ var s Size
- // Prepare some useful data.
- sizes := make([]int, len(widgets))
- var s2 int
-
- for i, widget := range widgets {
- min := widget.MinSize()
- minHint := widget.MinSizeHint()
+ for _, widget := range widgets {
+ min := widget.BaseWidget().minSizeEffective()
if l.orientation == Horizontal {
- if min.Width > 0 {
- sizes[i] = mini(minHint.Width, min.Width)
- } else {
- sizes[i] = minHint.Width
- }
-
- s2 = maxi(s2, maxi(minHint.Height, min.Height))
+ s.Width += min.Width
+ s.Height = maxi(s.Height, min.Height)
} else {
- if min.Height > 0 {
- sizes[i] = mini(minHint.Height, min.Height)
- } else {
- sizes[i] = minHint.Height
- }
-
- s2 = maxi(s2, maxi(minHint.Width, min.Width))
+ s.Height += min.Height
+ s.Width = maxi(s.Width, min.Width)
}
}
- s1 := l.spacing * (len(widgets) - 1)
-
if l.orientation == Horizontal {
- s1 += l.margins.HNear + l.margins.HFar
- s2 += l.margins.VNear + l.margins.VFar
+ s.Width += l.spacing * (len(widgets) - 1)
+ s.Width += l.margins.HNear + l.margins.HFar
+ s.Height += l.margins.VNear + l.margins.VFar
} else {
- s1 += l.margins.VNear + l.margins.VFar
- s2 += l.margins.HNear + l.margins.HFar
- }
-
- for _, s := range sizes {
- s1 += s
- }
-
- if l.orientation == Horizontal {
- return Size{s1, s2}
+ s.Height += l.spacing * (len(widgets) - 1)
+ s.Height += l.margins.VNear + l.margins.VFar
+ s.Width += l.margins.HNear + l.margins.HFar
}
- return Size{s2, s1}
+ return s
}
func (l *BoxLayout) Update(reset bool) error {
View
@@ -40,7 +40,7 @@ func (*CheckBox) LayoutFlags() LayoutFlags {
return 0
}
-func (cb *CheckBox) SizeHint() Size {
+func (cb *CheckBox) MinSizeHint() Size {
defaultSize := cb.dialogBaseUnitsToPixels(Size{50, 10})
textSize := cb.calculateTextSize()
@@ -50,3 +50,7 @@ func (cb *CheckBox) SizeHint() Size {
return Size{w, h}
}
+
+func (cb *CheckBox) SizeHint() Size {
+ return cb.MinSizeHint()
+}
View
@@ -56,7 +56,7 @@ func (*ComboBox) LayoutFlags() LayoutFlags {
return GrowableHorz
}
-func (cb *ComboBox) SizeHint() Size {
+func (cb *ComboBox) MinSizeHint() Size {
defaultSize := cb.dialogBaseUnitsToPixels(Size{50, 12})
if cb.model != nil && cb.maxItemTextWidth <= 0 {
@@ -70,6 +70,10 @@ func (cb *ComboBox) SizeHint() Size {
return Size{w, h}
}
+func (cb *ComboBox) SizeHint() Size {
+ return cb.MinSizeHint()
+}
+
func (cb *ComboBox) itemString(index int) string {
switch val := cb.model.Value(index).(type) {
case string:
View
@@ -66,10 +66,14 @@ func (*DateEdit) LayoutFlags() LayoutFlags {
return GrowableHorz
}
-func (de *DateEdit) SizeHint() Size {
+func (de *DateEdit) MinSizeHint() Size {
return de.dialogBaseUnitsToPixels(Size{64, 12})
}
+func (de *DateEdit) SizeHint() Size {
+ return de.MinSizeHint()
+}
+
func (de *DateEdit) systemTime() (*SYSTEMTIME, error) {
var st SYSTEMTIME
View
@@ -351,22 +351,14 @@ func (l *GridLayout) MinSize() Size {
widths := make([]int, len(l.cells[0]))
heights := make([]int, len(l.cells))
- type minSizes struct {
- minSize Size
- minSizeHint Size
- }
-
- widget2MinSizes := make(map[Widget]*minSizes)
+ widget2MinSize := make(map[Widget]Size)
for widget, _ := range l.widget2Info {
if !shouldLayoutWidget(widget) {
continue
}
- min := widget.MinSize()
- hint := widget.MinSizeHint()
-
- widget2MinSizes[widget] = &minSizes{min, hint}
+ widget2MinSize[widget] = widget.BaseWidget().minSizeEffective()
}
for row := 0; row < len(heights); row++ {
@@ -377,18 +369,14 @@ func (l *GridLayout) MinSize() Size {
continue
}
- minSizes := widget2MinSizes[widget]
-
- min := minSizes.minSize
- hint := minSizes.minSizeHint
-
+ min := widget2MinSize[widget]
info := l.widget2Info[widget]
if info.spanHorz == 1 {
- widths[col] = maxi(widths[col], maxi(hint.Width, min.Width))
+ widths[col] = maxi(widths[col], min.Width)
}
if info.spanVert == 1 {
- heights[row] = maxi(heights[row], maxi(hint.Height, min.Height))
+ heights[row] = maxi(heights[row], min.Height)
}
}
}
View
@@ -45,7 +45,7 @@ func (l *Label) MinSizeHint() Size {
}
func (l *Label) SizeHint() Size {
- return l.calculateTextSize()
+ return l.MinSizeHint()
}
func (l *Label) Text() string {
View
@@ -147,6 +147,10 @@ func (*LineEdit) LayoutFlags() LayoutFlags {
return ShrinkableHorz | GrowableHorz | GreedyHorz
}
+func (le *LineEdit) MinSizeHint() Size {
+ return le.dialogBaseUnitsToPixels(Size{20, 12})
+}
+
func (le *LineEdit) SizeHint() Size {
return le.dialogBaseUnitsToPixels(Size{50, 12})
}
View
@@ -53,7 +53,7 @@ func (*ListBox) setOrigWndProcPtr(ptr uintptr) {
}
func (*ListBox) LayoutFlags() LayoutFlags {
- return ShrinkableHorz | ShrinkableVert | GrowableHorz | GrowableVert | GreedyHorz | GreedyVert
+ return ShrinkableHorz | ShrinkableVert | GrowableHorz | GrowableVert | GreedyHorz | GreedyVert
}
func (lb *ListBox) itemString(index int) string {
@@ -78,7 +78,7 @@ func (lb *ListBox) itemString(index int) string {
func (lb *ListBox) insertItemAt(index int) error {
str := lb.itemString(index)
lp := uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(str)))
- ret := int (SendMessage(lb.hWnd, LB_INSERTSTRING, uintptr(index), lp))
+ ret := int(SendMessage(lb.hWnd, LB_INSERTSTRING, uintptr(index), lp))
if ret == LB_ERRSPACE || ret == LB_ERR {
return newError("SendMessage(LB_INSERTSTRING)")
}
@@ -111,7 +111,6 @@ func (lb *ListBox) resetItems() error {
return nil
}
-
func (lb *ListBox) attachModel() {
itemsResetHandler := func() {
lb.resetItems()
@@ -184,7 +183,7 @@ func (lb *ListBox) calculateMaxItemTextWidth() int {
var maxWidth int
- if lb.model == nil{
+ if lb.model == nil {
return -1
}
count := lb.model.ItemCount()
View
@@ -103,6 +103,10 @@ func (*NumberEdit) LayoutFlags() LayoutFlags {
return ShrinkableHorz | GrowableHorz
}
+func (ne *NumberEdit) MinSizeHint() Size {
+ return ne.dialogBaseUnitsToPixels(Size{20, 12})
+}
+
func (ne *NumberEdit) SizeHint() Size {
s := ne.dialogBaseUnitsToPixels(Size{50, 12})
return Size{s.Width, maxi(s.Height, 22)}
View
@@ -40,6 +40,10 @@ func (*ProgressBar) LayoutFlags() LayoutFlags {
return ShrinkableHorz | GrowableHorz | GreedyHorz
}
+func (pb *ProgressBar) MinSizeHint() Size {
+ return pb.dialogBaseUnitsToPixels(Size{10, 14})
+}
+
func (pb *ProgressBar) SizeHint() Size {
return pb.dialogBaseUnitsToPixels(Size{50, 14})
}
View
@@ -42,17 +42,16 @@ func (*PushButton) LayoutFlags() LayoutFlags {
return GrowableHorz
}
-func (pb *PushButton) SizeHint() Size {
+func (pb *PushButton) MinSizeHint() Size {
var s Size
SendMessage(pb.hWnd, BCM_GETIDEALSIZE, 0, uintptr(unsafe.Pointer(&s)))
- minSize := pb.dialogBaseUnitsToPixels(Size{50, 14})
-
- s.Width = maxi(s.Width, minSize.Width)
- s.Height = maxi(s.Height, minSize.Height)
+ return maxSize(s, pb.dialogBaseUnitsToPixels(Size{50, 14}))
+}
- return s
+func (pb *PushButton) SizeHint() Size {
+ return pb.MinSizeHint()
}
func (pb *PushButton) ensureProperDialogDefaultButton(hwndFocus HWND) {
View
@@ -40,7 +40,7 @@ func (*RadioButton) LayoutFlags() LayoutFlags {
return 0
}
-func (rb *RadioButton) SizeHint() Size {
+func (rb *RadioButton) MinSizeHint() Size {
defaultSize := rb.dialogBaseUnitsToPixels(Size{50, 10})
textSize := rb.calculateTextSize()
@@ -50,3 +50,7 @@ func (rb *RadioButton) SizeHint() Size {
return Size{w, h}
}
+
+func (rb *RadioButton) SizeHint() Size {
+ return rb.MinSizeHint()
+}
View
@@ -10,6 +10,15 @@ type Rectangle struct {
X, Y, Width, Height int
}
+func rectangleFromRECT(r winapi.RECT) Rectangle {
+ return Rectangle{
+ X: int(r.Left),
+ Y: int(r.Top),
+ Width: int(r.Right - r.Left),
+ Height: int(r.Bottom - r.Top),
+ }
+}
+
func (r Rectangle) Left() int {
return r.X
}
View
36 size.go
@@ -7,3 +7,39 @@ package walk
type Size struct {
Width, Height int
}
+
+func minSize(a, b Size) Size {
+ var s Size
+
+ if a.Width < b.Width {
+ s.Width = a.Width
+ } else {
+ s.Width = b.Width
+ }
+
+ if a.Height < b.Height {
+ s.Height = a.Height
+ } else {
+ s.Height = b.Height
+ }
+
+ return s
+}
+
+func maxSize(a, b Size) Size {
+ var s Size
+
+ if a.Width > b.Width {
+ s.Width = a.Width
+ } else {
+ s.Width = b.Width
+ }
+
+ if a.Height > b.Height {
+ s.Height = a.Height
+ } else {
+ s.Height = b.Height
+ }
+
+ return s
+}
Oops, something went wrong.

0 comments on commit 86f375e

Please sign in to comment.