Some more TODO cleanup and name adjustment.

This commit is contained in:
Pietro Gagliardi 2017-06-06 14:14:33 -04:00
parent a415a846f7
commit b3e3b27f71
8 changed files with 27 additions and 29 deletions

View File

@ -386,9 +386,9 @@ static void applyAndFreeFontAttributes(struct foreachParams *p)
} }
static const CTTextAlignment ctaligns[] = { static const CTTextAlignment ctaligns[] = {
[uiDrawTextLayoutAlignLeft] = kCTTextAlignmentLeft, [uiDrawTextAlignLeft] = kCTTextAlignmentLeft,
[uiDrawTextLayoutAlignCenter] = kCTTextAlignmentCenter, [uiDrawTextAlignCenter] = kCTTextAlignmentCenter,
[uiDrawTextLayoutAlignRight] = kCTTextAlignmentRight, [uiDrawTextAlignRight] = kCTTextAlignmentRight,
}; };
static CTParagraphStyleRef mkParagraphStyle(uiDrawTextLayoutParams *p) static CTParagraphStyleRef mkParagraphStyle(uiDrawTextLayoutParams *p)

View File

@ -906,7 +906,7 @@ struct example *mkAttributesExample(void)
setupAttributedString(); setupAttributedString();
params.String = attrstr; params.String = attrstr;
params.DefaultFont = &defaultFont; params.DefaultFont = &defaultFont;
params.Align = uiDrawTextLayoutAlignLeft; params.Align = uiDrawTextAlignLeft;
return &attributesExample; return &attributesExample;
} }

View File

@ -259,7 +259,7 @@ struct example *mkBasicExample(void)
attrstr = uiNewAttributedString(text); attrstr = uiNewAttributedString(text);
params.String = attrstr; params.String = attrstr;
params.DefaultFont = &defaultFont; params.DefaultFont = &defaultFont;
params.Align = uiDrawTextLayoutAlignLeft; params.Align = uiDrawTextAlignLeft;
return &basicExample; return &basicExample;
} }

View File

@ -201,7 +201,7 @@ static void changeFont(uiFontButton *b, void *data)
static void changeTextAlign(uiCombobox *c, void *data) static void changeTextAlign(uiCombobox *c, void *data)
{ {
// note the order of the items added below // note the order of the items added below
params.Align = (uiDrawTextLayoutAlign) uiComboboxSelected(textAlign); params.Align = (uiDrawTextAlign) uiComboboxSelected(textAlign);
redraw(); redraw();
} }
@ -248,7 +248,7 @@ struct example *mkEmptyStringExample(void)
attrstr = uiNewAttributedString(text); attrstr = uiNewAttributedString(text);
params.String = attrstr; params.String = attrstr;
params.DefaultFont = &defaultFont; params.DefaultFont = &defaultFont;
params.Align = uiDrawTextLayoutAlignLeft; params.Align = uiDrawTextAlignLeft;
return &hitTestExample; return &hitTestExample;
} }

View File

@ -210,7 +210,7 @@ static void changeFont(uiFontButton *b, void *data)
static void changeTextAlign(uiCombobox *c, void *data) static void changeTextAlign(uiCombobox *c, void *data)
{ {
// note the order of the items added below // note the order of the items added below
params.Align = (uiDrawTextLayoutAlign) uiComboboxSelected(textAlign); params.Align = (uiDrawTextAlign) uiComboboxSelected(textAlign);
redraw(); redraw();
} }
@ -257,7 +257,7 @@ struct example *mkHitTestExample(void)
attrstr = uiNewAttributedString(text); attrstr = uiNewAttributedString(text);
params.String = attrstr; params.String = attrstr;
params.DefaultFont = &defaultFont; params.DefaultFont = &defaultFont;
params.Align = uiDrawTextLayoutAlignLeft; params.Align = uiDrawTextAlignLeft;
return &hitTestExample; return &hitTestExample;
} }

View File

@ -34,7 +34,8 @@ _UI_ENUM(uiAttribute) {
uiAttributeUnderlineColor, // enum uiDrawUnderlineColor uiAttributeUnderlineColor, // enum uiDrawUnderlineColor
// TODO note these are copied // TODO note these are copied
// TODO figure out how we're going to deal with being able to edit features over time... // TODO add a function to uiAttributedString to get an attribute's value at a specific index or in a specific range, so we can edit
// (TODO related to above: what about memory?)
uiAttributeFeatures, // use Features uiAttributeFeatures, // use Features
}; };
@ -52,11 +53,9 @@ _UI_ENUM(uiDrawUnderlineColor) {
uiDrawUnderlineColorAuxiliary, // for instance, the color used by smart replacements on OS X uiDrawUnderlineColorAuxiliary, // for instance, the color used by smart replacements on OS X
}; };
// TODO rename?
typedef struct uiOpenTypeFeatures uiOpenTypeFeatures; typedef struct uiOpenTypeFeatures uiOpenTypeFeatures;
// TODO pass the feature set? // TODO pass the feature set?
typedef uiForEach (*uiOpenTypeFeaturesForEachFunc)(char a, char b, char c, char d, uint32_t value, void *data); typedef uiForEach (*uiOpenTypeFeaturesForEachFunc)(char a, char b, char c, char d, uint32_t value, void *data);
// TODO detailed constructor?
_UI_EXTERN uiOpenTypeFeatures *uiNewOpenTypeFeatures(void); _UI_EXTERN uiOpenTypeFeatures *uiNewOpenTypeFeatures(void);
_UI_EXTERN void uiFreeOpenTypeFeatures(uiOpenTypeFeatures *otf); _UI_EXTERN void uiFreeOpenTypeFeatures(uiOpenTypeFeatures *otf);
// TODO put above Free? // TODO put above Free?
@ -80,10 +79,10 @@ struct uiAttributeSpec {
double G; double G;
double B; double B;
double A; double A;
const uiOpenTypeFeatures *Features; // TODO rename to OpenTypeFeatures? const uiOpenTypeFeatures *Features;
}; };
// TODO make the spec const in a way that doesn't allow fields to be modified? // TODO how would we make spec const in this case, to prevent fields from being modified?
typedef uiForEach (*uiAttributedStringForEachAttributeFunc)(uiAttributedString *s, uiAttributeSpec *spec, size_t start, size_t end, void *data); typedef uiForEach (*uiAttributedStringForEachAttributeFunc)(uiAttributedString *s, uiAttributeSpec *spec, size_t start, size_t end, void *data);
// @role uiAttributedString constructor // @role uiAttributedString constructor
@ -139,7 +138,6 @@ _UI_ENUM(uiDrawTextItalic) {
uiDrawTextItalicItalic, uiDrawTextItalicItalic,
}; };
// TODO realign this so that Normal == 0?
_UI_ENUM(uiDrawTextStretch) { _UI_ENUM(uiDrawTextStretch) {
uiDrawTextStretchUltraCondensed, uiDrawTextStretchUltraCondensed,
uiDrawTextStretchExtraCondensed, uiDrawTextStretchExtraCondensed,
@ -164,18 +162,17 @@ typedef struct uiDrawTextLayout uiDrawTextLayout;
typedef struct uiDrawTextLayoutParams uiDrawTextLayoutParams; typedef struct uiDrawTextLayoutParams uiDrawTextLayoutParams;
typedef struct uiDrawTextLayoutLineMetrics uiDrawTextLayoutLineMetrics; typedef struct uiDrawTextLayoutLineMetrics uiDrawTextLayoutLineMetrics;
// TODO drop the Layout from this? _UI_ENUM(uiDrawTextAlign) {
_UI_ENUM(uiDrawTextLayoutAlign) { uiDrawTextAlignLeft,
uiDrawTextLayoutAlignLeft, uiDrawTextAlignCenter,
uiDrawTextLayoutAlignCenter, uiDrawTextAlignRight,
uiDrawTextLayoutAlignRight,
}; };
struct uiDrawTextLayoutParams { struct uiDrawTextLayoutParams {
uiAttributedString *String; uiAttributedString *String;
uiDrawFontDescriptor *DefaultFont; uiDrawFontDescriptor *DefaultFont;
double Width; double Width;
uiDrawTextLayoutAlign Align; uiDrawTextAlign Align;
}; };
// Height will equal ParagraphSpacingBefore + LineHeightSpace + Ascent + Descent + Leading + LineSpacing + ParagraphSpacing. // Height will equal ParagraphSpacingBefore + LineHeightSpace + Ascent + Descent + Leading + LineSpacing + ParagraphSpacing.
@ -253,10 +250,11 @@ _UI_EXTERN double uiDrawTextLayoutByteLocationInLine(uiDrawTextLayout *tl, size_
_UI_EXTERN void uiDrawCaret(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout, size_t pos, int *line); _UI_EXTERN void uiDrawCaret(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout, size_t pos, int *line);
// TODO allow blinking // TODO allow blinking
// TODO allow secondary carets
typedef struct uiFontButton uiFontButton; typedef struct uiFontButton uiFontButton;
#define uiFontButton(this) ((uiFontButton *) (this)) #define uiFontButton(this) ((uiFontButton *) (this))
// TODO have a function that sets an entire font descriptor to a range in a uiAttributedString at once? // TODO have a function that sets an entire font descriptor to a range in a uiAttributedString at once, for SetFont?
_UI_EXTERN void uiFontButtonFont(uiFontButton *b, uiDrawFontDescriptor *desc); _UI_EXTERN void uiFontButtonFont(uiFontButton *b, uiDrawFontDescriptor *desc);
// TOOD SetFont, mechanics // TOOD SetFont, mechanics
_UI_EXTERN void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data); _UI_EXTERN void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data);

