Adding a legend to a chart.
stolk opened this issue · 2 comments
stolk commented
So I am using a chart with many lines in it.
Now I want to label the colours, and also give them a toggle.
How can I have the labels in the checkbox use the same color as the lines? Is there a quick way to color either the foreground or background of a label, or a checkbox?
void Overlay::DrawStats(void)
{
if ( !m_economy)
return;
nk_context* ctx = static_cast<nk_context*>(m_context);
const int opts =
NK_WINDOW_BORDER |
NK_WINDOW_MOVABLE |
NK_WINDOW_MINIMIZABLE |
NK_WINDOW_NO_SCROLLBAR |
NK_WINDOW_SCALABLE |
NK_WINDOW_TITLE;
struct nk_color colours[] =
{
nk_rgb(0,122,183),
nk_rgb(255,113,0),
nk_rgb(0,166,29),
nk_rgb(251,0,27),
nk_rgb(163,98,192),
nk_rgb(158,80,72),
nk_rgb(128,128,128),
nk_rgb(190,191,0),
nk_rgb(0,197,209),
};
const int winW = 320;
const int winH = 400;
const int winX = 16;
const int winY = m_screenHeight - winH - 16;
SetFont(F_SANS_REGULAR);
if (nk_begin(ctx, "Economy", nk_rect(winX, winY, winW, winH), opts))
{
SetFont(F_MONO_SYSTEM);
nk_layout_row_dynamic(ctx, 200, 1);
const int hsz = m_economy->HistorySize();
const int head = m_economy->m_hist_head;
const int nump = 6;
if ( hsz>2 )
{
if ( nk_chart_begin_colored(ctx, NK_CHART_LINES, colours[0], nk_rgb(0,0,0), hsz, -1, 50) )
{
for ( int p=2; p<nump; ++p )
nk_chart_add_slot_colored(ctx, NK_CHART_LINES, colours[p-1], nk_rgb(0,0,0), hsz, -1, 50);
for ( int i=0; i<hsz; ++i )
{
const int idx = ( head + i ) & HISTMASK;
for ( int p=1; p<nump; ++p )
{
int val = m_economy->m_productionhistory[idx][p];
nk_chart_push_slot(ctx, val, p-1);
}
}
}
}
nk_layout_row_dynamic(ctx, 20, 5);
static int vals[5] = {1,1,1,1,1};
nk_checkbox_label(ctx, prodnames[1], vals+0);
nk_checkbox_label(ctx, prodnames[2], vals+1);
nk_checkbox_label(ctx, prodnames[3], vals+2);
nk_checkbox_label(ctx, prodnames[4], vals+3);
nk_checkbox_label(ctx, prodnames[5], vals+4);
}
nk_end(ctx);
}
dumblob commented
Look at the following sections in nuklear.h
:
/* =============================================================================
*
* STYLE
*
* ============================================================================= */
/* =============================================================================
*
* COLOR
*
* ============================================================================= */
stolk commented
Thanks