2#include "nuklear_internal.h"
10nk_progress_behavior(nk_flags *state,
struct nk_input *in,
11 struct nk_rect r,
struct nk_rect cursor, nk_size max, nk_size value, nk_bool modifiable)
13 int left_mouse_down = 0;
14 int left_mouse_click_in_cursor = 0;
16 nk_widget_state_reset(state);
17 if (!in || !modifiable)
return value;
18 left_mouse_down = in && in->mouse.buttons[NK_BUTTON_LEFT].down;
19 left_mouse_click_in_cursor = in && nk_input_has_mouse_click_down_in_rect(in,
20 NK_BUTTON_LEFT, cursor, nk_true);
21 if (nk_input_is_mouse_hovering_rect(in, r))
24 if (in && left_mouse_down && left_mouse_click_in_cursor) {
25 if (left_mouse_down && left_mouse_click_in_cursor) {
26 float ratio = NK_MAX(0, (
float)(in->mouse.pos.x - cursor.x)) / (float)cursor.w;
27 value = (nk_size)NK_CLAMP(0, (
float)max * ratio, (float)max);
28 in->mouse.buttons[NK_BUTTON_LEFT].clicked_pos.x = cursor.x + cursor.w/2.0f;
35 else if (nk_input_is_mouse_prev_hovering_rect(in, r))
42 const struct nk_rect *scursor, nk_size value, nk_size max)
52 background = &style->active;
53 cursor = &style->cursor_active;
55 background = &style->hover;
56 cursor = &style->cursor_hover;
58 background = &style->normal;
59 cursor = &style->cursor_normal;
63 switch(background->type) {
64 case NK_STYLE_ITEM_IMAGE:
65 nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor));
67 case NK_STYLE_ITEM_NINE_SLICE:
68 nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor));
70 case NK_STYLE_ITEM_COLOR:
71 nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor));
72 nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor));
77 switch(cursor->type) {
78 case NK_STYLE_ITEM_IMAGE:
79 nk_draw_image(out, *scursor, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor));
81 case NK_STYLE_ITEM_NINE_SLICE:
82 nk_draw_nine_slice(out, *scursor, &cursor->data.slice, nk_rgb_factor(nk_white, style->color_factor));
84 case NK_STYLE_ITEM_COLOR:
85 nk_fill_rect(out, *scursor, style->rounding, nk_rgb_factor(cursor->data.color, style->color_factor));
86 nk_stroke_rect(out, *scursor, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor));
91nk_do_progress(nk_flags *state,
93 nk_size value, nk_size max, nk_bool modifiable,
102 if (!out || !style)
return 0;
105 cursor.w = NK_MAX(bounds.w, 2 * style->padding.x + 2 * style->border);
106 cursor.h = NK_MAX(bounds.h, 2 * style->padding.y + 2 * style->border);
107 cursor = nk_pad_rect(bounds,
nk_vec2(style->padding.x + style->border, style->padding.y + style->border));
108 prog_scale = (float)value / (
float)max;
111 prog_value = NK_MIN(value, max);
112 prog_value = nk_progress_behavior(state, in, bounds, cursor,max, prog_value, modifiable);
113 cursor.w = cursor.w * prog_scale;
116 if (style->draw_begin) style->draw_begin(out, style->userdata);
117 nk_draw_progress(out, *state, style, &bounds, &cursor, value, max);
118 if (style->draw_end) style->draw_end(out, style->userdata);
122nk_progress(
struct nk_context *ctx, nk_size *cur, nk_size max, nk_bool is_modifyable)
135 NK_ASSERT(ctx->current);
136 NK_ASSERT(ctx->current->layout);
137 if (!ctx || !ctx->current || !ctx->current->layout || !cur)
142 layout = win->layout;
143 state = nk_widget(&bounds, ctx);
144 if (!state)
return 0;
148 *cur = nk_do_progress(&ctx->last_widget_state, &win->buffer, bounds,
149 *cur, max, is_modifyable, &style->progress, in);
150 return (*cur != old_value);
153nk_prog(
struct nk_context *ctx, nk_size cur, nk_size max, nk_bool modifyable)
155 nk_progress(ctx, &cur, max, modifyable);
main API and documentation file
@ NK_WINDOW_ROM
sets window widgets into a read only mode and does not allow input changes
NK_API void nk_draw_image(struct nk_command_buffer *, struct nk_rect, const struct nk_image *, struct nk_color)
misc
NK_API void nk_fill_rect(struct nk_command_buffer *, struct nk_rect, float rounding, struct nk_color)
filled shades
@ NK_WIDGET_STATE_LEFT
!< widget is currently activated
@ NK_WIDGET_STATE_ACTIVED
!< widget is being hovered
@ NK_WIDGET_STATE_ENTERED
!< widget is neither active nor hovered
@ NK_WIDGET_STATE_HOVER
!< widget has been hovered on the current frame
@ NK_WIDGET_STATE_ACTIVE
!< widget is being hovered
@ NK_WIDGET_STATE_HOVERED
!< widget is from this frame on not hovered anymore
@ NK_WIDGET_DISABLED
The widget is manually disabled and acts like NK_WIDGET_ROM.
@ NK_WIDGET_ROM
The widget is partially visible and cannot be updated.