Skip to content

Commit 0608d32

Browse files
committed
TweakS
1 parent 5ada134 commit 0608d32

6 files changed

Lines changed: 40 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void nk_console_set_active_widget(nk_console* widget);
9797
9898
| Define | Description |
9999
| ------ | ----------- |
100+
| `NK_BUTTON_TRIGGER_ON_RELEASE` | When enabled, will allow touch drag scrolling controls
100101
| `NK_CONSOLE_DRAG_THRESHOLD` | When using touch and drag to scroll, the amount of threshold movement needed to consider it a scroll |
101102
| `NK_CONSOLE_AXIS_DEADZONE` | The amount of movement the axis needs prior to moving the cursor |
102103
| `NK_CONSOLE_AXIS_REPEAT_INTERVAL` | When using the gamepad axis to move, how frequently the cursor will move |

demo/sdl3_renderer/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ SDL_AppResult SDL_AppIterate(void *appstate) {
177177
SDL_RenderClear(app->renderer);
178178

179179
nk_sdl_render(ctx, NK_ANTI_ALIASING_ON);
180+
181+
// The SDL Renderer allows handling SDL_StartTextInput()
180182
nk_console_sdl_update_text_input(app->console, app->window);
181183

182184
SDL_RenderPresent(app->renderer);

demo/sdl_renderer/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ int main(int argc, char *argv[]) {
138138
SDL_RenderClear(renderer);
139139

140140
nk_sdl_render(NK_ANTI_ALIASING_ON);
141+
142+
// The SDL Renderer allows handling SDL_StartTextInput()
141143
nk_console_sdl_update_text_input(console, win);
142144

143145
SDL_RenderPresent(renderer);

nuklear_console.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,11 @@ NK_API nk_bool nk_console_navigate_to_path(nk_console* console, const char* path
316316
/**
317317
* Define NK_BUTTON_TRIGGER_ON_RELEASE prior to nuklear.h.
318318
*
319-
* This is required because the input events are triggered incorrectly otherwise.
319+
* This is required because the input events are triggered incorrectly otherwise, resulting in undesirable behavior.
320320
*
321321
* @code
322-
* #define NK_IMPLEMENTATION
323322
* #define NK_BUTTON_TRIGGER_ON_RELEASE
323+
* #define NK_IMPLEMENTATION
324324
* #include "nuklear.h"
325325
*
326326
* #define NK_CONSOLE_IMPLEMENTATION
@@ -330,7 +330,7 @@ NK_API nk_bool nk_console_navigate_to_path(nk_console* console, const char* path
330330
* You are able to ignore this warning by using #define NK_CONSOLE_IGNORE_BUTTON_TRIGGER_ON_RELEASE
331331
*/
332332
#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" .
333+
#warning "nuklear_console requires NK_BUTTON_TRIGGER_ON_RELEASE. Add #define NK_BUTTON_TRIGGER_ON_RELEASE prior to #define NK_IMPLEMENTATION ."
334334
#endif
335335
#endif
336336

@@ -994,6 +994,15 @@ NK_API void nk_console_render(nk_console* console) {
994994
cvector_clear(console->events);
995995
}
996996
}
997+
998+
// Update drag scroll bounds so they're valid when nk_console_render is called directly (e.g. SDL/GLFW demos) rather than via nk_console_render_window.
999+
if (console->ctx->current != NULL) {
1000+
struct nk_rect content = nk_window_get_content_region(console->ctx);
1001+
float rendered_h = console->ctx->current->layout->at_y - console->ctx->current->layout->bounds.y + console->ctx->current->layout->row.height;
1002+
data->drag_scroll_max_y = (nk_uint)NK_MAX(0.0f, rendered_h - content.h);
1003+
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);
1004+
}
1005+
9971006
return;
9981007
}
9991008

nuklear_console_input.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ NK_API struct nk_rect nk_console_input_render(nk_console* console) {
126126
return widget_bounds;
127127
}
128128

129+
/**
130+
* Go back as a post-render hook so that it handles the events safely afterwards.
131+
*/
132+
static void nk_console_input_back_post_render(nk_console* console, void* user_data) {
133+
NK_UNUSED(user_data);
134+
nk_console_button_back(console, NULL);
135+
}
136+
129137
/**
130138
* Render the "Press a Button" prompt.
131139
*
@@ -200,7 +208,7 @@ static struct nk_rect nk_console_input_active_render(nk_console* console) {
200208
if (finished == nk_true) {
201209
top_data->input_processed = nk_true;
202210
data->timer = 0.0f;
203-
nk_console_button_back(console, NULL);
211+
nk_console_add_event(console, NK_CONSOLE_EVENT_POST_RENDER_ONCE, &nk_console_input_back_post_render);
204212
}
205213

206214
return nk_rect(0, 0, 0, 0);

nuklear_console_key.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ extern "C" {
3838
*/
3939
NK_API nk_console* nk_console_key(nk_console* parent, const char* label, nk_rune* out_key);
4040
NK_API struct nk_rect nk_console_key_render(nk_console* widget);
41+
42+
/**
43+
* Retrieves the name of the of the given Nuklear rune.
44+
*/
4145
NK_API const char* nk_console_key_name(nk_rune key);
4246

4347
#if defined(__cplusplus)
@@ -86,7 +90,7 @@ NK_API const char* nk_console_key_name(nk_rune key) {
8690
case NK_KEY_RIGHT: return "Right";
8791
case NK_KEY_TEXT_INSERT_MODE: return "Insert";
8892
case NK_KEY_TEXT_REPLACE_MODE: return "Replace";
89-
case NK_KEY_TEXT_RESET_MODE: return "Reset Mode";
93+
case NK_KEY_TEXT_RESET_MODE: return "Escape"; // Nuklear uses ESCAPE as Reset Mode
9094
case NK_KEY_TEXT_LINE_START: return "Home";
9195
case NK_KEY_TEXT_LINE_END: return "End";
9296
case NK_KEY_TEXT_START: return "Ctrl+Home";
@@ -155,6 +159,14 @@ NK_API struct nk_rect nk_console_key_render(nk_console* console) {
155159
return widget_bounds;
156160
}
157161

162+
/**
163+
* Go back as a post-render hook so that it handles the events safely afterwards.
164+
*/
165+
static void nk_console_key_back_post_render(nk_console* console, void* user_data) {
166+
NK_UNUSED(user_data);
167+
nk_console_button_back(console, NULL);
168+
}
169+
158170
/**
159171
* Render the "Press a Key" capture prompt.
160172
*/
@@ -248,7 +260,7 @@ static struct nk_rect nk_console_key_active_render(nk_console* console) {
248260
if (finished == nk_true) {
249261
top_data->input_processed = nk_true;
250262
data->timer = 0.0f;
251-
nk_console_button_back(console, NULL);
263+
nk_console_add_event(console, NK_CONSOLE_EVENT_POST_RENDER_ONCE, &nk_console_key_back_post_render);
252264
}
253265

254266
return nk_rect(0, 0, 0, 0);

0 commit comments

Comments
 (0)