Переглянути джерело

Element 'select': Respect 'height' property on selectbox set by user in style sheet.

Michael Ragazzon 5 роки тому
батько
коміт
62458e03dc
2 змінених файлів з 8 додано та 10 видалено
  1. 8 6
      Source/Controls/WidgetDropDown.cpp
  2. 0 4
      changelog.md

+ 8 - 6
Source/Controls/WidgetDropDown.cpp

@@ -98,13 +98,14 @@ void WidgetDropDown::OnRender()
 		// The following procedure should ensure that the selection box is never (partly) outside of the context's window.
 		// This is achieved by positioning the box either above or below the 'select' element, and possibly shrinking
 		// the element's height.
+		// We try to respect user values of 'height', 'min-height', and 'max-height'. However, when we need to shrink the box
+		// we will override the 'height' property.
 		using Rml::Core::Vector2f;
 
-		// The procedure below assumes that the 'height' property is set to 'auto'.
-		// Note that we do respect the 'max-height' if set by the user.
-		if(selection_element->GetComputedValues().height.type != Core::Style::Height::Auto)
+		// Previously set 'height' property from this procedure must be removed for the calculations below to work as intended.
+		if(selection_element->GetLocalStyleProperties().count(Core::PropertyId::Height) == 1)
 		{
-			selection_element->SetProperty(Core::PropertyId::Height, Core::Property(Core::Style::Height::Auto));
+			selection_element->RemoveProperty(Core::PropertyId::Height);
 			selection_element->GetOwnerDocument()->UpdateDocument();
 		}
 
@@ -126,8 +127,8 @@ void WidgetDropDown::OnRender()
 		const float height_below = window_height - absolute_y - offset_y_below;
 		const float height_above = absolute_y + offset_y_above;
 
-		// Format the selection box and retrieve the 'native' height occupied by all the options, but limited
-		// by 'max-height' if set by the user.
+		// Format the selection box and retrieve the 'native' height occupied by all the options, while respecting
+		// the 'min/max-height' properties.
 		Core::ElementUtilities::FormatElement(selection_element, parent_element->GetBox().GetSize(Core::Box::BORDER));
 		const float content_height = selection_element->GetOffsetHeight();
 
@@ -526,6 +527,7 @@ void WidgetDropDown::ShowSelectBox(bool show)
 	else
 	{
 		selection_element->SetProperty(Core::PropertyId::Visibility, Core::Property(Core::Style::Visibility::Hidden));
+		selection_element->RemoveProperty(Core::PropertyId::Height);
 		value_element->SetPseudoClass("checked", false);
 		button_element->SetPseudoClass("checked", false);
 		DetachScrollEvent();

+ 0 - 4
changelog.md

@@ -40,10 +40,6 @@ The library now makes use of CMake's precompiled header support (requires CMake
 - Changes to font effects are now properly applied whenever the `font-effect` property is changed [#98](https://github.com/mikke89/RmlUi/issues/98).
 - Fix structural pseudo-selectors only being applied if written with parenthesis [#30](https://github.com/mikke89/RmlUi/issues/30#issuecomment-597648310).
 
-### Breaking changes
-
-- The `height` property of `selectbox` will no longer take any effect. Note that `max-height` can still be used.
-
 
 ## RmlUi 3.2