Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demo/common/overview.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ overview(struct nk_context *ctx)

#ifdef INCLUDE_STYLE
/* styles */
static const char* themes[] = {"Black", "White", "Red", "Blue", "Dark", "Dracula",
static const char* themes[] = {"Black", "White", "Red", "Blue", "Dark", "Dracula",
"Catppucin Latte", "Catppucin Frappe", "Catppucin Macchiato", "Catppucin Mocha"};
static int current_theme = 0;
#endif
Expand Down Expand Up @@ -820,7 +820,7 @@ overview(struct nk_context *ctx)
if (nk_popup_begin(ctx, NK_POPUP_STATIC, "Error", 0, s))
{
nk_layout_row_dynamic(ctx, 25, 1);
nk_label(ctx, "A terrible error as occurred", NK_TEXT_LEFT);
nk_label(ctx, "A terrible error has occurred", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 2);
if (nk_button_label(ctx, "OK")) {
popup_active = 0;
Expand Down
102 changes: 55 additions & 47 deletions demo/sdl_opengl2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>

long SDL_GetTicks64()
{
return SDL_GetTicks();
}

#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
Expand Down Expand Up @@ -79,13 +84,18 @@ int
main(int argc, char *argv[])
{
/* Platform */
struct nk_buffer cmds;
struct nk_draw_null_texture tex_null;
GLuint font_tex;
struct nk_font_atlas atlas;
Uint64 time_of_last_frame;
SDL_Window *win;
SDL_GLContext glContext;
int win_width, win_height;
int running = 1;

/* GUI */
struct nk_context *ctx;
struct nk_context ctx;
struct nk_colorf bg;

#ifdef INCLUDE_CONFIGURATOR
Expand All @@ -111,83 +121,82 @@ main(int argc, char *argv[])
SDL_GetWindowSize(win, &win_width, &win_height);

/* GUI */
ctx = nk_sdl_init(win);
nk_sdl_init(&ctx, &cmds, &time_of_last_frame);
/* Load Fonts: if none of these are loaded a default font will be used */
/* Load Cursor: if you uncomment cursor loading please hide the cursor */
{struct nk_font_atlas *atlas;
nk_sdl_font_stash_begin(&atlas);
/*struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/
/*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Roboto-Regular.ttf", 16, 0);*/
/*struct nk_font *future = nk_font_atlas_add_from_file(atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/
/*struct nk_font *clean = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/
/*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/
/*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/
nk_sdl_font_stash_end();
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &roboto->handle)*/;}
{nk_sdl_font_stash_begin(&atlas);
/*struct nk_font *droid = nk_font_atlas_add_from_file(&atlas, "../../../extra_font/DroidSans.ttf", 14, 0);*/
/*struct nk_font *roboto = nk_font_atlas_add_from_file(&atlas, "../../../extra_font/Roboto-Regular.ttf", 16, 0);*/
/*struct nk_font *future = nk_font_atlas_add_from_file(&atlas, "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/
/*struct nk_font *clean = nk_font_atlas_add_from_file(&atlas, "../../../extra_font/ProggyClean.ttf", 12, 0);*/
/*struct nk_font *tiny = nk_font_atlas_add_from_file(&atlas, "../../../extra_font/ProggyTiny.ttf", 10, 0);*/
/*struct nk_font *cousine = nk_font_atlas_add_from_file(&atlas, "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/
nk_sdl_font_stash_end(&ctx, &atlas, &tex_null, &font_tex);
/*nk_style_load_all_cursors(&ctx, atlas.cursors);*/
/*nk_style_set_font(&ctx, &roboto->handle)*/;}

bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
while (running)
{
/* Input */
SDL_Event evt;
nk_input_begin(ctx);
nk_input_begin(&ctx);
while (SDL_PollEvent(&evt)) {
if (evt.type == SDL_QUIT) goto cleanup;
nk_sdl_handle_event(&evt);
nk_sdl_handle_event(&ctx, &evt);
}
nk_sdl_handle_grab(); /* optional grabbing behavior */
nk_input_end(ctx);
nk_sdl_handle_grab(&ctx, win); /* optional grabbing behavior */
nk_input_end(&ctx);

/* GUI */
if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250),
if (nk_begin(&ctx, "Demo", nk_rect(50, 50, 230, 250),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
enum {EASY, HARD};
static int op = EASY;
static int property = 20;

nk_layout_row_static(ctx, 30, 80, 1);
if (nk_button_label(ctx, "button"))
nk_layout_row_static(&ctx, 30, 80, 1);
if (nk_button_label(&ctx, "button"))
fprintf(stdout, "button pressed\n");
nk_layout_row_dynamic(ctx, 30, 2);
if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);

nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 1);
if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) {
nk_layout_row_dynamic(ctx, 120, 1);
bg = nk_color_picker(ctx, bg, NK_RGBA);
nk_layout_row_dynamic(ctx, 25, 1);
bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f);
bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f);
bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f);
bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f);
nk_combo_end(ctx);
nk_layout_row_dynamic(&ctx, 30, 2);
if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;
nk_layout_row_dynamic(&ctx, 25, 1);
nk_property_int(&ctx, "Compression:", 0, &property, 100, 10, 1);

nk_layout_row_dynamic(&ctx, 20, 1);
nk_label(&ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(&ctx, 25, 1);
if (nk_combo_begin_color(&ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(&ctx),400))) {
nk_layout_row_dynamic(&ctx, 120, 1);
bg = nk_color_picker(&ctx, bg, NK_RGBA);
nk_layout_row_dynamic(&ctx, 25, 1);
bg.r = nk_propertyf(&ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f);
bg.g = nk_propertyf(&ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f);
bg.b = nk_propertyf(&ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f);
bg.a = nk_propertyf(&ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f);
nk_combo_end(&ctx);
}
}
nk_end(ctx);
nk_end(&ctx);

/* -------------- EXAMPLES ---------------- */
#ifdef INCLUDE_CALCULATOR
calculator(ctx);
calculator(&ctx);
#endif
#ifdef INCLUDE_CANVAS
canvas(ctx);
canvas(&ctx);
#endif
#ifdef INCLUDE_OVERVIEW
overview(ctx);
overview(&ctx);
#endif
#ifdef INCLUDE_CONFIGURATOR
style_configurator(ctx, color_table);
style_configurator(&ctx, color_table);
#endif
#ifdef INCLUDE_NODE_EDITOR
node_editor(ctx);
node_editor(&ctx);
#endif
/* ----------------------------------------- */

Expand All @@ -201,15 +210,14 @@ main(int argc, char *argv[])
* defaults everything back into a default state.
* Make sure to either a.) save and restore or b.) reset your own state after
* rendering the UI. */
nk_sdl_render(NK_ANTI_ALIASING_ON);
nk_sdl_render(&ctx, &cmds, &tex_null, win, NK_ANTI_ALIASING_ON, &time_of_last_frame);
SDL_GL_SwapWindow(win);
}

cleanup:
nk_sdl_shutdown();
nk_sdl_shutdown(&ctx, &atlas, &cmds, font_tex);
SDL_GL_DeleteContext(glContext);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}

Loading
Loading