View File

@ -95,9 +95,9 @@ static void computeLineMetrics(uiDrawTextLayout *tl)
} }
static const PangoAlignment pangoAligns[] = { static const PangoAlignment pangoAligns[] = {
[uiDrawTextLayoutAlignLeft] = PANGO_ALIGN_LEFT, [uiDrawTextAlignLeft] = PANGO_ALIGN_LEFT,
[uiDrawTextLayoutAlignCenter] = PANGO_ALIGN_CENTER, [uiDrawTextAlignCenter] = PANGO_ALIGN_CENTER,
[uiDrawTextLayoutAlignRight] = PANGO_ALIGN_RIGHT, [uiDrawTextAlignRight] = PANGO_ALIGN_RIGHT,
}; };
uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p) uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)

View File

@ -134,10 +134,10 @@ static void computeLineInfo(uiDrawTextLayout *tl)
} }
// TODO should be const but then I can't operator[] on it; the real solution is to find a way to do designated array initializers in C++11 but I do not know enough C++ voodoo to make it work (it is possible but no one else has actually done it before) // TODO should be const but then I can't operator[] on it; the real solution is to find a way to do designated array initializers in C++11 but I do not know enough C++ voodoo to make it work (it is possible but no one else has actually done it before)
static std::map<uiDrawTextItalic, DWRITE_TEXT_ALIGNMENT> dwriteAligns = { static std::map<uiDrawTextAlign, DWRITE_TEXT_ALIGNMENT> dwriteAligns = {
{ uiDrawTextLayoutAlignLeft, DWRITE_TEXT_ALIGNMENT_LEADING }, { uiDrawTextAlignLeft, DWRITE_TEXT_ALIGNMENT_LEADING },
{ uiDrawTextLayoutAlignCenter, DWRITE_TEXT_ALIGNMENT_CENTER }, { uiDrawTextAlignCenter, DWRITE_TEXT_ALIGNMENT_CENTER },
{ uiDrawTextLayoutAlignRight, DWRITE_TEXT_ALIGNMENT_TRAILING }, { uiDrawTextAlignRight, DWRITE_TEXT_ALIGNMENT_TRAILING },
}; };
uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p) uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)