Skip to content

Commit

Permalink
Fixed SetDropdownMenu (ByOANC07U4) and added ClearMenuItems to Menu...
Browse files Browse the repository at this point in the history
Fixed SetDropdownMenu not copying menu items properly (ByOANC07U4),
Added ClearMenuItems to Menu (dp8btys7DG)
  • Loading branch information
Neko-Box-Coder committed May 14, 2023
1 parent 9786337 commit 846dd4a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
5 changes: 4 additions & 1 deletion Include/ssGUI/GUIObjectClasses/CompositeClasses/Dropdown.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ namespace ssGUI
virtual ssGUI::Menu* GetDropdownMenu();

//function: SetDropdownMenu
//Sets the dropdown menu GUI object
//Sets the dropdown menu GUI object.
//The menu items in the new menu will be cleared
//and all the menu items from the old dropdown menu will moved to the new one.
//Passing nullptr will unset the dropdown menu object.
virtual void SetDropdownMenu(ssGUI::Menu* menu);

//function: GetType
Expand Down
4 changes: 4 additions & 0 deletions Include/ssGUI/GUIObjectClasses/Menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ namespace ssGUI
//function: RemoveMenuItem
//Deletes the menu item
void RemoveMenuItem(ssGUI::MenuItem* menuItem);

//function: ClearMenuItems
//Deletes all the menu items
void ClearMenuItems();

//function: AddMenuItem
//This is equivalent to
Expand Down
16 changes: 5 additions & 11 deletions Src/ssGUI/GUIObjectClasses/CompositeClasses/Dropdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,10 @@ namespace ssGUI

void Dropdown::ClearItems()
{
for(int i = 0; i < Items.size(); i++)
{
ssGUI::MenuItem* currentItem = static_cast<ssGUI::MenuItem*>(CurrentObjectsReferences.GetObjectReference(Items[i].second));
if(GetDropdownMenu() != nullptr)
GetDropdownMenu()->ClearMenuItems();

if(currentItem == nullptr)
continue;

currentItem->Delete();
}
Items.clear();

SetSelectedItem(-1);
}

Expand Down Expand Up @@ -314,11 +307,12 @@ namespace ssGUI
glm::vec2 globalPos = menu->GetGlobalPosition();
menu->SetParent(this, true);
menu->SetGlobalPosition(globalPos);
menu->ClearMenuItems();

auto itemsCopy = Items;
Items.clear();
for(int i = 0; i < Items.size(); i++)
AddItem(Items[i].first);
for(int i = 0; i < itemsCopy.size(); i++)
AddItem(itemsCopy[i].first);
}

ssGUI::Enums::GUIObjectType Dropdown::GetType() const
Expand Down
11 changes: 11 additions & 0 deletions Src/ssGUI/GUIObjectClasses/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ namespace ssGUI
SetSize(glm::vec2(GetSize().x, GetSize().y - itemSize.y - layoutItemSpacing));
}

void Menu::ClearMenuItems()
{
std::vector<ssGUI::GUIObject*> children = GetListOfChildren();

for(int i = 0; i < children.size(); i++)
{
if(children[i]->GetType() == ssGUI::Enums::GUIObjectType::MENU_ITEM)
RemoveMenuItem(static_cast<ssGUI::MenuItem*>(children[i]));
}
}

ssGUI::MenuItem* Menu::AddMenuItem()
{
ssGUI::MenuItem* menuItem = AddChild<ssGUI::MenuItem>();
Expand Down

0 comments on commit 846dd4a

Please sign in to comment.