- nvgTextBreakLines: wordMinX was relative to rowStartX, which caused problems when rowStartX change on line break, but wordMinX was still relative to the previous rowStartX - fixed font size on perf graphs - made demo to use row minx/maxx instead of row->width - fixed demo hover distanceshared-context
@@ -25,7 +25,7 @@ | |||||
#define ICON_TRASH 0xE729 | #define ICON_TRASH 0xE729 | ||||
//static float minf(float a, float b) { return a < b ? a : b; } | //static float minf(float a, float b) { return a < b ? a : b; } | ||||
static float maxf(float a, float b) { return a > b ? a : b; } | |||||
//static float maxf(float a, float b) { return a > b ? a : b; } | |||||
//static float absf(float a) { return a >= 0.0f ? a : -a; } | //static float absf(float a) { return a >= 0.0f ? a : -a; } | ||||
static float clampf(float a, float mn, float mx) { return a < mn ? mn : (a > mx ? mx : a); } | static float clampf(float a, float mn, float mx) { return a < mn ? mn : (a > mx ? mx : a); } | ||||
@@ -868,8 +868,10 @@ void drawParagraph(NVGcontext* vg, float x, float y, float width, float height, | |||||
float caretx, px; | float caretx, px; | ||||
float bounds[4]; | float bounds[4]; | ||||
float a; | float a; | ||||
const char* hoverText = "Hover your mouse over the text to see calculated caret position."; | |||||
float gx,gy; | float gx,gy; | ||||
int gutter = 0; | int gutter = 0; | ||||
const char* boxText = "Testing\nsome multiline\ntext."; | |||||
NVG_NOTUSED(height); | NVG_NOTUSED(height); | ||||
nvgSave(vg); | nvgSave(vg); | ||||
@@ -891,7 +893,7 @@ void drawParagraph(NVGcontext* vg, float x, float y, float width, float height, | |||||
nvgBeginPath(vg); | nvgBeginPath(vg); | ||||
nvgFillColor(vg, nvgRGBA(255,255,255,hit?64:16)); | nvgFillColor(vg, nvgRGBA(255,255,255,hit?64:16)); | ||||
nvgRect(vg, x, y, row->width, lineh); | |||||
nvgRect(vg, x + row->minx, y, row->maxx - row->minx, lineh); | |||||
nvgFill(vg); | nvgFill(vg); | ||||
nvgFillColor(vg, nvgRGBA(255,255,255,255)); | nvgFillColor(vg, nvgRGBA(255,255,255,255)); | ||||
@@ -948,12 +950,12 @@ void drawParagraph(NVGcontext* vg, float x, float y, float width, float height, | |||||
nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_TOP); | nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_TOP); | ||||
nvgTextLineHeight(vg, 1.2f); | nvgTextLineHeight(vg, 1.2f); | ||||
nvgTextBoxBounds(vg, x,y, 150, "Hover your mouse over the text to see calculated caret position.", NULL, bounds); | |||||
nvgTextBoxBounds(vg, x,y, 150, hoverText, NULL, bounds); | |||||
// Fade the tooltip out when close to it. | // Fade the tooltip out when close to it. | ||||
gx = fabsf((mx - (bounds[0]+bounds[2])*0.5f) / (bounds[0] - bounds[2])); | |||||
gy = fabsf((my - (bounds[1]+bounds[3])*0.5f) / (bounds[1] - bounds[3])); | |||||
a = maxf(gx, gy) - 0.5f; | |||||
gx = clampf(mx, bounds[0], bounds[2]) - mx; | |||||
gy = clampf(my, bounds[1], bounds[3]) - my; | |||||
a = sqrtf(gx*gx + gy*gy) / 30.0f; | |||||
a = clampf(a, 0, 1); | a = clampf(a, 0, 1); | ||||
nvgGlobalAlpha(vg, a); | nvgGlobalAlpha(vg, a); | ||||
@@ -967,7 +969,7 @@ void drawParagraph(NVGcontext* vg, float x, float y, float width, float height, | |||||
nvgFill(vg); | nvgFill(vg); | ||||
nvgFillColor(vg, nvgRGBA(0,0,0,220)); | nvgFillColor(vg, nvgRGBA(0,0,0,220)); | ||||
nvgTextBox(vg, x,y, 150, "Hover your mouse over the text to see calculated caret position.", NULL); | |||||
nvgTextBox(vg, x,y, 150, hoverText, NULL); | |||||
nvgRestore(vg); | nvgRestore(vg); | ||||
} | } | ||||
@@ -151,36 +151,36 @@ void renderGraph(NVGcontext* vg, float x, float y, PerfGraph* fps) | |||||
nvgFontFace(vg, "sans"); | nvgFontFace(vg, "sans"); | ||||
if (fps->name[0] != '\0') { | if (fps->name[0] != '\0') { | ||||
nvgFontSize(vg, 14.0f); | |||||
nvgFontSize(vg, 12.0f); | |||||
nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_TOP); | nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_TOP); | ||||
nvgFillColor(vg, nvgRGBA(240,240,240,192)); | nvgFillColor(vg, nvgRGBA(240,240,240,192)); | ||||
nvgText(vg, x+3,y+1, fps->name, NULL); | |||||
nvgText(vg, x+3,y+3, fps->name, NULL); | |||||
} | } | ||||
if (fps->style == GRAPH_RENDER_FPS) { | if (fps->style == GRAPH_RENDER_FPS) { | ||||
nvgFontSize(vg, 18.0f); | |||||
nvgFontSize(vg, 15.0f); | |||||
nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_TOP); | nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_TOP); | ||||
nvgFillColor(vg, nvgRGBA(240,240,240,255)); | nvgFillColor(vg, nvgRGBA(240,240,240,255)); | ||||
sprintf(str, "%.2f FPS", 1.0f / avg); | sprintf(str, "%.2f FPS", 1.0f / avg); | ||||
nvgText(vg, x+w-3,y+1, str, NULL); | |||||
nvgText(vg, x+w-3,y+3, str, NULL); | |||||
nvgFontSize(vg, 15.0f); | |||||
nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_BOTTOM); | |||||
nvgFontSize(vg, 13.0f); | |||||
nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_BASELINE); | |||||
nvgFillColor(vg, nvgRGBA(240,240,240,160)); | nvgFillColor(vg, nvgRGBA(240,240,240,160)); | ||||
sprintf(str, "%.2f ms", avg * 1000.0f); | sprintf(str, "%.2f ms", avg * 1000.0f); | ||||
nvgText(vg, x+w-3,y+h-1, str, NULL); | |||||
nvgText(vg, x+w-3,y+h-3, str, NULL); | |||||
} | } | ||||
else if (fps->style == GRAPH_RENDER_PERCENT) { | else if (fps->style == GRAPH_RENDER_PERCENT) { | ||||
nvgFontSize(vg, 18.0f); | |||||
nvgFontSize(vg, 15.0f); | |||||
nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_TOP); | nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_TOP); | ||||
nvgFillColor(vg, nvgRGBA(240,240,240,255)); | nvgFillColor(vg, nvgRGBA(240,240,240,255)); | ||||
sprintf(str, "%.1f %%", avg * 1.0f); | sprintf(str, "%.1f %%", avg * 1.0f); | ||||
nvgText(vg, x+w-3,y+1, str, NULL); | |||||
nvgText(vg, x+w-3,y+3, str, NULL); | |||||
} else { | } else { | ||||
nvgFontSize(vg, 18.0f); | |||||
nvgFontSize(vg, 15.0f); | |||||
nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_TOP); | nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_TOP); | ||||
nvgFillColor(vg, nvgRGBA(240,240,240,255)); | nvgFillColor(vg, nvgRGBA(240,240,240,255)); | ||||
sprintf(str, "%.2f ms", avg * 1000.0f); | sprintf(str, "%.2f ms", avg * 1000.0f); | ||||
nvgText(vg, x+w-3,y+1, str, NULL); | |||||
nvgText(vg, x+w-3,y+3, str, NULL); | |||||
} | } | ||||
} | } |
@@ -2704,7 +2704,7 @@ int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, floa | |||||
rowStartX = iter.x; | rowStartX = iter.x; | ||||
rowStart = iter.str; | rowStart = iter.str; | ||||
rowEnd = iter.next; | rowEnd = iter.next; | ||||
rowWidth = iter.nextx - rowStartX; // q.x1 - rowStartX; | |||||
rowWidth = iter.nextx - rowStartX; | |||||
rowMinX = q.x0 - rowStartX; | rowMinX = q.x0 - rowStartX; | ||||
rowMaxX = q.x1 - rowStartX; | rowMaxX = q.x1 - rowStartX; | ||||
wordStart = iter.str; | wordStart = iter.str; | ||||
@@ -2734,7 +2734,7 @@ int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, floa | |||||
if ((ptype == NVG_SPACE && (type == NVG_CHAR || type == NVG_CJK_CHAR)) || type == NVG_CJK_CHAR) { | if ((ptype == NVG_SPACE && (type == NVG_CHAR || type == NVG_CJK_CHAR)) || type == NVG_CJK_CHAR) { | ||||
wordStart = iter.str; | wordStart = iter.str; | ||||
wordStartX = iter.x; | wordStartX = iter.x; | ||||
wordMinX = q.x0 - rowStartX; | |||||
wordMinX = q.x0; | |||||
} | } | ||||
// Break to new line when a character is beyond break width. | // Break to new line when a character is beyond break width. | ||||
@@ -2771,13 +2771,13 @@ int nvgTextBreakLines(NVGcontext* ctx, const char* string, const char* end, floa | |||||
nrows++; | nrows++; | ||||
if (nrows >= maxRows) | if (nrows >= maxRows) | ||||
return nrows; | return nrows; | ||||
// Update row | |||||
rowStartX = wordStartX; | rowStartX = wordStartX; | ||||
rowStart = wordStart; | rowStart = wordStart; | ||||
rowEnd = iter.next; | rowEnd = iter.next; | ||||
rowWidth = iter.nextx - rowStartX; | rowWidth = iter.nextx - rowStartX; | ||||
rowMinX = wordMinX; | |||||
rowMinX = wordMinX - rowStartX; | |||||
rowMaxX = q.x1 - rowStartX; | rowMaxX = q.x1 - rowStartX; | ||||
// No change to the word start | |||||
} | } | ||||
// Set null break point | // Set null break point | ||||
breakEnd = rowStart; | breakEnd = rowStart; | ||||