Skip to content
Snippets Groups Projects
Commit 34a41f41 authored by Joakim Hunskaar's avatar Joakim Hunskaar
Browse files

added step value

parent a63c5ce8
No related branches found
No related tags found
1 merge request!11New widget slider
...@@ -7,9 +7,10 @@ ...@@ -7,9 +7,10 @@
namespace TDT4102 { namespace TDT4102 {
class Slider : public TDT4102::Widget { class Slider : public TDT4102::Widget {
private: private:
int value = 0; int value;
int minValue = 0; int minValue;
int maxValue = 100; int maxValue;
int stepValue;
nk_color sliderBarColor = nk_rgba(100, 100, 100, 255); nk_color sliderBarColor = nk_rgba(100, 100, 100, 255);
nk_color sliderBarColorActive = nk_rgba(100, 100, 100, 255); nk_color sliderBarColorActive = nk_rgba(100, 100, 100, 255);
nk_color sliderBarColorHover = nk_rgba(100, 100, 100, 255); nk_color sliderBarColorHover = nk_rgba(100, 100, 100, 255);
...@@ -20,7 +21,7 @@ namespace TDT4102 { ...@@ -20,7 +21,7 @@ namespace TDT4102 {
protected: protected:
void update(nk_context* context) override; void update(nk_context* context) override;
public: public:
explicit Slider(TDT4102::Point location, unsigned int width, unsigned int height, int min, int max, int initialValue); explicit Slider(TDT4102::Point location, unsigned int width, unsigned int height, int min = 0, int max = 100, int initialValue = 0, int step = 1);
int getValue() const; int getValue() const;
void setSliderBarColor(Color newColor) {sliderBarColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};}; void setSliderBarColor(Color newColor) {sliderBarColor = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};};
void setSliderBarColorActive(Color newColor) {sliderBarColorActive = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};} void setSliderBarColorActive(Color newColor) {sliderBarColorActive = nk_color{(nk_byte)newColor.redChannel, (nk_byte)newColor.greenChannel, (nk_byte)newColor.blueChannel, (nk_byte)newColor.alphaChannel};}
......
#include "widgets/Slider.h" #include "widgets/Slider.h"
TDT4102::Slider::Slider(TDT4102::Point location, unsigned int width, unsigned int height, int min, int max, int initialValue) TDT4102::Slider::Slider(TDT4102::Point location, unsigned int width, unsigned int height, int min, int max, int initialValue, int step)
: TDT4102::Widget(location, width, height) { : TDT4102::Widget(location, width, height) {
minValue = min; minValue = min;
maxValue = max; maxValue = max;
value = initialValue; value = initialValue;
stepValue = step;
} }
int TDT4102::Slider::getValue() const { int TDT4102::Slider::getValue() const {
...@@ -22,7 +23,7 @@ void TDT4102::Slider::update(nk_context *context) { ...@@ -22,7 +23,7 @@ void TDT4102::Slider::update(nk_context *context) {
nk_style_push_style_item(context, &s->slider.cursor_hover, nk_style_item_color(sliderCursorColorHover)); nk_style_push_style_item(context, &s->slider.cursor_hover, nk_style_item_color(sliderCursorColorHover));
nk_style_push_style_item(context, &s->slider.cursor_active, nk_style_item_color(sliderCursorColorActive)); nk_style_push_style_item(context, &s->slider.cursor_active, nk_style_item_color(sliderCursorColorActive));
if (nk_slider_int(context, minValue, &value, maxValue, 1)) { if (nk_slider_int(context, minValue, &value, maxValue, stepValue)) {
fire(); fire();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment