Skip to content

Commit

Permalink
Event forwarding (E3f7YWZQO3) & Update to Standard Slider (4WvgDW71cH)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Box-Coder committed May 15, 2023
1 parent dda003a commit 976495b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Include/ssGUI/DataClasses/EventCallbackManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ namespace ssGUI
//function: GetListOfEventCallbacks
//Returns all the event callbacks on the GUI Object
virtual std::vector<ssGUI::EventCallback*> GetListOfEventCallbacks();

//function: ForwardEvent
//Forwards the specified event we received to the specified GUI Object
virtual void ForwardEvent(ssGUI::GUIObject* objToForwardTo, ssGUI::Enums::EventType forwardEvent);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//namespace: ssGUI
namespace ssGUI
{

/*class: StandardSlider
A standard slider that contains a title text, slider object and value text.
Expand Down Expand Up @@ -84,7 +83,8 @@ namespace ssGUI
virtual void ConstructRenderInfo() override;

virtual void AddDisplayValueEventCallback();
virtual void RemoveDisplayValueEventCallback();
//virtual void RemoveDisplayValueEventCallback();
virtual void UpdateDisplayTextContent();

public:
static const std::string ListenerKey;
Expand Down
22 changes: 22 additions & 0 deletions Src/Examples/Playground/StandardWindowPlayground.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "ssGUI/Extensions/AdvancedPosition.hpp"
#include "ssGUI/HeaderGroups/StandardGroup.hpp"
#include "ssGUI/Extensions/Border.hpp"

#include "ssLogger/ssLog.hpp"
#include "ExamplesResources.h"

//Image Test
int main()
{
ssGUI::MainWindow mainWindow;

//Creating ssGUIManager and run it
ssGUI::ssGUIManager guiManager;
auto* window = mainWindow.AddChild<ssGUI::StandardWindow>();

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

guiManager.StartRunning();

return 0;
}
27 changes: 27 additions & 0 deletions Src/ssGUI/DataClasses/EventCallbackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ssGUI/DataClasses/Renderer.hpp"
#include "ssGUI/Factory.hpp"
#include "ssGUI/GUIObjectClasses/GUIObject.hpp"

namespace ssGUI
{
Expand Down Expand Up @@ -86,4 +87,30 @@ namespace ssGUI

return returnVector;
}

void EventCallbackManager::ForwardEvent(ssGUI::GUIObject* objToForwardTo, ssGUI::Enums::EventType forwardEvent)
{
if(objToForwardTo == nullptr)
{
ssGUI_WARNING(ssGUI_DATA_TAG, "Can't forward event to nullptr GUI Object");
return;
}

auto* ecb = AddEventCallback(forwardEvent);
ssGUI::ssGUIObjectIndex forwardObjId = ecb->AddObjectReference(objToForwardTo);
ecb->AddEventListener
(
"Event Callback Manager",
CurrentObject,
[forwardObjId, forwardEvent](ssGUI::EventInfo info)
{
ssGUI::GUIObject* forwardToObj = info.References->GetObjectReference(forwardObjId);
if(forwardToObj == nullptr)
return;

if(forwardToObj->IsEventCallbackExist(forwardEvent))
forwardToObj->GetEventCallback(forwardEvent)->Notify(info.EventSource, info.CustomInfo);
}
);
}
}
39 changes: 31 additions & 8 deletions Src/ssGUI/GUIObjectClasses/CompositeClasses/StandardSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,34 @@ namespace ssGUI
standardSlider->GetDisplayValue()));
}
);

//Forward events from slider to this
slider->ForwardEvent(this, Enums::EventType::SLIDER_VALUE_CHANGED);
slider->ForwardEvent(this, Enums::EventType::SLIDER_VALUE_CHANGED_VIA_GUI);
slider->ForwardEvent(this, Enums::EventType::SLIDER_VALUE_FINISHED_CHANGING);
}

void StandardSlider::RemoveDisplayValueEventCallback()
//void StandardSlider::RemoveDisplayValueEventCallback()
//{
// ssGUI::Slider* slider = GetSliderObject();
// if(slider == nullptr)
// return;

// ssGUI::EventCallback* ecb = slider->GetEventCallback(ssGUI::Enums::EventType::SLIDER_VALUE_CHANGED);

// if(ecb != nullptr)
// ecb->RemoveEventListener(ListenerKey, this);
//}

void StandardSlider::UpdateDisplayTextContent()
{
ssGUI::Slider* slider = GetSliderObject();
if(slider == nullptr)
return;

ssGUI::EventCallback* ecb = slider->GetEventCallback(ssGUI::Enums::EventType::SLIDER_VALUE_CHANGED);

if(ecb != nullptr)
ecb->RemoveEventListener(ListenerKey, this);
ecb->Notify(slider);
}

const std::string StandardSlider::ListenerKey = "Standard Slider";
Expand All @@ -88,14 +104,16 @@ namespace ssGUI
DisplayInteger(false),
DisplayDecimalPlaces(3)
{
SetSize(glm::vec2(300, 10));

//Add layout
auto* layout = AddExtension<ssGUI::Extensions::Layout>();
layout->SetUpdateContainerMinMaxSize(false);
layout->SetHorizontalLayout(true);

SetMinSize(glm::vec2(200, 10));
SetSize(glm::vec2(300, 10));

//Set layout preferred sizes
layout->AddPreferredSizeMultipliers(0.3f, 0.5f, 0.1f);
layout->AddPreferredSizeMultipliers(0.25f, 0.5f, 0.15f);

//Add components
auto* sliderTitle = AddChild<ssGUI::Text>();
Expand Down Expand Up @@ -185,7 +203,8 @@ namespace ssGUI
slider->SetParent(wrapper, true);
}

SliderObject = CurrentObjectsReferences.AddObjectReference(slider);
SliderObject = CurrentObjectsReferences.AddObjectReference(slider);
AddDisplayValueEventCallback();
}

ssGUI::Slider* StandardSlider::GetSliderObject() const
Expand Down Expand Up @@ -215,7 +234,8 @@ namespace ssGUI
MoveChildToLast(text);
}

SliderDisplayValueTextObject = CurrentObjectsReferences.AddObjectReference(text);
SliderDisplayValueTextObject = CurrentObjectsReferences.AddObjectReference(text);
UpdateDisplayTextContent();
}

ssGUI::Text* StandardSlider::GetDisplayValueTextObject() const
Expand All @@ -229,6 +249,7 @@ namespace ssGUI
return;

MinDisplayValue = min;
UpdateDisplayTextContent();
}

float StandardSlider::GetMinDisplayValue() const
Expand All @@ -242,6 +263,7 @@ namespace ssGUI
return;

MaxDisplayValue = max;
UpdateDisplayTextContent();
}

float StandardSlider::GetMaxDisplayValue() const
Expand All @@ -256,6 +278,7 @@ namespace ssGUI

MinDisplayValue = min;
MaxDisplayValue = max;
UpdateDisplayTextContent();
}

void StandardSlider::SetDisplayValue(float displayValue)
Expand Down

0 comments on commit 976495b

Please sign in to comment.