From dfffc4c851db7c39398df7cdc3070ba2e4723ac4 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 23 Dec 2016 12:24:20 -0500 Subject: [PATCH] Started the API definition of the new uiDrawTextLayout. --- common/ui_attrstr.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/common/ui_attrstr.h b/common/ui_attrstr.h index a333fb78..f22fb3a4 100644 --- a/common/ui_attrstr.h +++ b/common/ui_attrstr.h @@ -28,3 +28,48 @@ _UI_EXTERN void uiAttributedStringDelete(uiAttributedString *s, size_t start, si _UI_EXTERN size_t uiAttributedStringNumGraphemes(uiAttributedString *s); _UI_EXTERN size_t uiAttributedStringByteIndexToGrapheme(uiAttributedString *s, size_t pos); _UI_EXTERN size_t uiAttributedStringGraphemeToByteIndex(uiAttributedString *s, size_t pos); + +typedef struct uiDrawTextLayout uiDrawTextLayout; +typedef struct uiDrawTextLayoutLineMetrics uiDrawTextLayoutLineMetrics; +typedef struct uiDrawTextLayoutByteRangeRectangle uiDrawTextLayoutByteRangeRectangle; + +struct uiDrawTextLayoutLineMetrics { + double X; + double Y; + double Width; + double Ascent; + double Descent; + double Leading; +}; + +_UI_ENUM(uiDrawTextLayoutHitTestResult) { + uiDrawTextLayoutHitTestResultNowhere, + uiDrawTextLayoutHitTestResultOnLineTrailingWhitespace, + uiDrawTextLayoutHitTestResultOnCharacter, +}; + +struct uiDrawTextLayoutByteRangeRectangle { + int Line; + double X; + double Y; + double Width; + double Height; + size_t RealStart; + size_t RealEnd; +}; + +_UI_EXTERN uiDrawTextLayout *uiDrawNewTextLayout(uiAttributedString *s, /* TODO default font */, double width); +_UI_EXTERN void uiDrawFreeTextLayout(uiDrawTextLayout *tl); +_UI_EXTERN void uiDrawText(uiDrawContext *c, uiDrawTextLayout *tl, double x, double y); +_UI_EXTERN void uiDrawTextLayoutExtents(uiDrawTextLayout *tl, double *width, double *height); +_UI_EXTERN int uiDrawTextLayoutNumLines(uiDrawTextLayout *tl); +_UI_EXTERN void uiDrawTextLayoutLineByteRange(uiDrawTextLayout *tl, int line, size_t *start, size_t *end); +_UI_EXTERN void uiDrawTextLayoutLineGetMetrics(uiDrawTextLayout *tl, int line, uiDrawTextLayoutLineMetrics *m); +// TODO redo this? remove it entirely? +_UI_EXTERN void uiDrawTextLayoutByteIndexToGraphemeRect(uiDrawTextLayout *tl, size_t pos, int *line, double *x, double *y, double *width, double *height); +// TODO partial offset? +_UI_EXTERN uiDrawTextLayoutHitTestResult uiDrawTextLayoutHitTest(uiDrawTextLayout *tl, double x, double y, size_t *byteIndex, int *line); +_UI_EXTERN void uiDrawTextLayoutByteRangeToRectangle(uiDrawTextLayout *tl, size_t start, size_t end, uiDrawTextLayoutByteRangeRectangle *r); +// TODO draw only a line? +// TODO other layout-specific attributes (alignment, wrapping, etc.)? +// TODO number of lines visible for clipping rect, range visible for clipping rect?