Skip to content

Commit

Permalink
GUI2/Slider: improved some comments and naming related to value labels
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Aug 26, 2017
1 parent 15105c2 commit 683c95c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/gui/widgets/slider.cpp
Expand Up @@ -42,7 +42,7 @@ slider::slider(const implementation::builder_slider& builder)
, minimum_value_(0)
, minimum_value_label_()
, maximum_value_label_()
, value_labels_()
, value_label_generator_()
, current_item_mouse_position_(0, 0)
{
connect_signal<event::SDL_KEY_DOWN>(std::bind(&slider::signal_handler_sdl_key_down, this, _2, _3, _5));
Expand Down Expand Up @@ -133,8 +133,8 @@ void slider::set_maximum_value(const int maximum_value)

t_string slider::get_value_label() const
{
if(value_labels_) {
return value_labels_(get_item_position(), get_item_count());
if(value_label_generator_) {
return value_label_generator_(get_item_position(), get_item_count());
} else if(!minimum_value_label_.empty() && get_value() == get_minimum_value()) {
return minimum_value_label_;
} else if(!maximum_value_label_.empty() && get_value() == get_maximum_value()) {
Expand Down
16 changes: 8 additions & 8 deletions src/gui/widgets/slider.hpp
Expand Up @@ -94,11 +94,11 @@ class slider : public scrollbar_base, public integer_selector

void set_value_labels(const std::vector<t_string>& value_labels);

typedef std::function<t_string(int /*current position*/, int /*num positions*/)> tlabel_creator;
using label_generator = std::function<t_string(int /*current position*/, int /*num positions*/)>;

void set_value_labels(const tlabel_creator& value_labels)
void set_value_labels(const label_generator& generator)
{
value_labels_ = value_labels;
value_label_generator_ = generator;
}

/**
Expand Down Expand Up @@ -178,12 +178,11 @@ class slider : public scrollbar_base, public integer_selector
t_string maximum_value_label_;

/**
* This allows the slider to show custom texts instead of the values.
* This vector should have the same amount of items as options for the
* sliders. When set these texts are shown instead of the values. It also
* overrides minimum_value_label_ and maximum_value_label_.
* Function to output custom value labels for the slider. When set
* its output is shown instead of the numeric values. It also overrides
* minimum_value_label_ and maximum_value_label_.
*/
tlabel_creator value_labels_;
label_generator value_label_generator_;

/**
* When initially pressing the positioner and every time a new value is chosen through dragging,
Expand Down Expand Up @@ -255,6 +254,7 @@ struct builder_slider : public builder_styled_widget
t_string minimum_value_label_;
t_string maximum_value_label_;

/* This vector should have the same number of items as the slider's values. */
std::vector<t_string> value_labels_;
};

Expand Down

0 comments on commit 683c95c

Please sign in to comment.