Skip to content

Commit

Permalink
Rework standard window, standard button to be more flexible (2I9s7fU2K2)
Browse files Browse the repository at this point in the history
Rework standard window and standard button custom composite children to be more flexible (2I9s7fU2K2)
  • Loading branch information
Neko-Box-Coder committed May 14, 2023
1 parent cffa91e commit 9786337
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 126 deletions.
16 changes: 10 additions & 6 deletions Include/ssGUI/GUIObjectClasses/CompositeClasses/StandardButton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ namespace ssGUI

StandardButton(StandardButton const& other);

virtual void UpdateButtonText();
virtual void UpdateButtonImage();
virtual void UpdateButtonText(bool init);
virtual void UpdateButtonImage(bool init);

public:
//string: ListenerKey
Expand All @@ -202,19 +202,23 @@ namespace ssGUI
virtual ~StandardButton() override;

//function: SetButtonIconObject
//Sets the icon image object, by default it will be generated
//Sets the icon image object, by default it will be generated.
//The new image object will be automatically parent to a wrapper.
//Passing nullptr will unset the button icon object.
virtual void SetButtonIconObject(ssGUI::Image* image);

//function: GetButtonIconObject
//Gets the icon image object, by default it will be generated
//Gets the icon image object, by default it will be generated.
virtual ssGUI::Image* GetButtonIconObject() const;

//function: SetButtonTextObject
//Sets the text object, by default it will be generated
//Sets the text object, by default it will be generated.
//The text content from the old text will be transferred to the new text object.
//Passing nullptr will unset the button icon object.
virtual void SetButtonTextObject(ssGUI::Text* text);

//function: GetButtonTextObject
//Gets the text object, by default it will be generated
//Gets the text object, by default it will be generated.
virtual ssGUI::Text* GetButtonTextObject() const;

//function: SetAdaptiveButtonTextColor
Expand Down
37 changes: 20 additions & 17 deletions Include/ssGUI/GUIObjectClasses/CompositeClasses/StandardWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ namespace ssGUI

StandardWindow(StandardWindow const& other);

virtual void UpdateTitleText();
virtual void UpdateIconImage();
virtual void UpdateCloseButton();
virtual void UpdateTitleText(bool init);
virtual void UpdateIconImage(bool init);
virtual void UpdateCloseButton(bool init);

public:
//string: ListenerKey
Expand All @@ -231,10 +231,13 @@ namespace ssGUI
StandardWindow();
virtual ~StandardWindow() override;

/*function: SetWindowTitleObject
Sets the window title text object.
You can use <GUIObject::SetUserCreated> and <GUIObject::SetHeapAllocated> to allow
Standard Window to manage the lifetime of the text object instead.*/
//function: SetWindowTitleObject
//Sets the window title text object.
//The title content from the old text will be transferred to the new one.
//The Y position, height and the color of the new text is directly controlled by <StandardWindow>
//using <AdvancedPosition: ssGUI::Extensions::AdvancedPosition> and <AdvancedSize: ssGUI::Extensions::AdvancedPosition>.
//The font size is also directly controlled by <StandardWindow> if <IsAutoFontSize> is true.
//Passing nullptr will unset the window title object.
virtual void SetWindowTitleObject(ssGUI::Text* text);

//function: GetWindowTitleObject
Expand All @@ -257,10 +260,11 @@ namespace ssGUI
//Gets the font size multiplier to have a finer adjustment over it
virtual float GetAutoFontSizeMultiplier() const;

/*function: SetWindowIconGUIObject
Sets the window icon image object.
You can use <GUIObject::SetUserCreated> and <GUIObject::SetHeapAllocated> to allow
Standard Window to manage the lifetime of the text object instead.*/
//function: SetWindowIconGUIObject
//Sets the window icon image object.
//The X offset, Y position and size of the new icon object is directly controlled by <StandardWindow>
//using <AdvancedPosition: ssGUI::Extensions::AdvancedPosition> and <AdvancedSize: ssGUI::Extensions::AdvancedPosition>.
//Passing nullptr will unset the window icon object.
virtual void SetWindowIconGUIObject(ssGUI::Image* image);

//function: GetWindowIconGUIObject
Expand All @@ -269,18 +273,17 @@ namespace ssGUI

//TODO: Add a way to set default window icon

/*function: SetCloseButtonObject
Sets the close button object.
You can use <GUIObject::SetUserCreated> and <GUIObject::SetHeapAllocated> to allow
Standard Window to manage the lifetime of the text object instead.*/
//function: SetCloseButtonObject
//Sets the close button object.
//The X offset, Y position and size of the new close button object is directly controlled by <StandardWindow>
//using <AdvancedPosition: ssGUI::Extensions::AdvancedPosition> and <AdvancedSize: ssGUI::Extensions::AdvancedPosition>.
//Passing nullptr will unset the close button object.
virtual void SetCloseButtonObject(ssGUI::Button* button);

//function: GetCloseButtonObject
//Returns the pointer to the close button object. Nullptr if it doesn't exist
virtual ssGUI::Button* GetCloseButtonObject() const;

//TODO: Rename to titlebar padding instead

//function: SetHorizontalPadding
//Sets the horizontal padding for the icon, title and close button objects, in pixels
virtual void SetHorizontalPadding(int padding);
Expand Down
59 changes: 33 additions & 26 deletions Src/ssGUI/GUIObjectClasses/CompositeClasses/StandardButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ssGUI
ButtonImageWrapper = other.ButtonImageWrapper;
}

void StandardButton::UpdateButtonText()
void StandardButton::UpdateButtonText(bool init)
{
ssLOG_FUNC_ENTRY();
auto buttonTextObj = CurrentObjectsReferences.GetObjectReference(ButtonText);
Expand All @@ -49,13 +49,17 @@ namespace ssGUI

// if(!buttonTextObj->GetExtension(ssGUI::Extensions::AdvancedSize::EXTENSION_NAME))
// buttonTextObj->AddExtension(ssGUI::Factory::Create<ssGUI::Extensions::AdvancedSize>());

if(init)
{
static_cast<ssGUI::Text*>(buttonTextObj)->SetTextHorizontalAlignment(ssGUI::Enums::AlignmentHorizontal::CENTER);
static_cast<ssGUI::Text*>(buttonTextObj)->SetTextVerticalAlignment(ssGUI::Enums::AlignmentVertical::CENTER);
}

static_cast<ssGUI::Text*>(buttonTextObj)->SetTextHorizontalAlignment(ssGUI::Enums::AlignmentHorizontal::CENTER);
static_cast<ssGUI::Text*>(buttonTextObj)->SetTextVerticalAlignment(ssGUI::Enums::AlignmentVertical::CENTER);
ssLOG_FUNC_EXIT();
}

void StandardButton::UpdateButtonImage()
void StandardButton::UpdateButtonImage(bool init)
{
ssLOG_FUNC_ENTRY();
auto buttonImgObj = CurrentObjectsReferences.GetObjectReference(ButtonImage);
Expand Down Expand Up @@ -83,25 +87,28 @@ namespace ssGUI
// if(!buttonImgWrapper->HasTag(ssGUI::Tags::FLOATING))
// buttonImgWrapper->AddTag(ssGUI::Tags::FLOATING);

ssGUI::Extensions::AdvancedSize* as;
ssGUI::Extensions::AdvancedPosition* ap;

if(!buttonImgObj->GetExtension(ssGUI::Extensions::AdvancedSize::EXTENSION_NAME))
buttonImgObj->AddExtension<ssGUI::Extensions::AdvancedSize>();
if(init)
{
ssGUI::Extensions::AdvancedSize* as;
ssGUI::Extensions::AdvancedPosition* ap;

if(!buttonImgObj->GetExtension(ssGUI::Extensions::AdvancedSize::EXTENSION_NAME))
buttonImgObj->AddExtension<ssGUI::Extensions::AdvancedSize>();

as = buttonImgObj->GetAnyExtension<ssGUI::Extensions::AdvancedSize>();
as = buttonImgObj->GetAnyExtension<ssGUI::Extensions::AdvancedSize>();

as->SetHorizontalPercentage(0.55);
as->SetHorizontalPixel(0);
as->SetVerticalPercentage(0.55);
as->SetVerticalPixel(0);
as->SetHorizontalPercentage(0.55);
as->SetHorizontalPixel(0);
as->SetVerticalPercentage(0.55);
as->SetVerticalPixel(0);

if(!buttonImgObj->GetExtension(ssGUI::Extensions::AdvancedPosition::EXTENSION_NAME))
buttonImgObj->AddExtension<ssGUI::Extensions::AdvancedPosition>();
if(!buttonImgObj->GetExtension(ssGUI::Extensions::AdvancedPosition::EXTENSION_NAME))
buttonImgObj->AddExtension<ssGUI::Extensions::AdvancedPosition>();

ap = buttonImgObj->GetAnyExtension<ssGUI::Extensions::AdvancedPosition>();
ap->SetHorizontalAlignment(ssGUI::Enums::AlignmentHorizontal::CENTER);
ap->SetVerticalAlignment(ssGUI::Enums::AlignmentVertical::CENTER);
ap = buttonImgObj->GetAnyExtension<ssGUI::Extensions::AdvancedPosition>();
ap->SetHorizontalAlignment(ssGUI::Enums::AlignmentHorizontal::CENTER);
ap->SetVerticalAlignment(ssGUI::Enums::AlignmentVertical::CENTER);
}

ssLOG_FUNC_EXIT();
}
Expand Down Expand Up @@ -241,8 +248,8 @@ namespace ssGUI
}
);

UpdateButtonText();
UpdateButtonImage();
UpdateButtonText(true);
UpdateButtonImage(true);
NotifyButtonEventCallbackManually();

ssLOG_FUNC_EXIT();
Expand Down Expand Up @@ -278,7 +285,7 @@ namespace ssGUI
}

glm::vec2 globalPos = image->GetGlobalPosition();
image->SetParent(buttonImgWrapper);
image->SetParent(buttonImgWrapper, true);
image->SetGlobalPosition(globalPos);

ssGUIObjectIndex newImageIndex = CurrentObjectsReferences.GetObjectIndex(image);
Expand All @@ -288,7 +295,7 @@ namespace ssGUI
else
ButtonImage = CurrentObjectsReferences.AddObjectReference(image);

UpdateButtonImage();
UpdateButtonImage(false);
}

ssGUI::Image* StandardButton::GetButtonIconObject() const
Expand Down Expand Up @@ -328,7 +335,7 @@ namespace ssGUI

text->SetText(oldText);

UpdateButtonText();
UpdateButtonText(false);
}

ssGUI::Text* StandardButton::GetButtonTextObject() const
Expand Down Expand Up @@ -381,8 +388,8 @@ namespace ssGUI
void StandardButton::SetButtonMode(Mode buttonMode)
{
ButtonMode = buttonMode;
UpdateButtonText();
UpdateButtonImage();
UpdateButtonText(false);
UpdateButtonImage(false);
}

StandardButton::Mode StandardButton::GetButtonMode() const
Expand Down
Loading

0 comments on commit 9786337

Please sign in to comment.