-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fddfe97
commit d244e97
Showing
6 changed files
with
304 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
Include/ssGUI/GUIObjectClasses/CompositeClasses/StandardCheckbox.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
Src/ssGUI/GUIObjectClasses/CompositeClasses/StandardCheckbox.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |