Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a style option to disable point markers on charts #602

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions demo/common/overview.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ overview(struct nk_context *ctx)
float id = 0;
static int col_index = -1;
static int line_index = -1;
static int show_markers = nk_true;
float step = (2*3.141592654f) / 32;

int i;
Expand All @@ -629,7 +630,10 @@ overview(struct nk_context *ctx)
/* line chart */
id = 0;
index = -1;
nk_layout_row_dynamic(ctx, 15, 1);
nk_checkbox_label(ctx, "Show markers", &show_markers);
nk_layout_row_dynamic(ctx, 100, 1);
ctx->style.chart.show_markers = show_markers;
if (nk_chart_begin(ctx, NK_CHART_LINES, 32, -1.0f, 1.0f)) {
for (i = 0; i < 32; ++i) {
nk_flags res = nk_chart_push(ctx, (float)cos(id));
Expand Down
17 changes: 13 additions & 4 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -5198,6 +5198,7 @@ struct nk_style_chart {
struct nk_vec2 padding;
float color_factor;
float disabled_factor;
nk_bool show_markers;
};

struct nk_style_combo {
Expand Down Expand Up @@ -5388,6 +5389,7 @@ struct nk_chart_slot {
int count;
struct nk_vec2 last;
int index;
nk_bool show_markers;
};

struct nk_chart {
Expand Down Expand Up @@ -18656,6 +18658,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
chart->rounding = 0;
chart->color_factor = 1.0f;
chart->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
chart->show_markers = nk_true;

/* combo */
combo = &style->combo;
Expand Down Expand Up @@ -28492,7 +28495,8 @@ nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type,
slot->highlight = highlight;
slot->min = NK_MIN(min_value, max_value);
slot->max = NK_MAX(min_value, max_value);
slot->range = slot->max - slot->min;}
slot->range = slot->max - slot->min;
slot->show_markers = style->show_markers;}

/* draw chart background */
background = &style->background;
Expand Down Expand Up @@ -28544,7 +28548,8 @@ nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type type,
slot->highlight = highlight;
slot->min = NK_MIN(min_value, max_value);
slot->max = NK_MAX(min_value, max_value);
slot->range = slot->max - slot->min;}
slot->range = slot->max - slot->min;
slot->show_markers = style->show_markers;}
}
NK_API void
nk_chart_add_slot(struct nk_context *ctx, const enum nk_chart_type type,
Expand Down Expand Up @@ -28591,7 +28596,9 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win,
i->mouse.buttons[NK_BUTTON_LEFT].clicked) ? NK_CHART_CLICKED: 0;
color = g->slots[slot].highlight;
}
nk_fill_rect(out, bounds, 0, color);
if (g->slots[slot].show_markers) {
nk_fill_rect(out, bounds, 0, color);
}
g->slots[slot].index += 1;
return ret;
}
Expand All @@ -28615,7 +28622,9 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win,
color = g->slots[slot].highlight;
}
}
nk_fill_rect(out, nk_rect(cur.x - 2, cur.y - 2, 4, 4), 0, color);
if (g->slots[slot].show_markers) {
nk_fill_rect(out, nk_rect(cur.x - 2, cur.y - 2, 4, 4), 0, color);
}

/* save current data point position */
g->slots[slot].last.x = cur.x;
Expand Down
2 changes: 2 additions & 0 deletions src/nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -4976,6 +4976,7 @@ struct nk_style_chart {
struct nk_vec2 padding;
float color_factor;
float disabled_factor;
nk_bool show_markers;
};

struct nk_style_combo {
Expand Down Expand Up @@ -5166,6 +5167,7 @@ struct nk_chart_slot {
int count;
struct nk_vec2 last;
int index;
nk_bool show_markers;
};

struct nk_chart {
Expand Down
14 changes: 10 additions & 4 deletions src/nuklear_chart.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ nk_chart_begin_colored(struct nk_context *ctx, enum nk_chart_type type,
slot->highlight = highlight;
slot->min = NK_MIN(min_value, max_value);
slot->max = NK_MAX(min_value, max_value);
slot->range = slot->max - slot->min;}
slot->range = slot->max - slot->min;
slot->show_markers = style->show_markers;}

/* draw chart background */
background = &style->background;
Expand Down Expand Up @@ -104,7 +105,8 @@ nk_chart_add_slot_colored(struct nk_context *ctx, const enum nk_chart_type type,
slot->highlight = highlight;
slot->min = NK_MIN(min_value, max_value);
slot->max = NK_MAX(min_value, max_value);
slot->range = slot->max - slot->min;}
slot->range = slot->max - slot->min;
slot->show_markers = style->show_markers;}
}
NK_API void
nk_chart_add_slot(struct nk_context *ctx, const enum nk_chart_type type,
Expand Down Expand Up @@ -151,7 +153,9 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win,
i->mouse.buttons[NK_BUTTON_LEFT].clicked) ? NK_CHART_CLICKED: 0;
color = g->slots[slot].highlight;
}
nk_fill_rect(out, bounds, 0, color);
if (g->slots[slot].show_markers) {
nk_fill_rect(out, bounds, 0, color);
}
g->slots[slot].index += 1;
return ret;
}
Expand All @@ -175,7 +179,9 @@ nk_chart_push_line(struct nk_context *ctx, struct nk_window *win,
color = g->slots[slot].highlight;
}
}
nk_fill_rect(out, nk_rect(cur.x - 2, cur.y - 2, 4, 4), 0, color);
if (g->slots[slot].show_markers) {
nk_fill_rect(out, nk_rect(cur.x - 2, cur.y - 2, 4, 4), 0, color);
}

/* save current data point position */
g->slots[slot].last.x = cur.x;
Expand Down
1 change: 1 addition & 0 deletions src/nuklear_style.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
chart->rounding = 0;
chart->color_factor = 1.0f;
chart->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
chart->show_markers = nk_true;

/* combo */
combo = &style->combo;
Expand Down