Browse Source

Added disabled factor & performance improvement

Added NK_WIDGET_DISABLED_FACTOR, global factor for disabled color
Yukyduky 2 years ago
parent
commit
5a6569a2c9
4 changed files with 70 additions and 64 deletions
  1. 35 32
      nuklear.h
  2. 4 1
      src/nuklear.h
  3. 7 7
      src/nuklear_color.c
  4. 24 24
      src/nuklear_style.c

+ 35 - 32
nuklear.h

@@ -3609,6 +3609,9 @@ NK_API void nk_menu_end(struct nk_context*);
  *                                  STYLE
  *
  * ============================================================================= */
+
+#define NK_WIDGET_DISABLED_FACTOR 0.5f
+
 enum nk_style_colors {
     NK_COLOR_TEXT,
     NK_COLOR_WINDOW,
@@ -3685,7 +3688,7 @@ NK_API struct nk_color nk_rgb_f(float r, float g, float b);
 NK_API struct nk_color nk_rgb_fv(const float *rgb);
 NK_API struct nk_color nk_rgb_cf(struct nk_colorf c);
 NK_API struct nk_color nk_rgb_hex(const char *rgb);
-NK_API struct nk_color nk_rgb_factor(const struct nk_color col, const float factor);
+NK_API struct nk_color nk_rgb_factor(struct nk_color col, const float factor);
 
 NK_API struct nk_color nk_rgba(int r, int g, int b, int a);
 NK_API struct nk_color nk_rgba_u32(nk_uint);
@@ -7632,14 +7635,14 @@ nk_parse_hex(const char *p, int length)
     return i;
 }
 NK_API struct nk_color
-nk_rgb_factor(const struct nk_color col, const float factor)
+nk_rgb_factor(struct nk_color col, const float factor)
 {
-    struct nk_color ret;
-    ret.r = col.r * factor;
-    ret.g = col.g * factor;
-    ret.b = col.b * factor;
-    ret.a = col.a;
-    return ret;
+    if (factor == 1.0f)
+        return col;
+    col.r *= factor;
+    col.g *= factor;
+    col.b *= factor;
+    return col;
 }
 NK_API struct nk_color
 nk_rgba(int r, int g, int b, int a)
@@ -18280,7 +18283,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     text->color = table[NK_COLOR_TEXT];
     text->padding = nk_vec2(0,0);
     text->color_factor = 1.0f;
-    text->disabled_factor = 0.5f;
+    text->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
 
     /* default button */
     button = &style->button;
@@ -18301,7 +18304,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 1.0f;
     button->rounding        = 4.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
 
@@ -18323,7 +18326,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
 
@@ -18345,7 +18348,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 1.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
 
@@ -18368,7 +18371,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     toggle->border          = 0.0f;
     toggle->spacing         = 4;
     toggle->color_factor    = 1.0f;
-    toggle->disabled_factor = 0.5f;
+    toggle->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
 
     /* option toggle */
     toggle = &style->option;
@@ -18389,7 +18392,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     toggle->border          = 0.0f;
     toggle->spacing         = 4;
     toggle->color_factor    = 1.0f;
-    toggle->disabled_factor = 0.5f;
+    toggle->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
 
     /* selectable */
     select = &style->selectable;
@@ -18412,7 +18415,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     select->userdata        = nk_handle_ptr(0);
     select->rounding        = 0.0f;
     select->color_factor    = 1.0f;
-    select->disabled_factor = 0.5f;
+    select->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     select->draw_begin      = 0;
     select->draw_end        = 0;
 
@@ -18439,7 +18442,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     slider->bar_height      = 8;
     slider->rounding        = 0;
     slider->color_factor    = 1.0f;
-    slider->disabled_factor = 0.5f;
+    slider->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     slider->draw_begin      = 0;
     slider->draw_end        = 0;
 
@@ -18460,7 +18463,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 1.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
     style->slider.dec_button = style->slider.inc_button;
@@ -18483,7 +18486,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     prog->cursor_rounding   = 0;
     prog->cursor_border     = 0;
     prog->color_factor      = 1.0f;
-    prog->disabled_factor   = 0.5f;
+    prog->disabled_factor   = NK_WIDGET_DISABLED_FACTOR;
     prog->draw_begin        = 0;
     prog->draw_end          = 0;
 
@@ -18508,7 +18511,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     scroll->border_cursor   = 0;
     scroll->rounding_cursor = 0;
     scroll->color_factor    = 1.0f;
-    scroll->disabled_factor = 0.5f;
+    scroll->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     scroll->draw_begin      = 0;
     scroll->draw_end        = 0;
     style->scrollv = style->scrollh;
@@ -18530,7 +18533,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 1.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
     style->scrollh.dec_button = style->scrollh.inc_button;
@@ -18563,7 +18566,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     edit->border            = 1;
     edit->rounding          = 0;
     edit->color_factor      = 1.0f;
-    edit->disabled_factor   = 0.5f;
+    edit->disabled_factor   = NK_WIDGET_DISABLED_FACTOR;
 
     /* property */
     property = &style->property;
@@ -18584,7 +18587,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     property->draw_begin    = 0;
     property->draw_end      = 0;
     property->color_factor  = 1.0f;
-    property->disabled_factor = 0.5f;
+    property->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
 
     /* property buttons */
     button = &style->property.dec_button;
@@ -18604,7 +18607,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
     style->property.inc_button = style->property.dec_button;
@@ -18632,7 +18635,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     edit->border            = 0;
     edit->rounding          = 0;
     edit->color_factor      = 1.0f;
-    edit->disabled_factor   = 0.5f;
+    edit->disabled_factor   = NK_WIDGET_DISABLED_FACTOR;
 
     /* chart */
     chart = &style->chart;
@@ -18645,7 +18648,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     chart->border           = 0;
     chart->rounding         = 0;
     chart->color_factor     = 1.0f;
-    chart->disabled_factor  = 0.5f;
+    chart->disabled_factor  = NK_WIDGET_DISABLED_FACTOR;
 
     /* combo */
     combo = &style->combo;
@@ -18665,7 +18668,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     combo->border           = 1;
     combo->rounding         = 0;
     combo->color_factor     = 1.0f;
-    combo->disabled_factor  = 0.5f;
+    combo->disabled_factor  = NK_WIDGET_DISABLED_FACTOR;
 
     /* combo button */
     button = &style->combo.button;
@@ -18685,7 +18688,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
 
@@ -18702,7 +18705,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     tab->border             = 1;
     tab->rounding           = 0;
     tab->color_factor       = 1.0f;
-    tab->disabled_factor    = 0.5f;
+    tab->disabled_factor    = NK_WIDGET_DISABLED_FACTOR;
 
     /* tab button */
     button = &style->tab.tab_minimize_button;
@@ -18722,7 +18725,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
     style->tab.tab_maximize_button =*button;
@@ -18745,7 +18748,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
     style->tab.node_maximize_button =*button;
@@ -18784,7 +18787,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
 
@@ -18806,7 +18809,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
 

+ 4 - 1
src/nuklear.h

@@ -3387,6 +3387,9 @@ NK_API void nk_menu_end(struct nk_context*);
  *                                  STYLE
  *
  * ============================================================================= */
+
+#define NK_WIDGET_DISABLED_FACTOR 0.5f
+
 enum nk_style_colors {
     NK_COLOR_TEXT,
     NK_COLOR_WINDOW,
@@ -3463,7 +3466,7 @@ NK_API struct nk_color nk_rgb_f(float r, float g, float b);
 NK_API struct nk_color nk_rgb_fv(const float *rgb);
 NK_API struct nk_color nk_rgb_cf(struct nk_colorf c);
 NK_API struct nk_color nk_rgb_hex(const char *rgb);
-NK_API struct nk_color nk_rgb_factor(const struct nk_color col, const float factor);
+NK_API struct nk_color nk_rgb_factor(struct nk_color col, const float factor);
 
 NK_API struct nk_color nk_rgba(int r, int g, int b, int a);
 NK_API struct nk_color nk_rgba_u32(nk_uint);

+ 7 - 7
src/nuklear_color.c

@@ -23,14 +23,14 @@ nk_parse_hex(const char *p, int length)
     return i;
 }
 NK_API struct nk_color
-nk_rgb_factor(const struct nk_color col, const float factor)
+nk_rgb_factor(struct nk_color col, const float factor)
 {
-    struct nk_color ret;
-    ret.r = col.r * factor;
-    ret.g = col.g * factor;
-    ret.b = col.b * factor;
-    ret.a = col.a;
-    return ret;
+    if (factor == 1.0f)
+        return col;
+    col.r *= factor;
+    col.g *= factor;
+    col.b *= factor;
+    return col;
 }
 NK_API struct nk_color
 nk_rgba(int r, int g, int b, int a)

+ 24 - 24
src/nuklear_style.c

@@ -114,7 +114,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     text->color = table[NK_COLOR_TEXT];
     text->padding = nk_vec2(0,0);
     text->color_factor = 1.0f;
-    text->disabled_factor = 0.5f;
+    text->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
 
     /* default button */
     button = &style->button;
@@ -135,7 +135,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 1.0f;
     button->rounding        = 4.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
 
@@ -157,7 +157,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
 
@@ -179,7 +179,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 1.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
 
