Browse Source

Add new RCSS property 'caret-color'

Michael Ragazzon 5 years ago
parent
commit
424bdaef3e

+ 1 - 0
Include/RmlUi/Core/ID.h

@@ -121,6 +121,7 @@ enum class PropertyId : uint8_t
 	Visibility,
 	Visibility,
 	BackgroundColor,
 	BackgroundColor,
 	Color,
 	Color,
+	CaretColor,
 	ImageColor,
 	ImageColor,
 	FontFamily,
 	FontFamily,
 	FontStyle,
 	FontStyle,

+ 2 - 1
Samples/basic/demo/data/demo.rml

@@ -509,8 +509,9 @@ progressbar {
 #controls textarea 
 #controls textarea 
 {
 {
 	font-size: 18px;
 	font-size: 18px;
-	font-effect: outline(2px #006600);
+	font-effect: outline(2px #060);
 	color: #ddd;
 	color: #ddd;
+	caret-color: #060;
 }
 }
 #controls textarea selection
 #controls textarea selection
 {
 {

+ 3 - 0
Source/Core/Elements/ElementFormControlTextArea.cpp

@@ -183,6 +183,9 @@ void ElementFormControlTextArea::OnPropertyChange(const PropertyIdSet& changed_p
 	if (changed_properties.Contains(PropertyId::Color) ||
 	if (changed_properties.Contains(PropertyId::Color) ||
 		changed_properties.Contains(PropertyId::BackgroundColor))
 		changed_properties.Contains(PropertyId::BackgroundColor))
 		widget->UpdateSelectionColours();
 		widget->UpdateSelectionColours();
+
+	if (changed_properties.Contains(PropertyId::CaretColor))
+		widget->GenerateCursor();
 }
 }
 
 
 // Returns the text content of the element.
 // Returns the text content of the element.

+ 0 - 1
Source/Core/Elements/ElementTextSelection.cpp

@@ -55,7 +55,6 @@ void ElementTextSelection::OnPropertyChange(const PropertyIdSet& changed_propert
 	if (widget == nullptr)
 	if (widget == nullptr)
 		return;
 		return;
 
 
-	// Check for a colour change.
 	if (changed_properties.Contains(PropertyId::Color) ||
 	if (changed_properties.Contains(PropertyId::Color) ||
 		changed_properties.Contains(PropertyId::BackgroundColor))
 		changed_properties.Contains(PropertyId::BackgroundColor))
 	{
 	{

+ 3 - 0
Source/Core/Elements/InputTypeText.cpp

@@ -107,6 +107,9 @@ void InputTypeText::OnPropertyChange(const PropertyIdSet& changed_properties)
 	if (changed_properties.Contains(PropertyId::Color) ||
 	if (changed_properties.Contains(PropertyId::Color) ||
 		changed_properties.Contains(PropertyId::BackgroundColor))
 		changed_properties.Contains(PropertyId::BackgroundColor))
 		widget->UpdateSelectionColours();
 		widget->UpdateSelectionColours();
+
+	if (changed_properties.Contains(PropertyId::CaretColor))
+		widget->GenerateCursor();
 }
 }
 
 
 // Checks for necessary functional changes in the control as a result of the event.
 // Checks for necessary functional changes in the control as a result of the event.

+ 15 - 2
Source/Core/Elements/WidgetTextInput.cpp

@@ -36,6 +36,7 @@
 #include "../../../Include/RmlUi/Core/GeometryUtilities.h"
 #include "../../../Include/RmlUi/Core/GeometryUtilities.h"
 #include "../../../Include/RmlUi/Core/Input.h"
 #include "../../../Include/RmlUi/Core/Input.h"
 #include "../../../Include/RmlUi/Core/Factory.h"
 #include "../../../Include/RmlUi/Core/Factory.h"
+#include "../../../Include/RmlUi/Core/Math.h"
 #include "../../../Include/RmlUi/Core/SystemInterface.h"
 #include "../../../Include/RmlUi/Core/SystemInterface.h"
 #include "../../../Include/RmlUi/Core/StringUtilities.h"
 #include "../../../Include/RmlUi/Core/StringUtilities.h"
 #include "../Clock.h"
 #include "../Clock.h"
@@ -209,6 +210,9 @@ void WidgetTextInput::UpdateSelectionColours()
 		selection_colour = colour_property->Get< Colourb >();
 		selection_colour = colour_property->Get< Colourb >();
 	else
 	else
 		selection_colour = Colourb(255 - colour.red, 255 - colour.green, 255 - colour.blue, colour.alpha);
 		selection_colour = Colourb(255 - colour.red, 255 - colour.green, 255 - colour.blue, colour.alpha);
+
+	// Color may have changed, so we update the cursor geometry.
+	GenerateCursor();
 }
 }
 
 
 // Updates the cursor, if necessary.
 // Updates the cursor, if necessary.
@@ -1137,9 +1141,18 @@ void WidgetTextInput::GenerateCursor()
 	Vector< int >& indices = cursor_geometry.GetIndices();
 	Vector< int >& indices = cursor_geometry.GetIndices();
 	indices.resize(6);
 	indices.resize(6);
 
 
-	cursor_size.x = ElementUtilities::GetDensityIndependentPixelRatio(text_element);
+	cursor_size.x = Math::RoundFloat( ElementUtilities::GetDensityIndependentPixelRatio(text_element) );
 	cursor_size.y = text_element->GetLineHeight() + 2.0f;
 	cursor_size.y = text_element->GetLineHeight() + 2.0f;
-	GeometryUtilities::GenerateQuad(&vertices[0], &indices[0], Vector2f(0, 0), cursor_size, parent->GetProperty< Colourb >("color"));
+
+	Colourb color = parent->GetComputedValues().color;
+
+	if (const Property* property = parent->GetProperty(PropertyId::CaretColor))
+	{
+		if (property->unit == Property::COLOUR)
+			color = property->Get<Colourb>();
+	}
+
+	GeometryUtilities::GenerateQuad(&vertices[0], &indices[0], Vector2f(0, 0), cursor_size, color);
 }
 }
 
 
 void WidgetTextInput::UpdateCursorPosition()
 void WidgetTextInput::UpdateCursorPosition()

+ 2 - 2
Source/Core/Elements/WidgetTextInput.h

@@ -65,6 +65,8 @@ public:
 
 
 	/// Update the colours of the selected text.
 	/// Update the colours of the selected text.
 	void UpdateSelectionColours();
 	void UpdateSelectionColours();
+	/// Generates the text cursor.
+	void GenerateCursor();
 
 
 	/// Updates the cursor, if necessary.
 	/// Updates the cursor, if necessary.
 	void OnUpdate();
 	void OnUpdate();
@@ -154,8 +156,6 @@ private:
 	/// @return The content area of the element.
 	/// @return The content area of the element.
 	Vector2f FormatText();
 	Vector2f FormatText();
 
 
-	/// Generates the text cursor.
-	void GenerateCursor();
 	/// Updates the position to render the cursor.
 	/// Updates the position to render the cursor.
 	void UpdateCursorPosition();
 	void UpdateCursorPosition();
 
 

+ 2 - 0
Source/Core/StyleSheetSpecification.cpp

@@ -361,6 +361,8 @@ void StyleSheetSpecification::RegisterDefaultProperties()
 
 
 	RegisterProperty(PropertyId::Color, "color", "white", true, false).AddParser("color");
 	RegisterProperty(PropertyId::Color, "color", "white", true, false).AddParser("color");
 
 
+	RegisterProperty(PropertyId::CaretColor, "caret-color", "auto", true, false).AddParser("keyword", "auto").AddParser("color");
+
 	RegisterProperty(PropertyId::ImageColor, "image-color", "white", false, false).AddParser("color");
 	RegisterProperty(PropertyId::ImageColor, "image-color", "white", false, false).AddParser("color");
 	RegisterProperty(PropertyId::Opacity, "opacity", "1", true, false).AddParser("number");
 	RegisterProperty(PropertyId::Opacity, "opacity", "1", true, false).AddParser("number");
 
 

+ 5 - 2
changelog.md

@@ -104,9 +104,10 @@ Use the RCSS `display` property to enable table formatting. See the style sheet
 
 
 ### New RCSS properties
 ### New RCSS properties
 
 
-- The `border-radius` property is now supported in RmlUi for drawing rounded backgrounds and borders. The gradient decorator is made compatible with this property.
+- The `border-radius` property is now supported in RmlUi for drawing rounded backgrounds and borders.
 - Implemented the `word-break` RCSS property.
 - Implemented the `word-break` RCSS property.
 - Implemented the `box-sizing` RCSS property.
 - Implemented the `box-sizing` RCSS property.
+- Implemented the `caret-color` RCSS property.
 
 
 ### New RML elements
 ### New RML elements
 
 
@@ -119,6 +120,7 @@ Use the RCSS `display` property to enable table formatting. See the style sheet
 - `<select>` elements now react to changes in the `value` attribute.
 - `<select>` elements now react to changes in the `value` attribute.
 - Element attributes can now use escaped RML characters, eg. `<p example="&quot;Quoted text&quot;"/>`. [#154](https://github.com/mikke89/RmlUi/pull/154) (thanks @actboy168).
 - Element attributes can now use escaped RML characters, eg. `<p example="&quot;Quoted text&quot;"/>`. [#154](https://github.com/mikke89/RmlUi/pull/154) (thanks @actboy168).
 - Tabs and panels in tab sets will no longer set the `display` property to `inline-block`, thus it is now possible to customize the display property.
 - Tabs and panels in tab sets will no longer set the `display` property to `inline-block`, thus it is now possible to customize the display property.
+- Changing the `fill-image` property of `<progressbar>` elements now actually updates the image.
 
 
 ### Input handling
 ### Input handling
 
 
@@ -152,15 +154,16 @@ Improved Lua plugin in several aspects.
 - Added ability to change the default base tag in documents [#112](https://github.com/mikke89/RmlUi/pull/112)  (thanks @aquawicket).
 - Added ability to change the default base tag in documents [#112](https://github.com/mikke89/RmlUi/pull/112)  (thanks @aquawicket).
 - Improved the SFML2 sample [#106](https://github.com/mikke89/RmlUi/pull/106) and [#103](https://github.com/mikke89/RmlUi/issues/103) (thanks @hachmeister).
 - Improved the SFML2 sample [#106](https://github.com/mikke89/RmlUi/pull/106) and [#103](https://github.com/mikke89/RmlUi/issues/103) (thanks @hachmeister).
 - Debugger improvements: Sort property names alphabetically. Fix a bug where the outlines would draw underneath the document.
 - Debugger improvements: Sort property names alphabetically. Fix a bug where the outlines would draw underneath the document.
+- Improved performance when using fonts with kerning.
 
 
 ### Bug fixes
 ### Bug fixes
 
 
 - Fix some situations where `text-decoration` would not be rendered. [#119](https://github.com/mikke89/RmlUi/issues/119).
 - Fix some situations where `text-decoration` would not be rendered. [#119](https://github.com/mikke89/RmlUi/issues/119).
-- Changing the `fill-image` property of \<progressbar\> elements now actually updates the image.
 - Fix a bug where font textures were leaked on `Rml::Shutdown()`. [#133](https://github.com/mikke89/RmlUi/issues/133)
 - Fix a bug where font textures were leaked on `Rml::Shutdown()`. [#133](https://github.com/mikke89/RmlUi/issues/133)
 - Fixed building with MinGW, and added it to the CI to avoid future breaks. [#108](https://github.com/mikke89/RmlUi/pull/108) (thanks @cloudwu).
 - Fixed building with MinGW, and added it to the CI to avoid future breaks. [#108](https://github.com/mikke89/RmlUi/pull/108) (thanks @cloudwu).
 - Fixed several compilation issues and warnings. [#118](https://github.com/mikke89/RmlUi/issues/118) [#97](https://github.com/mikke89/RmlUi/pull/97) [#157](https://github.com/mikke89/RmlUi/pull/157) (thanks @SpaceCat-Chan and @LWSS).
 - Fixed several compilation issues and warnings. [#118](https://github.com/mikke89/RmlUi/issues/118) [#97](https://github.com/mikke89/RmlUi/pull/97) [#157](https://github.com/mikke89/RmlUi/pull/157) (thanks @SpaceCat-Chan and @LWSS).
 - Fix \<textarea\> getting an unnecessary horizontal scrollbar. [#122](https://github.com/mikke89/RmlUi/issues/122)
 - Fix \<textarea\> getting an unnecessary horizontal scrollbar. [#122](https://github.com/mikke89/RmlUi/issues/122)
+- Fix text position changing in input fields when selecting text and font has kerning.
 - Fix text-decoration not always being regenerated. [#119](https://github.com/mikke89/RmlUi/issues/119)
 - Fix text-decoration not always being regenerated. [#119](https://github.com/mikke89/RmlUi/issues/119)
 
 
 ### Deprecated functionality
 ### Deprecated functionality