Skip to content

Commit

Permalink
Add template for adding child with wrapper and alignment (rzNz0819r5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Box-Coder committed May 7, 2023
1 parent 7c43c1b commit 1ad929c
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 64 deletions.
75 changes: 74 additions & 1 deletion Include/ssGUI/DataClasses/Hierarchy.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef SSGUI_HIERARCHY_H
#define SSGUI_HIERARCHY_H

#include "ssGUI/Enums/AlignmentHorizontal.hpp"
#include "ssGUI/Enums/AlignmentVertical.hpp"
#include "ssGUI/Factory.hpp"
#include "ssGUI/DataClasses/ObjectsReferences.hpp"
#include <vector>
Expand Down Expand Up @@ -120,6 +122,19 @@ namespace ssGUI
Hierarchy(Hierarchy const& other);

virtual void NotifyAndRemoveOnObjectDestroyEventCallbackIfExist();

void AddChild(ssGUI::GUIObject* guiObject, bool compositeChild);
void AddChild( ssGUI::GUIObject* guiObject,
ssGUI::Enums::AlignmentHorizontal horizontalAlignment,
ssGUI::Enums::AlignmentVertical verticalAlignment,
bool compositeChild);

void AddChildWithWrapper(ssGUI::GUIObject* guiObject, bool compositeChild);

void AddChildWithWrapper( ssGUI::GUIObject* guiObject,
ssGUI::Enums::AlignmentHorizontal horizontalAlignment,
ssGUI::Enums::AlignmentVertical verticalAlignment,
bool compositeChild);

public:
Hierarchy();
Expand Down Expand Up @@ -147,7 +162,7 @@ namespace ssGUI
if(std::is_base_of<ssGUI::GUIObject, T>::value)
{
auto* guiObject = ssGUI::Factory::Create<T>();
guiObject->SetParent(CurrentObject);
AddChild(guiObject, compositeChild);
return guiObject;
}
else
Expand All @@ -157,6 +172,64 @@ namespace ssGUI
}
}

//function: AddChild
//Same as above but with <AdvancedPosition: ssGUI::Extensions::AdvancedPosition> extension added
template<typename T>
T* AddChild(ssGUI::Enums::AlignmentHorizontal horizontalAlignment,
ssGUI::Enums::AlignmentVertical verticalAlignment,
bool compositeChild = false)
{
if(std::is_base_of<ssGUI::GUIObject, T>::value)
{
auto* guiObject = ssGUI::Factory::Create<T>();
AddChild(guiObject, horizontalAlignment, verticalAlignment, compositeChild);
return guiObject;
}
else
{
ssGUI_WARNING(ssGUI_DATA_TAG, "You cannot add non GUI object");
return nullptr;
}
}

//function: AddChildWithWrapper
//Same as <AddChild> but with empty GUI object as a wrapper
template<typename T>
T* AddChildWithWrapper(bool compositeChild = false)
{
if(std::is_base_of<ssGUI::GUIObject, T>::value)
{
auto* guiObject = ssGUI::Factory::Create<T>();
AddChildWithWrapper(guiObject, compositeChild);
return guiObject;
}
else
{
ssGUI_WARNING(ssGUI_DATA_TAG, "You cannot add non GUI object");
return nullptr;
}
}

//function: AddChildWithWrapper
//Same as above but with <AdvancedPosition: ssGUI::Extensions::AdvancedPosition> extension added
template<typename T>
T* AddChildWithWrapper( ssGUI::Enums::AlignmentHorizontal horizontalAlignment,
ssGUI::Enums::AlignmentVertical verticalAlignment,
bool compositeChild = false)
{
if(std::is_base_of<ssGUI::GUIObject, T>::value)
{
auto* guiObject = ssGUI::Factory::Create<T>();
AddChildWithWrapper(guiObject, horizontalAlignment, verticalAlignment, compositeChild);
return guiObject;
}
else
{
ssGUI_WARNING(ssGUI_DATA_TAG, "You cannot add non GUI object");
return nullptr;
}
}

//function: IsChildComposite
//True if the current child (see <FindChild>) belongs to this composite object
virtual bool IsChildComposite() const;
Expand Down
32 changes: 0 additions & 32 deletions Include/ssGUI/Extensions/Layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,38 +273,6 @@ namespace Extensions
//If a GUI Object is excluded, it will be ignored
virtual void UnexcludeObject(ssGUI::GUIObject* obj);

//function: AddChildWithWrapper
//Add a child to container with wrapper
//
//parameters:
//child - The child <GUIObject> that you wish to parent to the <GUIObject> this extension has attached to
//
//returns:
//The wrapper <GUIObject> that contains the *child*.
//This will be nullptr if this extension is not attached to a GUI object.
virtual ssGUI::GUIObject* AddChildWithWrapper(ssGUI::GUIObject* child);

