Skip to content

Commit

Permalink
use ranges::rotate to reorder clicked context
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisFloofyKitsune committed Nov 7, 2024
1 parent a838b90 commit c1b055a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions rts/Rml/Backends/RmlUi_Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,14 @@ void RmlGui::Update()
for (const auto& context : state->contexts) {
context->Update();
}


// move clicked context to top
if (state->clicked_context) {
auto context_pos = std::ranges::find(state->contexts, state->clicked_context);
if (context_pos != state->contexts.end()) {
// debug context is always to be on top
auto start = state->contexts.begin() + (state->debug_host_context ? 1 : 0);
if (context_pos != start) {
state->contexts.erase(context_pos);
state->contexts.insert(start, state->clicked_context);
}
// debug context is always to be at index 0 so it renders on top
auto start = state->contexts.begin() + (state->debug_host_context ? 1 : 0);
auto context_pos = std::ranges::find(start, state->contexts.end(), state->clicked_context);
if (context_pos != start && context_pos != state->contexts.end()) {
std::ranges::rotate(start, context_pos, context_pos + 1);
}
state->clicked_context = nullptr;
}
Expand Down

0 comments on commit c1b055a

Please sign in to comment.