Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
callout_box.hpp
Go to the documentation of this file.
1#pragma once
2
21
24#include <pulp/view/view.hpp>
25
26#include <functional>
27#include <memory>
28
29namespace pulp::view {
30
35
38
41 float arrow_length = 10.0f;
42 float arrow_width = 18.0f;
43 float margin = 8.0f;
44 float gap = 0.0f;
45 float corner_radius = 8.0f;
46};
47
52 float arrow_tip_x = 0.0f;
53 float arrow_tip_y = 0.0f;
54 float arrow_base_x = 0.0f;
55 float arrow_base_y = 0.0f;
56};
57
65CalloutPlacement place_callout(const Rect& anchor, float body_w, float body_h,
66 const Rect& window, CalloutSide preferred,
67 const CalloutStyle& style = {});
68
73class AnchoredCallout : public View {
74public:
76
78 void set_anchor(Rect anchor) { anchor_ = anchor; }
79 Rect anchor() const { return anchor_; }
80
81 void set_preferred_side(CalloutSide s) { preferred_ = s; }
82 CalloutSide preferred_side() const { return preferred_; }
83
84 void set_style(CalloutStyle style) { style_ = style; }
85 const CalloutStyle& style() const { return style_; }
86
89 void set_content_size(float w, float h) { content_w_ = w; content_h_ = h; }
90
93 void set_content(std::unique_ptr<View> content);
94 View* content() const { return content_; }
95
98
100 std::function<void()> on_dismiss;
101
104 static AnchoredCallout* show(View* root, Rect anchor, std::unique_ptr<View> content,
106 CalloutStyle style = {});
107
108 void paint(canvas::Canvas& canvas) override;
109 void layout_children() override;
110
111private:
112 Rect anchor_{};
113 CalloutSide preferred_ = CalloutSide::below;
114 CalloutStyle style_{};
115 float content_w_ = 0.0f, content_h_ = 0.0f;
116 View* content_ = nullptr;
117 static constexpr float kBodyPadding = 12.0f;
118};
119
120} // namespace pulp::view
Definition canvas.hpp:240
CalloutPlacement compute_placement(const Rect &window) const
Resolve the placement against window (typically this overlay's bounds).
void set_preferred_side(CalloutSide s)
Definition callout_box.hpp:81
std::function< void()> on_dismiss
Fired on Escape / outside-click dismiss.
Definition callout_box.hpp:100
static AnchoredCallout * show(View *root, Rect anchor, std::unique_ptr< View > content, CalloutSide preferred=CalloutSide::below, CalloutStyle style={})
Mount as a full-window overlay child of root, anchored to anchor, hosting content.
void set_style(CalloutStyle style)
Definition callout_box.hpp:84
void set_anchor(Rect anchor)
Anchor rect in the window/overlay LOCAL coordinate space.
Definition callout_box.hpp:78
View * content() const
Definition callout_box.hpp:94
Rect anchor() const
Definition callout_box.hpp:79
const CalloutStyle & style() const
Definition callout_box.hpp:85
AnchoredCallout()
Definition callout_box.hpp:75
void layout_children() override
void set_content(std::unique_ptr< View > content)
Attach the content view (ownership moves to the callout).
void paint(canvas::Canvas &canvas) override
CalloutSide preferred_side() const
Definition callout_box.hpp:82
void set_content_size(float w, float h)
The content box size (before the arrow / margins).
Definition callout_box.hpp:89
void set_focusable(bool f)
Definition view.hpp:669
Definition affine_transform.hpp:24
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
CalloutSide opposite_side(CalloutSide s)
Opposite side, used by the auto-flip.
@ s
Definition input_events.hpp:41
@ h
Definition input_events.hpp:39
@ w
Definition input_events.hpp:41
CalloutSide
Which side of the anchor the callout BODY sits on.
Definition callout_box.hpp:34
@ above
Definition callout_box.hpp:34
@ below
Definition callout_box.hpp:34
@ left_of
Definition callout_box.hpp:34
@ right_of
Definition callout_box.hpp:34
CalloutPlacement place_callout(const Rect &anchor, float body_w, float body_h, const Rect &window, CalloutSide preferred, const CalloutStyle &style={})
Place a body_w×body_h callout tethered to anchor, kept inside window.
Resolved placement in the window coordinate space.
Definition callout_box.hpp:49
float arrow_tip_x
triangle tip (touches/points at the anchor)
Definition callout_box.hpp:52
Rect body
the content box
Definition callout_box.hpp:50
float arrow_base_x
center of the triangle base, on the body edge
Definition callout_box.hpp:54
CalloutSide side
side chosen AFTER any auto-flip
Definition callout_box.hpp:51
float arrow_tip_y
Definition callout_box.hpp:53
float arrow_base_y
Definition callout_box.hpp:55
Tunables for the callout geometry. All lengths in the window coordinate space.
Definition callout_box.hpp:40
float margin
minimum gap kept between the body and the window edges
Definition callout_box.hpp:43
float corner_radius
body corner radius (arrow base stays clear of the corners)
Definition callout_box.hpp:45
float gap
extra gap between the anchor and the arrow tip
Definition callout_box.hpp:44
float arrow_length
how far the tip extends past the body edge toward the anchor
Definition callout_box.hpp:41
float arrow_width
base width of the triangle along the body edge
Definition callout_box.hpp:42
Axis-aligned rectangle in continuous (float) coordinates.
Definition geometry.hpp:52