Skip to content

Commit

Permalink
Keep modal state when using the focus flags in ElementDocument::Show …
Browse files Browse the repository at this point in the history
…(see #40)
  • Loading branch information
mikke89 committed Sep 14, 2019
1 parent f139eb6 commit 684b632
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Include/RmlUi/Core/ElementDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class StyleSheet;

/**
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.
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.
Expand Down
11 changes: 9 additions & 2 deletions Source/Core/ElementDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ void ElementDocument::PushToBack()

void ElementDocument::Show(FocusFlag focus_flag)
{
modal = false;
bool autofocus = false;
bool focus = false;
bool focus_previous = false;

switch (focus_flag)
{
case FocusFlag::None:
modal = false;
break;
case FocusFlag::Focus:
focus = true;
Expand Down Expand Up @@ -341,7 +341,7 @@ ElementPtr ElementDocument::CreateTextNode(const String& text)
// Is the current document modal
bool ElementDocument::IsModal() const
{
return modal && IsVisible();
return modal;
}

// Default load script implementation
Expand Down Expand Up @@ -445,6 +445,13 @@ void ElementDocument::OnPropertyChange(const PropertyIdSet& 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 (changed_properties.Contains(PropertyId::FontSize))
GetStyle()->DirtyPropertiesWithUnitRecursive(Property::REM);
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

None: No focus.
None: No focus, remove modal state.
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.
FocusPrevious: Focus the previously focused element in the document.
Expand Down

0 comments on commit 684b632

Please sign in to comment.