'--------------------------------------------------------------------------------------------- INCLUDE canvas INCLUDE canvas-plugin-nuklear '--------------------------------------------------------------------------------------------- SUB Show_Gui() LOCAL op1 = 1, op2 = 0 TYPE static int LOCAL check1 = 1, check2 = 1, property = 0, check = 1 TYPE static int LOCAL value = 0.6f TYPE static float LOCAL selected_item = 1 TYPE static int LOCAL Cities$ LOCAL style TYPE nuklear_style* LOCAL view TYPE nuklear_list LOCAL mycol = {1, 0, 0, 1} TYPE static nuklear_colorf ' First query all mouse events for this window nk_canvas_events(&win) ' Define coloring for buttons (Window 1) style = &win.ctx.style nk_style_push_style_item(&win.ctx, &style->button.normal, nk_style_item_color(nk_rgba(0,180,0,255))) nk_style_push_style_item(&win.ctx, &style->button.hover, nk_style_item_color(nk_rgba(0,255,0,255))) nk_style_push_style_item(&win.ctx, &style->button.active, nk_style_item_color(nk_rgba(0,200,0,255))) ' Title bar nk_style_push_style_item(&win.ctx, &style->window.header.normal, nk_style_item_color(nk_rgba(0,180,0,255))) nk_style_push_style_item(&win.ctx, &style->window.header.active, nk_style_item_color(nk_rgba(0,255,0,255))) /* More coloring features: - window.fixed_background - button.text_normal/text_hover_text_active for text on buttons - many more, see 'nuklear.h' for more items */ ' Then create window with title "Show" at position 100x100 and size 280x280 using some flags IF nk_begin(&win.ctx, "Show", nk_rect(100, 100, 280, 280), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_TITLE) THEN ' Menu widget window, 30 = height, 1 menubar nk_menubar_begin(&win.ctx) nk_layout_row_begin(&win.ctx, NK_STATIC, 30, 1) ' Width of menubar = 100 nk_layout_row_push(&win.ctx, 100) ' Popup where size is max 120x200 IF nk_menu_begin_label(&win.ctx, "File", NK_TEXT_LEFT, nk_vec2(120, 150)) THEN nk_layout_row_dynamic(&win.ctx, 30, 1) IF nk_menu_item_label(&win.ctx, "Open", NK_TEXT_LEFT) THEN PRINT "Open clicked" IF nk_menu_item_label(&win.ctx, "Close", NK_TEXT_LEFT) THEN PRINT "Close clicked" IF nk_menu_item_label(&win.ctx, "Hide", NK_TEXT_LEFT) THEN PRINT "Hide clicked" IF nk_menu_item_label(&win.ctx, "About", NK_TEXT_LEFT) THEN PRINT "About clicked" nk_menu_end(&win.ctx) ENDIF nk_menubar_end(&win.ctx) ' Some space between menu and other widgets, 10 = height, INT_MAX = ignore width, 0 widgets nk_layout_row_static(&win.ctx, 10, INT_MAX, 0) ' Radio buttons, dynamic layout, 30 = height, 2 widgets nk_layout_row_dynamic(&win.ctx, 30, 2) IF nk_radio_label(&win.ctx, "Easy", &op1) THEN op1 = 1 op2 = 0 ENDIF IF nk_radio_label(&win.ctx, "Hard", &op2) THEN op1 = 0 op2 = 1 ENDIF ' Label and slider, row layout, STATIC = use values for placement, 30 = height, 2 widgets nk_layout_row_begin(&win.ctx, NK_STATIC, 30, 2) DO nk_layout_row_push(&win.ctx, 130) nk_label(&win.ctx, "Volume:", NK_TEXT_LEFT) nk_layout_row_push(&win.ctx, 120) nk_slider_float(&win.ctx, 0, &value, 1.0f, 0.1f) DONE nk_layout_row_end(&win.ctx) ' Value modification widget, dynamic layout, 0 = ignore height, 1 widget nk_layout_row_dynamic(&win.ctx, 0, 1) nk_property_int(&win.ctx, "Compression:", 0, &property, 100, 10, 1) ' Check box, dynamic layout, 0 = ignore height, 2 widgets nk_layout_row_dynamic(&win.ctx, 0, 2) nk_checkbox_label(&win.ctx, "Large", &check1) nk_checkbox_label(&win.ctx, "Little", &check2) ' Buttons, relative layout, DYNAMIC = use percentages for placement, 30 = height, INT_MAX = max widgets nk_layout_space_begin(&win.ctx, NK_DYNAMIC, 30, INT_MAX) nk_layout_space_push(&win.ctx, nk_rect(0.0, 0.0, 0.35, 1.0)) IF nk_button_label(&win.ctx, "Help") THEN PRINT "Help pressed" nk_layout_space_push(&win.ctx, nk_rect(0.65, 0.0, 0.35, 1.0)) IF nk_button_label(&win.ctx, "Exit") THEN nk_canvas_free(&win) QUIT ENDIF ENDIF nk_end(&win.ctx) ' Pop button colors from stack nk_style_pop_style_item(&win.ctx) nk_style_pop_style_item(&win.ctx) nk_style_pop_style_item(&win.ctx) nk_style_pop_style_item(&win.ctx) nk_style_pop_style_item(&win.ctx) ' Create window with title "Combo" at position 400x100 and size 300x300 using some flags IF nk_begin(&win.ctx, "Another", nk_rect(400, 100, 300, 300), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_CLOSABLE|NK_WINDOW_TITLE|NK_WINDOW_MINIMIZABLE) THEN LOCAL items[] = { "One number", "Two numbers", "Three digits", "Four chars", "Five spaces", "Six specials" } TYPE STRING ' List height = 100 nk_layout_row_dynamic(&win.ctx, 100, 1) ' Row height = 25, row count = 5 IF nk_list_view_begin(&win.ctx, &view, "My List", NK_WINDOW_BORDER, 25, 5) THEN nk_layout_row_dynamic(&win.ctx, 25, 1) ' Show 3 rows nk_label(&win.ctx, items[view.begin + 0], NK_TEXT_LEFT) nk_label(&win.ctx, items[view.begin + 1], NK_TEXT_LEFT) nk_label(&win.ctx, items[view.begin + 2], NK_TEXT_LEFT) nk_list_view_end(&view) ENDIF ' Works with delimited string also Cities$ = "Oslo Paris Madrid" ' Combobox nk_layout_row_dynamic(&win.ctx, 30, 0) nk_layout_row_dynamic(&win.ctx, 30, 2) nk_label(&win.ctx, "Combobox:", NK_TEXT_CENTERED) IF nk_combo_begin_label(&win.ctx, TOKEN$(Cities$, selected_item), nk_vec2(nk_widget_width(&win.ctx), 120) ) THEN nk_layout_row_dynamic(&win.ctx, 25, 1) IF nk_combo_item_label(&win.ctx, TOKEN$(Cities$, 1), NK_TEXT_LEFT) THEN selected_item = 1 IF nk_combo_item_label(&win.ctx, TOKEN$(Cities$, 2), NK_TEXT_LEFT) THEN selected_item = 2 IF nk_combo_item_label(&win.ctx, TOKEN$(Cities$, 3), NK_TEXT_LEFT) THEN selected_item = 3 nk_combo_end(&win.ctx) ENDIF ' Color picker nk_layout_row_dynamic(&win.ctx, 30, 0) nk_layout_space_begin(&win.ctx, NK_DYNAMIC, 30, INT_MAX) nk_layout_space_push(&win.ctx, nk_rect(0.0, 0.0, 0.25, 1.0)) nk_label(&win.ctx, "Color:", NK_TEXT_LEFT) nk_layout_space_push(&win.ctx, nk_rect(0.35, 0.0, 0.30, 1.0)) IF nk_color_pick(&win.ctx, &mycol, NK_RGBA) THEN PRINT "Color r:", mycol.r, " g:", mycol.g, " b:", mycol.b, " a:", mycol.a nk_layout_space_push(&win.ctx, nk_rect(0.75, 0.0, 0.25, 1.0)) ' Another EXIT button IF nk_button_label(&win.ctx, "Exit") THEN nk_canvas_free(&win) QUIT ENDIF ENDIF nk_end(&win.ctx) ' Quit when window is closed IF nk_window_is_hidden(&win.ctx, "Another") THEN nk_canvas_free(&win) QUIT ENDIF ' Verify if there were changes in the GUI, if so, then clear screen and draw it. IF nk_canvas_changed(&win) THEN INK(100, 100, 100, 255) CLS nk_canvas_render(&win) ENDIF END SUB '--------------------------------------------------------------------------------------------- DECLARE win TYPE nuklear_type 'LOADFONT(DIRNAME$(ME$) & "/fonts/markers.jhf") WINDOW("Nuklear Demonstration", 1024, 768) ' Create a new Nuklear window win = nk_canvas_new() CALLBACK(20, Show_Gui) WAITKEY '---------------------------------------------------------------------------------------------