@@ -202,7 +202,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     toggle->border          = 0.0f;
     toggle->spacing         = 4;
     toggle->color_factor    = 1.0f;
-    toggle->disabled_factor = 0.5f;
+    toggle->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
 
     /* option toggle */
     toggle = &style->option;
@@ -223,7 +223,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     toggle->border          = 0.0f;
     toggle->spacing         = 4;
     toggle->color_factor    = 1.0f;
-    toggle->disabled_factor = 0.5f;
+    toggle->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
 
     /* selectable */
     select = &style->selectable;
@@ -246,7 +246,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     select->userdata        = nk_handle_ptr(0);
     select->rounding        = 0.0f;
     select->color_factor    = 1.0f;
-    select->disabled_factor = 0.5f;
+    select->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     select->draw_begin      = 0;
     select->draw_end        = 0;
 
@@ -273,7 +273,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     slider->bar_height      = 8;
     slider->rounding        = 0;
     slider->color_factor    = 1.0f;
-    slider->disabled_factor = 0.5f;
+    slider->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     slider->draw_begin      = 0;
     slider->draw_end        = 0;
 
@@ -294,7 +294,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 1.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
     style->slider.dec_button = style->slider.inc_button;
@@ -317,7 +317,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     prog->cursor_rounding   = 0;
     prog->cursor_border     = 0;
     prog->color_factor      = 1.0f;
-    prog->disabled_factor   = 0.5f;
+    prog->disabled_factor   = NK_WIDGET_DISABLED_FACTOR;
     prog->draw_begin        = 0;
     prog->draw_end          = 0;
 
@@ -342,7 +342,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     scroll->border_cursor   = 0;
     scroll->rounding_cursor = 0;
     scroll->color_factor    = 1.0f;
-    scroll->disabled_factor = 0.5f;
+    scroll->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     scroll->draw_begin      = 0;
     scroll->draw_end        = 0;
     style->scrollv = style->scrollh;
@@ -364,7 +364,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 1.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
     style->scrollh.dec_button = style->scrollh.inc_button;
@@ -397,7 +397,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     edit->border            = 1;
     edit->rounding          = 0;
     edit->color_factor      = 1.0f;
-    edit->disabled_factor   = 0.5f;
+    edit->disabled_factor   = NK_WIDGET_DISABLED_FACTOR;
 
     /* property */
     property = &style->property;
@@ -418,7 +418,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     property->draw_begin    = 0;
     property->draw_end      = 0;
     property->color_factor  = 1.0f;
-    property->disabled_factor = 0.5f;
+    property->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
 
     /* property buttons */
     button = &style->property.dec_button;
@@ -438,7 +438,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
     style->property.inc_button = style->property.dec_button;
@@ -466,7 +466,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     edit->border            = 0;
     edit->rounding          = 0;
     edit->color_factor      = 1.0f;
-    edit->disabled_factor   = 0.5f;
+    edit->disabled_factor   = NK_WIDGET_DISABLED_FACTOR;
 
     /* chart */
     chart = &style->chart;
@@ -479,7 +479,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     chart->border           = 0;
     chart->rounding         = 0;
     chart->color_factor     = 1.0f;
-    chart->disabled_factor  = 0.5f;
+    chart->disabled_factor  = NK_WIDGET_DISABLED_FACTOR;
 
     /* combo */
     combo = &style->combo;
@@ -499,7 +499,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     combo->border           = 1;
     combo->rounding         = 0;
     combo->color_factor     = 1.0f;
-    combo->disabled_factor  = 0.5f;
+    combo->disabled_factor  = NK_WIDGET_DISABLED_FACTOR;
 
     /* combo button */
     button = &style->combo.button;
@@ -519,7 +519,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
 
@@ -536,7 +536,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     tab->border             = 1;
     tab->rounding           = 0;
     tab->color_factor       = 1.0f;
-    tab->disabled_factor    = 0.5f;
+    tab->disabled_factor    = NK_WIDGET_DISABLED_FACTOR;
 
     /* tab button */
     button = &style->tab.tab_minimize_button;
@@ -556,7 +556,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
     style->tab.tab_maximize_button =*button;
@@ -579,7 +579,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
     style->tab.node_maximize_button =*button;
@@ -618,7 +618,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;
 
@@ -640,7 +640,7 @@ nk_style_from_table(struct nk_context *ctx, const struct nk_color *table)
     button->border          = 0.0f;
     button->rounding        = 0.0f;
     button->color_factor    = 1.0f;
-    button->disabled_factor = 0.5f;
+    button->disabled_factor = NK_WIDGET_DISABLED_FACTOR;
     button->draw_begin      = 0;
     button->draw_end        = 0;