libgui 3.00
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiPopover Class Reference

A panel that opens beside the control that asked, over the screen it came from, with a tail that points at the control. More...

#include <GuiPopover.h>

Inheritance diagram for GuiPopover:
[legend]

Classes

struct  Anchor
 The control a popover opens beside, in canvas pixels. More...
 
struct  Insets
 What a popover keeps clear at the screen's edges: the bars at the top and bottom, and the margin at both sides. More...
 
struct  Position
 Where the panel's top-left corner goes. More...
 
struct  Tail
 The little tail on the panel: x,y is its top-left corner, w,h its size, direction the way it points (toward the anchor). More...
 

Public Types

enum class  TAIL { UP , DOWN , LEFT , RIGHT }
 Which way the tail points. More...
 

Public Member Functions

 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 keeping insets clear.
 
 GuiPopover (const Anchor &anchor, const Insets &insets, int screenWidth, int screenHeight)
 The same over a screen of screenWidth x screenHeight
 
- Public Member Functions inherited from GuiOverlay
 GuiOverlay (int w=0, int h=0)
 
- Public Member Functions inherited from GuiLayout
GuiLayout & add (GuiElement *e, const GuiItem &item=GuiItem())
 Adds a child. Children are laid out in the order they are added.
 
GuiLayout & add (GuiElement &e, const GuiItem &item=GuiItem())
 Adds a child by reference, so a builder can pass it straight in: row.add(ui.label("Hi"))
 
GuiLayout & addGap (float size)
 Adds a fixed gap along a row's width or a column's height.
 
GuiLayout & addSpace (float weight=1.0f)
 Adds flexible empty space that takes a share of what is left over, for example to push one child to each end of a row.
 
GuiLayout & setPadding (float all)
 Sets the space between the container's edge and its children.
 
GuiLayout & setPadding (float horizontal, float vertical)
 
GuiLayout & setPadding (float left, float top, float right, float bottom)
 
GuiLayout & setSpacing (float s)
 Sets the gap between neighbouring children (a grid uses both numbers)
 
GuiLayout & setSpacing (float x, float y)
 
GuiLayout & setJustify (LAYOUT_JUSTIFY j)
 Sets how leftover space along the main axis is spent when no child grows.
 
GuiLayout & setAlignItems (LAYOUT_ALIGN a)
 Sets the default alignment of children across the main axis.
 
GuiLayout & setFixedSize (int w, int h)
 Fixes the container's size (0 on an axis = fit the content)
 
GuiLayout & size (int w, int h)
 Short names for the setters above, for reading a layout top to bottom: ui.row().size(568, 0).gap(8).align(LAYOUT_ALIGN::CENTRE).add(...) */.
 
GuiLayout & gap (float s)
 
GuiLayout & gap (float x, float y)
 
GuiLayout & pad (float all)
 
GuiLayout & pad (float horizontal, float vertical)
 
GuiLayout & pad (float left, float top, float right, float bottom)
 
GuiLayout & align (LAYOUT_ALIGN a)
 
GuiLayout & justifyContent (LAYOUT_JUSTIFY j)
 
void invalidate ()
 Forces layout to run again.
 
void clear ()
 Removes every child.
 
void remove (GuiElement *e) override
 Removes the specified child.
 
void layout () override
 Brings the element's own layout up to date.
 
void draw () override
 Called constantly to redraw the element.
 
void update (InputController *c) override
 Called constantly to allow the element to respond to the current input data.
 
void getNaturalSize (int &w, int &h) override
 Layout protocol: how a layout container (GuiRow, GuiColumn, GuiGrid, GuiOverlay) asks about and arranges its children.
 
void setLayoutSize (int w, int h) override
 Gives the element a size chosen by a container (default: sets width and height)
 
void collectNavigable (std::vector< GuiElement * > &out) override
 Appends the elements that selection can move between (default: this element; layout containers add their children instead, so the D-pad moves through them)
 
