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)deactivateFontButton:(BOOL)activatingAnother;
- (void)deactivateOnClose:(NSNotification *)note;
- (uiDrawTextFont *)libuiFont;
- (void)getfontdesc:(uiDrawFontDescriptor *)uidesc;
@end
// only one may be active at one time
@ -138,9 +138,16 @@ struct uiFontButton {
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
@ -192,9 +199,9 @@ static void defaultOnChanged(uiFontButton *b, void *data)
// 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)

View File

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

View File

@ -31,8 +31,10 @@ static uiAttributedString *attrstr;
#define margins 10
static uiBox *panel;
static uiBox *vbox;
static uiLabel *caretLabel;
static uiCheckbox *showLineBounds;
static uiFontButton *fontButton;
static int caretLine = -1;
static size_t caretPos;
@ -189,22 +191,38 @@ static void checkboxChecked(uiCheckbox *c, void *data)
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;
c = uiNewCheckbox(text);
uiCheckboxOnToggled(c, checkboxChecked, NULL);
uiBoxAppend(panel, uiControl(c), 0);
uiBoxAppend(box, uiControl(c), 0);
return c;
}
struct example *mkHitTestExample(void)
{
panel = uiNewVerticalBox();
panel = uiNewHorizontalBox();
vbox = uiNewVerticalBox();
uiBoxAppend(panel, uiControl(vbox), 1);
caretLabel = uiNewLabel("Caret information is shown here");
uiBoxAppend(panel, uiControl(caretLabel), 0);
showLineBounds = newCheckbox("Show Line Bounds (for debugging metrics)");
uiBoxAppend(vbox, uiControl(caretLabel), 0);
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.panel = uiControl(panel);