Added hide/show functionality to widgets

This commit is contained in:
OmniaX-Dev 2026-04-15 23:01:42 +02:00
parent 84c4c2eb88
commit 959034df62
6 changed files with 38 additions and 15 deletions

View file

@ -11,7 +11,7 @@ $accentColor = rgb(255, 0, 0)
(label) { (label) {
textColor = $accentColor textColor = $accentColor
backgroundColor = #000000FF backgroundColor = Color(#000000FF)
borderColor = $accentColor borderColor = $accentColor
fontSize = 20 fontSize = 20
borderRadius = 0 borderRadius = 0

View file

@ -17,9 +17,9 @@
***find a way to add fixed update to gui::Window ***find a way to add fixed update to gui::Window
***Add triangle drawing functions to BasicRenderer2D ***Add triangle drawing functions to BasicRenderer2D
***Implement Panel title ***Implement Panel title
***Implement show/hide functionality for widgets
Add theme caching Add theme caching
Implement global scale (probably query desktop scale and adjust accordingly) Implement global scale (probably query desktop scale and adjust accordingly)
Implement show/hide functionality for widgets
Create reliable default stylesheet Create reliable default stylesheet
Implement cursors in Stylesheet Implement cursors in Stylesheet

View file

@ -46,6 +46,7 @@ namespace ogfx
{ {
if (w == nullptr) continue; if (w == nullptr) continue;
if (w->isInvalid()) continue; if (w->isInvalid()) continue;
if (!w->isVisible()) continue;
if (w->m_focused) if (w->m_focused)
{ {
w->m_focused = false; w->m_focused = false;
@ -105,6 +106,7 @@ namespace ogfx
{ {
if (w == nullptr) continue; if (w == nullptr) continue;
if (w->isInvalid()) continue; if (w->isInvalid()) continue;
if (!w->isVisible()) continue;
gfx.pushClippingRect({ w->getGlobalPosition(), w->getSize() }, true); gfx.pushClippingRect({ w->getGlobalPosition(), w->getSize() }, true);
w->__draw(gfx); w->__draw(gfx);
gfx.popClippingRect(); gfx.popClippingRect();
@ -138,6 +140,7 @@ namespace ogfx
Widget* w = m_widgetList[i]; Widget* w = m_widgetList[i];
if (w == nullptr) continue; if (w == nullptr) continue;
if (w->isInvalid()) continue; if (w->isInvalid()) continue;
if (!w->isVisible()) continue;
if (!w->contains(event.mouse->position_x, event.mouse->position_y, true)) if (!w->contains(event.mouse->position_x, event.mouse->position_y, true))
continue; continue;
w->__onMousePressed(event); w->__onMousePressed(event);
@ -160,6 +163,7 @@ namespace ogfx
Widget* w = m_widgetList[i]; Widget* w = m_widgetList[i];
if (w == nullptr) continue; if (w == nullptr) continue;
if (w->isInvalid()) continue; if (w->isInvalid()) continue;
if (!w->isVisible()) continue;
if (w == m_mousePressedOnWidget) continue; if (w == m_mousePressedOnWidget) continue;
event.mouse->mousePressedOnWidget = m_mousePressedOnWidget; event.mouse->mousePressedOnWidget = m_mousePressedOnWidget;
w->__onMouseReleased(event); w->__onMouseReleased(event);
@ -178,6 +182,7 @@ namespace ogfx
Widget* w = m_widgetList[i]; Widget* w = m_widgetList[i];
if (w == nullptr) continue; if (w == nullptr) continue;
if (w->isInvalid()) continue; if (w->isInvalid()) continue;
if (!w->isVisible()) continue;
if (!w->contains(event.mouse->position_x, event.mouse->position_y, true)) if (!w->contains(event.mouse->position_x, event.mouse->position_y, true))
{ {
if (w->m_mouseInside) if (w->m_mouseInside)
@ -223,6 +228,7 @@ namespace ogfx
Widget* w = m_widgetList[i]; Widget* w = m_widgetList[i];
if (w == nullptr) continue; if (w == nullptr) continue;
if (w->isInvalid()) continue; if (w->isInvalid()) continue;
if (!w->isVisible()) continue;
if (!w->contains(event.mouse->position_x, event.mouse->position_y, true)) if (!w->contains(event.mouse->position_x, event.mouse->position_y, true))
continue; continue;
w->__onMouseScrolled(event); w->__onMouseScrolled(event);
@ -238,6 +244,7 @@ namespace ogfx
Widget* w = m_widgetList[i]; Widget* w = m_widgetList[i];
if (w == nullptr) continue; if (w == nullptr) continue;
if (w->isInvalid()) continue; if (w->isInvalid()) continue;
if (!w->isVisible()) continue;
if (!w->contains(event.mouse->position_x, event.mouse->position_y, true)) if (!w->contains(event.mouse->position_x, event.mouse->position_y, true))
continue; continue;
w->__onMouseDragged(event); w->__onMouseDragged(event);
@ -248,13 +255,13 @@ namespace ogfx
void WidgetManager::onKeyPressed(const Event& event) void WidgetManager::onKeyPressed(const Event& event)
{ {
if (!m_focused) return; if (!m_focused || !m_focused->isVisible()) return;
m_focused->__onKeyPressed(event); m_focused->__onKeyPressed(event);
} }
void WidgetManager::onKeyReleased(const Event& event) void WidgetManager::onKeyReleased(const Event& event)
{ {
if (!m_focused) return; if (!m_focused || !m_focused->isVisible()) return;
m_focused->__onKeyReleased(event); m_focused->__onKeyReleased(event);
if (m_tabNavigationEnabled && event.keyboard->keyCode == KeyCode::Tab) if (m_tabNavigationEnabled && event.keyboard->keyCode == KeyCode::Tab)
focusNext(); focusNext();
@ -262,7 +269,7 @@ namespace ogfx
void WidgetManager::onTextEntered(const Event& event) void WidgetManager::onTextEntered(const Event& event)
{ {
if (!m_focused) return; if (!m_focused || !m_focused->isVisible()) return;
m_focused->__onTextEntered(event); m_focused->__onTextEntered(event);
} }
@ -317,6 +324,7 @@ namespace ogfx
void WidgetManager::processDragAndDrop(Widget* widget, const Event& event) void WidgetManager::processDragAndDrop(Widget* widget, const Event& event)
{ {
if (widget == nullptr) return; if (widget == nullptr) return;
if (!widget->isVisible()) return;
if (!widget->isDragAndDropEnabled()) return; if (!widget->isDragAndDropEnabled()) return;
if (!widget->isMouseInside()) return; if (!widget->isMouseInside()) return;
if (Widget::s_dragAndDropData != nullptr) if (Widget::s_dragAndDropData != nullptr)

View file

@ -166,8 +166,15 @@ namespace ogfx
return true; return true;
} }
void Widget::setVisible(bool v)
{
m_visible = v;
}
void Widget::__draw(ogfx::BasicRenderer2D& gfx) void Widget::__draw(ogfx::BasicRenderer2D& gfx)
{ {
if (!isVisible())
return;
if (isDrawBoxEnabled()) if (isDrawBoxEnabled())
gfx.fillRect({ getGlobalPosition(), getSize() }, getDrawBoxColor()); gfx.fillRect({ getGlobalPosition(), getSize() }, getDrawBoxColor());
else else

View file

@ -57,6 +57,7 @@ namespace ogfx
bool getThemeQualifier(const String& qualifier) const; bool getThemeQualifier(const String& qualifier) const;
bool addThemeID(const String& id); bool addThemeID(const String& id);
bool removeThemeID(const String& id); bool removeThemeID(const String& id);
void setVisible(bool v);
inline const ostd::Stylesheet::QualifierList& getThemeQualifierList(void) const { return m_qualifierList; } inline const ostd::Stylesheet::QualifierList& getThemeQualifierList(void) const { return m_qualifierList; }
inline virtual void onDraw(ogfx::BasicRenderer2D& gfx) { } inline virtual void onDraw(ogfx::BasicRenderer2D& gfx) { }
@ -152,6 +153,9 @@ namespace ogfx
inline i32 getBorderRadius(void) const { return m_borderRadius; } inline i32 getBorderRadius(void) const { return m_borderRadius; }
inline void setBorderWidth(i32 bw) { m_borderWidth = bw; } inline void setBorderWidth(i32 bw) { m_borderWidth = bw; }
inline i32 getBorderWidth(void) const { return m_borderWidth; } inline i32 getBorderWidth(void) const { return m_borderWidth; }
inline bool isVisible(void) const { return m_visible; }
inline void show(void) { setVisible(true); }
inline void hide(void) { setVisible(false); }
template<typename T> template<typename T>
inline T getThemeValue(const ostd::Stylesheet &theme, const String& key, const T& fallback) inline T getThemeValue(const ostd::Stylesheet &theme, const String& key, const T& fallback)
@ -210,6 +214,7 @@ namespace ogfx
bool m_stopEvents { true }; bool m_stopEvents { true };
bool m_clipContents { true }; bool m_clipContents { true };
bool m_acceptDragAndDrop { false }; bool m_acceptDragAndDrop { false };
bool m_visible { true };
MouseEventData::eButton m_pressedButton { MouseEventData::eButton::None }; MouseEventData::eButton m_pressedButton { MouseEventData::eButton::None };
stdvec<String> m_themeIDList; stdvec<String> m_themeIDList;

View file

@ -89,7 +89,7 @@ class Window : public ogfx::gui::Window
m_check1.setPosition(30, 30); m_check1.setPosition(30, 30);
m_check1.setText("Check this out!"); m_check1.setText("Check this out!");
m_check1.setStateChangedCallback([&](ogfx::gui::widgets::CheckBox& sender, bool state) -> void { m_check1.setStateChangedCallback([&](ogfx::gui::widgets::CheckBox& sender, bool state) -> void {
std::cout << STR_BOOL(state) << "\n"; m_panel1.setVisible(state);
}); });
addWidget(m_check1); addWidget(m_check1);
@ -124,13 +124,16 @@ class Window : public ogfx::gui::Window
m_label1.addThemeOverride("@:pressed.label.textColor", Colors::Crimson); m_label1.addThemeOverride("@:pressed.label.textColor", Colors::Crimson);
m_theme.loadFromFile("./testTheme.txt", true, getDefaultStylesheetVariableList()); m_theme.loadFromFile("./testTheme.oss", true, getDefaultStylesheetVariableList());
m_label2.addThemeOverride("@:hover.label.showBackground", true); m_label2.addThemeOverride("@:hover.label.showBackground", true);
m_label2.addThemeOverride("@:hover.label.backgroundColor", Colors::DarkGreen); m_label2.addThemeOverride("@:hover.label.backgroundColor", Colors::DarkGreen);
m_label3.setPosition(0, 30); m_label3.setPosition(0, 30);
m_label3.setText("Bella!"); m_label3.setText("Bella!");
m_label3.setMousePressedCallback([&](const ogfx::gui::Event& event) -> void {
std::cout << "BALALLA!\n";
});
m_label3.addThemeID("label3"); m_label3.addThemeID("label3");
m_panel1.addChild(m_label3); m_panel1.addChild(m_label3);