Integrate ContextMenu with Pinnable logic.

This commit is contained in:
2025-05-01 00:38:14 -05:00
parent d807faea58
commit 5ab0d89793
2 changed files with 28 additions and 9 deletions

View File

@@ -14,6 +14,7 @@
#include <JUI/Widgets/TextButton.hpp>
#include "ListLayout.hpp"
#include "JUI/Mixins/Pinnable.hpp"
namespace JUI {
@@ -55,13 +56,13 @@ namespace JUI {
};
/// A vertically-descending list menu of button objects, which supports sub-menus much like class UtilityBar.
/// @see UtilityBar
class ContextMenu : public Rect {
class ContextMenu : public Rect, public Pinnable {
public:
Event<> PresumeMouseFocusLost;
void PropogateTextSize(int value) {
for (auto* child : children) {
TextStyleInterface* textual = dynamic_cast<TextStyleInterface *>(child);
@@ -107,12 +108,26 @@ namespace JUI {
/// @return Whether the widget will automatically hide itself when the mouse leaves its bounding box.
[[nodiscard]] bool CloseOnHoverLoss() const;
void Update(float delta) override {
Rect::Update(delta);
if (parent->IsMouseInside() || IsMouseInside() || IsMouseInsideDescendants())
mouse_outside_tests = 0;
else
mouse_outside_tests++;
if (mouse_outside_tests >= 3)
PresumeMouseFocusLost();
}
protected:
VerticalListLayout* layout;
JGL::Font font;
bool close_on_hover_loss = true;
float aggregate_height = 0;
float estimated_width = 0;
float mouse_outside_tests = 0;
private: