Codechange: Let ClickSliderWidget handle rounding to nearest mark.
This commit is contained in:
committed by
Peter Nelson
parent
9d2efd4c96
commit
9a7c30a109
@@ -82,10 +82,13 @@ void DrawSliderWidget(Rect r, int min_value, int max_value, int nmarks, int valu
|
||||
* Handle click on a slider widget to change the value
|
||||
* @param r Rectangle of the widget
|
||||
* @param pt Clicked point
|
||||
* @param min_value Minimum value of slider
|
||||
* @param max_value Maximum value of slider
|
||||
* @param nmarks Number of marks displayed. Value will be rounded to nearest mark.
|
||||
* @param value[in,out] Value to modify
|
||||
* @return True if the value setting was modified
|
||||
*/
|
||||
bool ClickSliderWidget(Rect r, Point pt, int min_value, int max_value, int &value)
|
||||
bool ClickSliderWidget(Rect r, Point pt, int min_value, int max_value, int nmarks, int &value)
|
||||
{
|
||||
max_value -= min_value;
|
||||
|
||||
@@ -94,6 +97,11 @@ bool ClickSliderWidget(Rect r, Point pt, int min_value, int max_value, int &valu
|
||||
if (_current_text_dir == TD_RTL) new_value = max_value - new_value;
|
||||
new_value += min_value;
|
||||
|
||||
if (nmarks > 0) {
|
||||
const int step = max_value / (nmarks - 1);
|
||||
new_value = ((new_value + step / 2) / step) * step;
|
||||
}
|
||||
|
||||
if (new_value != value) {
|
||||
value = new_value;
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user