Skip to content

Commit

Permalink
fix: set visibility of all child components (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamajammary committed Jun 8, 2024
1 parent 0664514 commit 236d2c6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/LSG_Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,11 @@ void LSG_Component::SetSpacing(int spacing)
{
LSG_XML::SetAttribute(this->xmlNode, "spacing", std::to_string(spacing));
}

void LSG_Component::SetVisible(bool visible)
{
this->visible = visible;

for (auto child : this->GetChildren())
child->SetVisible(visible);
}
1 change: 1 addition & 0 deletions src/LSG_Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class LSG_Component : public LSG_IRenderable
void SetSizeFixed();
void SetSizePercent(LSG_Component* parent);
void SetSpacing(int spacing);
void SetVisible(bool visible);

protected:
void destroyTextures();
Expand Down
15 changes: 2 additions & 13 deletions src/LSG_Modal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bool LSG_Modal::CloseOnMouseClick(const SDL_Point& mousePosition)
bool close = (clickedCloseIcon || clickedOutside);

if (close)
LSG_Modal::SetVisible(this, false);
this->SetVisible(false);

return close;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ bool LSG_Modal::OnKeyDown(const SDL_KeyboardEvent& event)
if (!this->visible || this->hideCloseIcon || (event.keysym.sym != SDLK_ESCAPE))
return false;

LSG_Modal::SetVisible(this, false);
this->SetVisible(false);

return true;
}
Expand Down Expand Up @@ -293,14 +293,3 @@ void LSG_Modal::setTextures(const LSG_UMapStrStr& attributes)

this->textures[LSG_MODAL_TEXTURE_TITLE] = this->getTexture(title, fontSize);
}

void LSG_Modal::SetVisible(LSG_Component* component, bool visible)
{
if (!component)
return;

component->visible = visible;

for (auto child : component->GetChildren())
LSG_Modal::SetVisible(child, visible);
}
1 change: 0 additions & 1 deletion src/LSG_Modal.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class LSG_Modal : public LSG_Text

public:
static bool IsModalChild(LSG_Component* component);
static void SetVisible(LSG_Component* component, bool visible);

public:
bool CloseOnMouseClick(const SDL_Point& mousePosition);
Expand Down
5 changes: 1 addition & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,10 +1474,7 @@ void LSG_SetVisible(const std::string& id, bool visible)
if (!component)
throw std::invalid_argument(getErrorNoID("", id));

if (component->IsModal())
LSG_Modal::SetVisible(component, visible);
else
component->visible = visible;
component->SetVisible(visible);

LSG_UI::LayoutRoot();
}
Expand Down

0 comments on commit 236d2c6

Please sign in to comment.