Skip to content

Commit

Permalink
Add Get() checks for the menu and menubar visibility toggles to make …
Browse files Browse the repository at this point in the history
…sure they're registered before toggling.

Rename `GuiElement::SetVisiblity` to `GuiElement::SetVisibility`.
  • Loading branch information
Malkierian committed Aug 27, 2024
1 parent b59bf87 commit f1fcbf7
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/window/gui/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,14 @@ void Gui::DrawMenu() {
if (ImGui::IsKeyPressed(TOGGLE_BTN) || ImGui::IsKeyPressed(ImGuiKey_Escape) ||
(ImGui::IsKeyPressed(TOGGLE_PAD_BTN) && CVarGetInteger(CVAR_IMGUI_CONTROLLER_NAV, 0))) {
if (ImGui::IsKeyPressed(TOGGLE_BTN) || (ImGui::IsKeyPressed(TOGGLE_PAD_BTN) && !GetPadBtnTogglesMenu())) {
GetMenuBar()->ToggleVisibility();
if (GetMenuBar()) {
GetMenuBar()->ToggleVisibility();
}
} else if (ImGui::IsKeyPressed(ImGuiKey_Escape) ||
(ImGui::IsKeyPressed(TOGGLE_PAD_BTN) && GetPadBtnTogglesMenu())) {
GetMenu()->ToggleVisibility();
if (GetMenu()) {
GetMenu()->ToggleVisibility();
}
}
if (wnd->IsFullscreen()) {
Context::GetInstance()->GetWindow()->SetCursorVisibility(GetMenuOrMenubarVisible() ||
Expand Down
8 changes: 4 additions & 4 deletions src/window/gui/GuiElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ void GuiElement::Update() {
UpdateElement();
}

void GuiElement::SetVisiblity(bool visible) {
void GuiElement::SetVisibility(bool visible) {
mIsVisible = visible;
}

void GuiElement::Show() {
SetVisiblity(true);
SetVisibility(true);
}

void GuiElement::Hide() {
SetVisiblity(false);
SetVisibility(false);
}

void GuiElement::ToggleVisibility() {
SetVisiblity(!IsVisible());
SetVisibility(!IsVisible());
}

bool GuiElement::IsVisible() {
Expand Down
2 changes: 1 addition & 1 deletion src/window/gui/GuiElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GuiElement {
virtual void InitElement() = 0;
virtual void UpdateElement() = 0;

virtual void SetVisiblity(bool visible);
virtual void SetVisibility(bool visible);
bool mIsVisible;

private:
Expand Down
2 changes: 1 addition & 1 deletion src/window/gui/GuiMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void GuiMenuBar::SyncVisibilityConsoleVariable() {
}
}

void GuiMenuBar::SetVisiblity(bool visible) {
void GuiMenuBar::SetVisibility(bool visible) {
mIsVisible = visible;
SyncVisibilityConsoleVariable();
}
Expand Down
2 changes: 1 addition & 1 deletion src/window/gui/GuiMenuBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GuiMenuBar : public GuiElement {
void Draw() override;

protected:
void SetVisiblity(bool visible) override;
void SetVisibility(bool visible) override;

private:
void SyncVisibilityConsoleVariable();
Expand Down
2 changes: 1 addition & 1 deletion src/window/gui/GuiWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GuiWindow::GuiWindow(const std::string& consoleVariable, const std::string& name
: GuiWindow(consoleVariable, false, name, ImVec2{ -1, -1 }, ImGuiWindowFlags_None) {
}

void GuiWindow::SetVisiblity(bool visible) {
void GuiWindow::SetVisibility(bool visible) {
mIsVisible = visible;
SyncVisibilityConsoleVariable();
}
Expand Down
2 changes: 1 addition & 1 deletion src/window/gui/GuiWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GuiWindow : public GuiElement {
std::string GetName();

protected:
void SetVisiblity(bool visible) override;
void SetVisibility(bool visible) override;
void BeginGroupPanel(const char* name, const ImVec2& size);
void EndGroupPanel(float minHeight);
void SyncVisibilityConsoleVariable();
Expand Down

0 comments on commit f1fcbf7

Please sign in to comment.