Fixed Windows control sizing: turns out simply calling GetTextMetrics() was not enough, as the GetDC() functions don't load the control font into the DC; we have to do it ourselves with SelectObject() (according to GetTextMetrics()'s docs on MSDN). Upon re-evaluation, the only things that need custom fonts are menus and statusbars; I don't know if menus can be done with the standard contorls and statusbars change the font of all controls inside... so how fonts are handled in classData needs to change now.
This commit is contained in:
parent
af95232589
commit
8cb3991ef9
|
@ -62,6 +62,7 @@ var stdDlgSizes = [nctypes]dlgunits{
|
|||
}
|
||||
|
||||
var (
|
||||
_selectObject = gdi32.NewProc("SelectObject")
|
||||
_getTextMetrics = gdi32.NewProc("GetTextMetricsW")
|
||||
_getWindowDC = user32.NewProc("GetWindowDC")
|
||||
_releaseDC = user32.NewProc("ReleaseDC")
|
||||
|
@ -79,6 +80,12 @@ func (s *sysData) preferredSize() (width int, height int) {
|
|||
panic(fmt.Errorf("error getting DC for preferred size calculations: %v", err))
|
||||
}
|
||||
dc = _HANDLE(r1)
|
||||
r1, _, err = _selectObject.Call(
|
||||
uintptr(dc),
|
||||
uintptr(unsafe.Pointer(*classTypes[s.ctype].font)))
|
||||
if r1 == 0 { // failure
|
||||
panic(fmt.Errorf("error loading control font into device context for preferred size calculation: %v", err))
|
||||
}
|
||||
r1, _, err = _getTextMetrics.Call(
|
||||
uintptr(dc),
|
||||
uintptr(unsafe.Pointer(&tm)))
|
||||
|
|
|
@ -107,11 +107,13 @@ var classTypes = [nctypes]*classData{
|
|||
name: _PROGRESS_CLASS,
|
||||
style: _PBS_SMOOTH | controlstyle,
|
||||
xstyle: 0 | controlxstyle,
|
||||
font: &controlFont,
|
||||
},
|
||||
c_area: &classData{
|
||||
register: registerAreaWndClass,
|
||||
style: areastyle,
|
||||
xstyle: areaxstyle,
|
||||
font: &controlFont,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -192,6 +194,8 @@ func (s *sysData) make(window *sysData) (err error) {
|
|||
ret: ret,
|
||||
}
|
||||
<-ret
|
||||
} else if s.ctype != c_window {
|
||||
panic(fmt.Errorf("internal ui package error: control type %d does not have a font (needed for preferred size calculations)", s.ctype))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
5
todo.md
5
todo.md
|
@ -36,8 +36,9 @@ important things:
|
|||
- NSComboBox scans the entered text to see if it matches one of the items and returns the index of that item if it does; find out how to suppress this so that it returns -1 unless the item was chosen from the list (like the other platforms)
|
||||
- some Cocoa controls don't seem to resize correctly: Buttons have space around the edges and don't satisfy stretchiness
|
||||
- make sure GTK+ documentation version point differences (x in 4.3.x) don't matter
|
||||
- button sizes and LineEdit sizes on Windows seem too big; Comboboxes have margins
|
||||
- Cocoa has similar margining issues (like on Comboboxes)
|
||||
- LineEdit heights on Windows seem too big; either that or LineEdit and Button text is not vertically centered properly
|
||||
- are Checkboxes too small?
|
||||
- Cocoa has similar margining issues (like Comboboxes having margins)
|
||||
- sometimes the size of the drop-down part of a Combobox becomes 0 or 1 or some other impossibly small value on Windows
|
||||
- make gcc (Unix)/clang (Mac OS X) pedantic about warnings/errors; also -Werror
|
||||
- make sure scrollbars in Listbox work identically on all platforms (specifically the existence and autohiding of both horizontal and vertical scrollbars)
|
||||
|
|
Loading…
Reference in New Issue