Skip to content

Commit

Permalink
Update drop down and slider navigation behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Oct 18, 2023
1 parent 89a58f5 commit 2bd7018
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
26 changes: 19 additions & 7 deletions Source/Core/Elements/WidgetDropDown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void WidgetDropDown::SetSelection(Element* select_option, bool force)
value_rml_dirty = true;
}

bool WidgetDropDown::SeekSelection(bool seek_forward)
void WidgetDropDown::SeekSelection(bool seek_forward)
{
const int selected_option = GetSelection();
const int num_options = selection_element->GetNumChildren();
Expand All @@ -347,12 +347,11 @@ bool WidgetDropDown::SeekSelection(bool seek_forward)
if (!element->HasAttribute("disabled") && element->IsVisible())
{
SetSelection(element);
return true;
return;
}
}

// No valid option found, leave selection unchanged.
return false;
}

int WidgetDropDown::GetSelection() const
Expand Down Expand Up @@ -553,15 +552,28 @@ void WidgetDropDown::ProcessEvent(Event& event)
{
Input::KeyIdentifier key_identifier = (Input::KeyIdentifier)event.GetParameter<int>("key_identifier", 0);

auto HasNavigation = [this](PropertyId id) {
if (const Property* p = parent_element->GetProperty(id))
{
if (p->unit != Unit::KEYWORD || static_cast<Style::Nav>(p->Get<int>()) != Style::Nav::None)
return true;
}
return false;
};

switch (key_identifier)
{
case Input::KI_UP:
if (SeekSelection(false))
event.StopPropagation();
if (!box_visible && HasNavigation(PropertyId::NavUp))
break;
SeekSelection(false);
event.StopPropagation();
break;
case Input::KI_DOWN:
if (SeekSelection(true))
event.StopPropagation();
if (!box_visible && HasNavigation(PropertyId::NavDown))
break;
SeekSelection(true);
event.StopPropagation();
break;
case Input::KI_RETURN:
case Input::KI_NUMPADENTER:
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/Elements/WidgetDropDown.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ class WidgetDropDown : public EventListener {
void SetSelection(Element* option_element, bool force = false);
/// Seek to the next or previous valid (visible and not disabled) option.
/// @param[in] seek_forward True to select the next valid option, false to select the previous valid option.
/// @return True if selection changed.
bool SeekSelection(bool seek_forward = true);
void SeekSelection(bool seek_forward = true);
/// Returns the index of the currently selected item.
int GetSelection() const;

Expand Down
4 changes: 1 addition & 3 deletions Source/Core/Elements/WidgetSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,8 @@ void WidgetSlider::ProcessEvent(Event& event)

if (increment || decrement)
{
const float unclamped_bar_position = bar_position;
SetBarPosition(decrement ? OnLineDecrement() : OnLineIncrement());
if (unclamped_bar_position == bar_position)
event.StopPropagation();
event.StopPropagation();
}
}
break;
Expand Down

0 comments on commit 2bd7018

Please sign in to comment.