And re-added the uiFontButton on OS X and added one to the hit-test example.

This commit is contained in:
Pietro Gagliardi 2017-02-11 01:13:07 -05:00
parent bebaf72de3
commit 67949d79aa
3 changed files with 38 additions and 13 deletions

View File

@ -11,7 +11,7 @@
- (void)activateFontButton; - (void)activateFontButton;
- (void)deactivateFontButton:(BOOL)activatingAnother; - (void)deactivateFontButton:(BOOL)activatingAnother;
- (void)deactivateOnClose:(NSNotification *)note; - (void)deactivateOnClose:(NSNotification *)note;
- (uiDrawTextFont *)libuiFont; - (void)getfontdesc:(uiDrawFontDescriptor *)uidesc;
@end @end
// only one may be active at one time // only one may be active at one time
@ -138,9 +138,16 @@ struct uiFontButton {
NSFontPanelCollectionModeMask; NSFontPanelCollectionModeMask;
} }
- (uiDrawTextFont *)libuiFont - (void)getfontdesc:(uiDrawFontDescriptor *)uidesc
{ {
return mkTextFontFromNSFont(self->libui_font); CTFontRef ctfont;
CTFontDescriptorRef ctdesc;
ctfont = (CTFontRef) (self->libui_font);
ctdesc = CTFontCopyFontDescriptor(ctfont);
fontdescFromCTFontDescriptor(ctdesc, uidesc);
CFRelease(ctdesc);
uidesc->Size = CTFontGetSize(ctfont);
} }
@end @end
@ -192,9 +199,9 @@ static void defaultOnChanged(uiFontButton *b, void *data)
// do nothing // do nothing
} }
uiDrawTextFont *uiFontButtonFont(uiFontButton *b) void uiFontButtonFont(uiFontButton *b, uiDrawFontDescriptor *desc)
{ {
return [b->button libuiFont]; [b->button getfontdesc:desc];
} }
void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data) void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data)

View File

@ -304,7 +304,7 @@ void fontdescFromCTFontDescriptor(CTFontDescriptorRef ctdesc, uiDrawFontDescript
int wc; int wc;
uiDrawTextStretch stretch; uiDrawTextStretch stretch;
cffamily = (CFStringRef) CTFontDescriptorCopyAttribute(cfdesc, kCTFontFamilyNameAttribute); cffamily = (CFStringRef) CTFontDescriptorCopyAttribute(ctdesc, kCTFontFamilyNameAttribute);
if (cffamily == NULL) { if (cffamily == NULL) {
// TODO // TODO
} }
@ -312,7 +312,7 @@ void fontdescFromCTFontDescriptor(CTFontDescriptorRef ctdesc, uiDrawFontDescript
uidesc->Family = uiDarwinNSStringToText((NSString *) cffamily); uidesc->Family = uiDarwinNSStringToText((NSString *) cffamily);
CFRelease(cffamily); CFRelease(cffamily);
traits = (CFDictionaryRef) CTFontDescriptorCopyAttribute(cfdesc, kCTFontTraitsAttribute); traits = (CFDictionaryRef) CTFontDescriptorCopyAttribute(ctdesc, kCTFontTraitsAttribute);
if (traits == NULL) { if (traits == NULL) {
// TODO // TODO
} }
@ -331,7 +331,7 @@ void fontdescFromCTFontDescriptor(CTFontDescriptorRef ctdesc, uiDrawFontDescript
// TODO is this correct? // TODO is this correct?
for (stretch = uiDrawTextStretchUltraCondensed; stretch < uiDrawTextStretchUltraExpanded; stretch++) for (stretch = uiDrawTextStretchUltraCondensed; stretch < uiDrawTextStretchUltraExpanded; stretch++)
if (ctstretch <= stretchesToCTWidth[stretch]) if (ctstretch <= stretchesToCTWidths[stretch])
break; break;
uidesc->Stretch = stretch; uidesc->Stretch = stretch;
} }

View File

@ -31,8 +31,10 @@ static uiAttributedString *attrstr;
#define margins 10 #define margins 10
static uiBox *panel; static uiBox *panel;
static uiBox *vbox;
static uiLabel *caretLabel; static uiLabel *caretLabel;
static uiCheckbox *showLineBounds; static uiCheckbox *showLineBounds;
static uiFontButton *fontButton;
static int caretLine = -1; static int caretLine = -1;
static size_t caretPos; static size_t caretPos;
@ -189,22 +191,38 @@ static void checkboxChecked(uiCheckbox *c, void *data)
redraw(); redraw();
} }
static uiCheckbox *newCheckbox(const char *text) static void changeFont(uiFontButton *b, void *data)
{
// TODO free old font name
// TODO rename defaultFont
uiFontButtonFont(fontButton, &defaultFont);
// TODO dump the new font
redraw();
}
// TODO share?
static uiCheckbox *newCheckbox(uiBox *box, const char *text)
{ {
uiCheckbox *c; uiCheckbox *c;
c = uiNewCheckbox(text); c = uiNewCheckbox(text);
uiCheckboxOnToggled(c, checkboxChecked, NULL); uiCheckboxOnToggled(c, checkboxChecked, NULL);
uiBoxAppend(panel, uiControl(c), 0); uiBoxAppend(box, uiControl(c), 0);
return c; return c;
} }
struct example *mkHitTestExample(void) struct example *mkHitTestExample(void)
{ {
panel = uiNewVerticalBox(); panel = uiNewHorizontalBox();
vbox = uiNewVerticalBox();
uiBoxAppend(panel, uiControl(vbox), 1);
caretLabel = uiNewLabel("Caret information is shown here"); caretLabel = uiNewLabel("Caret information is shown here");
uiBoxAppend(panel, uiControl(caretLabel), 0); uiBoxAppend(vbox, uiControl(caretLabel), 0);
showLineBounds = newCheckbox("Show Line Bounds (for debugging metrics)"); showLineBounds = newCheckbox(vbox, "Show Line Bounds (for debugging metrics)");
fontButton = uiNewFontButton();
uiFontButtonOnChanged(fontButton, changeFont, NULL);
// TODO set the font button to the current defaultFont
uiBoxAppend(panel, uiControl(fontButton), 0);
hitTestExample.name = "Hit-Testing and Grapheme Boundaries"; hitTestExample.name = "Hit-Testing and Grapheme Boundaries";
hitTestExample.panel = uiControl(panel); hitTestExample.panel = uiControl(panel);