- Public Member Functions inherited from GuiWindow
 GuiWindow ()
 Constructor.
 
 GuiWindow (int w, int h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
 ~GuiWindow ()
 Destructor.
 
void append (GuiElement *e)
 Appends a GuiElement to the GuiWindow.
 
void appendWithAutoRemove (GuiElement *e)
 Appends a GuiElement to the GuiWindow, and instructs the GuiElement to inform its parent on destruction.
 
void insert (GuiElement *e, uint32_t i)
 Inserts a GuiElement into the GuiWindow at the specified index.
 
void remove (GuiElement *e)
 Removes the specified GuiElement from the GuiWindow.
 
void removeAll ()
 Removes all GuiElements.
 
bool find (GuiElement *e)
 Looks for the specified GuiElement.
 
GuiElement * getGuiElementAt (uint32_t index) const
 Returns the GuiElement at the specified index.
 
uint32_t getSize ()
 Returns the size of the list of elements.
 
void setVisible (bool v)
 Sets the visibility of the window.
 
void resetState ()
 Resets the window's state to STATE::DEFAULT.
 
void setState (STATE s, int c=-1)
 Sets the window state, propagated to every child element.
 
int getSelected ()
 Gets the index of the GuiElement inside the window that is currently selected.
 
void setFocus (int f)
 Sets the window focus.
 
void changeFocus (GuiElement *e)
 Change the focus to the specified element This is intended for the primary GuiWindow only.
 
void toggleFocus (InputController *c)
 Changes window focus to the next focusable window or element If no element is in focus, changes focus to the first available element If B or 1 button is pressed, changes focus to the next available element This is intended for the primary GuiWindow only.
 
void moveSelectionHor (int d)
 Moves the selected element to the element to the left or right.
 
void moveSelectionVert (int d)
 Moves the selected element to the element above or below.
 
void resetText ()
 Resets the text for all contained elements.
 
void draw ()
 Draws all the elements in this GuiWindow.
 
void update (InputController *c)
 Updates the window and all elements contains within Allows the GuiWindow and all elements to respond to the input data specified.
 
GuiWindow * getAsWindow () override
 Returns this instance cast as a GuiWindow pointer.
 
- Public Member Functions inherited from GuiElement
 GuiElement ()
 Constructor.
 
virtual ~GuiElement ()
 Destructor.
 
void setParent (GuiElement *e)
 Set the element's parent.
 
GuiElement * getParent ()
 Gets the element's parent.
 
void setRemoveOnDestroy (bool autoRemove)
 Whether to notify parent on destruction to allow removal.
 
int getLeft ()
 Gets the current leftmost coordinate of the element Considers horizontal alignment, x offset, width, and parent element's GetLeft() / GetWidth() values.
 
int getTop ()
 Gets the current topmost coordinate of the element Considers vertical alignment, y offset, height, and parent element's GetTop() / GetHeight() values.
 
void setMinY (int y)
 Sets the minimum y offset of the element.
 
int getMinY ()
 Gets the minimum y offset of the element.
 
void setMaxY (int y)
 Sets the maximum y offset of the element.
 
int getMaxY ()
 Gets the maximum y offset of the element.
 
void setMinX (int x)
 Sets the minimum x offset of the element.
 
int getMinX ()
 Gets the minimum x offset of the element.
 
void setMaxX (int x)
 Sets the maximum x offset of the element.
 
int getMaxX ()
 Gets the maximum x offset of the element.
 
int getWidth ()
 Gets the current width of the element.
 
int getHeight ()
 Gets the height of the element.
 
void setSize (int w, int h)
 Sets the size (width/height) of the element.
 
bool isVisible ()
 Checks whether or not the element is visible.
 
bool isSelectable ()
 Checks whether or not the element is selectable.
 
bool isClickable ()
 Checks whether or not the element is clickable.
 
bool isHoldable ()
 Checks whether or not the element is holdable.
 
void setSelectable (bool s)
 Sets whether or not the element is selectable.
 
void setClickable (bool c)
 Sets whether or not the element is clickable.
 
void setHoldable (bool h)
 Sets whether or not the element is holdable.
 
STATE getState ()
 Gets the element's current state.
 
int getStateChan ()
 Gets the controller channel that last changed the element's state.
 
void setAlpha (int a)
 Sets the element's alpha value.
 
int getAlpha ()
 Gets the element's alpha value Considers alpha, alphaDyn, and the parent element's GetAlpha() value.
 
void setScale (float s)
 Sets the element's x and y scale.
 
void setScaleX (float s)
 Sets the element's x scale.
 
void setScaleY (float s)
 Sets the element's y scale.
 
void setScale (int w, int h)
 Sets the element's x and y scale, using the provided max width/height.
 
float getScale ()
 Gets the element's current scale Considers scale, scaleDyn, and the parent element's GetScale() value.
 
float getScaleX ()
 Gets the element's current x scale Considers scale, scaleDyn, and the parent element's GetScale() value.
 
float getScaleY ()
 Gets the element's current y scale Considers scale, scaleDyn, and the parent element's GetScale() value.
 
void setTrigger (GuiTrigger *t)
 Set a new GuiTrigger for the element.
 
void setTrigger (uint8_t i, GuiTrigger *t)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool isRumble ()
 Checks whether rumble was requested by the element.
 
void setRumble (bool r)
 Sets whether or not the element is requesting a rumble event.
 
void setEffect (int e, int a, int t=0)
 Set an effect for the element.
 
void setEffectOnOver (int e, int a, int t=0)
 Sets an effect to be enabled on wiimote cursor over.
 
void setEffectGrow (int percent=110)
 Shortcut to SetEffectOnOver(EFFECT::SCALE, 4, percent)
 
int getEffect ()
 Gets the current element effects.
 
bool isInside (int x, int y)
 Checks whether the specified coordinates are within the element's boundaries.
 
void setPosition (int x, int y)
 Sets the element's position.
 
void updateEffects ()
 Updates the element's effects (dynamic values) Called by Draw(), used for animation purposes.
 
void setUpdateCallback (UpdateCallback u)
 Sets a function to called after after Update() Callback function can be used to response to changes in the state of the element, and/or update the element's attributes.
 
int isFocused ()
 Checks whether the element is in focus.
 
virtual void setAlignment (ALIGN_H hor, ALIGN_V vert)
 Sets the element's alignment respective to its parent element.
 
virtual void setLayoutPosition (int x, int y)
 Places the element so its top-left corner is at (x, y) relative to its parent's top-left (default: LEFT/TOP alignment plus an offset)
 

Static Public Member Functions

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 it) beside the anchor, points the tail at it in tailColor (the panel's face), and attaches ui.
 

Protected Attributes

UiScope ui
 Owns the panel and everything else the popover is made of; build the panel with it.
 
- Protected Attributes inherited from GuiLayout
GuiInsets padding
 
float spacingX
 
float spacingY
 
LAYOUT_JUSTIFY justify
 
LAYOUT_ALIGN alignItems
 
- Protected Attributes inherited from GuiWindow
std::vector< GuiElement * > _elements
 Contains all elements within the GuiWindow.
 
- Protected Attributes inherited from GuiElement
GuiTrigger * trigger [MAX_TRIGGERS]
 GuiTriggers (input actions) that this element responds to.
 
UpdateCallback updateCB
 Callback function to call when this element is updated.
 
GuiElement * parentElement
 Parent element.
 
bool removeOnDestroy
 Whether to instruct parent to remove this element when it is destroyed.
 
int focus
 Element focus (-1 = focus disabled, 0 = not focused, 1 = focused)
 
int width
 Element width.
 
int height
 Element height.
 
int xoffset
 Element X offset.
 
int yoffset
 Element Y offset.
 
int ymin
 Element's min Y offset allowed.
 
int ymax
 Element's max Y offset allowed.
 
int xmin
 Element's min X offset allowed.
 
int xmax
 Element's max X offset allowed.
 
int xoffsetDyn
 Element X offset, dynamic (added to xoffset value for animation effects)
 
int yoffsetDyn
 Element Y offset, dynamic (added to yoffset value for animation effects)
 
int alpha
 Element alpha value (0-255)
 
int alphaDyn
 Element alpha, dynamic (multiplied by alpha value for blending/fading effects)
 
float xscale
 Element X scale (1 = 100%)
 
float yscale
 Element Y scale (1 = 100%)
 
float scaleDyn
 Element scale, dynamic (multiplied by alpha value for blending/fading effects)
 
int effects
 Currently enabled effect(s).
 
int effectAmount
 Effect amount.
 
int effectTarget
 Effect target amount.
 
int effectsOver
 Effects to enable when wiimote cursor is over this element.
 
int effectAmountOver
 EffectAmount to set when wiimote cursor is over this element.
 
int effectTargetOver
 EffectTarget to set when wiimote cursor is over this element.
 
ALIGN_H alignmentHor
 Horizontal element alignment, respective to parent element (LEFT, RIGHT, CENTRE)
 
ALIGN_V alignmentVert
 Horizontal element alignment, respective to parent element (TOP, BOTTOM, MIDDLE)
 
STATE state
 Element state (DEFAULT, SELECTED, CLICKED, DISABLED)
 
int stateChan
 Which controller channel is responsible for the last change in state.
 
bool selectable
 Whether or not this element selectable (can change to SELECTED state)
 
bool clickable
 Whether or not this element is clickable (can change to CLICKED state)
 
bool holdable
 Whether or not this element is holdable (can change to HELD state)
 
bool visible
 Visibility of the element.
 
bool rumble
 Wiimote rumble (on/off) - set to on when this element requests a rumble event.
 

Additional Inherited Members

- Protected Member Functions inherited from GuiOverlay
GuiLayoutResult solve (const std::vector< Entry * > &visible, float fixedW, float fixedH) override
 Works out the container size and each visible entry's rectangle (what a subclass does)
 
- Protected Member Functions inherited from GuiWindow
bool collectNavigation (std::vector< GuiElement * > &out)
 Gathers the elements selection can move between, looking inside layout containers.
 
void moveSelectionIn (std::vector< GuiElement * > &list, NAV_DIR d)
 Moves the selection within a collected list by on-screen geometry.
 
void drawWash ()
 Draws the dimming over a disabled screen: the one place that colour is set.
 

Detailed Description

A panel that opens beside the control that asked, over the screen it came from, with a tail that points at the control.

It is a full-screen overlay: it places the panel (place()), draws the tail, and decides when the popover is dismissed. It closes on B from any controller, or on a click from any controller whose pointer is outside the panel; a click on the panel is the panel's own. What is on the panel, and how it looks, is up to the caller.

A popover does not run itself. Add it on top of the screen it came from (disabling that screen so it dims and stops listening), keep updating the window, and watch isDismissed(). To keep it open after all (a B that only stopped something inside it), call reopen().

Derive from it, say where it opens and what to keep clear in the constructor, build the panel in ui, and hand it over with setPanel(), which places the panel and attaches ui:

class Ask : public GuiPopover
{
public:
Ask(GuiElement& button) : GuiPopover(Anchor(button), Insets(60, 60, 20))
{
setPanel(ui.card().selectable(false).size(280, 160).add(ui.label("Sure?")));
}
};
Primary GUI class.
Definition GuiElement.h:62
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...
UiScope ui
Owns the panel and everything else the popover is made of; build the panel with it.
Definition GuiPopover.h:115
The control a popover opens beside, in canvas pixels.
Definition GuiPopover.h:40
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

The placement arithmetic (place(), tailAt(), maxHeight()) is static and needs no popover, so it can be tested on a host or used to draw a preview.

Definition at line 35 of file GuiPopover.h.

Member Enumeration Documentation

◆ TAIL

enum class GuiPopover::TAIL
strong

Which way the tail points.

Definition at line 67 of file GuiPopover.h.

Constructor & Destructor Documentation

◆ GuiPopover() [1/2]

GuiPopover::GuiPopover ( const Anchor & anchor = Anchor(),
const Insets & insets = Insets() )
explicit

A popover as large as the screen the platform reports, opening beside anchor (centered with none) and keeping insets clear.

Definition at line 94 of file GuiPopover.cpp.

◆ GuiPopover() [2/2]

GuiPopover::GuiPopover ( const Anchor & anchor,
const Insets & insets,
int screenWidth,
int screenHeight )

The same over a screen of screenWidth x screenHeight

Definition at line 99 of file GuiPopover.cpp.

Member Function Documentation

◆ tailAt()

GuiPopover::Tail GuiPopover::tailAt ( const Anchor & anchor,
const Position & at,
int panelW,
int panelH )
static

Puts the built panel (a card owned by ui, fixed or fit to its content: it is laid out here to measure it) beside the anchor, points the tail at it in tailColor (the panel's face), and attaches ui.

Call once, after the panel is built. The default tail !color is the theme's surfaceRaised. void setPanel(GuiCard& panel, PixelColor tailColor); void setPanel(GuiCard& panel);

!The most height a panel can have here: the band between the bars. Use it to size a panel before building it. int maxPanelHeight() const { return maxHeight(screenH, insets); } !Where the panel went (its top-left corner, in canvas pixels). Valid after setPanel(). const Position& position() const { return placed; } !The tail drawn on the panel; shown is false with no anchor or when the panel covers it. Valid after setPanel(). const Tail& tail() const { return placedTail; }

!Dismisses the popover as B does (a close button on the panel calls this) void dismiss(); !Whether B, a click outside the panel or dismiss() has asked for it to close bool isDismissed() const { return dismissed; } !The controller channel that dismissed it, or -1 for dismiss() or while it is open int dismissedBy() const { return by; } !Keeps it open after all: clears the dismissal void reopen() { dismissed = false; by = -1; } !Updates the panel first (a click on it is its own), then watches for the dismissal void update(InputController * c) override;

!The most height a popover can have: the band between the bars. static int maxHeight(int screenHeight, const Insets& insets); !Places a panel of w x h beside its anchor: below it when that fits above the bottom bar, else above it, !and failing both inside the band between the bars. A panel whose anchor is in a bar comes straight out of it, !so the bars bind only an anchor that is in the band. Horizontally it lines up with the anchor's right edge when !the anchor is on the right half of the screen and its left edge otherwise (or against a side margin, per the !anchor's edge), and always stays inside the side margins. With no anchor it is centered. static Position place(const Anchor& anchor, int w, int h, int screenWidth, int screenHeight, const Insets& insets); !Where the tail goes for a panel of panelW x panelH at at: on the side facing the anchor, level with the anchor's middle but kept clear of the panel's corners. Not shown when the panel covers the anchor or there is none.

Definition at line 66 of file GuiPopover.cpp.

Member Data Documentation

◆ ui

UiScope GuiPopover::ui
protected

Owns the panel and everything else the popover is made of; build the panel with it.

Definition at line 115 of file GuiPopover.h.


The documentation for this class was generated from the following files: