Skip to content

Commit 5ada134

Browse files
committed
Updates
1 parent 0c6f543 commit 5ada134

9 files changed

Lines changed: 34 additions & 53 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if (NOT nuklear_gamepad_FOUND)
1414
FetchContent_Declare(
1515
nuklear_gamepad
1616
GIT_REPOSITORY https://github.com/RobLoach/nuklear_gamepad.git
17-
GIT_TAG 625d716
17+
GIT_TAG 82056c3
1818
)
1919
FetchContent_GetProperties(nuklear_gamepad)
2020
if (NOT nuklear_gamepad_POPULATED)

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int main() {
4444

4545
## Widgets
4646

47-
Buttons, Checkboxes, Color Select, Comboboxes, Files, Directories, Gamepad Input Buttons, Labels, Properties, Sliders, Knobs, Radio Options, Images, Knob, Rows, TextEdit, Tree, Rule Horizontal, List View, Messages.
47+
Buttons, Checkboxes, Color Select, Comboboxes, Files, Directories, Gamepad Input Buttons, Labels, Properties, Sliders, Knobs, Radio Options, Images, Knob, Rows, TextEdit, Tree, Rule Horizontal, Keyboard Key, List View, Messages.
4848

4949
## API
5050

@@ -97,7 +97,6 @@ void nk_console_set_active_widget(nk_console* widget);
9797
9898
| Define | Description |
9999
| ------ | ----------- |
100-
| `NK_BUTTON_TRIGGER_ON_RELEASE` | When enabled, will allow for touch and drag to scroll the window |
101100
| `NK_CONSOLE_DRAG_THRESHOLD` | When using touch and drag to scroll, the amount of threshold movement needed to consider it a scroll |
102101
| `NK_CONSOLE_AXIS_DEADZONE` | The amount of movement the axis needs prior to moving the cursor |
103102
| `NK_CONSOLE_AXIS_REPEAT_INTERVAL` | When using the gamepad axis to move, how frequently the cursor will move |

demo/glfw/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define NK_IMPLEMENTATION
2323
#define NK_GLFW_GL3_IMPLEMENTATION
2424
#define NK_KEYSTATE_BASED_INPUT
25+
#define NK_BUTTON_TRIGGER_ON_RELEASE
2526
#include "../../vendor/Nuklear/nuklear.h"
2627
#include "../../vendor/Nuklear/demo/glfw_opengl3/nuklear_glfw_gl3.h"
2728

demo/raylib/main.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ void UpdateDrawFrame(void);
1616

1717
struct nk_context *ctx;
1818
nk_bool closeWindow = nk_false;
19-
struct nk_rect lastWindowSize;
2019

2120
int main() {
2221
SetConfigFlags(FLAG_WINDOW_RESIZABLE);
@@ -32,7 +31,6 @@ int main() {
3231
Texture texture = LoadTexture("resources/image.png");
3332

3433
console = nuklear_console_demo_init(ctx, NULL, TextureToNuklearImage(texture));
35-
lastWindowSize = nk_rect(0, 0, (float)GetScreenWidth() * 0.80f, (float)GetScreenHeight());
3634

3735
#if defined(PLATFORM_WEB)
3836
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
@@ -62,20 +60,8 @@ void UpdateDrawFrame(void) {
6260

6361
nk_gamepad_update(nk_console_get_gamepads(console));
6462

65-
int flags = NK_WINDOW_SCROLL_AUTO_HIDE;
66-
67-
// Center the window using the previous frame's rendered size, capped to screen
68-
float windowW = lastWindowSize.w < GetScreenWidth() ? lastWindowSize.w : GetScreenWidth();
69-
float windowH = lastWindowSize.h < GetScreenHeight() ? lastWindowSize.h : GetScreenHeight();
70-
struct nk_rect centered = nk_rect(
71-
(GetScreenWidth() - windowW) / 2.0f,
72-
(GetScreenHeight() - windowH) / 2.0f,
73-
windowW,
74-
windowH
75-
);
76-
7763
// Nuklear GUI Code
78-
lastWindowSize = nk_console_render_window(console, "nuklear_console", centered, flags);
64+
nk_console_render_window(console, "nuklear_console", nk_rect(0, 0, (float)GetScreenWidth(), (float)GetScreenHeight()), NK_WINDOW_SCROLL_AUTO_HIDE);
7965

8066
// Render
8167
BeginDrawing();

demo/sdl3_renderer/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define NK_INCLUDE_DEFAULT_FONT
2222
#define NK_INCLUDE_COMMAND_USERDATA
2323
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
24+
#define NK_BUTTON_TRIGGER_ON_RELEASE
2425
#define NK_IMPLEMENTATION
2526
#include "../../vendor/Nuklear/nuklear.h"
2627

demo/sdl_renderer/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define NK_INCLUDE_COMMAND_USERDATA
2121
#define NK_IMPLEMENTATION
2222
#define NK_SDL_RENDERER_IMPLEMENTATION
23+
#define NK_BUTTON_TRIGGER_ON_RELEASE
2324
#include "../../vendor/Nuklear/nuklear.h"
2425
#include "../../vendor/Nuklear/demo/sdl_renderer/nuklear_sdl_renderer.h"
2526

@@ -112,7 +113,7 @@ int main(int argc, char *argv[]) {
112113
nk_input_begin(ctx);
113114

114115
nk_gamepad_update(nk_console_get_gamepads(console));
115-
116+
116117
while (SDL_PollEvent(&evt)) {
117118
if (evt.type == SDL_QUIT) goto cleanup;
118119
if (evt.type == SDL_KEYUP && evt.key.keysym.scancode == SDL_SCANCODE_ESCAPE) running = 0;

nuklear_console.h

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,28 @@ NK_API nk_bool nk_console_navigate_to_path(nk_console* console, const char* path
312312
#ifndef NK_CONSOLE_IMPLEMENTATION_ONCE
313313
#define NK_CONSOLE_IMPLEMENTATION_ONCE
314314

315+
#ifndef NK_BUTTON_TRIGGER_ON_RELEASE
316+
/**
317+
* Define NK_BUTTON_TRIGGER_ON_RELEASE prior to nuklear.h.
318+
*
319+
* This is required because the input events are triggered incorrectly otherwise.
320+
*
321+
* @code
322+
* #define NK_IMPLEMENTATION
323+
* #define NK_BUTTON_TRIGGER_ON_RELEASE
324+
* #include "nuklear.h"
325+
*
326+
* #define NK_CONSOLE_IMPLEMENTATION
327+
* #include "nuklear_console.h"
328+
* @endcode
329+
*
330+
* You are able to ignore this warning by using #define NK_CONSOLE_IGNORE_BUTTON_TRIGGER_ON_RELEASE
331+
*/
332+
#ifndef NK_CONSOLE_IGNORE_BUTTON_TRIGGER_ON_RELEASE
333+
#warning nuklear_console requires NK_BUTTON_TRIGGER_ON_RELEASE. Define it directly prior to #include "nuklear.h" .
334+
#endif
335+
#endif
336+
315337
#ifndef NK_CONSOLE_AXIS_DEADZONE
316338
#define NK_CONSOLE_AXIS_DEADZONE 0.22f
317339
#endif
@@ -880,10 +902,6 @@ static void nk_console_axis_update(nk_console* console) {
880902
* Handles the Touch and Drag Scrolling.
881903
*/
882904
static void nk_console_window_touch_drag(nk_console* console, nk_console_top_data* top_data) {
883-
#ifndef NK_BUTTON_TRIGGER_ON_RELEASE
884-
NK_UNUSED(console);
885-
NK_UNUSED(top_data);
886-
#else
887905
struct nk_input* in = &console->ctx->input;
888906
if (nk_window_is_hovered(console->ctx) && nk_input_is_mouse_pressed(in, NK_BUTTON_LEFT)) {
889907
top_data->drag_scroll_origin = in->mouse.pos;
@@ -906,7 +924,6 @@ static void nk_console_window_touch_drag(nk_console* console, nk_console_top_dat
906924
} else {
907925
top_data->drag_scroll_active = nk_false;
908926
}
909-
#endif
910927
}
911928

912929
NK_API void nk_console_render(nk_console* console) {
@@ -1113,10 +1130,8 @@ NK_API struct nk_rect nk_console_render_window(nk_console* console, const char*
11131130
float rendered_h = console->ctx->current->layout->at_y - console->ctx->current->layout->bounds.y + console->ctx->current->layout->row.height;
11141131
window_bounds = nk_window_get_bounds(console->ctx);
11151132
window_bounds.h = window_bounds.h - content.h + rendered_h;
1116-
#ifdef NK_BUTTON_TRIGGER_ON_RELEASE
11171133
top_data->drag_scroll_max_y = (nk_uint)NK_MAX(0.0f, rendered_h - content.h);
11181134
top_data->drag_scroll_max_x = (nk_uint)NK_MAX(0.0f, console->ctx->current->layout->max_x - console->ctx->current->layout->bounds.x - content.w);
1119-
#endif
11201135
}
11211136

11221137
// Finish the window processing.

nuklear_console_input.h

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,6 @@ NK_API struct nk_rect nk_console_input_render(nk_console* widget);
5555
extern "C" {
5656
#endif
5757

58-
/**
59-
* Get the name of a gamepad button.
60-
*
61-
* @param button The button to get the name of.
62-
*
63-
* @return The name of the button.
64-
*/
65-
static const char* nk_console_input_button_name(enum nk_gamepad_button button) {
66-
switch (button) {
67-
case NK_GAMEPAD_BUTTON_INVALID: return "<None>";
68-
case NK_GAMEPAD_BUTTON_A: return "A";
69-
case NK_GAMEPAD_BUTTON_B: return "B";
70-
case NK_GAMEPAD_BUTTON_X: return "X";
71-
case NK_GAMEPAD_BUTTON_Y: return "Y";
72-
case NK_GAMEPAD_BUTTON_LB: return "Left Bumper";
73-
case NK_GAMEPAD_BUTTON_RB: return "Right Bumper";
74-
case NK_GAMEPAD_BUTTON_BACK: return "Back";
75-
case NK_GAMEPAD_BUTTON_START: return "Start";
76-
case NK_GAMEPAD_BUTTON_UP: return "Up";
77-
case NK_GAMEPAD_BUTTON_DOWN: return "Down";
78-
case NK_GAMEPAD_BUTTON_LEFT: return "Left";
79-
case NK_GAMEPAD_BUTTON_RIGHT: return "Right";
80-
default: return "Unknown";
81-
}
82-
}
83-
8458
NK_API struct nk_rect nk_console_input_render(nk_console* console) {
8559
if (console == NULL || console->data == NULL) {
8660
return nk_rect(0, 0, 0, 0);
@@ -139,7 +113,10 @@ NK_API struct nk_rect nk_console_input_render(nk_console* console) {
139113
const char* swap_label = console->label;
140114
int swap_label_length = console->label_length;
141115
console->columns = 0;
142-
console->label = nk_console_input_button_name(*data->out_gamepad_button);
116+
console->label = (*data->out_gamepad_button < 0) ? "<None>" : nk_gamepad_button_name(nk_console_get_gamepads(console), *data->out_gamepad_button);
117+
if (console->label == NULL) {
118+
console->label = "Unknown";
119+
}
143120
console->label_length = 0;
144121
struct nk_rect widget_bounds = nk_console_button_render(console);
145122
console->columns = swap_columns;

test/nuklear_console_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define NK_INCLUDE_STANDARD_VARARGS
1313
#define NK_INCLUDE_DEFAULT_ALLOCATOR
1414
#define PNTR_NUKLEAR_IMPLEMENTATION
15+
#define NK_BUTTON_TRIGGER_ON_RELEASE
1516
#include "pntr_nuklear.h"
1617

1718
#define NK_GAMEPAD_NONE

0 commit comments

Comments
 (0)