Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/glfw_opengl3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
BIN = demo

# Flags
CFLAGS += -std=c89 -Wall -Wextra -pedantic
CFLAGS += -g -std=c89 -Wall -Wextra -pedantic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with this being here 🤷 you can remove if you want but meh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it. Honestly I'm always adding it to whatever demo I'm using to test my changes. It's already in 2 of the Makefiles (probably from me), and it doesn't really make sense not having it for non-release/production development demos anyway.


SRC = main.c
OBJ = $(SRC:.c=.o)
Expand Down
2 changes: 2 additions & 0 deletions demo/glfw_opengl3/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <assert.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <ctype.h>


#include <GL/glew.h>
#include <GLFW/glfw3.h>
Expand All @@ -21,6 +22,7 @@
#define NK_INCLUDE_DEFAULT_FONT
#define NK_IMPLEMENTATION
#define NK_GLFW_GL3_IMPLEMENTATION
/*#define NK_IS_WORD_BOUNDARY(c) (!isalnum(c))*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/*#define NK_IS_WORD_BOUNDARY(c) (!isalnum(c))*/

#include "../../nuklear.h"
#include "nuklear_glfw_gl3.h"

Expand Down
57 changes: 37 additions & 20 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occu
NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame.
NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit
NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for each frame rather than key press/release events
NK_IS_WORD_BOUNDARY(c) | Define this to a function macro that takes a single nk_rune (nk_uint) and returns true if it's a word separator. If not defined, uses the default definition (see nk_is_word_boundary())

!!! WARNING
The following flags will pull in the standard C library:
Expand Down Expand Up @@ -27054,34 +27055,44 @@ nk_is_word_boundary( struct nk_text_edit *state, int idx)
{
int len;
nk_rune c;
if (idx <= 0) return 1;
if (idx < 0) return 1;
if (!nk_str_at_rune(&state->string, idx, &c, &len)) return 1;
return (c == ' ' || c == '\t' ||c == 0x3000 || c == ',' || c == ';' ||
c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']' ||
c == '|');
#ifndef NK_IS_WORD_BOUNDARY
return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' ||
c == '\v' || c == 0x3000);
#else
return NK_IS_WORD_BOUNDARY(c);
#endif
}
NK_INTERN int
nk_textedit_move_to_word_previous(struct nk_text_edit *state)
{
int c = state->cursor - 1;
while( c >= 0 && !nk_is_word_boundary(state, c))
--c;

if( c < 0 )
c = 0;
if (c > 0) {
if (nk_is_word_boundary(state, c)) {
while (c >= 0 && nk_is_word_boundary(state, --c));
}
while (!nk_is_word_boundary(state, --c));
c++;
} else {
return 0;
}

return c;
}
NK_INTERN int
nk_textedit_move_to_word_next(struct nk_text_edit *state)
{
const int len = state->string.len;
int c = state->cursor+1;
while( c < len && !nk_is_word_boundary(state, c))
++c;

if( c > len )
c = len;
int c = state->cursor;
if (c < len) {
if (!nk_is_word_boundary(state, c)) {
while (c < len && !nk_is_word_boundary(state, ++c));
}
while (c < len && nk_is_word_boundary(state, ++c));
} else {
return len;
}

return c;
}
Expand Down Expand Up @@ -27266,7 +27277,7 @@ nk_textedit_key(struct nk_text_edit *state, enum nk_keys key, int shift_mod,
case NK_KEY_TEXT_WORD_LEFT:
if (shift_mod) {
if( !NK_TEXT_HAS_SELECTION( state ) )
nk_textedit_prep_selection_at_cursor(state);
nk_textedit_prep_selection_at_cursor(state);
state->cursor = nk_textedit_move_to_word_previous(state);
state->select_end = state->cursor;
nk_textedit_clamp(state );
Expand Down Expand Up @@ -28287,10 +28298,12 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
} else edit->scrollbar.x = 0;

if (flags & NK_EDIT_MULTILINE) {
/* vertical scroll */
/* vertical scroll: like horizontal, it only adjusts if the
* cursor leaves the visible area, and then only just enough
* to keep it visible */
if (cursor_pos.y < edit->scrollbar.y)
edit->scrollbar.y = NK_MAX(0.0f, cursor_pos.y - row_height);
if (cursor_pos.y >= edit->scrollbar.y + row_height)
edit->scrollbar.y = NK_MAX(0.0f, cursor_pos.y);
if (cursor_pos.y > edit->scrollbar.y + area.h - row_height)
edit->scrollbar.y = edit->scrollbar.y + row_height;
} else edit->scrollbar.y = 0;
}
Expand All @@ -28313,9 +28326,13 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
scroll_step = scroll.h * 0.10f;
scroll_inc = scroll.h * 0.01f;
scroll_target = text_size.y;
edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, 0,
edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, edit->active && in,
scroll_offset, scroll_target, scroll_step, scroll_inc,
&style->scrollbar, in, font);
/* Eat mouse scroll if we're active */
if (edit->active && in && in->mouse.scroll_delta.y) {
in->mouse.scroll_delta.y = 0;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/HEADER.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occu
NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame.
NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit
NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for each frame rather than key press/release events
NK_IS_WORD_BOUNDARY(c) | Define this to a function macro that takes a single nk_rune (nk_uint) and returns true if it's a word separator. If not defined, uses the default definition (see nk_is_word_boundary())

!!! WARNING
The following flags will pull in the standard C library:
Expand Down
14 changes: 10 additions & 4 deletions src/nuklear_edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,12 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
} else edit->scrollbar.x = 0;

if (flags & NK_EDIT_MULTILINE) {
/* vertical scroll */
/* vertical scroll: like horizontal, it only adjusts if the
* cursor leaves the visible area, and then only just enough
* to keep it visible */
if (cursor_pos.y < edit->scrollbar.y)
edit->scrollbar.y = NK_MAX(0.0f, cursor_pos.y - row_height);
if (cursor_pos.y >= edit->scrollbar.y + row_height)
edit->scrollbar.y = NK_MAX(0.0f, cursor_pos.y);
if (cursor_pos.y > edit->scrollbar.y + area.h - row_height)
edit->scrollbar.y = edit->scrollbar.y + row_height;
} else edit->scrollbar.y = 0;
}
Expand All @@ -506,9 +508,13 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
scroll_step = scroll.h * 0.10f;
scroll_inc = scroll.h * 0.01f;
scroll_target = text_size.y;
edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, 0,
edit->scrollbar.y = nk_do_scrollbarv(&ws, out, scroll, edit->active && in,
scroll_offset, scroll_target, scroll_step, scroll_inc,
&style->scrollbar, in, font);
/* Eat mouse scroll if we're active */
if (edit->active && in && in->mouse.scroll_delta.y) {
in->mouse.scroll_delta.y = 0;
}
}
}

Expand Down
42 changes: 26 additions & 16 deletions src/nuklear_text_editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,34 +277,44 @@ nk_is_word_boundary( struct nk_text_edit *state, int idx)
{
int len;
nk_rune c;
if (idx <= 0) return 1;
if (idx < 0) return 1;
if (!nk_str_at_rune(&state->string, idx, &c, &len)) return 1;
return (c == ' ' || c == '\t' ||c == 0x3000 || c == ',' || c == ';' ||
c == '(' || c == ')' || c == '{' || c == '}' || c == '[' || c == ']' ||
c == '|');
#ifndef NK_IS_WORD_BOUNDARY
return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' ||
c == '\v' || c == 0x3000);
#else
return NK_IS_WORD_BOUNDARY(c);
#endif
}
NK_INTERN int
nk_textedit_move_to_word_previous(struct nk_text_edit *state)
{
int c = state->cursor - 1;
while( c >= 0 && !nk_is_word_boundary(state, c))
--c;

if( c < 0 )
c = 0;
if (c > 0) {
if (nk_is_word_boundary(state, c)) {
while (c >= 0 && nk_is_word_boundary(state, --c));
}
while (!nk_is_word_boundary(state, --c));
c++;
} else {
return 0;
}

return c;
}
NK_INTERN int
nk_textedit_move_to_word_next(struct nk_text_edit *state)
{
const int len = state->string.len;
int c = state->cursor+1;
while( c < len && !nk_is_word_boundary(state, c))
++c;

if( c > len )
c = len;
int c = state->cursor;
if (c < len) {
if (!nk_is_word_boundary(state, c)) {
while (c < len && !nk_is_word_boundary(state, ++c));
}
while (c < len && nk_is_word_boundary(state, ++c));
} else {
return len;
}

return c;
}
Expand Down Expand Up @@ -489,7 +499,7 @@ nk_textedit_key(struct nk_text_edit *state, enum nk_keys key, int shift_mod,
case NK_KEY_TEXT_WORD_LEFT:
if (shift_mod) {
if( !NK_TEXT_HAS_SELECTION( state ) )
nk_textedit_prep_selection_at_cursor(state);
nk_textedit_prep_selection_at_cursor(state);
state->cursor = nk_textedit_move_to_word_previous(state);
state->select_end = state->cursor;
nk_textedit_clamp(state );
Expand Down