Skip to content

Commit

Permalink
Merge pull request #669 from PROP65/knob
Browse files Browse the repository at this point in the history
New Widget: Knobs
  • Loading branch information
RobLoach authored Aug 28, 2024
2 parents c3282bf + 1f0c22c commit b1c2227
Show file tree
Hide file tree
Showing 10 changed files with 799 additions and 9 deletions.
8 changes: 8 additions & 0 deletions demo/common/overview.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ overview(struct nk_context *ctx)
/* Basic widgets */
static int int_slider = 5;
static float float_slider = 2.5f;
static int int_knob = 5;
static float float_knob = 2.5f;
static nk_size prog_value = 40;
static float property_float = 2;
static int property_int = 10;
Expand Down Expand Up @@ -264,6 +266,12 @@ overview(struct nk_context *ctx)
nk_labelf(ctx, NK_TEXT_LEFT, "Progressbar: %u" , (int)prog_value);
nk_progress(ctx, &prog_value, 100, NK_MODIFIABLE);

nk_layout_row(ctx, NK_STATIC, 40, 2, ratio);
nk_labelf(ctx, NK_TEXT_LEFT, "Knob int: %d", int_knob);
nk_knob_int(ctx, 0, &int_knob, 10, 1, NK_DOWN, 60.0f);
nk_labelf(ctx, NK_TEXT_LEFT, "Knob float: %.2f", float_knob);
nk_knob_float(ctx, 0, &float_knob, 5.0, 0.5f, NK_DOWN, 60.0f);

nk_layout_row(ctx, NK_STATIC, 25, 2, ratio);
nk_label(ctx, "Property float:", NK_TEXT_LEFT);
nk_property_float(ctx, "Float:", 0, &property_float, 64.0f, 0.1f, 0.2f);
Expand Down
20 changes: 20 additions & 0 deletions demo/common/style.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ set_style(struct nk_context *ctx, enum theme theme)
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(150, 150, 150, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(160, 160, 160, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(180, 180, 180, 255);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_RED) {
table[NK_COLOR_TEXT] = nk_rgba(190, 190, 190, 255);
Expand Down Expand Up @@ -63,6 +67,10 @@ set_style(struct nk_context *ctx, enum theme theme)
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(181, 45, 69, 220);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_BLUE) {
table[NK_COLOR_TEXT] = nk_rgba(20, 20, 20, 255);
Expand Down Expand Up @@ -93,6 +101,10 @@ set_style(struct nk_context *ctx, enum theme theme)
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(156, 193, 220, 255);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_DARK) {
table[NK_COLOR_TEXT] = nk_rgba(210, 210, 210, 255);
Expand Down Expand Up @@ -123,6 +135,10 @@ set_style(struct nk_context *ctx, enum theme theme)
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255);
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255);
table[NK_COLOR_TAB_HEADER] = nk_rgba(48, 83, 111, 255);
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else if (theme == THEME_DRACULA) {
struct nk_color background = nk_rgba(40, 42, 54, 255);
Expand Down Expand Up @@ -164,6 +180,10 @@ set_style(struct nk_context *ctx, enum theme theme)
table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = comment;
table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = purple;
table[NK_COLOR_TAB_HEADER] = currentline;
table[NK_COLOR_KNOB] = table[NK_COLOR_SLIDER];
table[NK_COLOR_KNOB_CURSOR] = table[NK_COLOR_SLIDER_CURSOR];
table[NK_COLOR_KNOB_CURSOR_HOVER] = table[NK_COLOR_SLIDER_CURSOR_HOVER];
table[NK_COLOR_KNOB_CURSOR_ACTIVE] = table[NK_COLOR_SLIDER_CURSOR_ACTIVE];
nk_style_from_table(ctx, table);
} else {
nk_style_default(ctx);
Expand Down
Loading

0 comments on commit b1c2227

Please sign in to comment.