<commit_before>//------------------------------------------------------------------------------
//  nuklear-sapp.c
//
//  Demonstrates Nuklear UI rendering in C via
//  sokol_gfx.h + sokol_nuklear.h + nuklear.h
//
//  Nuklear UI on github: https://github.com/Immediate-Mode-UI/Nuklear
//------------------------------------------------------------------------------
#include "sokol_app.h"
#include "sokol_gfx.h"
#include "sokol_glue.h"
#include "dbgui/dbgui.h"

// include nuklear.h before the sokol_nuklear.h implementation
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_IMPLEMENTATION

#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
#if defined(_MSC_VER)
#pragma warning(disable:4996)   // sprintf,fopen,localtime: This function or variable may be unsafe
#endif
#include "nuklear/nuklear.h"
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif

#define SOKOL_NUKLEAR_IMPL
#include "sokol_nuklear.h"

// needed by the Nuklear sample UI code
#include <time.h>
#include <limits.h>

static int draw_demo_ui(struct nk_context* ctx);

void init(void) {
    // setup sokol-gfx, sokol-time and sokol-imgui
    sg_setup(&(sg_desc){
        .context = sapp_sgcontext()
    });
    __dbgui_setup(sapp_sample_count());

    // use sokol-nuklear with all default-options (we're not doing
    // multi-sampled rendering or using non-default pixel formats)
    snk_setup(&(snk_desc_t){
        .dpi_scale = sapp_dpi_scale()
    });
}

void frame(void) {
    struct nk_context *ctx = snk_new_frame();

    // see big function at end of file
    draw_demo_ui(ctx);

    // the sokol_gfx draw pass
    const sg_pass_action pass_action = {
        .colors[0] = {
            .action = SG_ACTION_CLEAR, .value = { 0.25f, 0.5f, 0.7f, 1.0f }
        }
    };
    sg_begin_default_pass(&pass_action, sapp_width(), sapp_height());
    snk_render(sapp_width(), sapp_height());
    __dbgui_draw();
    sg_end_pass();
    sg_commit();
}

void cleanup(void) {
    __dbgui_shutdown();
    snk_shutdown();
    sg_shutdown();
}

void input(const sapp_event* event) {
    if (!__dbgui_event_with_retval(event)) {
        snk_handle_event(event);
    }
}

sapp_desc sokol_main(int argc, char* argv[]) {
    (void)argc;
    (void)argv;
    return (sapp_desc) {
        .init_cb = init,
        .frame_cb = frame,
        .cleanup_cb = cleanup,
        .event_cb = input,
        .enable_clipboard = true,
        .width = 1024,
        .height = 768,
        .window_title = "nuklear (sokol-app)",
        .ios_keyboard_resizes_canvas = true
    };
}

/* copied from: https://github.com/Immediate-Mode-UI/Nuklear/blob/master/demo/overview.c */
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif
static int
draw_demo_ui(struct nk_context *ctx)
{
    /* window flags */
    static int show_menu = nk_true;
    static int titlebar = nk_true;
    static int border = nk_true;
    static int resize = nk_true;
    static int movable = nk_true;
    static int no_scrollbar = nk_false;
    static int scale_left = nk_false;
    static nk_flags window_flags = 0;<commit_msg>minor code cleanup in nuklear-sapp<commit_after>//------------------------------------------------------------------------------
//  nuklear-sapp.c
//
//  Demonstrates Nuklear UI rendering in C via
//  sokol_gfx.h + sokol_nuklear.h + nuklear.h
//
//  Nuklear UI on github: https://github.com/Immediate-Mode-UI/Nuklear
//------------------------------------------------------------------------------
#include "sokol_app.h"
#include "sokol_gfx.h"
#include "sokol_glue.h"
#include "dbgui/dbgui.h"

// include nuklear.h before the sokol_nuklear.h implementation
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_IMPLEMENTATION

// NOTE: in real-world code it makes sense to include the nuklear.h implementation
// in a separate .c file and do all the "warning hygiene" there.
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
#if defined(_MSC_VER)
#pragma warning(disable:4996)   // sprintf,fopen,localtime: This function or variable may be unsafe
#endif
#include "nuklear/nuklear.h"
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif

#define SOKOL_NUKLEAR_IMPL
#include "sokol_nuklear.h"

static int draw_demo_ui(struct nk_context* ctx);

void init(void) {
    // setup sokol-gfx, sokol-time and sokol-imgui
    sg_setup(&(sg_desc){
        .context = sapp_sgcontext()
    });
    __dbgui_setup(sapp_sample_count());

    // use sokol-nuklear with all default-options (we're not doing
    // multi-sampled rendering or using non-default pixel formats)
    snk_setup(&(snk_desc_t){
        .dpi_scale = sapp_dpi_scale()
    });
}

void frame(void) {
    struct nk_context *ctx = snk_new_frame();

    // see big function at end of file
    draw_demo_ui(ctx);

    // the sokol_gfx draw pass
    const sg_pass_action pass_action = {
        .colors[0] = {
            .action = SG_ACTION_CLEAR, .value = { 0.25f, 0.5f, 0.7f, 1.0f }
        }
    };
    sg_begin_default_pass(&pass_action, sapp_width(), sapp_height());
    snk_render(sapp_width(), sapp_height());
    __dbgui_draw();
    sg_end_pass();
    sg_commit();
}

void cleanup(void) {
    __dbgui_shutdown();
    snk_shutdown();
    sg_shutdown();
}

void input(const sapp_event* event) {
    if (!__dbgui_event_with_retval(event)) {
        snk_handle_event(event);
    }
}

sapp_desc sokol_main(int argc, char* argv[]) {
    (void)argc;
    (void)argv;
    return (sapp_desc) {
        .init_cb = init,
        .frame_cb = frame,
        .cleanup_cb = cleanup,
        .event_cb = input,
        .enable_clipboard = true,
        .width = 1024,
        .height = 768,
        .window_title = "nuklear (sokol-app)",
        .ios_keyboard_resizes_canvas = true
    };
}

/* copied from: https://github.com/Immediate-Mode-UI/Nuklear/blob/master/demo/overview.c */
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif

#include <time.h>
#include <limits.h>

static int
draw_demo_ui(struct nk_context *ctx)
{
    /* window flags */
    static int show_menu = nk_true;
    static int titlebar = nk_true;
    static int border = nk_true;
    static int resize = nk_true;
    static int movable = nk_true;
    static int no_scrollbar = nk_false;
    static int scale_left = nk_false;
    static nk_flags window_flags = 0;
{'fraction_non_alphanumeric': 0.15352811466372657, 'fraction_numerical': 0.006063947078280044, 'mean_word_length': 2.9590834697217674, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2182208', 'n_tokens_mistral': 2628, 'n_tokens_neox': 2536, 'n_words': 568}