-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RmlUI Context handling improvements #1761
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,6 +308,34 @@ void RmlGui::OnContextDestroy(Rml::Context* context) | |
state->contexts.erase(std::ranges::find(state->contexts, context)); | ||
} | ||
|
||
Rml::Context* RmlGui::GetOrCreateContext(const std::string& name) | ||
{ | ||
if (!RmlInitialized()) { | ||
return nullptr; | ||
} | ||
|
||
Rml::Context* context = Rml::GetContext(name); | ||
if (context == nullptr) { | ||
context = Rml::CreateContext(name, {0, 0}); | ||
} else if (state->contexts_to_remove.contains(context)) { | ||
state->contexts_to_remove.erase(context); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could do without the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't realize I could do that |
||
} | ||
|
||
return context; | ||
} | ||
|
||
Rml::Context* RmlGui::GetContext(const std::string& name) { | ||
if (!RmlInitialized()) { | ||
return nullptr; | ||
} | ||
|
||
Rml::Context* context = Rml::GetContext(name); | ||
if (context != nullptr && !state->contexts_to_remove.contains(context)) { | ||
return context; | ||
} | ||
return nullptr; | ||
} | ||
|
||
void RmlGui::MarkContextForRemoval(Rml::Context *context) { | ||
if (!RmlInitialized() || context == nullptr) { | ||
return; | ||
|
@@ -326,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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.