FlatUI
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Enumerations Groups Pages
Common Widgets

A collection of common widgets, such as buttons, sliders, and scroll bars. More...

Detailed Description

A collection of common widgets, such as buttons, sliders, and scroll bars.

This file contains some common widgets that will be widely useful.

FlatUI is structured to be very compositional, meaning that no one widget will always be universally useful for every UI. This means that these widgets are intended for the average UI, but may not be sufficient for custom use cases that extend beyond the scope of these widgets. Therefore these widgets may also serve as building blocks, or as examples, to easily build your own specialized widgets.

Enumerations

enum  flatui::ButtonProperty { kButtonPropertyDisabled = 1, kButtonPropertyImageLeft = 2, kButtonPropertyImageRight = 4 }
 Specifies the button properties used in common widgets. More...
 

Functions

ButtonProperty flatui::operator| (ButtonProperty a, ButtonProperty b)
 The bitwise OR operator for ButtonProperties. More...
 
ButtonProperty flatui::operator|= (ButtonProperty &a, const ButtonProperty &b)
 The bitwise OR assignment operator for ButtonProperties. More...
 
void flatui::SetHoverClickColor (const mathfu::vec4 &hover_color, const mathfu::vec4 &click_color)
 Some of the widgets provide user feedback by rendering a transparent background color to signal that the user is hovering over or clicking/touching/interacting with the widget. More...
 
Event flatui::TextButton (const char *text, float size, const Margin &margin)
 A simple button showing clickable text. More...
 
Event flatui::ImageButton (const fplbase::Texture &texture, float size, const Margin &margin, const char *id)
 A simple button showing a clickable image. More...
 
Event flatui::ToggleImageButton (const fplbase::Texture &up_texture, const fplbase::Texture &down_texture, float size, const Margin &margin, const char *id)
 A button showing a different image when clicked or not. More...
 
Event flatui::TextButton (const fplbase::Texture &texture, const Margin &texture_margin, const char *text, float size, const Margin &margin, const ButtonProperty property)
 A simple button showing clickable text with an image shown beside it. More...
 
Event flatui::CheckBox (const fplbase::Texture &texture_checked, const fplbase::Texture &texture_unchecked, const char *label, float size, const Margin &margin, bool *is_checked)
 A checkbox with a label next to it. More...
 
Event flatui::Slider (const fplbase::Texture &tex_bar, const fplbase::Texture &tex_knob, const mathfu::vec2 &size, float bar_height, const char *id, float *slider_value)
 A clider to change a numeric value. More...
 
Event flatui::ScrollBar (const fplbase::Texture &tex_background, const fplbase::Texture &tex_foreground, const mathfu::vec2 &size, float bar_size, const char *id, float *scroll_value)
 A scrollbar to indicate position in a scroll view. More...
 
void flatui::EventBackground (Event event)
 Sets a background color of the widget based on the event status. More...
 

Enumeration Type Documentation

Specifies the button properties used in common widgets.

kButtonPropertyDisabled disables buttons (CheckEvent() calls will be skipped). kButtonPropertyImageLeft shows the specified image to the left of the text label in a TextButton. kButtonPropertyImageRight shows the specified image to the right of the text label in a TextButton.

Function Documentation

Event flatui::CheckBox ( const fplbase::Texture &  texture_checked,
const fplbase::Texture &  texture_unchecked,
const char *  label,
float  size,
const Margin &  margin,
bool *  is_checked 
)

A checkbox with a label next to it.

Parameters
[in]texture_checkedA const reference to the Texture for when the box is checked.
[in]texture_uncheckedA const reference to the Texture for when the box is unchecked.
[in]labelA C-string to be used as the label that appears next to the checkbox.
[in]sizeA float corresponding to the size of the checkbox and label.
[in]marginA Margin around the checkbox.
[in,out]is_checkedA pointer to a bool determining if the checkbox is checked or not. It will capture the output of the kEventWentUp as well.
Returns
Returns the Event type for the checkbox.
void flatui::EventBackground ( Event  event)

Sets a background color of the widget based on the event status.

If the event is kEventIsDown, the background color used will be the click_color. If the event is kEventHover, the background color used will be hover_color.

Parameters
[in]eventThe Event type used to determine the background color.
Event flatui::ImageButton ( const fplbase::Texture &  texture,
float  size,
const Margin &  margin,
const char *  id 
)

A simple button showing a clickable image.

Note
Uses the colors that are set via SetHoverClickColor.
Parameters
[in]textureThe Texture of the image to display.
[in]sizeA float indicating the vertical height.
[in]marginA Margin around the texture.
[in]idA C-string to uniquely identify the button.
Returns
Returns the Event type for the button.
ButtonProperty flatui::operator| ( ButtonProperty  a,
ButtonProperty  b 
)
inline

The bitwise OR operator for ButtonProperties.

E.g. c = a | b;

Parameters
[in]aThe first ButtonProperty whose int value should be used in the bitwise OR.
[in]bThe second ButtonProperty whose int value should be used in the bitwise OR.
Returns
Returns a new ButtonProperty that is formed from the result of the bitwise OR of the two input ButtonProperties' int values.
ButtonProperty flatui::operator|= ( ButtonProperty &  a,
const ButtonProperty &  b 
)
inline

The bitwise OR assignment operator for ButtonProperties.

E.g. a |= b;

Parameters
[in]aThe modifiable ButtonProperty lvalue whose int value should be used in the bitwise OR. It also captures the return value of the function.
[in]bThe second ButtonProperty whose int value is used in the bitwise OR.
Returns
Returns a new ButtonProperty that is formed from the result of the bitwise OR of the two input ButtonProperties' int values.
Event flatui::ScrollBar ( const fplbase::Texture &  tex_background,
const fplbase::Texture &  tex_foreground,
const mathfu::vec2 &  size,
float  bar_size,
const char *  id,
float *  scroll_value 
)

A scrollbar to indicate position in a scroll view.

Note
The background and foreground Textures must be a ninepatch texture.
Parameters
[in]tex_backgroundA const Texture reference for the background.
[in]tex_foregroundA const Texture reference for the foreground.
[in]sizeA const vec2 reference to specify the whole size, including the margin, and the relative size of the scroll bar.
[in]bar_sizeA float corresponding to the size of the scroll bar.
[in]idA C-string to uniquely identify the scroll bar.
[out]scroll_valueA pointer to a float between 0.0 and 1.0 inclusive, which contains the position of the slider.
Returns
Returns the Event type for the scroll bar.
void flatui::SetHoverClickColor ( const mathfu::vec4 &  hover_color,
const mathfu::vec4 &  click_color 
)

Some of the widgets provide user feedback by rendering a transparent background color to signal that the user is hovering over or clicking/touching/interacting with the widget.

Be default, these are a dark grey and a medium grey, respectively. Both are semi-transparent.

Parameters
[in]hover_colorA const vec4 reference to the RGBA color values to use when hovering over a widget.
[in]click_colorA const vec4 reference to the RGBA color values to use when clicking on a widget.
Event flatui::Slider ( const fplbase::Texture &  tex_bar,
const fplbase::Texture &  tex_knob,
const mathfu::vec2 &  size,
float  bar_height,
const char *  id,
float *  slider_value 
)

A clider to change a numeric value.

Parameters
[in]tex_barThe Texture for the slider. Typically this is a bar of some kind as a ninepatch texture.
[in]tex_knobThe Texture for the knob to move on top of the tex_bar.
[in]sizeA const vec2 reference to specify the whole size, including the margin, and relative size of the slider.
[in]bar_heightA float corresponding the the Y ratio of the bar (usually 0.5).
[in]idA C-string to uniquely identify the slider.
[out]slider_valueA pointer to a float between 0.0 and 1.0 inclusive, which contains the position of the slider.
Event flatui::TextButton ( const char *  text,
float  size,
const Margin &  margin 
)

A simple button showing clickable text.

Note
Uses the colors that are set via SetHoverClickColor.
Parameters
[in]textA C-string of text to display on the button.
[in]sizeA float indicating the vertical height.
[in]marginA Margin that should be placed around the text.
Returns
Returns the Event type for the button.
Event flatui::TextButton ( const fplbase::Texture &  texture,
const Margin &  texture_margin,
const char *  text,
float  size,
const Margin &  margin,
const ButtonProperty  property 
)

A simple button showing clickable text with an image shown beside it.

Note
Uses the colors that are set via SetHoverClickColor.
Parameters
[in]textureThe Texture of the image to display beside the button.
[in]texture_marginThe Margin around the texture.
[in]textA C-string of text to display on the button.
[in]sizeA float indicating the vertical height.
[in]marginA Margin that should be placed around the text.
[in]propertyA ButtonProperty enum corresponding to where the image should be placed, relative to the button.
Returns
Returns the Event type for the button.
Event flatui::ToggleImageButton ( const fplbase::Texture &  up_texture,
const fplbase::Texture &  down_texture,
float  size,
const Margin &  margin,
const char *  id 
)

A button showing a different image when clicked or not.

Parameters
[in]up_textureThe Texture of the image to display if not clicked.
[in]down_textureThe Texture of the image to display if clicked.
[in]sizeA float indicating the vertical height.
[in]marginA Margin around the texture.
[in]idA C-string to uniquely identify the button.
Returns
Returns the Event type for the button.