Added hide/show functionality to widgets
This commit is contained in:
parent
84c4c2eb88
commit
959034df62
6 changed files with 38 additions and 15 deletions
|
|
@ -11,7 +11,7 @@ $accentColor = rgb(255, 0, 0)
|
|||
|
||||
(label) {
|
||||
textColor = $accentColor
|
||||
backgroundColor = #000000FF
|
||||
backgroundColor = Color(#000000FF)
|
||||
borderColor = $accentColor
|
||||
fontSize = 20
|
||||
borderRadius = 0
|
||||
|
|
@ -17,9 +17,9 @@
|
|||
***find a way to add fixed update to gui::Window
|
||||
***Add triangle drawing functions to BasicRenderer2D
|
||||
***Implement Panel title
|
||||
***Implement show/hide functionality for widgets
|
||||
Add theme caching
|
||||
Implement global scale (probably query desktop scale and adjust accordingly)
|
||||
Implement show/hide functionality for widgets
|
||||
Create reliable default stylesheet
|
||||
Implement cursors in Stylesheet
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ namespace ogfx
|
|||
{
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
if (!w->isVisible()) continue;
|
||||
if (w->m_focused)
|
||||
{
|
||||
w->m_focused = false;
|
||||
|
|
@ -105,6 +106,7 @@ namespace ogfx
|
|||
{
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
if (!w->isVisible()) continue;
|
||||
gfx.pushClippingRect({ w->getGlobalPosition(), w->getSize() }, true);
|
||||
w->__draw(gfx);
|
||||
gfx.popClippingRect();
|
||||
|
|
@ -138,6 +140,7 @@ namespace ogfx
|
|||
Widget* w = m_widgetList[i];
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
if (!w->isVisible()) continue;
|
||||
if (!w->contains(event.mouse->position_x, event.mouse->position_y, true))
|
||||
continue;
|
||||
w->__onMousePressed(event);
|
||||
|
|
@ -160,6 +163,7 @@ namespace ogfx
|
|||
Widget* w = m_widgetList[i];
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
if (!w->isVisible()) continue;
|
||||
if (w == m_mousePressedOnWidget) continue;
|
||||
event.mouse->mousePressedOnWidget = m_mousePressedOnWidget;
|
||||
w->__onMouseReleased(event);
|
||||
|
|
@ -178,6 +182,7 @@ namespace ogfx
|
|||
Widget* w = m_widgetList[i];
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
if (!w->isVisible()) continue;
|
||||
if (!w->contains(event.mouse->position_x, event.mouse->position_y, true))
|
||||
{
|
||||
if (w->m_mouseInside)
|
||||
|
|
@ -223,6 +228,7 @@ namespace ogfx
|
|||
Widget* w = m_widgetList[i];
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
if (!w->isVisible()) continue;
|
||||
if (!w->contains(event.mouse->position_x, event.mouse->position_y, true))
|
||||
continue;
|
||||
w->__onMouseScrolled(event);
|
||||
|
|
@ -238,6 +244,7 @@ namespace ogfx
|
|||
Widget* w = m_widgetList[i];
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
if (!w->isVisible()) continue;
|
||||
if (!w->contains(event.mouse->position_x, event.mouse->position_y, true))
|
||||
continue;
|
||||
w->__onMouseDragged(event);
|
||||
|
|
@ -248,13 +255,13 @@ namespace ogfx
|
|||
|
||||
void WidgetManager::onKeyPressed(const Event& event)
|
||||
{
|
||||
if (!m_focused) return;
|
||||
if (!m_focused || !m_focused->isVisible()) return;
|
||||
m_focused->__onKeyPressed(event);
|
||||
}
|
||||
|
||||
void WidgetManager::onKeyReleased(const Event& event)
|
||||
{
|
||||
if (!m_focused) return;
|
||||
if (!m_focused || !m_focused->isVisible()) return;
|
||||
m_focused->__onKeyReleased(event);
|
||||
if (m_tabNavigationEnabled && event.keyboard->keyCode == KeyCode::Tab)
|
||||
focusNext();
|
||||
|
|
@ -262,7 +269,7 @@ namespace ogfx
|
|||
|
||||
void WidgetManager::onTextEntered(const Event& event)
|
||||
{
|
||||
if (!m_focused) return;
|
||||
if (!m_focused || !m_focused->isVisible()) return;
|
||||
m_focused->__onTextEntered(event);
|
||||
}
|
||||
|
||||
|
|
@ -317,6 +324,7 @@ namespace ogfx
|
|||
void WidgetManager::processDragAndDrop(Widget* widget, const Event& event)
|
||||
{
|
||||
if (widget == nullptr) return;
|
||||
if (!widget->isVisible()) return;
|
||||
if (!widget->isDragAndDropEnabled()) return;
|
||||
if (!widget->isMouseInside()) return;
|
||||
if (Widget::s_dragAndDropData != nullptr)
|
||||
|
|
|
|||
|
|
@ -128,16 +128,16 @@ namespace ogfx
|
|||
|
||||
void Widget::setThemeQualifier(const String& qualifier, bool value)
|
||||
{
|
||||
for (auto& [name, state] : m_qualifierList)
|
||||
{
|
||||
if (name == qualifier)
|
||||
{
|
||||
for (auto& [name, state] : m_qualifierList)
|
||||
{
|
||||
if (name == qualifier)
|
||||
{
|
||||
if (state == value) return;
|
||||
state = value;
|
||||
state = value;
|
||||
reloadTheme();
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Widget::getThemeQualifier(const String& qualifier) const
|
||||
|
|
@ -166,8 +166,15 @@ namespace ogfx
|
|||
return true;
|
||||
}
|
||||
|
||||
void Widget::setVisible(bool v)
|
||||
{
|
||||
m_visible = v;
|
||||
}
|
||||
|
||||
void Widget::__draw(ogfx::BasicRenderer2D& gfx)
|
||||
{
|
||||
if (!isVisible())
|
||||
return;
|
||||
if (isDrawBoxEnabled())
|
||||
gfx.fillRect({ getGlobalPosition(), getSize() }, getDrawBoxColor());
|
||||
else
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ namespace ogfx
|
|||
bool getThemeQualifier(const String& qualifier) const;
|
||||
bool addThemeID(const String& id);
|
||||
bool removeThemeID(const String& id);
|
||||
void setVisible(bool v);
|
||||
inline const ostd::Stylesheet::QualifierList& getThemeQualifierList(void) const { return m_qualifierList; }
|
||||
|
||||
inline virtual void onDraw(ogfx::BasicRenderer2D& gfx) { }
|
||||
|
|
@ -152,6 +153,9 @@ namespace ogfx
|
|||
inline i32 getBorderRadius(void) const { return m_borderRadius; }
|
||||
inline void setBorderWidth(i32 bw) { m_borderWidth = bw; }
|
||||
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>
|
||||
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_clipContents { true };
|
||||
bool m_acceptDragAndDrop { false };
|
||||
bool m_visible { true };
|
||||
MouseEventData::eButton m_pressedButton { MouseEventData::eButton::None };
|
||||
|
||||
stdvec<String> m_themeIDList;
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class Window : public ogfx::gui::Window
|
|||
m_check1.setPosition(30, 30);
|
||||
m_check1.setText("Check this out!");
|
||||
m_check1.setStateChangedCallback([&](ogfx::gui::widgets::CheckBox& sender, bool state) -> void {
|
||||
std::cout << STR_BOOL(state) << "\n";
|
||||
m_panel1.setVisible(state);
|
||||
});
|
||||
addWidget(m_check1);
|
||||
|
||||
|
|
@ -124,13 +124,16 @@ class Window : public ogfx::gui::Window
|
|||
|
||||
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.backgroundColor", Colors::DarkGreen);
|
||||
|
||||
m_label3.setPosition(0, 30);
|
||||
m_label3.setText("Bella!");
|
||||
m_label3.setMousePressedCallback([&](const ogfx::gui::Event& event) -> void {
|
||||
std::cout << "BALALLA!\n";
|
||||
});
|
||||
m_label3.addThemeID("label3");
|
||||
m_panel1.addChild(m_label3);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue