Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
modal.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <pulp/view/view.hpp>
7#include <functional>
8
9namespace pulp::view {
10
25class ModalOverlay : public View {
26public:
28 std::function<void()> on_dismiss;
29
32
34 float backdrop_opacity = 0.5f;
35
36 void paint(canvas::Canvas& canvas) override {
37 // Draw dimmed backdrop
38 auto b = local_bounds();
39 canvas.set_fill_color(canvas::Color::rgba8(0, 0, 0,
40 static_cast<uint8_t>(backdrop_opacity * 255)));
41 canvas.fill_rect(b.x, b.y, b.width, b.height);
42 }
43
44 bool on_key_event(const KeyEvent& event) override {
45 if (event.is_down && event.key == KeyCode::escape) {
47 return true;
48 }
49 return false;
50 }
51
52 void on_mouse_event(const MouseEvent& event) override {
53 // If click is on backdrop (not on a child), dismiss
55 auto* target = hit_test(event.position);
56 if (target == this) {
58 }
59 }
60 }
61
62 bool wants_mouse_input() const override { return true; }
63};
64
65} // namespace pulp::view
Definition canvas.hpp:240
A modal overlay that captures focus and dims the background.
Definition modal.hpp:25
void on_mouse_event(const MouseEvent &event) override
Mouse down with full event context.
Definition modal.hpp:52
float backdrop_opacity
Backdrop opacity (0 = transparent, 1 = opaque black).
Definition modal.hpp:34
bool on_key_event(const KeyEvent &event) override
Key event with modifiers and up/down state.
Definition modal.hpp:44
std::function< void()> on_dismiss
Called when the modal is dismissed (Escape or backdrop click).
Definition modal.hpp:28
bool wants_mouse_input() const override
True if this widget handles mouse down/drag through virtual methods even when it does not expose JS p...
Definition modal.hpp:62
bool dismiss_on_backdrop_click
Whether clicking the dimmed backdrop dismisses the modal.
Definition modal.hpp:31
void paint(canvas::Canvas &canvas) override
Definition modal.hpp:36
virtual View * hit_test(Point local_point)
Rect local_bounds() const
Definition view.hpp:88
Definition affine_transform.hpp:24
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ b
Definition input_events.hpp:39
@ escape
Definition input_events.hpp:57
static constexpr Color rgba8(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Construct from 8-bit channels [0,255] — convenience for legacy/hex code.
Definition canvas.hpp:61
Rich key event with key code, modifiers, and repeat state.
Definition input_events.hpp:193
KeyCode key
Definition input_events.hpp:194
bool is_down
True for key-down, false for key-up.
Definition input_events.hpp:196
Rich mouse/pointer event with position, modifiers, button state, pointer ID, and stylus properties.
Definition input_events.hpp:104
bool is_down
True for mouse-down / touch-began events.
Definition input_events.hpp:111
Point position
Position in local view coordinates.
Definition input_events.hpp:105