Fixed Mac OS X Button appearance; turns out it was using the wrong font. Also updated the TODO file to mark this fix and remove other stale/already fixed details.

This commit is contained in:
Pietro Gagliardi 2014-04-04 14:52:38 -04:00
parent 2884d45f0f
commit be668a965a
4 changed files with 40 additions and 5 deletions

View File

@ -21,6 +21,7 @@ Go wrapper functions (bleh_darwin.go) call these directly and take care of stdin
#include <AppKit/NSEvent.h> #include <AppKit/NSEvent.h>
#include <AppKit/NSGraphics.h> #include <AppKit/NSGraphics.h>
#include <AppKit/NSBitmapImageRep.h> #include <AppKit/NSBitmapImageRep.h>
#include <AppKit/NSCell.h>
/* exception to the above: cgo doesn't like Nil and delegate_darwin.go has //export so I can't have this there */ /* exception to the above: cgo doesn't like Nil and delegate_darwin.go has //export so I can't have this there */
Class NilClass = Nil; Class NilClass = Nil;
@ -317,3 +318,33 @@ struct xpoint getTranslatedEventPoint(id self, id event)
ret.y = (int64_t) p.y; ret.y = (int64_t) p.y;
return ret; return ret;
} }
/*
we don't need this here technically it can be done in Go just fine but it's easier here
*/
static id c_NSFont;
static SEL s_setFont;
static SEL s_systemFontOfSize;
static SEL s_systemFontSizeForControlSize;
static BOOL setFont_init = NO;
static CGFloat (*objc_msgSend_cgfloatret)(id, SEL, ...) =
(CGFloat (*)(id, SEL, ...)) objc_msgSend_fpret;
void objc_setFont(id what, unsigned int csize)
{
CGFloat size;
if (setFont_init == NO) {
c_NSFont = objc_getClass("NSFont");
s_setFont = sel_getUid("setFont:");
s_systemFontOfSize = sel_getUid("systemFontOfSize:");
s_systemFontSizeForControlSize = sel_getUid("systemFontSizeForControlSize:");
setFont_init = YES;
}
size = objc_msgSend_cgfloatret(c_NSFont, s_systemFontSizeForControlSize, (NSControlSize) csize);
objc_msgSend(what, s_setFont,
objc_msgSend(c_NSFont, s_systemFontOfSize, size));
}

View File

@ -117,4 +117,7 @@ extern BOOL addAreaViewDrawMethod(Class);
extern void drawImage(void *, int64_t, int64_t, int64_t, int64_t, int64_t); extern void drawImage(void *, int64_t, int64_t, int64_t, int64_t, int64_t);
extern struct xpoint getTranslatedEventPoint(id, id); extern struct xpoint getTranslatedEventPoint(id, id);
/* for sysdata_darwin.go */
extern void objc_setFont(id, unsigned int);
#endif #endif

View File

@ -118,7 +118,7 @@ var classTypes = [nctypes]*classData{
C.BOOL(C.YES)) // defer creation of device until we show the window C.BOOL(C.YES)) // defer creation of device until we show the window
objc_setDelegate(win, appDelegate) objc_setDelegate(win, appDelegate)
// this is needed for Areas in the window to receive mouse move events // this is needed for Areas in the window to receive mouse move events
C.objc_msgSend_bool(win, _setAcceptsMouseMovedEvents, C.BOOL(C.YES)) // C.objc_msgSend_bool(win, _setAcceptsMouseMovedEvents, C.BOOL(C.YES))
return win return win
}, },
show: func(what C.id) { show: func(what C.id) {
@ -139,6 +139,9 @@ var classTypes = [nctypes]*classData{
objc_msgSend_uint(button, _setBezelStyle, 1) // NSRoundedBezelStyle objc_msgSend_uint(button, _setBezelStyle, 1) // NSRoundedBezelStyle
C.objc_msgSend_id(button, _setTarget, appDelegate) C.objc_msgSend_id(button, _setTarget, appDelegate)
C.objc_msgSend_sel(button, _setAction, _buttonClicked) 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, 0) // NSRegularControlSize
addControl(parentWindow, button) addControl(parentWindow, button)
return button return button
}, },

View File

@ -28,18 +28,16 @@ important things:
- because the main event loop is not called if initialization fails, it is presently impossible for MsgBoxError() to work if UI initialization fails; this basically means we cannot allow initializiation to fail on Mac OS X if we want to be able to report UI init failures to the user with one (which would be desirable, maybe (would violate Windows HIG?)) - because the main event loop is not called if initialization fails, it is presently impossible for MsgBoxError() to work if UI initialization fails; this basically means we cannot allow initializiation to fail on Mac OS X if we want to be able to report UI init failures to the user with one (which would be desirable, maybe (would violate Windows HIG?))
- figure out where to auto-place windows in Cocoa (also window coordinates are still not flipped properly so (0,0) on screen is the bottom-left) - figure out where to auto-place windows in Cocoa (also window coordinates are still not flipped properly so (0,0) on screen is the bottom-left)
- also provide a method to center windows; Cocoa provides one for us but - also provide a method to center windows; Cocoa provides one for us but
- I think Cocoa NSButton text is not vertically aligned properly...? - I think Cocoa listbox item text is too low?
- and listbox item text is too low?
- NSPopUpButton does allow no initial selection ([b setSelectedIndex:-1]); use it - NSPopUpButton does allow no initial selection ([b setSelectedIndex:-1]); use it
- need to use it /after/ adding initial items, otherwise it won't work - need to use it /after/ adding initial items, otherwise it won't work
- find out if I can do the same with the ListBoxes - find out if I can do the same with the ListBoxes
- 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) - 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 - some Cocoa controls don't seem to resize correctly: Buttons have space around the edges
- make sure GTK+ documentation version point differences (x in 4.3.x) don't matter - make sure GTK+ documentation version point differences (x in 4.3.x) don't matter
- LineEdit heights on Windows seem too big; either that or LineEdit, Button, and Label text is not vertically centered properly - LineEdit heights on Windows seem too big; either that or LineEdit, Button, and Label text is not vertically centered properly
- are Checkboxes and Comboboxes too small? - are Checkboxes and Comboboxes too small?
- Cocoa has similar margining issues (like Comboboxes having margins) - Cocoa has similar margining issues (like Comboboxes having margins)
- oh, because message boxes use a different font on Windows 7 now, apparently?... Microsoft... TODO find out for sure
- sometimes the size of the drop-down part of a Combobox becomes 0 or 1 or some other impossibly small value on Windows - 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 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) - make sure scrollbars in Listbox work identically on all platforms (specifically the existence and autohiding of both horizontal and vertical scrollbars)