Integrate ContextMenu with Pinnable logic.
This commit is contained in:
@@ -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:
|
||||
|
||||
|
Reference in New Issue
Block a user