Fixed Window close button simply setting the element to invisible and not properly calling Open()/Close() procedure.

This commit is contained in:
2025-06-27 15:27:29 -05:00
parent 3b973c2c45
commit d935608e05
2 changed files with 31 additions and 9 deletions

View File

@@ -34,6 +34,9 @@ namespace JUI {
/// which can be dragged around, resized, and docked into other applicable widgets.
class Window : public Widget, public RectBase, public Clickable, public Hoverable, public Draggable, public Resizable, public Dockable {
public:
Event<> OnOpen;
Event<> OnClose;
/// The default constructor sets a default style for this Window.
Window();
/// Construct a window widget by specifying it's parent.
@@ -173,8 +176,13 @@ namespace JUI {
{
// TODO: Consider how this plays with Clickable::OnClick and Clickable::OnRelease
if (this->visible && this->focused)
return Widget::ObserveMouseInput(btn, pressed);
if (visible) {
if (!pressed)
return Widget::ObserveMouseInput(btn, false);
if (this->focused)
return Widget::ObserveMouseInput(btn, pressed);
}
// Special case to allow drop of "Resizing"
if (btn == MouseButton::Right && pressed == false)
@@ -184,10 +192,12 @@ namespace JUI {
}
[[nodiscard]] bool IsOpen() const;
void Open();
void Close();
void SetOpen(bool value);
void Toggle();
[[nodiscard]] bool IsClosed() const;
virtual void Open();
virtual void Close();
virtual void SetOpen(bool value);
virtual void Toggle();
protected:
void UpdateInternalWidgetsTitlebarHeight();

View File

@@ -102,7 +102,7 @@ namespace JUI {
exit_btn->PressedImageColor(Colors::Reds::DarkRed);
exit_btn->OnReleaseEvent += [&] (...) {
this->Visible(false);
this->Close();
};
}
@@ -315,8 +315,18 @@ namespace JUI {
}
void Window::SetOpen(bool value) {
bool value_changed = value != open;
open = value;
Visible(open);
Visible(value);
if (value_changed) {
if (value)
OnOpen.Invoke();
else
OnClose.Invoke();
}
}
void Window::Toggle() {
@@ -346,4 +356,6 @@ namespace JUI {
}
bool Window::IsOpen() const { return open;}
}
bool Window::IsClosed() const { return !open;}
}