fixed panel spacing
This commit is contained in:
parent
3197437cac
commit
523a604258
19
Makefile
19
Makefile
|
@ -6,29 +6,30 @@ CC = gcc
|
||||||
DCC = clang
|
DCC = clang
|
||||||
|
|
||||||
# Flags
|
# Flags
|
||||||
CFLAGS = -std=c89 -pedantic-errors -Wdeprecated-declarations -D_POSIX_C_SOURCE=200809L
|
CFLAGS = -std=c89 -pedantic-errors -Wdeprecated-declarations
|
||||||
CFLAGS = -g -Wextra -Werror -Wformat -Wunreachable-code
|
CFLAGS = -g -Wall -Wextra -Wformat-security -Wunreachable-code
|
||||||
CFLAGS += -fstack-protector-strong -Winline -Wshadow -Wwrite-strings -fstrict-aliasing
|
CFLAGS += -fstack-protector-strong -Winline -Wshadow -Wwrite-strings -fstrict-aliasing
|
||||||
CFLAGS += -Wstrict-prototypes -Wold-style-definition -Wconversion
|
CFLAGS += -Wstrict-prototypes -Wold-style-definition -Wconversion -Wfloat-equal
|
||||||
CFLAGS += -Wredundant-decls -Wnested-externs -Wmissing-include-dirs
|
CFLAGS += -Wredundant-decls -Wnested-externs -Wmissing-include-dirs
|
||||||
CFLAGS += -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wmissing-prototypes -Wconversion
|
CFLAGS += -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wmissing-prototypes -Wconversion
|
||||||
CFLAGS += -Wswitch-default -Wundef -Wno-unused -Wstrict-overflow=5 -Wsign-conversion
|
CFLAGS += -Wswitch-default -Wundef -Wno-unused -Wstrict-overflow=5 -Wsign-conversion
|
||||||
CFLAGS += -Winit-self -Wstrict-aliasing -fsanitize=address -fsanitize=undefined
|
CFLAGS += -Winit-self -Wstrict-aliasing -fsanitize=address -fsanitize=undefined -ftrapv
|
||||||
|
CFLAGS += -Wswitch-enum -Winvalid-pch
|
||||||
|
|
||||||
SRC = gui.c opengl.c
|
SRC = gui.c opengl.c
|
||||||
OBJ = $(SRC:.c=.o)
|
OBJ = $(SRC:.c=.o)
|
||||||
|
|
||||||
# Modes
|
# Modes
|
||||||
.PHONY: gcc
|
|
||||||
gcc: CC = gcc
|
|
||||||
gcc: $(BIN)
|
|
||||||
|
|
||||||
.PHONY: clang
|
.PHONY: clang
|
||||||
clang: CC = clang
|
clang: CC = clang
|
||||||
clang: $(BIN)
|
clang: $(BIN)
|
||||||
|
|
||||||
|
.PHONY: gcc
|
||||||
|
gcc: CC = gcc
|
||||||
|
gcc: $(BIN)
|
||||||
|
|
||||||
$(BIN):
|
$(BIN):
|
||||||
@mkdir -p bin
|
@mkdir -p bin
|
||||||
rm -f bin/$(BIN) $(OBJS)
|
rm -f bin/$(BIN) $(OBJS)
|
||||||
$(CC) $(SRC) $(CFLAGS) -o bin/$(BIN) -lX11 -lGL -lGLU
|
$(CC) $(SRC) -D_POSIX_C_SOURCE=200809L $(CFLAGS) -o bin/$(BIN) -lX11 -lGL -lGLU
|
||||||
|
|
||||||
|
|
22
gui.c
22
gui.c
|
@ -7,8 +7,6 @@
|
||||||
|
|
||||||
#define NULL (void*)0
|
#define NULL (void*)0
|
||||||
#define UTF_INVALID 0xFFFD
|
#define UTF_INVALID 0xFFFD
|
||||||
#define PI 3.141592654f
|
|
||||||
|
|
||||||
#define PASTE(a,b) a##b
|
#define PASTE(a,b) a##b
|
||||||
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||||
#define MAX(a,b) ((a) < (b) ? (b) : (a))
|
#define MAX(a,b) ((a) < (b) ? (b) : (a))
|
||||||
|
@ -16,8 +14,6 @@
|
||||||
#define LEN(a) (sizeof(a)/sizeof(a)[0])
|
#define LEN(a) (sizeof(a)/sizeof(a)[0])
|
||||||
#define ABS(a) (((a) < 0) ? -(a) : (a))
|
#define ABS(a) (((a) < 0) ? -(a) : (a))
|
||||||
#define UNUSED(a) ((void)(a))
|
#define UNUSED(a) ((void)(a))
|
||||||
#define DEG2RAD(a) ((a) * (PI / 180.0f))
|
|
||||||
#define RAD2DEG(a) ((a) * (180.0f / PI))
|
|
||||||
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
|
#define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
|
||||||
#define INBOX(x, y, x0, y0, x1, y1) (BETWEEN(x, x0, x1) && BETWEEN(y, y0, y1))
|
#define INBOX(x, y, x0, y0, x1, y1) (BETWEEN(x, x0, x1) && BETWEEN(y, y0, y1))
|
||||||
|
|
||||||
|
@ -29,9 +25,7 @@
|
||||||
#define vec2_mov(to,from) (to).x = (from).x, (to).y = (from).y
|
#define vec2_mov(to,from) (to).x = (from).x, (to).y = (from).y
|
||||||
#define vec2_len(v) ((float)fsqrt((v).x*(v).x+(v).y*(v).y))
|
#define vec2_len(v) ((float)fsqrt((v).x*(v).x+(v).y*(v).y))
|
||||||
#define vec2_sub(r,a,b) do {(r).x=(a).x-(b).x; (r).y=(a).y-(b).y;} while(0)
|
#define vec2_sub(r,a,b) do {(r).x=(a).x-(b).x; (r).y=(a).y-(b).y;} while(0)
|
||||||
#define vec2_add(r,a,b) do {(r).x=(a).x+(b).x; (r).y=(a).y+(b).y;} while(0)
|
|
||||||
#define vec2_muls(r, v, s) do {(r).x=(v).x*(s); (r).y=(v).y*(s);} while(0)
|
#define vec2_muls(r, v, s) do {(r).x=(v).x*(s); (r).y=(v).y*(s);} while(0)
|
||||||
#define vec2_norm(r, v) do {float _ = vec2_len(v); if (_) vec2_muls(r, v, 1.0f/_);} while(0)
|
|
||||||
|
|
||||||
static const gui_texture null_tex = (void*)0;
|
static const gui_texture null_tex = (void*)0;
|
||||||
static const struct gui_rect null_rect = {-9999, -9999, 9999 * 2, 9999 * 2};
|
static const struct gui_rect null_rect = {-9999, -9999, 9999 * 2, 9999 * 2};
|
||||||
|
@ -50,9 +44,7 @@ fsqrt(float x)
|
||||||
val.f = x;
|
val.f = x;
|
||||||
val.i = 0x5f375a86 - (val.i>>1);
|
val.i = 0x5f375a86 - (val.i>>1);
|
||||||
val.f = val.f*(1.5f-xhalf*val.f*val.f);
|
val.f = val.f*(1.5f-xhalf*val.f*val.f);
|
||||||
if (val.f != 0.0f)
|
|
||||||
return 1.0f/val.f;
|
return 1.0f/val.f;
|
||||||
return val.f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void*
|
static void*
|
||||||
|
@ -159,7 +151,7 @@ gui_default_config(struct gui_config *config)
|
||||||
config->header_height = 50.0f;
|
config->header_height = 50.0f;
|
||||||
config->scrollbar_width = 16;
|
config->scrollbar_width = 16;
|
||||||
config->scroll_factor = 2;
|
config->scroll_factor = 2;
|
||||||
config->panel_padding = gui_make_vec2(8.0f, 8.0f);
|
config->panel_padding = gui_make_vec2(10.0f, 10.0f);
|
||||||
config->panel_min_size = gui_make_vec2(32.0f, 32.0f);
|
config->panel_min_size = gui_make_vec2(32.0f, 32.0f);
|
||||||
config->item_spacing = gui_make_vec2(8.0f, 4.0f);
|
config->item_spacing = gui_make_vec2(8.0f, 4.0f);
|
||||||
config->item_padding = gui_make_vec2(4.0f, 4.0f);
|
config->item_padding = gui_make_vec2(4.0f, 4.0f);
|
||||||
|
@ -373,8 +365,7 @@ gui_vertex_line(struct gui_draw_buffer* buffer, gui_float x0, gui_float y0,
|
||||||
vec2_load(b, x1, y1);
|
vec2_load(b, x1, y1);
|
||||||
vec2_sub(d, b, a);
|
vec2_sub(d, b, a);
|
||||||
|
|
||||||
len = vec2_len(d);
|
len = 0.5f / vec2_len(d);
|
||||||
if (len) len = 0.5f / vec2_len(d);
|
|
||||||
vec2_muls(hn, d, len);
|
vec2_muls(hn, d, len);
|
||||||
vec2_load(hp0, +hn.y, -hn.x);
|
vec2_load(hp0, +hn.y, -hn.x);
|
||||||
vec2_load(hp1, -hn.y, +hn.x);
|
vec2_load(hp1, -hn.y, +hn.x);
|
||||||
|
@ -602,7 +593,6 @@ gui_slider(struct gui_draw_buffer *buffer, const struct gui_slider *slider,
|
||||||
gui_float cursor_w;
|
gui_float cursor_w;
|
||||||
|
|
||||||
if (!buffer || !slider || !in) return 0;
|
if (!buffer || !slider || !in) return 0;
|
||||||
if (slider->step == 0.0f) return slider->value;
|
|
||||||
x = slider->x; y = slider->y;
|
x = slider->x; y = slider->y;
|
||||||
w = MAX(slider->w, 2 * slider->pad_x);
|
w = MAX(slider->w, 2 * slider->pad_x);
|
||||||
h = MAX(slider->h, 2 * slider->pad_y);
|
h = MAX(slider->h, 2 * slider->pad_y);
|
||||||
|
@ -825,8 +815,8 @@ gui_histo(struct gui_draw_buffer *buffer, const struct gui_histo *histo,
|
||||||
gui_rectf(buffer, x, y, w, h, histo->background);
|
gui_rectf(buffer, x, y, w, h, histo->background);
|
||||||
canvas_x = x + histo->pad_x;
|
canvas_x = x + histo->pad_x;
|
||||||
canvas_y = y + histo->pad_y;
|
canvas_y = y + histo->pad_y;
|
||||||
canvas_w = w - 2 * histo->pad_x;
|
canvas_w = MAX(0, w - 2 * histo->pad_x);
|
||||||
canvas_h = h - 2 * histo->pad_y;
|
canvas_h = MAX(0, h - 2 * histo->pad_y);
|
||||||
if (histo->value_count) {
|
if (histo->value_count) {
|
||||||
gui_float padding = (gui_float)(histo->value_count-1) * histo->pad_x;
|
gui_float padding = (gui_float)(histo->value_count-1) * histo->pad_x;
|
||||||
item_w = (canvas_w - padding) / (gui_float)(histo->value_count);
|
item_w = (canvas_w - padding) / (gui_float)(histo->value_count);
|
||||||
|
@ -1024,10 +1014,10 @@ gui_panel_alloc(struct gui_rect *bounds, struct gui_panel *panel)
|
||||||
space = panel->width - padding - spacing;
|
space = panel->width - padding - spacing;
|
||||||
|
|
||||||
item_width = space / (gui_float)panel->row_columns;
|
item_width = space / (gui_float)panel->row_columns;
|
||||||
item_offset = config->item_padding.x + (gui_float)panel->index * item_width;
|
item_offset = (gui_float)panel->index * item_width;
|
||||||
item_spacing = (gui_float)panel->index * config->item_spacing.x;
|
item_spacing = (gui_float)panel->index * config->item_spacing.x;
|
||||||
|
|
||||||
bounds->x = panel->x + item_offset + item_spacing;
|
bounds->x = panel->x + item_offset + item_spacing + config->panel_padding.x;
|
||||||
bounds->y = panel->at_y;
|
bounds->y = panel->at_y;
|
||||||
bounds->w = item_width;
|
bounds->w = item_width;
|
||||||
bounds->h = panel->row_height - config->item_spacing.y;
|
bounds->h = panel->row_height - config->item_spacing.y;
|
||||||
|
|
4
gui.h
4
gui.h
|
@ -102,7 +102,7 @@ struct gui_font_glyph {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct gui_font {
|
struct gui_font {
|
||||||
gui_short height;
|
gui_float height;
|
||||||
gui_float scale;
|
gui_float scale;
|
||||||
gui_texture texture;
|
gui_texture texture;
|
||||||
struct gui_vec2 tex_size;
|
struct gui_vec2 tex_size;
|
||||||
|
@ -128,8 +128,8 @@ struct gui_toggle {
|
||||||
gui_float w, h;
|
gui_float w, h;
|
||||||
gui_float pad_x, pad_y;
|
gui_float pad_x, pad_y;
|
||||||
gui_int active;
|
gui_int active;
|
||||||
const char *text;
|
|
||||||
gui_size length;
|
gui_size length;
|
||||||
|
const char *text;
|
||||||
struct gui_color font;
|
struct gui_color font;
|
||||||
struct gui_color background;
|
struct gui_color background;
|
||||||
struct gui_color foreground;
|
struct gui_color foreground;
|
||||||
|
|
15
opengl.c
15
opengl.c
|
@ -34,16 +34,13 @@
|
||||||
#define MAX_BUFFER (32 * 1024)
|
#define MAX_BUFFER (32 * 1024)
|
||||||
#define INPUT_MAX 64
|
#define INPUT_MAX 64
|
||||||
|
|
||||||
#define MIN(a,b)((a) < (b) ? (a) : (b))
|
|
||||||
#define MAX(a,b)((a) < (b) ? (b) : (a))
|
|
||||||
#define CLAMP(i,v,x) (MAX(MIN(v,x), i))
|
|
||||||
#define LEN(a)(sizeof(a)/sizeof(a)[0])
|
#define LEN(a)(sizeof(a)/sizeof(a)[0])
|
||||||
#define UNUSED(a)((void)(a))
|
#define UNUSED(a)((void)(a))
|
||||||
|
|
||||||
/* types */
|
/* types */
|
||||||
struct XWindow {
|
struct XWindow {
|
||||||
Display *dpy;
|
|
||||||
Window root;
|
Window root;
|
||||||
|
Display *dpy;
|
||||||
XVisualInfo *vi;
|
XVisualInfo *vi;
|
||||||
Colormap cmap;
|
Colormap cmap;
|
||||||
XSetWindowAttributes swa;
|
XSetWindowAttributes swa;
|
||||||
|
@ -139,6 +136,7 @@ kpress(struct GUI *gui, XEvent* e)
|
||||||
else if ((*keysym >= 'a' && *keysym <= 'z') ||
|
else if ((*keysym >= 'a' && *keysym <= 'z') ||
|
||||||
(*keysym >= '0' && *keysym <= '9'))
|
(*keysym >= '0' && *keysym <= '9'))
|
||||||
gui_input_char(&gui->in, (unsigned char*)keysym);
|
gui_input_char(&gui->in, (unsigned char*)keysym);
|
||||||
|
XFree(keysym);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -157,6 +155,7 @@ krelease(struct GUI *gui, XEvent* e)
|
||||||
gui_input_key(&gui->in, GUI_KEY_ENTER, gui_false);
|
gui_input_key(&gui->in, GUI_KEY_ENTER, gui_false);
|
||||||
else if (*keysym == XK_BackSpace)
|
else if (*keysym == XK_BackSpace)
|
||||||
gui_input_key(&gui->in, GUI_KEY_BACKSPACE, gui_false);
|
gui_input_key(&gui->in, GUI_KEY_BACKSPACE, gui_false);
|
||||||
|
XFree(keysym);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -437,12 +436,10 @@ main(int argc, char *argv[])
|
||||||
memset(&xw, 0, sizeof xw);
|
memset(&xw, 0, sizeof xw);
|
||||||
memset(&gui, 0, sizeof gui);
|
memset(&gui, 0, sizeof gui);
|
||||||
xw.dpy = XOpenDisplay(NULL);
|
xw.dpy = XOpenDisplay(NULL);
|
||||||
if (!xw.dpy)
|
if (!xw.dpy) die("XOpenDisplay failed\n");
|
||||||
die("XOpenDisplay failed\n");
|
|
||||||
xw.root = DefaultRootWindow(xw.dpy);
|
xw.root = DefaultRootWindow(xw.dpy);
|
||||||
xw.vi = glXChooseVisual(xw.dpy, 0, att);
|
xw.vi = glXChooseVisual(xw.dpy, 0, att);
|
||||||
if (!xw.vi)
|
if (!xw.vi) die("Failed to find appropriate visual\n");
|
||||||
die("Failed to find appropriate visual\n");
|
|
||||||
xw.cmap = XCreateColormap(xw.dpy,xw.root,xw.vi->visual,AllocNone);
|
xw.cmap = XCreateColormap(xw.dpy,xw.root,xw.vi->visual,AllocNone);
|
||||||
xw.swa.colormap = xw.cmap;
|
xw.swa.colormap = xw.cmap;
|
||||||
xw.swa.event_mask =
|
xw.swa.event_mask =
|
||||||
|
@ -515,7 +512,9 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
|
free(buffer);
|
||||||
delfont(gui.font);
|
delfont(gui.font);
|
||||||
|
XFree(xw.vi);
|
||||||
glXMakeCurrent(xw.dpy, None, NULL);
|
glXMakeCurrent(xw.dpy, None, NULL);
|
||||||
glXDestroyContext(xw.dpy, xw.glc);
|
glXDestroyContext(xw.dpy, xw.glc);
|
||||||
XDestroyWindow(xw.dpy, xw.win);
|
XDestroyWindow(xw.dpy, xw.win);
|
||||||
|
|
Loading…
Reference in New Issue