libgui 3.00
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiPopover.h
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2026
4 * GuiPopover.h
5 *
6 * A question asked in place: a panel that opens beside the control that asked
7 * it, over the screen it came from.
8 ***************************************************************************/
9#pragma once
10
35class GuiPopover : public GuiOverlay
36{
37 public:
39 struct Anchor
40 {
43 enum Edge { AUTO, LEFT_MARGIN, RIGHT_MARGIN, BESIDE };
44 int x, y, w, h;
45 bool valid;
46 Edge edge;
48 Anchor() : x(0), y(0), w(0), h(0), valid(false), edge(AUTO) {}
50 Anchor(int ax, int ay, int aw, int ah, Edge e = AUTO) : x(ax), y(ay), w(aw), h(ah), valid(true), edge(e) {}
52 explicit Anchor(GuiElement& control, Edge e = AUTO) : x(control.getLeft()), y(control.getTop()), w(control.getWidth()), h(control.getHeight()), valid(true), edge(e) {}
53 };
54
57 struct Insets
58 {
59 int top, bottom, side;
60 Insets(int t = 0, int b = 0, int s = 0) : top(t), bottom(b), side(s) {}
61 };
62
64 struct Position { int x, y; };
65
67 enum class TAIL { UP, DOWN, LEFT, RIGHT };
68
70 struct Tail { bool shown; TAIL direction; int x, y, w, h; };
71
74 explicit GuiPopover(const Anchor& anchor = Anchor(), const Insets& insets = Insets());
76 GuiPopover(const Anchor& anchor, const Insets& insets, int screenWidth, int screenHeight);
77
81 void setPanel(GuiCard& panel, PixelColor tailColor);
82 void setPanel(GuiCard& panel);
83
85 int maxPanelHeight() const { return maxHeight(screenH, insets); }
87 const Position& position() const { return placed; }
89 const Tail& tail() const { return placedTail; }
90
92 void dismiss();
94 bool isDismissed() const { return dismissed; }
96 int dismissedBy() const { return by; }
98 void reopen() { dismissed = false; by = -1; }
100 void update(InputController * c) override;
101
103 static int maxHeight(int screenHeight, const Insets& insets);
109 static Position place(const Anchor& anchor, int w, int h, int screenWidth, int screenHeight, const Insets& insets);
112 static Tail tailAt(const Anchor& anchor, const Position& at, int panelW, int panelH);
113
114 protected:
115 UiScope ui;
116 private:
117 Anchor anchor;
118 Insets insets;
119 int screenW, screenH;
120 GuiTrigger * cancel; // B
121 GuiTrigger * click; // the primary press, for a click outside the panel
122 GuiElement * panel;
123 Position placed;
124 Tail placedTail;
125 bool dismissed;
126 int by;
127};
Primary GUI class.
Definition GuiElement.h:62
int getTop()
Gets the current topmost coordinate of the element Considers vertical alignment, y offset,...
int getWidth()
Gets the current width of the element.
int getLeft()
Gets the current leftmost coordinate of the element Considers horizontal alignment,...
int getHeight()
Gets the height of the element.
void update(InputController *c) override
Called constantly to allow the element to respond to the current input data.
GuiOverlay(int w=0, int h=0)
GuiPopover(const Anchor &anchor=Anchor(), const Insets &insets=Insets())
A popover as large as the screen the platform reports, opening beside anchor (centered with none) and...
static Tail tailAt(const Anchor &anchor, const Position &at, int panelW, int panelH)
Puts the built panel (a card owned by ui, fixed or fit to its content: it is laid out here to measure...
UiScope ui
Owns the panel and everything else the popover is made of; build the panel with it.
Definition GuiPopover.h:115
TAIL
Which way the tail points.
Definition GuiPopover.h:67
Input-condition matcher attached to a GuiElement (via setSimpleTrigger() etc.) and evaluated against ...
Definition GuiTrigger.h:34
The control a popover opens beside, in canvas pixels.
Definition GuiPopover.h:40
Edge
Which way the panel lines up: with the anchor's nearer edge (AUTO), or against a side margin to leave...
Definition GuiPopover.h:43
Anchor()
No anchor: the popover is centered.
Definition GuiPopover.h:48
Anchor(GuiElement &control, Edge e=AUTO)
The popover opens beside control, where it is now.
Definition GuiPopover.h:52
Anchor(int ax, int ay, int aw, int ah, Edge e=AUTO)
The popover opens beside the rectangle ax,ay,aw,ah
Definition GuiPopover.h:50
bool valid
false for a popover with no anchor: it is centered
Definition GuiPopover.h:45
What a popover keeps clear at the screen's edges: the bars at the top and bottom, and the margin at b...
Definition GuiPopover.h:58
Where the panel's top-left corner goes.
Definition GuiPopover.h:64
The little tail on the panel: x,y is its top-left corner, w,h its size, direction the way it points (...
Definition GuiPopover.h:70
8-bit-per-channel RGBA color used by the video interfaces.
Definition Mesh.h:16