refactor(editor): streamline ImGui card management across various editors
- Refactored multiple editor classes to ensure that ImGui::End() is always called after ImGui::Begin(), enhancing state management and preventing potential rendering issues. - Updated the DungeonEditor, GraphicsEditor, ScreenEditor, MessageEditor, MusicEditor, and SpriteEditor to follow this pattern, improving code consistency and reliability. Benefits: - Improves the stability of the editor UI by ensuring proper handling of ImGui state. - Enhances code readability and maintainability by standardizing the usage of ImGui functions across different editor components.
This commit is contained in:
@@ -250,12 +250,14 @@ void EditorCard::SetPosition(Position pos) {
|
||||
bool EditorCard::Begin(bool* p_open) {
|
||||
// Check visibility flag first - if provided and false, don't show the card
|
||||
if (p_open && !*p_open) {
|
||||
imgui_begun_ = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Handle icon-collapsed state
|
||||
if (icon_collapsible_ && collapsed_to_icon_) {
|
||||
DrawFloatingIconButton();
|
||||
imgui_begun_ = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -320,6 +322,9 @@ bool EditorCard::Begin(bool* p_open) {
|
||||
closable_ ? actual_p_open : nullptr,
|
||||
flags);
|
||||
|
||||
// Mark that ImGui::Begin() was called - End() must always be called now
|
||||
imgui_begun_ = true;
|
||||
|
||||
// Register card window for test automation
|
||||
if (ImGui::GetCurrentWindow() && ImGui::GetCurrentWindow()->ID != 0) {
|
||||
std::string card_path = absl::StrFormat("EditorCard:%s", title_.c_str());
|
||||
@@ -332,12 +337,16 @@ bool EditorCard::Begin(bool* p_open) {
|
||||
}
|
||||
|
||||
void EditorCard::End() {
|
||||
// Check if window was focused this frame
|
||||
focused_ = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows);
|
||||
|
||||
ImGui::End();
|
||||
ImGui::PopStyleColor(2);
|
||||
ImGui::PopStyleVar(2);
|
||||
// Only call ImGui::End() and pop styles if ImGui::Begin() was called
|
||||
if (imgui_begun_) {
|
||||
// Check if window was focused this frame
|
||||
focused_ = ImGui::IsWindowFocused(ImGuiFocusedFlags_ChildWindows);
|
||||
|
||||
ImGui::End();
|
||||
ImGui::PopStyleColor(2);
|
||||
ImGui::PopStyleVar(2);
|
||||
imgui_begun_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void EditorCard::Focus() {
|
||||
|
||||
@@ -98,9 +98,9 @@ class Toolset {
|
||||
* tile_card.SetPosition(CardPosition::Right);
|
||||
*
|
||||
* if (tile_card.Begin()) {
|
||||
* // Draw tile selector content
|
||||
* tile_card.End();
|
||||
* // Draw tile selector content when visible
|
||||
* }
|
||||
* tile_card.End(); // Always call End() after Begin()
|
||||
* ```
|
||||
*/
|
||||
class EditorCard {
|
||||
@@ -154,6 +154,7 @@ class EditorCard {
|
||||
bool first_draw_ = true;
|
||||
bool focused_ = false;
|
||||
bool* p_open_ = nullptr;
|
||||
bool imgui_begun_ = false; // Track if ImGui::Begin() was called
|
||||
|
||||
// UX enhancements
|
||||
bool headless_ = false; // Minimal chrome, no title bar
|
||||
|
||||
Reference in New Issue
Block a user