Browse Source

moved text offset up by one pixel

pull/1/head
Leonard Ritter 10 years ago
parent
commit
bc04c71ed7
2 changed files with 101 additions and 4 deletions
  1. +8
    -4
      blendish.h
  2. +93
    -0
      example.cpp

+ 8
- 4
blendish.h View File

@@ -35,7 +35,7 @@ extern "C" {


/* /*


Revision 3 (2014-07-08)
Revision 4 (2014-07-09)


Summary Summary
------- -------
@@ -545,6 +545,9 @@ void bndUpDownArrow(NVGcontext *ctx, float x, float y, float s, NVGcolor color);
// max glyphs for position testing // max glyphs for position testing
#define BND_MAX_GLYPHS 1024 #define BND_MAX_GLYPHS 1024


// text distance from bottom
#define BND_TEXT_PAD_DOWN 7

//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////


BND_INLINE float bnd_clamp(float v, float mn, float mx) { BND_INLINE float bnd_clamp(float v, float mn, float mx) {
@@ -1168,7 +1171,7 @@ void bndIconLabelValue(NVGcontext *ctx, float x, float y, float w, float h,
+ nvgTextBounds(ctx, 1, 1, value, NULL, NULL); + nvgTextBounds(ctx, 1, 1, value, NULL, NULL);
x += ((w-BND_PAD_RIGHT-pleft)-width)*0.5f; x += ((w-BND_PAD_RIGHT-pleft)-width)*0.5f;
} }
y += h-6;
y += h-BND_TEXT_PAD_DOWN;
nvgText(ctx, x, y, label, NULL); nvgText(ctx, x, y, label, NULL);
x += label_width; x += label_width;
nvgText(ctx, x, y, BND_LABEL_SEPARATOR, NULL); nvgText(ctx, x, y, BND_LABEL_SEPARATOR, NULL);
@@ -1178,7 +1181,8 @@ void bndIconLabelValue(NVGcontext *ctx, float x, float y, float w, float h,
nvgTextAlign(ctx, nvgTextAlign(ctx,
(align==BND_LEFT)?(NVG_ALIGN_LEFT|NVG_ALIGN_BASELINE): (align==BND_LEFT)?(NVG_ALIGN_LEFT|NVG_ALIGN_BASELINE):
(NVG_ALIGN_CENTER|NVG_ALIGN_BASELINE)); (NVG_ALIGN_CENTER|NVG_ALIGN_BASELINE));
nvgTextBox(ctx,x+pleft,y+h-6,w-BND_PAD_RIGHT-pleft,label, NULL);
nvgTextBox(ctx,x+pleft,y+h-BND_TEXT_PAD_DOWN,
w-BND_PAD_RIGHT-pleft,label, NULL);
} }
} else if (iconid >= 0) { } else if (iconid >= 0) {
bndIcon(ctx,x+2,y+2,iconid); bndIcon(ctx,x+2,y+2,iconid);
@@ -1199,7 +1203,7 @@ void bndIconLabelCaret(NVGcontext *ctx, float x, float y, float w, float h,
if (bnd_font < 0) return; if (bnd_font < 0) return;
x+=pleft; x+=pleft;
y+=h-6;
y+=h-BND_TEXT_PAD_DOWN;


nvgFontFaceId(ctx, bnd_font); nvgFontFaceId(ctx, bnd_font);
nvgFontSize(ctx, fontsize); nvgFontSize(ctx, fontsize);


+ 93
- 0
example.cpp View File

@@ -16,6 +16,77 @@
#define BLENDISH_IMPLEMENTATION #define BLENDISH_IMPLEMENTATION
#include "blendish.h" #include "blendish.h"


#include <assert.h>

////////////////////////////////////////////////////////////////////////////////

#define UI_IMPLEMENTATION
#ifndef _UI_H_
#define _UI_H_

typedef struct UIcontext UIcontext;

UIcontext *uiCreateContext();
void uiMakeCurrent(UIcontext *ctx);
void uiDestroyContext(UIcontext *ctx);

void uiSetButton(int button, int enabled);
int uiGetButton(int button);

void uiSetCursor(int x, int y);
void uiGetCursor(int *x, int *y);

#endif // _UI_H_

#ifdef UI_IMPLEMENTATION

struct UIcontext {
int cx, cy;
unsigned long long buttons;
};

static UIcontext *ui_context = NULL;

UIcontext *uiCreateContext() {
UIcontext *ctx = (UIcontext *)malloc(sizeof(UIcontext));
return ctx;
}

void uiMakeCurrent(UIcontext *ctx) {
ui_context = ctx;
}

void uiDestroyContext(UIcontext *ctx) {
free(ctx);
}

void uiSetButton(int button, int enabled) {
assert(ui_context);
unsigned long long mask = 1ull<<button;
ui_context->buttons = (enabled)?
(ui_context->buttons | mask):
(ui_context->buttons & ~mask);
}

int uiGetButton(int button) {
assert(ui_context);
return (ui_context->buttons & (1ull<<button))?1:0;
}

void uiSetCursor(int x, int y) {
assert(ui_context);
ui_context->cx = x;
ui_context->cy = y;
}

void uiGetCursor(int *x, int *y) {
assert(ui_context);
*x = ui_context->cx;
*y = ui_context->cy;
}

#endif // UI_IMPLEMENTATION

//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////


void init(NVGcontext *vg) { void init(NVGcontext *vg) {
@@ -209,6 +280,9 @@ void draw(NVGcontext *vg, float w, float h) {
x += BND_TOOL_WIDTH-1; x += BND_TOOL_WIDTH-1;
bndRadioButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_LEFT, bndRadioButton(vg,x,y,BND_TOOL_WIDTH,BND_WIDGET_HEIGHT,BND_CORNER_LEFT,
BND_DEFAULT,BND_ICONID(5,11),NULL); BND_DEFAULT,BND_ICONID(5,11),NULL);
} }


//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -218,6 +292,17 @@ void errorcb(int error, const char* desc)
printf("GLFW error %d: %s\n", error, desc); printf("GLFW error %d: %s\n", error, desc);
} }


static void mousebutton(GLFWwindow *window, int button, int action, int mods) {
NVG_NOTUSED(window);
NVG_NOTUSED(mods);
uiSetButton(button, (action==GLFW_PRESS)?1:0);
}

static void cursorpos(GLFWwindow *window, double x, double y) {
NVG_NOTUSED(window);
uiSetCursor((int)x,(int)y);
}

static void key(GLFWwindow* window, int key, int scancode, int action, int mods) static void key(GLFWwindow* window, int key, int scancode, int action, int mods)
{ {
NVG_NOTUSED(scancode); NVG_NOTUSED(scancode);
@@ -230,6 +315,10 @@ int main()
{ {
GLFWwindow* window; GLFWwindow* window;
struct NVGcontext* vg = NULL; struct NVGcontext* vg = NULL;
UIcontext *uictx;
uictx = uiCreateContext();
uiMakeCurrent(uictx);


if (!glfwInit()) { if (!glfwInit()) {
printf("Failed to init GLFW."); printf("Failed to init GLFW.");
@@ -252,6 +341,8 @@ int main()
} }


glfwSetKeyCallback(window, key); glfwSetKeyCallback(window, key);
glfwSetCursorPosCallback(window, cursorpos);
glfwSetMouseButtonCallback(window, mousebutton);


glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);
#ifdef NANOVG_GLEW #ifdef NANOVG_GLEW
@@ -304,6 +395,8 @@ int main()
glfwPollEvents(); glfwPollEvents();
} }


uiDestroyContext(uictx);

nvgDeleteGL3(vg); nvgDeleteGL3(vg);


glfwTerminate(); glfwTerminate();


Loading…
Cancel
Save