浏览代码

Fixed #569 and added additional formated tooltip

vurtun 7 年之前
父节点
当前提交
f7833d0379
共有 3 个文件被更改,包括 25 次插入15 次删除
  1. 1 0
      CHANGELOG.txt
  2. 4 11
      demo/overview.c
  3. 20 4
      nuklear.h

+ 1 - 0
CHANGELOG.txt

@@ -11,6 +11,7 @@
 
 Changes:
 --------
+- 2017/12/04 (2.00.6) - Added formated string tooltip widget
 - 2017/11/18 (2.00.5) - Fixed window becoming hidden with flag NK_WINDOW_NO_INPUT
 - 2017/11/15 (2.00.4) - Fixed font merging
 - 2017/11/07 (2.00.3) - Fixed window size and position modifier functions

+ 4 - 11
demo/overview.c

@@ -564,12 +564,8 @@ overview(struct nk_context *ctx)
                 nk_chart_end(ctx);
             }
 
-            if (index != -1) {
-                char buffer[NK_MAX_NUMBER_BUFFER];
-                float val = (float)cos((float)index*step);
-                sprintf(buffer, "Value: %.2f", val);
-                nk_tooltip(ctx, buffer);
-            }
+            if (index != -1)
+                nk_tooltipf(ctx, "Value: %.2f", (float)cos((float)index*step));
             if (line_index != -1) {
                 nk_layout_row_dynamic(ctx, 20, 1);
                 nk_labelf(ctx, NK_TEXT_LEFT, "Selected value: %.2f", (float)cos((float)index*step));
@@ -589,11 +585,8 @@ overview(struct nk_context *ctx)
                 }
                 nk_chart_end(ctx);
             }
-            if (index != -1) {
-                char buffer[NK_MAX_NUMBER_BUFFER];
-                sprintf(buffer, "Value: %.2f", (float)fabs(sin(step * (float)index)));
-                nk_tooltip(ctx, buffer);
-            }
+            if (index != -1)
+                nk_tooltipf(ctx, "Value: %.2f", (float)fabs(sin(step * (float)index)));
             if (col_index != -1) {
                 nk_layout_row_dynamic(ctx, 20, 1);
                 nk_labelf(ctx, NK_TEXT_LEFT, "Selected value: %.2f", (float)fabs(sin(step * (float)col_index)));

+ 20 - 4
nuklear.h

@@ -2106,6 +2106,9 @@ NK_API void nk_contextual_end(struct nk_context*);
  *
  * ============================================================================= */
 NK_API void nk_tooltip(struct nk_context*, const char*);
+#ifdef NK_INCLUDE_STANDARD_VARARGS
+NK_API void nk_tooltipf(struct nk_context*, const char*, ...);
+#endif
 NK_API int nk_tooltip_begin(struct nk_context*, float width);
 NK_API void nk_tooltip_end(struct nk_context*);
 /* =============================================================================
@@ -22469,10 +22472,10 @@ nk_tooltip_begin(struct nk_context *ctx, float width)
     if (win->popup.win && (win->popup.type & NK_PANEL_SET_NONBLOCK))
         return 0;
 
-    bounds.w = width;
-    bounds.h = nk_null_rect.h;
-    bounds.x = (in->mouse.pos.x + 1) - win->layout->clip.x;
-    bounds.y = (in->mouse.pos.y + 1) - win->layout->clip.y;
+    bounds.w = nk_iceilf(width);
+    bounds.h = nk_iceilf(nk_null_rect.h);
+    bounds.x = nk_ifloorf(in->mouse.pos.x + 1) - win->layout->clip.x;
+    bounds.y = nk_ifloorf(in->mouse.pos.y + 1) - win->layout->clip.y;
 
     ret = nk_popup_begin(ctx, NK_POPUP_DYNAMIC,
         "__##Tooltip##__", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER, bounds);
@@ -22528,6 +22531,19 @@ nk_tooltip(struct nk_context *ctx, const char *text)
         nk_tooltip_end(ctx);
     }
 }
+#ifdef NK_INCLUDE_STANDARD_VARARGS
+NK_API void
+nk_tooltipf(struct nk_context *ctx, const char *fmt, ...)
+{
+    char buf[256];
+    va_list args;
+    va_start(args, fmt);
+    nk_strfmt(buf, NK_LEN(buf), fmt, args);
+    va_end(args);
+    nk_tooltip(ctx, buf);
+}
+#endif
+
 /* -------------------------------------------------------------
  *
  *                          CONTEXTUAL