Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two Issues with Fonts #601

Open
raphael10-collab opened this issue Dec 28, 2023 · 0 comments
Open

Two Issues with Fonts #601

raphael10-collab opened this issue Dec 28, 2023 · 0 comments

Comments

@raphael10-collab
Copy link

raphael10-collab commented Dec 28, 2023

I have issues in the font management:

First Issue:

I tried to follow step-by-step these indications: https://github.com/Immediate-Mode-UI/Nuklear/wiki/Complete-font-guide#configuring-the-fon :

struct nk_font * latin, * icons, * japan; // This name is how you will access and switch the fonts in your GUI definition

struct nk_font_atlas  *atlas;

struct nk_font_config cfg_latin = nk_font_config(0);

but got this error:

/home/raphy/MyPrj/src/basic.cc:48:23: error: variable ‘nk_font_config cfg_latin’ has initializer but incomplete type
   48 | struct nk_font_config cfg_latin = nk_font_config(0);

Second Issue:

Executing the compiled and built file:

raphy@raohy:~/MyPrj$ ./cmakebuilddir/basic 
basic: /home/raphy/MyPrj/src/../../Nuklear/nuklear.h:20345: nk_bool nk_begin_titled(nk_context*, const char*, const char*, nk_rect, nk_flags): Assertion `ctx->style.font && ctx->style.font->width && "if this triggers you forgot to add a font"' failed.
Aborted (core dumped)

This is /src/basic.cc file :

#include "iostream"
#define NK_IMPLEMENTATION
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
//#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#include "../../Nuklear/nuklear.h"
#include "nuklear_glfw_gl3.h"

int main(int argc, char* argv[]) {
    // init gui state
    enum {EASY, HARD};
    static int op = EASY;
    static float value = 0.6f;
    static int i =  20;
    struct nk_context ctx;

    nk_init_default(&ctx, 0);

    if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
        NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
        // fixed widget pixel width
        nk_layout_row_static(&ctx, 30, 80, 1);
        if (nk_button_label(&ctx, "button")) {
            // event handling
        }
        // fixed widget window ratio width
        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;
        // custom widget pixel width
        nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
        {
            nk_layout_row_push(&ctx, 50);
            nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
            nk_layout_row_push(&ctx, 110);
            nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
        }
        nk_layout_row_end(&ctx);
    }
    nk_end(&ctx);

    return 0;
}

CMakeLists.txt :

cmake_minimum_required(VERSION 3.24)
project (MyPrj LANGUAGES C CXX)

find_package(PkgConfig REQUIRED)
pkg_check_modules(glew REQUIRED IMPORTED_TARGET glew)
pkg_check_modules(gl REQUIRED IMPORTED_TARGET gl)
pkg_check_modules(x11 REQUIRED IMPORTED_TARGET x11)
pkg_check_modules(glu REQUIRED IMPORTED_TARGET glu)
pkg_check_modules(openlibm REQUIRED IMPORTED_TARGET openlibm)

find_package(glfw3 REQUIRED)

add_executable(basic
    src/basic.cc
)

target_compile_options(basic PUBLIC ${glfw_CFLAGS_OTHER} ${glew_CFLAGS_OTHER} ${gl_CFLAGS_OTHER} ${x11_CFLAGS_OTHER} ${glu_CFLAGS_OTHER} ${openlibm_CFLAGS_OTHER})
target_include_directories(basic PUBLIC ${webkit2gtk_INCLUDE_DIRS} ${gtk_INCLUDE_DIRS})
target_include_directories(basic PUBLIC libs/webview)


target_link_libraries(basic PUBLIC
    glfw
    PkgConfig::glew
    PkgConfig::gl
    PkgConfig::x11
    PkgConfig::glu
    PkgConfig::openlibm
)

How to make it work?

@raphael10-collab raphael10-collab changed the title nk_font_atlas atlas has incomplete type and cannot be defined Issue in Font Management Dec 28, 2023
@raphael10-collab raphael10-collab changed the title Issue in Font Management Two Issues with Fonts Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant