Removed keyboard callbacks because they are unnecessary

This commit is contained in:
seibelj 2017-01-06 13:50:31 -05:00
parent bc6c9c7093
commit e6798bc1b4

191
nuklear.h
View File

@ -1,5 +1,5 @@
/*
Nuklear - v1.18 - public domain
Nuklear - v1.20 - public domain
no warrenty implied; use at your own risk.
authored from 2015-2016 by Micha Mettke
@ -127,14 +127,6 @@ OPTIONAL DEFINES:
Can be combined with the style structures.
<!> If used needs to be defined for implementation and header <!>
NK_INCLUDE_DYNAMIC_SOFT_KEYBOARD
Defining this means that when a textedit field is begun editing,
nuklear will look for ctx->open_keyboard() and ctx->close_keyboard()
functions to call. Set these functions during nk_context initialization
in your backend. This is "DYNAMIC" because a PC soft keyboard is always open,
but a mobile device will show and hide the soft keyboard dynamically
as needed.
NK_BUTTON_TRIGGER_ON_RELEASE
Different platforms require button clicks occuring either on buttons being
pressed (up to down) or released (down to up).
@ -464,7 +456,7 @@ typedef char nk_glyph[NK_UTF_SIZE];
typedef union {void *ptr; int id;} nk_handle;
struct nk_image {nk_handle handle;unsigned short w,h;unsigned short region[4];};
struct nk_cursor {struct nk_image img; struct nk_vec2 size, offset;};
struct nk_scroll {unsigned short x, y;};
struct nk_scroll {nk_uint x, y;};
enum nk_heading {NK_UP, NK_RIGHT, NK_DOWN, NK_LEFT};
enum nk_button_behavior {NK_BUTTON_DEFAULT, NK_BUTTON_REPEATER};
@ -485,8 +477,6 @@ typedef void (*nk_plugin_free)(nk_handle, void *old);
typedef int(*nk_plugin_filter)(const struct nk_text_edit*, nk_rune unicode);
typedef void(*nk_plugin_paste)(nk_handle, struct nk_text_edit*);
typedef void(*nk_plugin_copy)(nk_handle, const char*, int len);
typedef void(*nk_plugin_open_keyboard)(void);
typedef void(*nk_plugin_close_keyboard)(void);
struct nk_allocator {
nk_handle userdata;
@ -517,8 +507,8 @@ struct nk_list_view {
/* private: */
int total_height;
struct nk_context *ctx;
nk_ushort *scroll_pointer;
nk_ushort scroll_value;
nk_uint *scroll_pointer;
nk_uint scroll_value;
};
enum nk_symbol_type {
@ -774,10 +764,10 @@ NK_API float nk_layout_ratio_from_pixel(struct nk_context*, f
/* Layout: Group */
NK_API int nk_group_begin(struct nk_context*, const char *title, nk_flags);
NK_API void nk_group_end(struct nk_context*);
NK_API int nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char*, nk_flags);
NK_API int nk_group_scrolled_begin(struct nk_context*, struct nk_scroll*, const char *title, nk_flags);
NK_API void nk_group_scrolled_end(struct nk_context*);
NK_API void nk_group_end(struct nk_context*);
NK_API int nk_list_view_begin(struct nk_context*, struct nk_list_view *out, const char *id, nk_flags, int row_height, int row_count);
NK_API void nk_list_view_end(struct nk_list_view*);
@ -2688,7 +2678,8 @@ struct nk_panel {
enum nk_panel_type type;
nk_flags flags;
struct nk_rect bounds;
struct nk_scroll *offset;
nk_uint *offset_x;
nk_uint *offset_y;
float at_x, at_y, max_x;
float footer_height;
float header_height;
@ -2942,10 +2933,6 @@ struct nk_context {
#endif
#ifdef NK_INCLUDE_COMMAND_USERDATA
nk_handle userdata;
#endif
#ifdef NK_INCLUDE_DYNAMIC_SOFT_KEYBOARD
nk_plugin_open_keyboard open_keyboard;
nk_plugin_close_keyboard close_keyboard;
#endif
/* text editor objects are quite big because of an internal
* undo/redo stack. Therefore it does not make sense to have one for
@ -14140,8 +14127,7 @@ nk_edit_draw_text(struct nk_command_buffer *out,
}
NK_INTERN nk_flags
nk_do_edit(struct nk_context *ctx,
nk_flags *state, struct nk_command_buffer *out,
nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
struct nk_rect bounds, nk_flags flags, nk_plugin_filter filter,
struct nk_text_edit *edit, const struct nk_style_edit *style,
struct nk_input *in, const struct nk_user_font *font)
@ -14196,23 +14182,13 @@ nk_do_edit(struct nk_context *ctx,
edit->cursor = edit->string.len;
in = 0;
}
#ifdef NK_INCLUDE_DYNAMIC_SOFT_KEYBOARD
if (ctx->open_keyboard)
ctx->open_keyboard();
#endif
} else if (!edit->active) edit->mode = NK_TEXT_EDIT_MODE_VIEW;
if (flags & NK_EDIT_READ_ONLY)
edit->mode = NK_TEXT_EDIT_MODE_VIEW;
ret = (edit->active) ? NK_EDIT_ACTIVE: NK_EDIT_INACTIVE;
if (prev_state != edit->active)
{
ret |= (edit->active) ? NK_EDIT_ACTIVATED: NK_EDIT_DEACTIVATED;
#ifdef NK_INCLUDE_DYNAMIC_SOFT_KEYBOARD
if (!edit->active)
ctx->close_keyboard();
#endif
}
/* handle user input */
if (edit->active && in)
@ -14778,7 +14754,7 @@ nk_draw_property(struct nk_command_buffer *out, const struct nk_style_property *
}
NK_INTERN void
nk_do_property(struct nk_context *ctx, nk_flags *ws,
nk_do_property(nk_flags *ws,
struct nk_command_buffer *out, struct nk_rect property,
const char *name, struct nk_property_variant *variant,
float inc_per_pixel, char *buffer, int *len,
@ -14918,7 +14894,7 @@ nk_do_property(struct nk_context *ctx, nk_flags *ws,
text_edit->string.buffer.memory.ptr = dst;
text_edit->string.buffer.size = NK_MAX_NUMBER_BUFFER;
text_edit->mode = NK_TEXT_EDIT_MODE_INSERT;
nk_do_edit(ctx, ws, out, edit, NK_EDIT_ALWAYS_INSERT_MODE, filters[filter],
nk_do_edit(ws, out, edit, NK_EDIT_ALWAYS_INSERT_MODE, filters[filter],
text_edit, &style->edit, (*state == NK_PROPERTY_EDIT) ? in: 0, font);
*length = text_edit->string.len;
@ -16088,7 +16064,7 @@ nk_clear(struct nk_context *ctx)
while (iter) {
/* make sure minimized windows do not get removed */
if ((iter->flags & NK_WINDOW_MINIMIZED) &&
!(iter)->flags & NK_WINDOW_CLOSED) {
!(iter->flags & NK_WINDOW_CLOSED)) {
iter = iter->next;
continue;
}
@ -16674,12 +16650,12 @@ nk_panel_end(struct nk_context *ctx)
empty_space.y = layout->bounds.y;
empty_space.w = panel_padding.x + layout->border;
empty_space.h = layout->bounds.h;
if (layout->offset->y == 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR))
if (*layout->offset_y == 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR))
empty_space.w += scrollbar_size.x;
nk_fill_rect(out, empty_space, 0, style->window.background);
/* fill bottom empty space */
if (layout->offset->x != 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR)) {
if (*layout->offset_x != 0 && !(layout->flags & NK_WINDOW_NO_SCROLLBAR)) {
empty_space.x = window->bounds.x;
empty_space.y = layout->bounds.y + layout->bounds.h;
empty_space.w = window->bounds.w;
@ -16707,7 +16683,7 @@ nk_panel_end(struct nk_context *ctx)
scroll.w = scrollbar_size.x;
scroll.h = layout->bounds.h;
scroll_offset = layout->offset->y;
scroll_offset = *layout->offset_y;
scroll_step = scroll.h * 0.10f;
scroll_inc = scroll.h * 0.01f;
scroll_target = (float)(int)(layout->at_y - scroll.y);
@ -16753,7 +16729,7 @@ nk_panel_end(struct nk_context *ctx)
scroll_offset = nk_do_scrollbarv(&state, out, scroll, scroll_has_scrolling,
scroll_offset, scroll_target, scroll_step, scroll_inc,
&ctx->style.scrollv, in, style->font);
layout->offset->y = (unsigned short)scroll_offset;
*layout->offset_y = (nk_uint)scroll_offset;
if (in && scroll_has_scrolling)
in->mouse.scroll_delta = 0;
}
@ -16765,7 +16741,7 @@ nk_panel_end(struct nk_context *ctx)
scroll.w = layout->bounds.w;
scroll.h = scrollbar_size.y;
scroll_offset = layout->offset->x;
scroll_offset = *layout->offset_x;
scroll_target = (float)(int)(layout->max_x - scroll.x);
scroll_step = layout->max_x * 0.05f;
scroll_inc = layout->max_x * 0.005f;
@ -16773,7 +16749,7 @@ nk_panel_end(struct nk_context *ctx)
scroll_offset = nk_do_scrollbarh(&state, out, scroll, scroll_has_scrolling,
scroll_offset, scroll_target, scroll_step, scroll_inc,
&ctx->style.scrollh, in, style->font);
layout->offset->x = (unsigned short)scroll_offset;
*layout->offset_x = (nk_uint)scroll_offset;
}
}
@ -17369,7 +17345,8 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title,
win->layout = (struct nk_panel*)nk_create_panel(ctx);
ctx->current = win;
ret = nk_panel_begin(ctx, title, NK_PANEL_WINDOW);
win->layout->offset = &win->scrollbar;
win->layout->offset_x = &win->scrollbar.x;
win->layout->offset_y = &win->scrollbar.y;
return ret;
}
@ -17774,8 +17751,9 @@ nk_menubar_begin(struct nk_context *ctx)
layout->menu.x = layout->at_x;
layout->menu.y = layout->at_y + layout->row.height;
layout->menu.w = layout->bounds.w;
layout->menu.offset = *layout->offset;
layout->offset->y = 0;
layout->menu.offset.x = *layout->offset_x;
layout->menu.offset.y = *layout->offset_y;
*layout->offset_y = 0;
}
NK_API void
@ -17801,7 +17779,8 @@ nk_menubar_end(struct nk_context *ctx)
layout->bounds.y += layout->menu.h + ctx->style.window.spacing.y + layout->row.height;
layout->bounds.h -= layout->menu.h + ctx->style.window.spacing.y + layout->row.height;
*layout->offset = layout->menu.offset;
*layout->offset_x = layout->menu.offset.x;
*layout->offset_y = layout->menu.offset.y;
layout->at_y = layout->bounds.y - layout->row.height;
layout->clip.y = layout->bounds.y;
@ -18122,8 +18101,8 @@ nk_layout_space_to_screen(struct nk_context *ctx, struct nk_vec2 ret)
win = ctx->current;
layout = win->layout;
ret.x += layout->at_x - layout->offset->x;
ret.y += layout->at_y - layout->offset->y;
ret.x += layout->at_x - *layout->offset_x;
ret.y += layout->at_y - *layout->offset_y;
return ret;
}
@ -18139,8 +18118,8 @@ nk_layout_space_to_local(struct nk_context *ctx, struct nk_vec2 ret)
win = ctx->current;
layout = win->layout;
ret.x += -layout->at_x + layout->offset->x;
ret.y += -layout->at_y + layout->offset->y;
ret.x += -layout->at_x + *layout->offset_x;
ret.y += -layout->at_y + *layout->offset_y;
return ret;
}
@ -18156,8 +18135,8 @@ nk_layout_space_rect_to_screen(struct nk_context *ctx, struct nk_rect ret)
win = ctx->current;
layout = win->layout;
ret.x += layout->at_x - layout->offset->x;
ret.y += layout->at_y - layout->offset->y;
ret.x += layout->at_x - *layout->offset_x;
ret.y += layout->at_y - *layout->offset_y;
return ret;
}
@ -18173,8 +18152,8 @@ nk_layout_space_rect_to_local(struct nk_context *ctx, struct nk_rect ret)
win = ctx->current;
layout = win->layout;
ret.x += -layout->at_x + layout->offset->x;
ret.y += -layout->at_y + layout->offset->y;
ret.x += -layout->at_x + *layout->offset_x;
ret.y += -layout->at_y + *layout->offset_y;
return ret;
}
@ -18248,9 +18227,9 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
case NK_LAYOUT_DYNAMIC_FREE: {
/* panel width depended free widget placing */
bounds->x = layout->at_x + (layout->bounds.w * layout->row.item.x);
bounds->x -= layout->offset->x;
bounds->x -= *layout->offset_x;
bounds->y = layout->at_y + (layout->row.height * layout->row.item.y);
bounds->y -= layout->offset->y;
bounds->y -= *layout->offset_y;
bounds->w = layout->bounds.w * layout->row.item.w;
bounds->h = layout->row.height * layout->row.item.h;
return;
@ -18290,9 +18269,9 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
bounds->w = layout->row.item.w;
if (((bounds->x + bounds->w) > layout->max_x) && modify)
layout->max_x = (bounds->x + bounds->w);
bounds->x -= layout->offset->x;
bounds->x -= *layout->offset_x;
bounds->y = layout->at_y + layout->row.item.y;
bounds->y -= layout->offset->y;
bounds->y -= *layout->offset_y;
bounds->h = layout->row.item.h;
return;
};
@ -18309,11 +18288,11 @@ nk_layout_widget_space(struct nk_rect *bounds, const struct nk_context *ctx,
/* set the bounds of the newly allocated widget */
bounds->w = item_width;
bounds->h = layout->row.height - spacing.y;
bounds->y = layout->at_y - layout->offset->y;
bounds->y = layout->at_y - *layout->offset_y;
bounds->x = layout->at_x + item_offset + item_spacing + padding.x;
if (((bounds->x + bounds->w) > layout->max_x) && modify)
layout->max_x = bounds->x + bounds->w;
bounds->x -= layout->offset->x;
bounds->x -= *layout->offset_x;
}
NK_INTERN void
@ -18462,7 +18441,7 @@ nk_tree_state_base(struct nk_context *ctx, enum nk_tree_type type,
/* increase x-axis cursor widget position pointer */
if (*state == NK_MAXIMIZED) {
layout->at_x = header.x + layout->offset->x + style->tab.indent;
layout->at_x = header.x + *layout->offset_x + style->tab.indent;
layout->bounds.w = NK_MAX(layout->bounds.w, style->tab.indent);
layout->bounds.w -= (style->tab.indent + style->window.padding.x);
layout->row.tree_depth++;
@ -19726,7 +19705,7 @@ nk_edit_buffer(struct nk_context *ctx, nk_flags flags,
filter = (!filter) ? nk_filter_default: filter;
prev_state = (unsigned char)edit->active;
in = (flags & NK_EDIT_READ_ONLY) ? 0: in;
ret_flags = nk_do_edit(ctx, &ctx->last_widget_state, &win->buffer, bounds, flags,
ret_flags = nk_do_edit(&ctx->last_widget_state, &win->buffer, bounds, flags,
filter, edit, &style->edit, in, style->font);
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
@ -19853,7 +19832,7 @@ nk_property(struct nk_context *ctx, const char *name, struct nk_property_variant
/* execute property widget */
old_state = *state;
nk_do_property(ctx, &ctx->last_widget_state, &win->buffer, bounds, name,
nk_do_property(&ctx->last_widget_state, &win->buffer, bounds, name,
variant, inc_per_pixel, buffer, len, state, cursor,
&style->property, filter, in, style->font, &ctx->text_edit);
@ -20333,8 +20312,8 @@ nk_plot_function(struct nk_context *ctx, enum nk_chart_type type, void *userdata
*
* --------------------------------------------------------------*/
NK_API int
nk_group_scrolled_begin(struct nk_context *ctx,
struct nk_scroll *scroll, const char *title, nk_flags flags)
nk_group_scrolled_offset_begin(struct nk_context *ctx,
nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags)
{
struct nk_rect bounds;
struct nk_window panel;
@ -20355,8 +20334,8 @@ nk_group_scrolled_begin(struct nk_context *ctx,
nk_zero(&panel, sizeof(panel));
panel.bounds = bounds;
panel.flags = flags;
panel.scrollbar.x = scroll->x;
panel.scrollbar.y = scroll->y;
panel.scrollbar.x = *x_offset;
panel.scrollbar.y = *y_offset;
panel.buffer = win->buffer;
panel.layout = (struct nk_panel*)nk_create_panel(ctx);
ctx->current = &panel;
@ -20364,7 +20343,8 @@ nk_group_scrolled_begin(struct nk_context *ctx,
win->buffer = panel.buffer;
win->buffer.clip = panel.layout->clip;
panel.layout->offset = scroll;
panel.layout->offset_x = x_offset;
panel.layout->offset_y = y_offset;
panel.layout->parent = win->layout;
win->layout = panel.layout;
ctx->current = win;
@ -20413,8 +20393,8 @@ nk_group_scrolled_end(struct nk_context *ctx)
pan.bounds.w += ctx->style.window.scrollbar_size.x;
pan.bounds.h += ctx->style.window.scrollbar_size.y;
}
pan.scrollbar.x = (unsigned short)g->offset->x;
pan.scrollbar.y = (unsigned short)g->offset->y;
pan.scrollbar.x = *g->offset_x;
pan.scrollbar.y = *g->offset_y;
pan.flags = g->flags;
pan.buffer = win->buffer;
pan.layout = g;
@ -20435,13 +20415,19 @@ nk_group_scrolled_end(struct nk_context *ctx)
return;
}
NK_API int
nk_group_scrolled_begin(struct nk_context *ctx,
struct nk_scroll *scroll, const char *title, nk_flags flags)
{return nk_group_scrolled_offset_begin(ctx, &scroll->x, &scroll->y, title, flags);}
NK_API int
nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags)
{
int title_len;
nk_hash title_hash;
union {struct nk_scroll *s; nk_uint *i;} value;
struct nk_window *win;
nk_uint *x_offset;
nk_uint *y_offset;
NK_ASSERT(ctx);
NK_ASSERT(title);
@ -20454,21 +20440,22 @@ nk_group_begin(struct nk_context *ctx, const char *title, nk_flags flags)
win = ctx->current;
title_len = (int)nk_strlen(title);
title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_GROUP);
value.i = nk_find_value(win, title_hash);
if (!value.i) {
value.i = nk_add_value(ctx, win, title_hash, 0);
NK_ASSERT(value.i);
if (!value.i) return 0;
*value.i = 0;
}
return nk_group_scrolled_begin(ctx, value.s, title, flags);
x_offset = nk_find_value(win, title_hash);
if (!x_offset) {
x_offset = nk_add_value(ctx, win, title_hash, 0);
y_offset = nk_add_value(ctx, win, title_hash+1, 0);
NK_ASSERT(x_offset);
NK_ASSERT(y_offset);
if (!x_offset || !y_offset) return 0;
*x_offset = *y_offset = 0;
} else y_offset = nk_find_value(win, title_hash+1);
return nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags);
}
NK_API void
nk_group_end(struct nk_context *ctx)
{
nk_group_scrolled_end(ctx);
}
{nk_group_scrolled_end(ctx);}
NK_API int
nk_list_view_begin(struct nk_context *ctx, struct nk_list_view *view,
@ -20476,7 +20463,8 @@ nk_list_view_begin(struct nk_context *ctx, struct nk_list_view *view,
{
int title_len;
nk_hash title_hash;
union {struct nk_scroll *s; nk_uint *i;} value;
nk_uint *x_offset;
nk_uint *y_offset;
int result;
struct nk_window *win;
@ -20494,21 +20482,24 @@ nk_list_view_begin(struct nk_context *ctx, struct nk_list_view *view,
item_spacing = style->window.spacing;
row_height += NK_MAX(0, (int)item_spacing.y);
/* find persistent group scrollbar offset */
/* find persistent list view scrollbar offset */
title_len = (int)nk_strlen(title);
title_hash = nk_murmur_hash(title, (int)title_len, NK_PANEL_GROUP);
value.i = nk_find_value(win, title_hash);
if (!value.i) {
value.i = nk_add_value(ctx, win, title_hash, 0);
NK_ASSERT(value.i);
if (!value.i) return 0;
*value.i = 0;
}
view->scroll_value = value.s->y;
view->scroll_pointer = &value.s->y;
x_offset = nk_find_value(win, title_hash);
if (!x_offset) {
x_offset = nk_add_value(ctx, win, title_hash, 0);
y_offset = nk_add_value(ctx, win, title_hash+1, 0);
value.s->y = 0;
result = nk_group_scrolled_begin(ctx, value.s, title, flags);
NK_ASSERT(x_offset);
NK_ASSERT(y_offset);
if (!x_offset || !y_offset) return 0;
*x_offset = *y_offset = 0;
} else y_offset = nk_find_value(win, title_hash+1);
view->scroll_value = *y_offset;
view->scroll_pointer = y_offset;
*y_offset = 0;
result = nk_group_scrolled_offset_begin(ctx, x_offset, y_offset, title, flags);
win = ctx->current;
layout = win->layout;
@ -20536,7 +20527,7 @@ nk_list_view_end(struct nk_list_view *view)
win = ctx->current;
layout = win->layout;
layout->at_y = layout->bounds.y + (float)view->total_height;
*view->scroll_pointer = (nk_ushort)(*view->scroll_pointer + view->scroll_value);
*view->scroll_pointer = *view->scroll_pointer + view->scroll_value;
nk_group_end(view->ctx);
}
@ -20619,7 +20610,8 @@ nk_popup_begin(struct nk_context *ctx, enum nk_popup_type type,
root = root->parent;
}
win->popup.active = 1;
popup->layout->offset = &popup->scrollbar;
popup->layout->offset_x = &popup->scrollbar.x;
popup->layout->offset_y = &popup->scrollbar.y;
popup->layout->parent = win->layout;
return 1;
} else {
@ -20708,7 +20700,8 @@ nk_nonblock_begin(struct nk_context *ctx,
nk_panel_begin(ctx, 0, panel_type);
win->buffer = popup->buffer;
popup->layout->parent = win->layout;
popup->layout->offset = &popup->scrollbar;
popup->layout->offset_x = &popup->scrollbar.x;
popup->layout->offset_y = &popup->scrollbar.y;
/* set read only mode to all parent panels */
{struct nk_panel *root;
@ -22017,4 +22010,4 @@ NK_API void
nk_menu_end(struct nk_context *ctx)
{nk_contextual_end(ctx);}
#endif
#endif