From da68adf420b2360c71a12fcb50d842e3a23ee467 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 5 Apr 2014 15:10:02 -0400 Subject: [PATCH] Gave controls their proper fonts on Mac OS X. --- listbox_darwin.go | 6 ++++++ sysdata_darwin.go | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/listbox_darwin.go b/listbox_darwin.go index da2a0af..bf05b3c 100644 --- a/listbox_darwin.go +++ b/listbox_darwin.go @@ -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 diff --git a/sysdata_darwin.go b/sysdata_darwin.go index c267569..609dea2 100644 --- a/sysdata_darwin.go +++ b/sysdata_darwin.go @@ -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 },