Skip to content

Commit d8ada91

Browse files
committed
Run for your life or prepare to meet the
_..._ .-'_..._''. /| . .--. .' .' '.\ || .'| |__| / .' .-. .- || .| < | .--. .| . ' .-,.--. \ \ / / || __ __ .' |_ | | | | .' |_ | | | .-. | __ \ \ / / ||/'__ '. .:--.'. .' | _ | | .'''-. | | .' | | | | | | | .:--.'. .--------. \ \ / / |:/` '. '/ | \ |'--. .-' .' | | |/.'''. \| |'--. .-' . ' | | | |/ | \ | |____ | \ \ / / || | |`" __ | | | | . | /| / | || | | | \ '. .| | '- `" __ | | / / \ ` / ||\ / ' .'.''| | | | .'.'| |//| | | ||__| | | '. `._____.-'/| | .'.''| | .' / \ / |/\'..' / / / | |_ | '.'.'.'.-' / | | | | | '.' `-.______ / | | / / | |_ / /___ / / ' `'-'` \ \._,\ '/ | / .' \_.' | '. | '. | / ` |_| \ \._,\ '/| ||`-' / `--' `" `'-' '---' '---' `'-' `--' `" |_________| '..'
1 parent 4e7c7a2 commit d8ada91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2861
-2178
lines changed

boxlayout.go

+119-145
Large diffs are not rendered by default.

button.go

+35-10
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,6 @@ func (b *Button) init() {
8686
b.textChangedPublisher.Event()))
8787
}
8888

89-
func (b *Button) MinSizeHint() Size {
90-
var s win.SIZE
91-
92-
b.SendMessage(win.BCM_GETIDEALSIZE, 0, uintptr(unsafe.Pointer(&s)))
93-
94-
return maxSize(Size{int(s.CX), int(s.CY)}, b.dialogBaseUnitsToPixels(Size{50, 14}))
95-
}
96-
9789
func (b *Button) ApplyDPI(dpi int) {
9890
b.WidgetBase.ApplyDPI(dpi)
9991

@@ -119,7 +111,7 @@ func (b *Button) SetImage(image Image) error {
119111

120112
b.image = image
121113

122-
b.updateParentLayout()
114+
b.RequestLayout()
123115

124116
b.imageChangedPublisher.Publish()
125117

@@ -143,7 +135,9 @@ func (b *Button) SetText(value string) error {
143135
return err
144136
}
145137

146-
return b.updateParentLayout()
138+
b.RequestLayout()
139+
140+
return nil
147141
}
148142

149143
func (b *Button) Checked() bool {
@@ -229,3 +223,34 @@ func (b *Button) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) uint
229223

230224
return b.WidgetBase.WndProc(hwnd, msg, wParam, lParam)
231225
}
226+
227+
func (b *Button) idealSize() Size {
228+
var s win.SIZE
229+
230+
b.SendMessage(win.BCM_GETIDEALSIZE, 0, uintptr(unsafe.Pointer(&s)))
231+
232+
return maxSize(Size{int(s.CX), int(s.CY)}, b.dialogBaseUnitsToPixels(Size{50, 14}))
233+
}
234+
235+
func (b *Button) CreateLayoutItem(ctx *LayoutContext) LayoutItem {
236+
return &buttonLayoutItem{
237+
idealSize: b.idealSize(),
238+
}
239+
}
240+
241+
type buttonLayoutItem struct {
242+
LayoutItemBase
243+
idealSize Size
244+
}
245+
246+
func (li *buttonLayoutItem) LayoutFlags() LayoutFlags {
247+
return 0
248+
}
249+
250+
func (li *buttonLayoutItem) IdealSize() Size {
251+
return li.MinSize()
252+
}
253+
254+
func (li *buttonLayoutItem) MinSize() Size {
255+
return li.idealSize
256+
}

canvas.go

+5-17
Original file line numberDiff line numberDiff line change
@@ -464,25 +464,14 @@ func (c *Canvas) fontHeight(font *Font) (height int, err error) {
464464
return
465465
}
466466

467-
func (c *Canvas) measureTextForDPI(text string, font *Font, bounds Rectangle, format DrawTextFormat, dpi int) (boundsMeasured Rectangle, runesFitted int, err error) {
468-
// HACK: We don't want to actually draw on the Canvas here, but if we use
469-
// the DT_CALCRECT flag to avoid drawing, DRAWTEXTPARAMc.UiLengthDrawn will
470-
// not contain a useful value. To work around this, we create an in-memory
471-
// metafile and draw into that instead.
472-
if c.measureTextMetafile == nil {
473-
c.measureTextMetafile, err = NewMetafile(c)
474-
if err != nil {
475-
return
476-
}
477-
}
478-
467+
func (c *Canvas) measureTextForDPI(text string, font *Font, bounds Rectangle, format DrawTextFormat, dpi int) (boundsMeasured Rectangle, err error) {
479468
hFont := win.HGDIOBJ(font.handleForDPI(dpi))
480-
oldHandle := win.SelectObject(c.measureTextMetafile.hdc, hFont)
469+
oldHandle := win.SelectObject(c.hdc, hFont)
481470
if oldHandle == 0 {
482471
err = newError("SelectObject failed")
483472
return
484473
}
485-
defer win.SelectObject(c.measureTextMetafile.hdc, oldHandle)
474+
defer win.SelectObject(c.hdc, oldHandle)
486475

487476
rect := &win.RECT{
488477
int32(bounds.X),
@@ -494,10 +483,10 @@ func (c *Canvas) measureTextForDPI(text string, font *Font, bounds Rectangle, fo
494483
params.CbSize = uint32(unsafe.Sizeof(params))
495484

496485
strPtr := syscall.StringToUTF16Ptr(text)
497-
dtfmt := uint32(format) | win.DT_EDITCONTROL | win.DT_WORDBREAK | win.DT_CALCRECT
486+
dtfmt := uint32(format) | win.DT_CALCRECT | win.DT_EDITCONTROL | win.DT_NOPREFIX | win.DT_WORDBREAK
498487

499488
height := win.DrawTextEx(
500-
c.measureTextMetafile.hdc, strPtr, -1, rect, dtfmt, &params)
489+
c.hdc, strPtr, -1, rect, dtfmt, &params)
501490
if height == 0 {
502491
err = newError("DrawTextEx failed")
503492
return
@@ -509,7 +498,6 @@ func (c *Canvas) measureTextForDPI(text string, font *Font, bounds Rectangle, fo
509498
int(rect.Right - rect.Left),
510499
int(height),
511500
}
512-
runesFitted = int(params.UiLengthDrawn)
513501

514502
return
515503
}

checkbox.go

-8
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ func NewCheckBox(parent Container) (*CheckBox, error) {
6060
return cb, nil
6161
}
6262

63-
func (*CheckBox) LayoutFlags() LayoutFlags {
64-
return 0
65-
}
66-
67-
func (cb *CheckBox) SizeHint() Size {
68-
return cb.MinSizeHint()
69-
}
70-
7163
func (cb *CheckBox) TextOnLeftSide() bool {
7264
return cb.hasStyleBits(win.BS_LEFTTEXT)
7365
}

combobox.go

+51-29
Original file line numberDiff line numberDiff line change
@@ -228,38 +228,12 @@ func newComboBoxWithStyle(parent Container, style uint32) (*ComboBox, error) {
228228
return cb, nil
229229
}
230230

231-
func (cb *ComboBox) LayoutFlags() LayoutFlags {
232-
if cb.Editable() {
233-
return GrowableHorz | GreedyHorz
234-
}
235-
236-
return GrowableHorz
237-
}
238-
239-
func (cb *ComboBox) MinSizeHint() Size {
240-
defaultSize := cb.dialogBaseUnitsToPixels(Size{30, 12})
241-
242-
if cb.model != nil && cb.maxItemTextWidth <= 0 {
243-
cb.maxItemTextWidth = cb.calculateMaxItemTextWidth()
244-
}
245-
246-
// FIXME: Use GetThemePartSize instead of guessing
247-
w := maxi(defaultSize.Width, cb.maxItemTextWidth+int(win.GetSystemMetricsForDpi(win.SM_CXVSCROLL, uint32(cb.DPI())))+8)
248-
h := defaultSize.Height + 1
249-
250-
return Size{w, h}
251-
}
252-
253-
func (cb *ComboBox) SizeHint() Size {
254-
return cb.MinSizeHint()
255-
}
256-
257231
func (cb *ComboBox) applyFont(font *Font) {
258232
cb.WidgetBase.applyFont(font)
259233

260234
if cb.model != nil {
261235
cb.maxItemTextWidth = cb.calculateMaxItemTextWidth()
262-
cb.updateParentLayout()
236+
cb.RequestLayout()
263237
}
264238
}
265239

@@ -330,7 +304,7 @@ func (cb *ComboBox) resetItems() error {
330304
}
331305
}
332306

333-
cb.updateParentLayout()
307+
cb.RequestLayout()
334308

335309
return nil
336310
}
@@ -689,7 +663,13 @@ func (cb *ComboBox) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) u
689663
return 0
690664
}
691665

692-
case win.WM_SIZE:
666+
case win.WM_WINDOWPOSCHANGED:
667+
wp := (*win.WINDOWPOS)(unsafe.Pointer(lParam))
668+
669+
if wp.Flags&win.SWP_NOSIZE != 0 {
670+
break
671+
}
672+
693673
if cb.Editable() {
694674
result := cb.WidgetBase.WndProc(hwnd, msg, wParam, lParam)
695675

@@ -701,3 +681,45 @@ func (cb *ComboBox) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) u
701681

702682
return cb.WidgetBase.WndProc(hwnd, msg, wParam, lParam)
703683
}
684+
685+
func (cb *ComboBox) CreateLayoutItem(ctx *LayoutContext) LayoutItem {
686+
var layoutFlags LayoutFlags
687+
if cb.Editable() {
688+
layoutFlags = GrowableHorz | GreedyHorz
689+
} else {
690+
layoutFlags = GrowableHorz
691+
}
692+
693+
defaultSize := cb.dialogBaseUnitsToPixels(Size{30, 12})
694+
695+
if cb.model != nil && cb.maxItemTextWidth <= 0 {
696+
cb.maxItemTextWidth = cb.calculateMaxItemTextWidth()
697+
}
698+
699+
// FIXME: Use GetThemePartSize instead of guessing
700+
w := maxi(defaultSize.Width, cb.maxItemTextWidth+int(win.GetSystemMetricsForDpi(win.SM_CXVSCROLL, uint32(cb.DPI())))+8)
701+
h := defaultSize.Height + 1
702+
703+
return &comboBoxLayoutItem{
704+
layoutFlags: layoutFlags,
705+
idealSize: Size{w, h},
706+
}
707+
}
708+
709+
type comboBoxLayoutItem struct {
710+
LayoutItemBase
711+
layoutFlags LayoutFlags
712+
idealSize Size
713+
}
714+
715+
func (li *comboBoxLayoutItem) LayoutFlags() LayoutFlags {
716+
return li.layoutFlags
717+
}
718+
719+
func (li *comboBoxLayoutItem) IdealSize() Size {
720+
return li.idealSize
721+
}
722+
723+
func (li *comboBoxLayoutItem) MinSize() Size {
724+
return li.idealSize
725+
}

composite.go

-30
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,3 @@ func NewCompositeWithStyle(parent Window, style uint32) (*Composite, error) {
4242
func NewComposite(parent Container) (*Composite, error) {
4343
return NewCompositeWithStyle(parent, 0)
4444
}
45-
46-
func (c *Composite) onInsertedWidget(index int, widget Widget) (err error) {
47-
err = c.ContainerBase.onInsertedWidget(index, widget)
48-
49-
c.ensureAppropriateParentScrollViewCompositeSize()
50-
51-
return
52-
}
53-
54-
func (c *Composite) onRemovedWidget(index int, widget Widget) (err error) {
55-
err = c.ContainerBase.onRemovedWidget(index, widget)
56-
57-
c.ensureAppropriateParentScrollViewCompositeSize()
58-
59-
return
60-
}
61-
62-
func (c *Composite) onClearedWidgets() error {
63-
c.ensureAppropriateParentScrollViewCompositeSize()
64-
65-
return c.ContainerBase.onClearedWidgets()
66-
}
67-
68-
func (c *Composite) ensureAppropriateParentScrollViewCompositeSize() {
69-
if parent := c.Parent(); parent != nil {
70-
if sv, ok := parent.(*ScrollView); ok {
71-
sv.updateCompositeSize()
72-
}
73-
}
74-
}

0 commit comments

Comments
 (0)