Browse Source

Keep modal state when using the focus flags in ElementDocument::Show (see #40)

Michael Ragazzon 6 years ago
parent
commit
684b632f07
3 changed files with 11 additions and 4 deletions
  1. 1 1
      Include/RmlUi/Core/ElementDocument.h
  2. 9 2
      Source/Core/ElementDocument.cpp
  3. 1 1
      readme.md

+ 1 - 1
Include/RmlUi/Core/ElementDocument.h

@@ -42,7 +42,7 @@ class StyleSheet;
 
 
 /**
 /**
 	Flags used for displaying the document.
 	Flags used for displaying the document.
-	   None: No focus.
+	   None: No focus, remove modal state.
 	   Focus: Focus the first tab element with the 'autofocus' attribute or else the document.
 	   Focus: Focus the first tab element with the 'autofocus' attribute or else the document.
 	   Modal: Focus the first tab element with the 'autofocus' attribute or else the document, other documents cannot receive focus.
 	   Modal: Focus the first tab element with the 'autofocus' attribute or else the document, other documents cannot receive focus.
 	   FocusPrevious: Focus the previously focused element in the document.
 	   FocusPrevious: Focus the previously focused element in the document.

+ 9 - 2
Source/Core/ElementDocument.cpp

@@ -206,7 +206,6 @@ void ElementDocument::PushToBack()
 
 
 void ElementDocument::Show(FocusFlag focus_flag)
 void ElementDocument::Show(FocusFlag focus_flag)
 {
 {
-	modal = false;
 	bool autofocus = false;
 	bool autofocus = false;
 	bool focus = false;
 	bool focus = false;
 	bool focus_previous = false;
 	bool focus_previous = false;
@@ -214,6 +213,7 @@ void ElementDocument::Show(FocusFlag focus_flag)
 	switch (focus_flag)
 	switch (focus_flag)
 	{
 	{
 	case FocusFlag::None:
 	case FocusFlag::None:
+		modal = false;
 		break;
 		break;
 	case FocusFlag::Focus:
 	case FocusFlag::Focus:
 		focus = true;
 		focus = true;
@@ -341,7 +341,7 @@ ElementPtr ElementDocument::CreateTextNode(const String& text)
 // Is the current document modal
 // Is the current document modal
 bool ElementDocument::IsModal() const
 bool ElementDocument::IsModal() const
 {
 {
-	return modal && IsVisible();
+	return modal;
 }
 }
 
 
 // Default load script implementation
 // Default load script implementation
@@ -445,6 +445,13 @@ void ElementDocument::OnPropertyChange(const PropertyIdSet& changed_properties)
 {
 {
 	Element::OnPropertyChange(changed_properties);
 	Element::OnPropertyChange(changed_properties);
 
 
+	if (changed_properties.Contains(PropertyId::Visibility) ||
+		changed_properties.Contains(PropertyId::Display))
+	{
+		if (!IsVisible())
+			modal = false;
+	}
+
 	// If the document's font-size has been changed, we need to dirty all rem properties.
 	// If the document's font-size has been changed, we need to dirty all rem properties.
 	if (changed_properties.Contains(PropertyId::FontSize))
 	if (changed_properties.Contains(PropertyId::FontSize))
 		GetStyle()->DirtyPropertiesWithUnitRecursive(Property::REM);
 		GetStyle()->DirtyPropertiesWithUnitRecursive(Property::REM);

+ 1 - 1
readme.md

@@ -280,7 +280,7 @@ Elements with property `tab-index: auto;` and the `autofocus` attribute set on t
 ```
 ```
 enum class FocusFlag { None, Focus, Modal, FocusPrevious, ModalPrevious, FocusDocument, ModalDocument };
 enum class FocusFlag { None, Focus, Modal, FocusPrevious, ModalPrevious, FocusDocument, ModalDocument };
 
 
-None: No focus.
+None: No focus, remove modal state.
 Focus: Focus the first tab element with the 'autofocus' attribute or else the document.
 Focus: Focus the first tab element with the 'autofocus' attribute or else the document.
 Modal: Focus the first tab element with the 'autofocus' attribute or else the document, other documents cannot receive focus.
 Modal: Focus the first tab element with the 'autofocus' attribute or else the document, other documents cannot receive focus.
 FocusPrevious: Focus the previously focused element in the document.
 FocusPrevious: Focus the previously focused element in the document.