Skip to content

Commit

Permalink
Standard Checkbox (IO4b10Mdn1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Box-Coder committed Aug 30, 2023
1 parent fddfe97 commit d244e97
Show file tree
Hide file tree
Showing 6 changed files with 304 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Include/ssGUI/Enums/GUIObjectType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ namespace Enums
SCROLLBAR = 1 << 14,
IMAGE_CANVAS = 1 << 15,
STANDARD_SLIDER = 1 << 16,
COUNT = 1 << 17
STANDARD_CHECKBOX = 1 << 17,
COUNT = 1 << 18
};

inline ssGUI::Enums::GUIObjectType operator|(ssGUI::Enums::GUIObjectType a, ssGUI::Enums::GUIObjectType b)
Expand All @@ -97,7 +98,7 @@ namespace Enums
{
inline std::string InternalGUIObjectTypeToString(GUIObjectType guiObjectType)
{
static_assert((int)GUIObjectType::COUNT == 1 << 17, "ToString");
static_assert((int)GUIObjectType::COUNT == 1 << 18, "ToString");
switch(guiObjectType)
{
RETURN_ENUM_STRING(GUIObjectType::WINDOW);
Expand All @@ -117,6 +118,7 @@ namespace Enums
RETURN_ENUM_STRING(GUIObjectType::SCROLLBAR);
RETURN_ENUM_STRING(GUIObjectType::IMAGE_CANVAS);
RETURN_ENUM_STRING(GUIObjectType::STANDARD_SLIDER);
RETURN_ENUM_STRING(GUIObjectType::STANDARD_CHECKBOX);
RETURN_ENUM_STRING(GUIObjectType::COUNT);
}

Expand All @@ -127,10 +129,10 @@ namespace Enums
//function: GUIObjectTypeToString
inline std::string GUIObjectTypeToString(GUIObjectType guiObjectType)
{
static_assert((int)GUIObjectType::COUNT == 1 << 17, "ToString");
static_assert((int)GUIObjectType::COUNT == 1 << 18, "ToString");

std::string curString;
for(int i = 0; i < 18; ++i)
for(int i = 0; i < 19; ++i)
{
std::string returnString = InternalGUIObjectTypeToString(guiObjectType & (GUIObjectType)(1 << i));
if(!returnString.empty())
Expand Down
110 changes: 110 additions & 0 deletions Include/ssGUI/GUIObjectClasses/CompositeClasses/StandardCheckbox.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#ifndef SSGUI_STANDARD_CHECKBOX_HPP
#define SSGUI_STANDARD_CHECKBOX_HPP

#include "ssGUI/GUIObjectClasses/Text.hpp"
#include "ssGUI/GUIObjectClasses/Checkbox.hpp"

//namespace: ssGUI
namespace ssGUI
{
/*class: StandardCheckbox
A standard checkbox that contains a title text and a checkbox object.
Variables & Constructor:
============================== C++ ==============================
protected:
ssGUIObjectIndex CheckboxTitleTextObject;
ssGUIObjectIndex CheckboxObject;
=================================================================
============================== C++ ==============================
StandardCheckbox::StandardCheckbox() : CheckboxTitleTextObject(-1),
CheckboxObject(-1)
{
//Add layout
auto* layout = AddExtension<ssGUI::Extensions::Layout>();
layout->SetUpdateContainerMinMaxSize(false);
layout->SetHorizontalLayout(true);
SetMinSize(glm::vec2(150, 30));
SetSize(glm::vec2(150, 30));
//Set layout preferred sizes
layout->AddPreferredSizeMultipliers(0.85f, 0.15f);
//Add components
auto* checkboxTitle = AddChild<ssGUI::Text>();
checkboxTitle->SetText("Checkbox:");
CheckboxTitleTextObject = CurrentObjectsReferences.AddObjectReference(checkboxTitle);
auto* checkbox = AddChildWithWrapper<ssGUI::Checkbox>( ssGUI::Enums::AlignmentHorizontal::CENTER,
ssGUI::Enums::AlignmentVertical::CENTER,
true);
CheckboxObject = CurrentObjectsReferences.AddObjectReference(checkbox);
ForwardCheckboxEvents();
}
=================================================================
*/
class StandardCheckbox : public Widget
{
private:
StandardCheckbox& operator=(StandardCheckbox const& other) = default;

protected:
ssGUIObjectIndex CheckboxTitleTextObject;
ssGUIObjectIndex CheckboxObject;

StandardCheckbox(StandardCheckbox const& other);

void ForwardCheckboxEvents();

virtual void ConstructRenderInfo() override;

public:
//string: ListenerKey
static const std::string ListenerKey;

StandardCheckbox();
virtual ~StandardCheckbox() override;

/*function: SetTitleTextObject
Sets the title text GUI Object.
The text content of the old text GUI Object will be copied to the new one.
The old text GUI Object will be deleted and the new text GUI Object will be inserted at the same place as the old one.
Passing nullptr will unset the text GUI object.*/
virtual void SetTitleTextObject(ssGUI::Text* text);

//function: GetTitleTextObject
//Gets the title text GUI Object.
virtual ssGUI::Text* GetTitleTextObject() const;

/*function: SetCheckboxObject
Sets the actual checkbox GUI object.
The old checkbox GUI Object will be deleted and the new checkbox GUI Object will be inserted at the same place as the old one.
Passing nullptr will unset the checkbox GUI object.*/
virtual void SetCheckboxObject(ssGUI::Checkbox* checkbox);

//function: GetCheckboxObject
//Gets the actual checkbox GUI object.
virtual ssGUI::Checkbox* GetCheckboxObject() const;

//function: SetInteractable
//See <Widget::SetInteractable>
virtual void SetInteractable(bool interactable) override;

//function: SetBlockInput
//See <Widget::SetBlockInput>
virtual void SetBlockInput(bool blockInput) override;

//function: GetType
//See <Widget::GetType>
virtual ssGUI::Enums::GUIObjectType GetType() const override;

//function: Clone
//See <Widget::Clone>
virtual StandardCheckbox* Clone(bool cloneChildren) override;

};
}

#endif
1 change: 1 addition & 0 deletions Include/ssGUI/HeaderGroups/StandardGroup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ssGUI/GUIObjectClasses/CompositeClasses/StandardWindow.hpp"
#include "ssGUI/GUIObjectClasses/CompositeClasses/StandardButton.hpp"
#include "ssGUI/GUIObjectClasses/CompositeClasses/StandardSlider.hpp"
#include "ssGUI/GUIObjectClasses/CompositeClasses/StandardCheckbox.hpp"
#include "ssGUI/ssGUIManager.hpp"
#include "ssGUI/ssGUITags.hpp"
#include "ssGUI/Factory.hpp"
Expand Down
22 changes: 22 additions & 0 deletions Src/Examples/Playground/StandardCheckboxPlayground.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "ssGUI/Extensions/AdvancedPosition.hpp"
#include "ssGUI/Extensions/Layout.hpp"
#include "ssGUI/HeaderGroups/StandardGroup.hpp"

#include "ssGUI/HelperClasses/LogWithTagsAndLevel.hpp"
#include "ExamplesResources.h"

int main()
{
ssGUI::MainWindow mainWindow;

//Creating ssGUIManager and run it
ssGUI::ssGUIManager guiManager;
auto* window = mainWindow.AddChild<ssGUI::StandardWindow>();
window->AddExtension<ssGUI::Extensions::Layout>()->SetCoverFullLength(false);
auto* checkbox = window->AddChild<ssGUI::StandardCheckbox>();

guiManager.AddRootGUIObject((ssGUI::GUIObject*)&mainWindow);
guiManager.StartRunning();

return 0;
}
1 change: 1 addition & 0 deletions Src/ssGUI/GUIObjectClasses/CompositeClasses/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ target_sources(ssGUI PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/Scrollbar.cpp"
"${CMAKE_CURRENT_LIST_DIR}/ImageCanvas.cpp"
"${CMAKE_CURRENT_LIST_DIR}/StandardSlider.cpp"
"${CMAKE_CURRENT_LIST_DIR}/StandardCheckbox.cpp"
)
164 changes: 164 additions & 0 deletions Src/ssGUI/GUIObjectClasses/CompositeClasses/StandardCheckbox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#include "ssGUI/GUIObjectClasses/CompositeClasses/StandardCheckbox.hpp"
#include "ssGUI/Extensions/Layout.hpp"

namespace ssGUI
{
StandardCheckbox::StandardCheckbox(StandardCheckbox const& other) : Widget(other),
CheckboxTitleTextObject(other.CheckboxTitleTextObject),
CheckboxObject(other.CheckboxObject)
{
}

void StandardCheckbox::ForwardCheckboxEvents()
{
if(GetCheckboxObject() == nullptr)
return;

GetCheckboxObject()->ForwardEvent(this, ssGUI::Enums::EventType::BUTTON_STATE_CHANGED);
}

void StandardCheckbox::ConstructRenderInfo()
{
}

const std::string StandardCheckbox::ListenerKey = "Standard Checkbox";

StandardCheckbox::StandardCheckbox() : CheckboxTitleTextObject(-1),
CheckboxObject(-1)
{
//Add layout
auto* layout = AddExtension<ssGUI::Extensions::Layout>();
layout->SetUpdateContainerMinMaxSize(false);
layout->SetHorizontalLayout(true);

SetMinSize(glm::vec2(150, 30));
SetSize(glm::vec2(150, 30));

//Set layout preferred sizes
layout->AddPreferredSizeMultipliers(0.85f, 0.15f);

//Add components
auto* checkboxTitle = AddChild<ssGUI::Text>();
checkboxTitle->SetText("Checkbox:");
CheckboxTitleTextObject = CurrentObjectsReferences.AddObjectReference(checkboxTitle);

auto* checkbox = AddChildWithWrapper<ssGUI::Checkbox>( ssGUI::Enums::AlignmentHorizontal::CENTER,
ssGUI::Enums::AlignmentVertical::CENTER,
true);

CheckboxObject = CurrentObjectsReferences.AddObjectReference(checkbox);
ForwardCheckboxEvents();
}

StandardCheckbox::~StandardCheckbox()
{

}

void StandardCheckbox::SetTitleTextObject(ssGUI::Text* text)
{
if(text == nullptr)
{
if(GetTitleTextObject() != nullptr)
GetTitleTextObject()->Delete();

return;
}

std::wstring oldTitle = L"";

if(GetTitleTextObject() != nullptr)
{
oldTitle = GetTitleTextObject()->GetText();
text->SetParent(GetTitleTextObject()->GetParent(), true);
MoveChildAfterTargetChild(text, GetTitleTextObject());
GetTitleTextObject()->Delete();
}
else
{
text->SetParent(this, true);
MoveChildToFirst(text);
}

text->SetText(oldTitle);

CheckboxTitleTextObject = CurrentObjectsReferences.AddObjectReference(text);
}

ssGUI::Text* StandardCheckbox::GetTitleTextObject() const
{
return CurrentObjectsReferences.GetObjectReference<ssGUI::Text>(CheckboxTitleTextObject);
}

void StandardCheckbox::SetCheckboxObject(ssGUI::Checkbox* checkbox)
{
if(checkbox == nullptr)
{
if(GetCheckboxObject() != nullptr)
GetCheckboxObject()->Delete();

return;
}

if(GetCheckboxObject() != nullptr)
{
checkbox->SetParent(GetCheckboxObject()->GetParent(), true);
GetCheckboxObject()->Delete();
}
else
{
ssGUI::GUIObject* wrapper;
if(GetTitleTextObject() != nullptr)
wrapper = AddChildAfter<ssGUI::GUIObject>(GetTitleTextObject());
else
wrapper = AddChild<ssGUI::GUIObject>();

checkbox->SetParent(wrapper, true);
}

CheckboxObject = CurrentObjectsReferences.AddObjectReference(checkbox);

ForwardCheckboxEvents();
}

ssGUI::Checkbox* StandardCheckbox::GetCheckboxObject() const
{
return CurrentObjectsReferences.GetObjectReference<ssGUI::Checkbox>(CheckboxObject);
}

void StandardCheckbox::SetInteractable(bool interactable)
{
if(GetCheckboxObject() != nullptr)
GetCheckboxObject()->SetInteractable(true);

Widget::SetInteractable(interactable);
}

void StandardCheckbox::SetBlockInput(bool blockInput)
{
if(GetCheckboxObject() != nullptr)
GetCheckboxObject()->SetBlockInput(true);

Widget::SetBlockInput(blockInput);
}

ssGUI::Enums::GUIObjectType StandardCheckbox::GetType() const
{
return ssGUI::Enums::GUIObjectType::STANDARD_CHECKBOX | ssGUI::Enums::GUIObjectType::WIDGET;
}

StandardCheckbox* StandardCheckbox::Clone(bool cloneChildren)
{
ssGUI_LOG_FUNC();
StandardCheckbox* temp = new StandardCheckbox(*this);
CloneExtensionsAndEventCallbacks(temp);

if(cloneChildren)
{
if(CloneChildren(this, temp) == nullptr)
return nullptr;
}

return temp;
}
}

0 comments on commit d244e97

Please sign in to comment.