Browse Source

Cleanup widget slider

Michael Ragazzon 6 years ago
parent
commit
b993a65fa0

+ 3 - 3
Samples/basic/demo/src/main.cpp

@@ -368,9 +368,9 @@ public:
 			auto el_rating_emoji = element->GetElementById("rating_emoji");
 			if (el_rating && el_rating_emoji)
 			{
-				enum { Sad, Mediocre, Exciting, Celebrate, Champion, CountBonus };
-				static const Rml::Core::String emojis[CountBonus] = { u8"😢", u8"😐", u8"😮", u8"😎", u8"🏆" };
-				int value = std::atoi(static_cast<Rml::Controls::ElementFormControl*>(element)->GetValue().c_str());
+				enum { Sad, Mediocre, Exciting, Celebrate, Champion, CountEmojis };
+				static const Rml::Core::String emojis[CountEmojis] = { u8"😢", u8"😐", u8"😮", u8"😎", u8"🏆" };
+				int value = event.GetParameter("value", 50);
 				
 				Rml::Core::String emoji;
 				if (value <= 0)

+ 0 - 5
Source/Controls/InputTypeRange.cpp

@@ -66,7 +66,6 @@ bool InputTypeRange::OnAttributeChange(const Core::ElementAttributes& changed_at
 {
 	bool dirty_layout = false;
 
-	// Check if maxlength has been defined.
 	auto it_orientation = changed_attributes.find("orientation");
 	if (it_orientation != changed_attributes.end())
 	{
@@ -75,22 +74,18 @@ bool InputTypeRange::OnAttributeChange(const Core::ElementAttributes& changed_at
 		dirty_layout = true;
 	}
 
-	// Check if size has been defined.
 	auto it_step = changed_attributes.find("step");
 	if (it_step != changed_attributes.end())
 		widget->SetStep(it_step->second.Get(1.0f));
 
-	// Check if min has been defined.
 	auto it_min = changed_attributes.find("min");
 	if (it_min != changed_attributes.end())
 		widget->SetMinValue(it_min->second.Get(0.0f));
 
-	// Check if max has been defined.
 	auto it_max = changed_attributes.find("max");
 	if (it_max != changed_attributes.end())
 		widget->SetMaxValue(it_max->second.Get(100.f));
 
-	// Check if the value has been changed.
 	auto it_value = changed_attributes.find("value");
 	if (it_value != changed_attributes.end())
 		widget->SetValue(it_value->second.Get(0.0f));

+ 2 - 2
Source/Controls/WidgetSlider.cpp

@@ -187,8 +187,8 @@ void WidgetSlider::GetDimensions(Rml::Core::Vector2f& dimensions) const
 {
 	switch (orientation)
 	{
-		case VERTICAL:		dimensions.x = 16; dimensions.y = 256; break;
-		case HORIZONTAL:	dimensions.x = 256; dimensions.y = 16; break;
+		case VERTICAL:   dimensions.x = 16; dimensions.y = 256; break;
+		case HORIZONTAL: dimensions.x = 256; dimensions.y = 16; break;
 	}
 }
 

+ 2 - 12
Source/Controls/WidgetSlider.h

@@ -106,19 +106,7 @@ protected:
 	/// decrement arrow.
 	/// @return The new position of the bar.
 	virtual float OnLineDecrement() = 0;
-	/// Called when the slider is incremented by one 'page', either by the page-up key or a mouse-click on the
-	/// track below / right of the bar.
-	/// @param[in] click_position The parametric position of the click along the track, or -1 if this was not generated by a mouse click.
-	/// @return The new position of the bar.
-	virtual float OnPageIncrement(float click_position) = 0;
-	/// Called when the slider is incremented by one 'page', either by the page-down key or a mouse-click on the
-	/// track above / left of the bar.
-	/// @param[in] click_position The parametric position of the click along the track, or -1 if this was not generated by a mouse click.
-	/// @return The new position of the bar.
-	virtual float OnPageDecrement(float click_position) = 0;
 
-protected:
-    ElementFormControl* parent;
 private:
 	/// Determine the normalized bar position given an absolute position coordinate.
 	/// @param[in] absolute_position Absolute position along the axis determined by 'orientation'.
@@ -127,6 +115,8 @@ private:
 
 	void PositionBar();
 
+    ElementFormControl* parent;
+
 	Orientation orientation;
 
 	// The background track element, across which the bar slides.

+ 1 - 14
Source/Controls/WidgetSliderInput.cpp

@@ -29,7 +29,6 @@
 #include "WidgetSliderInput.h"
 #include "../../Include/RmlUi/Core/Math.h"
 #include "../../Include/RmlUi/Core/Element.h"
-#include "../../Include/RmlUi/Controls/ElementFormControl.h"
 
 namespace Rml {
 namespace Controls {
@@ -111,18 +110,6 @@ float WidgetSliderInput::OnLineDecrement()
 	return SetValueInternal(value - step);
 }
 
-// Called when the slider is incremented by one 'page'.
-float WidgetSliderInput::OnPageIncrement(float click_position)
-{
-	return OnBarChange(click_position);
-}
-
-// Called when the slider is incremented by one 'page'.
-float WidgetSliderInput::OnPageDecrement(float click_position)
-{
-	return OnBarChange(click_position);
-}
-
 // Clamps the new value, sets it on the slider.
 float WidgetSliderInput::SetValueInternal(float new_value)
 {
@@ -142,7 +129,7 @@ float WidgetSliderInput::SetValueInternal(float new_value)
 
     Rml::Core::Dictionary parameters;
     parameters["value"] = value;
-    parent->DispatchEvent(Core::EventId::Change, parameters);
+    GetParent()->DispatchEvent(Core::EventId::Change, parameters);
 
 	return (value - min_value) / (max_value - min_value);
 }

+ 0 - 8
Source/Controls/WidgetSliderInput.h

@@ -79,14 +79,6 @@ protected:
 	/// decrement arrow.
 	/// @return The new position of the bar.
 	float OnLineDecrement() override;
-	/// Called when the slider is incremented by one 'page', either by the page-up key or a mouse-click on the
-	/// track below / right of the bar.
-	/// @return The new position of the bar.
-	float OnPageIncrement(float click_position) override;
-	/// Called when the slider is incremented by one 'page', either by the page-down key or a mouse-click on the
-	/// track above / left of the bar.
-	/// @return The new position of the bar.
-	float OnPageDecrement(float click_position) override;
 
 private:
 	/// Clamps the new value, sets it on the slider and returns it as a number from 0 to 1, 0 being the minimum

+ 2 - 2
Source/Core/WidgetSlider.cpp

@@ -202,8 +202,8 @@ void WidgetSlider::GetDimensions(Vector2f& dimensions) const
 	switch (orientation)
 	{
 		RMLUI_UNUSED_SWITCH_ENUM(UNKNOWN);
-		case VERTICAL:		dimensions.x = 256; dimensions.y = 16; break;
-		case HORIZONTAL:	dimensions.x = 16; dimensions.y = 256; break;
+		case VERTICAL:   dimensions.x = 16; dimensions.y = 256; break;
+		case HORIZONTAL: dimensions.x = 256; dimensions.y = 16; break;
 	}
 }