/*function: AddChildWithAlignment
This is equivilent to:
========================= c++ =========================
ssGUI::GUIObject* wrapper = AddChildWithWrapper(child);
if(wrapper != nullptr)
{
if(!child->IsAnyExtensionExist<ssGUI::Extensions::AdvancedPosition>())
child->AddExtension(ssGUI::Factory::Create<ssGUI::Extensions::AdvancedPosition>());
ssGUI::Extensions::AdvancedPosition* ap = child->GetAnyExtension<ssGUI::Extensions::AdvancedPosition>();
ap->SetHorizontalAlignment(horizontal);
ap->SetVerticalAlignment(vertical);
}
return wrapper;
=======================================================
*/
virtual ssGUI::GUIObject* AddChildWithAlignment(ssGUI::GUIObject* child, ssGUI::Enums::AlignmentHorizontal horizontal, ssGUI::Enums::AlignmentVertical vertical);

//function: Internal_OnRecursiveChildAdded
//(Internal ssGUI function) Listener function when a child is being added
virtual void Internal_OnRecursiveChildAdded(ssGUI::GUIObject* child);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions Src/ssGUI/DataClasses/Hierarchy.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "ssGUI/DataClasses/Hierarchy.hpp"

#include "ssGUI/Extensions/AdvancedPosition.hpp"
#include "ssGUI/GUIObjectClasses/GUIObject.hpp"
#include "ssGUI/DataClasses/EventCallbackManager.hpp"
#include "ssGUI/DataClasses/Renderer.hpp"
Expand Down Expand Up @@ -47,6 +48,38 @@ namespace ssGUI
}
ssLOG_FUNC_EXIT();
}

void Hierarchy::AddChild(ssGUI::GUIObject* guiObject,bool compositeChild)
{
guiObject->SetParent(CurrentObject, compositeChild);
}

void Hierarchy::AddChild( ssGUI::GUIObject* guiObject,
ssGUI::Enums::AlignmentHorizontal horizontalAlignment,
ssGUI::Enums::AlignmentVertical verticalAlignment,
bool compositeChild)
{
AddChild(guiObject, compositeChild);
auto* ap = guiObject->AddExtension<ssGUI::Extensions::AdvancedPosition>();
ap->SetAlignment(horizontalAlignment, verticalAlignment);
}

void Hierarchy::AddChildWithWrapper(ssGUI::GUIObject* guiObject, bool compositeChild)
{
auto* wrapper = ssGUI::Create<ssGUI::GUIObject>();
AddChild(wrapper, compositeChild);
wrapper->AddChild(guiObject, compositeChild);
}

void Hierarchy::AddChildWithWrapper(ssGUI::GUIObject* guiObject,
ssGUI::Enums::AlignmentHorizontal horizontalAlignment,
ssGUI::Enums::AlignmentVertical verticalAlignment,
bool compositeChild)
{
AddChildWithWrapper(guiObject, compositeChild);
auto* ap = guiObject->AddExtension<ssGUI::Extensions::AdvancedPosition>();
ap->SetAlignment(horizontalAlignment, verticalAlignment);
}

Hierarchy::Hierarchy() : Parent(-1),
Children(),
Expand Down
31 changes: 0 additions & 31 deletions Src/ssGUI/Extensions/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,37 +979,6 @@ namespace Extensions
}
}

ssGUI::GUIObject* Layout::AddChildWithWrapper(ssGUI::GUIObject* child)
{
if(Container == nullptr)
return nullptr;

ssGUI::GUIObject* wrapper = ssGUI::Factory::Create<ssGUI::GUIObject>();
wrapper->SetParent(Container);
wrapper->SetUserCreated(false);

child->SetParent(wrapper);
return wrapper;
}

ssGUI::GUIObject* Layout::AddChildWithAlignment(ssGUI::GUIObject* child, ssGUI::Enums::AlignmentHorizontal horizontal, ssGUI::Enums::AlignmentVertical vertical)
{
ssGUI::GUIObject* wrapper = AddChildWithWrapper(child);

if(wrapper != nullptr)
{
if(!child->IsAnyExtensionExist<ssGUI::Extensions::AdvancedPosition>())
child->AddExtension<ssGUI::Extensions::AdvancedPosition>();

ssGUI::Extensions::AdvancedPosition* ap = child->GetAnyExtension<ssGUI::Extensions::AdvancedPosition>();

ap->SetHorizontalAlignment(horizontal);
ap->SetVerticalAlignment(vertical);
}

return wrapper;
}

void Layout::Internal_OnRecursiveChildAdded(ssGUI::GUIObject* child)
{
ssLOG_FUNC_ENTRY();
Expand Down

0 comments on commit 1ad929c

Please sign in to comment.