Przeglądaj źródła

Changed Fields behavior to provide live preview of the input values

marco.bellan 9 lat temu
rodzic
commit
65109bd22e

+ 3 - 4
Source/BansheeEditor/Include/BsGUIFloatField.h

@@ -78,13 +78,12 @@ namespace BansheeEngine
 		void styleUpdated() override;
 		void styleUpdated() override;
 
 
 		/**	Triggered when the input box value changes. */
 		/**	Triggered when the input box value changes. */
-		void valueChanged(const WString& newValue);
+		void valueChanging(const WString& newValue);
 
 
 		/**
 		/**
-		 * Triggered when the input box value changes, but unlike the previous overload the value is parsed into a floating
-		 * point value.
+		 * Triggered when the input box value changes and is confirmed.
 		 */
 		 */
-		void valueChanged(float newValue);
+		void valueChanged(float newValue, bool confirmed = true);
 
 
 		/**	Triggers when the input box receives or loses keyboard focus. */
 		/**	Triggers when the input box receives or loses keyboard focus. */
 		void focusChanged(bool focus);
 		void focusChanged(bool focus);

+ 1 - 1
Source/BansheeEditor/Include/BsGUISliderField.h

@@ -77,7 +77,7 @@ namespace BansheeEngine
 		void styleUpdated() override;
 		void styleUpdated() override;
 
 
 		/**	Triggered when the input box value changes definitively. */
 		/**	Triggered when the input box value changes definitively. */
-		void inputBoxValueChanged(bool confirmed);
+		void inputBoxValueChanged(bool confirmed = true);
 
 
 		/**	Triggered when the input box value is changing. */
 		/**	Triggered when the input box value is changing. */
 		void inputBoxValueChanging(const WString&);
 		void inputBoxValueChanging(const WString&);

+ 15 - 6
Source/BansheeEditor/Source/BsGUIFloatField.cpp

@@ -26,7 +26,7 @@ namespace BansheeEngine
 		mInputBox = GUIInputBox::create(false, GUIOptions(GUIOption::flexibleWidth()), getSubStyleName(getInputStyleType()));
 		mInputBox = GUIInputBox::create(false, GUIOptions(GUIOption::flexibleWidth()), getSubStyleName(getInputStyleType()));
 		mInputBox->setFilter(&GUIFloatField::floatFilter);
 		mInputBox->setFilter(&GUIFloatField::floatFilter);
 
 
-		mInputBox->onValueChanged.connect(std::bind((void(GUIFloatField::*)(const WString&))&GUIFloatField::valueChanged, this, _1));
+		mInputBox->onValueChanged.connect(std::bind((void(GUIFloatField::*)(const WString&))&GUIFloatField::valueChanging, this, _1));
 		mInputBox->onFocusChanged.connect(std::bind(&GUIFloatField::focusChanged, this, _1));
 		mInputBox->onFocusChanged.connect(std::bind(&GUIFloatField::focusChanged, this, _1));
 		mInputBox->onConfirm.connect(std::bind(&GUIFloatField::inputConfirmed, this));
 		mInputBox->onConfirm.connect(std::bind(&GUIFloatField::inputConfirmed, this));
 
 
@@ -116,7 +116,7 @@ namespace BansheeEngine
 					if (oldValue != newValue)
 					if (oldValue != newValue)
 					{
 					{
 						setValue(newValue);
 						setValue(newValue);
-						valueChanged(newValue);
+						valueChanged(newValue, true);
 					}
 					}
 				}
 				}
 			}
 			}
@@ -195,14 +195,20 @@ namespace BansheeEngine
 		mInputBox->setStyle(getSubStyleName(getInputStyleType()));
 		mInputBox->setStyle(getSubStyleName(getInputStyleType()));
 	}
 	}
 
 
-	void GUIFloatField::valueChanged(const WString& newValue)
+	void GUIFloatField::valueChanging(const WString& newValue)
 	{
 	{
-		valueChanged(parseFloat(newValue));
+		valueChanged(parseFloat(newValue), false);
 	}
 	}
 
 
-	void GUIFloatField::valueChanged(float newValue)
+	void GUIFloatField::valueChanged(float newValue, bool confirmed)
 	{
 	{
-		CmdInputFieldValueChange<GUIFloatField, float>::execute(this, newValue);
+		if (confirmed) {
+			CmdInputFieldValueChange<GUIFloatField, float>::execute(this, newValue);
+		}
+		else
+		{
+			onValueChanged(newValue);
+		}
 	}
 	}
 
 
 	void GUIFloatField::focusChanged(bool focus)
 	void GUIFloatField::focusChanged(bool focus)
@@ -215,12 +221,15 @@ namespace BansheeEngine
 		else
 		else
 		{
 		{
 			UndoRedo::instance().popGroup("InputBox");
 			UndoRedo::instance().popGroup("InputBox");
+			valueChanged(parseFloat(mInputBox->getText()));
+			onConfirm();
 			mHasInputFocus = false;
 			mHasInputFocus = false;
 		}
 		}
 	}
 	}
 
 
 	void GUIFloatField::inputConfirmed()
 	void GUIFloatField::inputConfirmed()
 	{
 	{
+		valueChanged(parseFloat(mInputBox->getText()));
 		onConfirm();
 		onConfirm();
 	}
 	}
 
 

+ 1 - 1
Source/BansheeEditor/Source/BsGUISliderField.cpp

@@ -124,7 +124,7 @@ namespace BansheeEngine
 		inputBoxValueChanged(false);
 		inputBoxValueChanged(false);
 	}
 	}
 
 
-	void GUISliderField::inputBoxValueChanged(bool confirmed = true)
+	void GUISliderField::inputBoxValueChanged(bool confirmed)
 	{
 	{
 		float newFloatValue = parseFloat(mInputBox->getText());
 		float newFloatValue = parseFloat(mInputBox->getText());
 		if (mSlider->getValue() != newFloatValue) {
 		if (mSlider->getValue() != newFloatValue) {