libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::GuiElement Class Referenceabstract

Abstract base class for all visible GUI elements (windows, menu bars, overlays). More...

#include <GuiElement.h>

Inheritance diagram for Ship::GuiElement:
[legend]
Collaboration diagram for Ship::GuiElement:
[legend]

Public Member Functions

 GuiElement (const std::string &name, bool isVisible)
 Constructs a GuiElement with an explicit initial visibility.
 
 GuiElement (const std::string &name)
 Constructs a GuiElement that starts hidden.
 
virtual ~GuiElement ()
 
virtual void Draw ()=0
 Renders the element for the current frame.
 
void Update ()
 Updates element state for the current frame (called before Draw).
 
void Show ()
 Makes the element visible (equivalent to SetVisibility(true)).
 
void Hide ()
 Hides the element (equivalent to SetVisibility(false)).
 
void ToggleVisibility ()
 Flips the visibility state between shown and hidden.
 
bool IsVisible ()
 Returns true if the element is currently visible.
 
virtual void DrawElement ()=0
 Renders the element's content (pure ImGui draw calls).
 
- Public Member Functions inherited from Ship::Component
 Component (const std::string &name, std::shared_ptr< Context > context=nullptr)
 Constructs a Component with the given name.
 
virtual ~Component ()
 
void Init (const nlohmann::json &initArgs=nlohmann::json::object())
 Performs one-time initialization of this component.
 
bool IsInitialized () const
 Returns true once Init() (or MarkInitialized()) has completed successfully.
 
const std::string & GetName () const
 Returns the name of this Component.
 
std::string ToString () const
 Returns a human-readable string representation (e.g. "Name (id)").
 
std::string ToTreeString (int depth=0) const
 Returns a human-readable tree representation of this component and its children.
 
 operator std::string () const
 Conversion operator to std::string; equivalent to ToString().
 
ParentComponentListGetParents ()
 Returns a mutable reference to the parent list.
 
const ParentComponentListGetParents () const
 Returns a const reference to the parent list.
 
ComponentListGetChildren ()
 Returns a mutable reference to the child list.
 
const ComponentListGetChildren () const
 Returns a const reference to the child list.
 
virtual std::shared_ptr< ComponentTryGetSharedComponent () noexcept
 Returns a shared_ptr to this Component when available, otherwise nullptr.
 
virtual std::shared_ptr< ComponentGetSharedComponent ()
 Returns a shared_ptr to this Component via the correct enable_shared_from_this base.
 
template<typename T >
bool HasInChildren () const
 Checks whether any descendant Component matches type T via BFS.
 
template<typename T >
std::shared_ptr< T > GetFirstInChildren () const
 Returns the first descendant that matches type T via BFS.
 
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > GetInChildren () const
 Returns all descendants that match type T via BFS.
 
template<typename T >
bool HasInParents () const
 Checks whether any ancestor Component matches type T via BFS.
 
template<typename T >
std::shared_ptr< T > GetFirstInParents () const
 Returns the first ancestor that matches type T via BFS.
 
template<typename T >
std::shared_ptr< std::vector< std::shared_ptr< T > > > GetInParents () const
 Returns all ancestors that match type T via BFS.
 
- Public Member Functions inherited from Ship::Part
 Part ()
 Constructs a Part and assigns it a unique ID.
 
 Part (std::shared_ptr< Context > context)
 Constructs a Part with an explicit Context reference and unique ID.
 
virtual ~Part ()=default
 
uint64_t GetId () const
 Returns the unique identifier for this Part.
 
bool operator== (const Part &other) const
 Compares two Parts for equality by their unique IDs.
 
std::shared_ptr< ContextGetContext () const
 Returns the Context this Part belongs to, or nullptr if unset.
 
void SetContext (std::shared_ptr< Context > ctx)
 Sets the Context this Part belongs to.
 

Protected Member Functions

void OnInit (const nlohmann::json &initArgs=nlohmann::json::object()) override
 Component initialization hook.
 
virtual void UpdateElement ()=0
 Per-frame logic update called by Update(). Subclasses perform state updates here.
 
virtual void SetVisibility (bool visible)
 Changes the visibility flag and optionally persists it to a CVar.
 
- Protected Member Functions inherited from Ship::Component
void MarkInitialized ()
 Marks this component as initialized without going through Init().
 
template<typename T >
std::shared_ptr< T > RequireDependency (const std::shared_ptr< T > &dependency, const std::string &dependencyName) const
 Returns a cached dependency after validating it exists and is initialized.
 
- Protected Member Functions inherited from Ship::Part
virtual void OnAdded (bool forced)
 Called after this Part has been added to a PartList.
 
virtual void OnRemoved (bool forced)
 Called after this Part has been removed from a PartList.
 

Protected Attributes

bool mIsVisible
 Current visibility state. Subclasses may read this directly.
 

Detailed Description

Abstract base class for all visible GUI elements (windows, menu bars, overlays).

GuiElement provides the lifecycle skeleton (Init -> Draw/Update -> Show/Hide) that every ImGui panel in the Ship GUI system must implement. Concrete subclasses are GuiWindow (for floating ImGui windows) and GuiMenuBar (for the top-of-screen menu bar), both of which override DrawElement(), OnInit(), and UpdateElement().

GuiElement uses the Component initialization system. Calling Init() delegates to Component::Init()GuiElement::OnInit() exactly once. Subclasses override OnInit() and must call the parent (GuiElement::OnInit() or Component::OnInit()) first. Draw() and Update() are called by the Gui layer every frame for visible elements.

class MyWindow : public Ship::GuiWindow {
public:
using GuiWindow::GuiWindow;
protected:
void OnInit(const nlohmann::json& initArgs = nlohmann::json::object()) override {
GuiWindow::OnInit(initArgs);
// widget/resource setup goes here
}
void UpdateElement() override { }
void DrawElement() override { ImGui::Text("Hello World"); }
};
A floating ImGui window managed by the Ship Gui layer.
Definition GuiWindow.h:39

Constructor & Destructor Documentation

◆ GuiElement() [1/2]

Ship::GuiElement::GuiElement ( const std::string &  name,
bool  isVisible 
)

Constructs a GuiElement with an explicit initial visibility.

Parameters
nameComponent name.
isVisibletrue if the element should start visible.

◆ GuiElement() [2/2]

Ship::GuiElement::GuiElement ( const std::string &  name)

Constructs a GuiElement that starts hidden.

Parameters
nameComponent name.

◆ ~GuiElement()

virtual Ship::GuiElement::~GuiElement ( )
virtual

Member Function Documentation

◆ Draw()

virtual void Ship::GuiElement::Draw ( )
pure virtual

Renders the element for the current frame.

Called every frame by the Gui layer when the element is visible. Delegates to DrawElement() after any subclass-specific boilerplate (e.g. Begin/End calls).

Implemented in Ship::GuiMenuBar, and Ship::GuiWindow.

◆ DrawElement()

virtual void Ship::GuiElement::DrawElement ( )
pure virtual

Renders the element's content (pure ImGui draw calls).

Implemented by concrete subclasses to emit ImGui widgets. For GuiWindow this is called between ImGui::Begin() and ImGui::End(); for GuiMenuBar between ImGui::BeginMainMenuBar() and ImGui::EndMainMenuBar().

Implemented in LUS::GfxDebuggerWindow, LUS::InputEditorWindow, Ship::SDLAddRemoveDeviceEventHandler, Ship::ComponentHierarchyWindow, Ship::ConsoleWindow, Ship::EventDebuggerWindow, and Ship::StatsWindow.

◆ Hide()

void Ship::GuiElement::Hide ( )

Hides the element (equivalent to SetVisibility(false)).

◆ IsVisible()

bool Ship::GuiElement::IsVisible ( )

Returns true if the element is currently visible.

◆ OnInit()

void Ship::GuiElement::OnInit ( const nlohmann::json &  initArgs = nlohmann::json::object())
overrideprotectedvirtual

Component initialization hook.

Called by Component::Init() exactly once. Subclasses override OnInit() for their specific setup and must call GuiElement::OnInit(initArgs) (or Component::OnInit(initArgs)) to preserve the initialization contract.

Reimplemented from Ship::Component.

Reimplemented in LUS::InputEditorWindow, Ship::StatsWindow, Ship::GuiMenuBar, and Ship::GuiWindow.

◆ SetVisibility()

virtual void Ship::GuiElement::SetVisibility ( bool  visible)
protectedvirtual

Changes the visibility flag and optionally persists it to a CVar.

The base implementation simply sets mIsVisible. GuiWindow and GuiMenuBar override this to also sync the value to their backing console variable.

Parameters
visibleNew visibility state.

Reimplemented in Ship::GuiMenuBar, and Ship::GuiWindow.

◆ Show()

void Ship::GuiElement::Show ( )

Makes the element visible (equivalent to SetVisibility(true)).

◆ ToggleVisibility()

void Ship::GuiElement::ToggleVisibility ( )

Flips the visibility state between shown and hidden.

◆ Update()

void Ship::GuiElement::Update ( )

Updates element state for the current frame (called before Draw).

Delegates to UpdateElement() for subclass-specific logic.

◆ UpdateElement()

virtual void Ship::GuiElement::UpdateElement ( )
protectedpure virtual

Per-frame logic update called by Update(). Subclasses perform state updates here.

Implemented in LUS::GfxDebuggerWindow, LUS::InputEditorWindow, Ship::SDLAddRemoveDeviceEventHandler, Ship::ConsoleWindow, Ship::EventDebuggerWindow, and Ship::StatsWindow.

Member Data Documentation

◆ mIsVisible

bool Ship::GuiElement::mIsVisible
protected

Current visibility state. Subclasses may read this directly.


The documentation for this class was generated from the following file: