Gave controls their proper fonts on Mac OS X.

This commit is contained in:
Pietro Gagliardi 2014-04-05 15:10:02 -04:00
parent 612eba9de3
commit da68adf420
2 changed files with 21 additions and 3 deletions

View File

@ -161,6 +161,8 @@ var (
_initWithIdentifier = sel_getUid("initWithIdentifier:")
_tableColumnWithIdentifier = sel_getUid("tableColumnWithIdentifier:")
_dataCell = sel_getUid("dataCell")
_setDataCell = sel_getUid("setDataCell:")
// _setEditable in sysdata_darwin.go
)
@ -168,6 +170,10 @@ func newListboxTableColumn() C.id {
column := C.objc_msgSend_noargs(_NSTableColumn, _alloc)
column = C.objc_msgSend_id(column, _initWithIdentifier, listboxItemKey)
C.objc_msgSend_bool(column, _setEditable, C.BOOL(C.NO))
// to set the font for each item, we set the font of the "data cell", which is more aptly called the "cell template"
dataCell := C.objc_msgSend_noargs(column, _dataCell)
applyStandardControlFont(dataCell)
C.objc_msgSend_id(column, _setDataCell, dataCell)
// TODO other properties?
bindListboxArray(column, newListboxArray())
return column

View File

@ -107,6 +107,16 @@ const (
_NSRegularControlSize = 0
)
// By default some controls do not use the correct font.
// These functions set the appropriate control font.
// Which one is used on each control was determined by comparing https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/AppleHIGuidelines/Characteristics/Characteristics.html#//apple_ref/doc/uid/TP40002721-SW10 to what Interface Builder says for each control.
// (not applicable to ProgressBar, Area)
// Button, Checkbox, Combobox, LineEdit, Label, Listbox
func applyStandardControlFont(id C.id) {
C.objc_setFont(id, _NSRegularControlSize)
}
var classTypes = [nctypes]*classData{
c_window: &classData{
make: func(parentWindow C.id, alternate bool) C.id {
@ -154,9 +164,7 @@ var classTypes = [nctypes]*classData{
C.objc_msgSend_uint(button, _setBezelStyle, C.uintptr_t(_NSRoundedBezelStyle))
C.objc_msgSend_id(button, _setTarget, appDelegate)
C.objc_msgSend_sel(button, _setAction, _buttonClicked)
// by default the button uses the wrong text size
// TODO do this for all controls
C.objc_setFont(button, _NSRegularControlSize)
applyStandardControlFont(button)
addControl(parentWindow, button)
return button
},
@ -174,6 +182,7 @@ var classTypes = [nctypes]*classData{
checkbox := C.objc_msgSend_noargs(_NSButton, _alloc)
checkbox = initWithDummyFrame(checkbox)
C.objc_msgSend_uint(checkbox, _setButtonType, C.uintptr_t(_NSSwitchButton))
applyStandardControlFont(checkbox)
addControl(parentWindow, checkbox)
return checkbox
},
@ -196,6 +205,7 @@ var classTypes = [nctypes]*classData{
C.int64_t(0), C.int64_t(0), C.int64_t(100), C.int64_t(100),
C.BOOL(C.NO))
}
applyStandardControlFont(combobox)
addControl(parentWindow, combobox)
return combobox
},
@ -239,6 +249,7 @@ var classTypes = [nctypes]*classData{
lineedit = C.objc_msgSend_noargs(_NSTextField, _alloc)
}
lineedit = initWithDummyFrame(lineedit)
applyStandardControlFont(lineedit)
addControl(parentWindow, lineedit)
return lineedit
},
@ -256,6 +267,7 @@ var classTypes = [nctypes]*classData{
C.objc_msgSend_bool(label, _setBordered, C.BOOL(C.NO))
C.objc_msgSend_bool(label, _setDrawsBackground, C.BOOL(C.NO))
// TODO others?
applyStandardControlFont(label)
addControl(parentWindow, label)
return label
},