FlatUI
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Enumerations Groups Pages
flatui.h File Reference
#include <functional>
#include <string>
#include "flatui/font_util.h"
#include "flatui/version.h"
#include "font_manager.h"
#include "fplbase/asset_manager.h"
#include "fplbase/input.h"
#include "mathfu/constants.h"

Go to the source code of this file.

Classes

struct  flatui::AnimCurveDescription
 Describes a curve's typical shape. More...
 
struct  flatui::Margin
 Specifies the margins for a group, in units of virtual resolution. More...
 
class  flatui::details::FloatConverter< T >
 converts from a mathfu::vector to a const float pointer and vice versa. More...
 
class  flatui::details::FloatConverter< float >
 
class  flatui::details::FloatConverter< mathfu::Vector< float, d > >
 

Namespaces

 flatui
 Namespace for FlatUI library.
 

Enumerations

enum  flatui::AnimType { kAnimEaseInEaseOut, kAnimSpring, kAnimTypeCount }
 Anim type describes the algorithm used to animate a UI element. More...
 
enum  flatui::Event {
  kEventNone = 0, kEventWentUp = 1, kEventWentDown = 2, kEventIsDown = 4,
  kEventStartDrag = 8, kEventEndDrag = 16, kEventIsDragging = 32, kEventHover = 64
}
 Event types are returned by most interactive elements. These are flags, because multiple events may occur during one frame, and thus should be tested using a Bitwise operators (&, |, etc.). More...
 
enum  flatui::Alignment {
  kAlignTop = 1, kAlignLeft = 1, kAlignCenter = 2, kAlignBottom = 3,
  kAlignRight = 3
}
 Alignment of the groups. More...
 
enum  flatui::Direction { kDirHorizontal = 4, kDirVertical = 8, kDirOverlay = 12 }
 Direction of the groups. More...
 
enum  flatui::EditStatus {
  kEditStatusNone = 0, kEditStatusInEdit = 1, kEditStatusUpdated = 2, kEditStatusFinished = 3,
  kEditStatusCanceled = 4
}
 Status of Edit widget. More...
 
enum  flatui::Layout {
  kLayoutHorizontalTop = kDirHorizontal| kAlignTop, kLayoutHorizontalCenter = kDirHorizontal| kAlignCenter, kLayoutHorizontalBottom = kDirHorizontal| kAlignBottom, kLayoutVerticalLeft = kDirVertical | kAlignLeft,
  kLayoutVerticalCenter = kDirVertical | kAlignCenter, kLayoutVerticalRight = kDirVertical | kAlignRight, kLayoutOverlay = kDirOverlay | kAlignCenter
}
 Specify how to layout a group. More...
 

Functions

void flatui::Run (fplbase::AssetManager &assetman, FontManager &fontman, fplbase::InputSystem &input, motive::MotiveEngine *motive_engine, const std::function< void()> &gui_definition)
 The core function that drives the GUI. More...
 
void flatui::Run (fplbase::AssetManager &assetman, FontManager &fontman, fplbase::InputSystem &input, const std::function< void()> &gui_definition)
 A version of the function above that doesn't use a MotiveEngine. With this version of Run(), user will not be able to use the animation features of FlatUI. If a user tries to use FlatUI's animation features with this version of Run(), the program will terminate with an error.
 
mathfu::vec2i flatui::VirtualToPhysical (const mathfu::vec2 &v)
 Converts a virtual screen coordinate to a physical value. More...
 
mathfu::vec2 flatui::PhysicalToVirtual (const mathfu::vec2i &v)
 Converts a physical screen coordinate to a virtual value. More...
 
float flatui::GetScale ()
 Get the scaling factor for the virtual resolution. More...
 
void flatui::Image (const fplbase::Texture &texture, float ysize, const char *id=kDefaultImageID)
 Render an image as a GUI element. More...
 
void flatui::SetImageColor (const mathfu::vec4 &color)
 Set the Images's tint. More...
 
void flatui::Label (const char *text, float ysize, HashedId label_id=kNullHash)
 Render a label as a GUI element. More...
 
void flatui::Label (const char *text, float ysize, const mathfu::vec2 &size, HashedId label_id=kNullHash)
 Render a multi-line version of a label as a GUI element. More...
 
void flatui::Label (const char *text, float ysize, const mathfu::vec2 &label_size, TextAlignment alignment, HashedId label_id=kNullHash)
 Render a multi-line label with a text alignment. More...
 
void flatui::HtmlLabel (const char *html, float ysize, const mathfu::vec2 &label_size, TextAlignment alignment, const char *id)
 Render simple HTML text. More...
 
void flatui::SetTextColor (const mathfu::vec4 &color)
 Set the Label's text color. More...
 
void flatui::SetTextOuterColor (const mathfu::vec4 &color, float size, const mathfu::vec2 &offset)
 Set the Label's outer color (e.g. drop shadow color). To use the feature, outer SDF generation needs to be enabled by EnableTextSDF() API. With SDF, each glyph image includes a distance to the nearest edge. The API utilizes the feature to render an outer region of a glyph. For more details of SDF, refer a paper from Valve: http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf. More...
 
void flatui::EnableTextSDF (bool inner_sdf, bool outer_sdf, float threshold)
 Enable/Disable a signed distance field generation with glyphs. A SDF generation of an inner region and an outer region is done separately and it costs some cycles. So if an application doesn't utilize inner SDF, just enable outer SDF. More...
 
void flatui::EnableTextHyphenation (bool enable)
 Enable/Disable the hyphenation in the text label. More...
 
bool flatui::SetTextFont (const char *font_name)
 Set the Label's font. More...
 
bool flatui::SetTextFont (const char *font_names[], int32_t count)
 Set the Label's fonts with a fallback priority. When rendering a text, if a glyph is not found in the first font in the array, the renderer will look up the glyph in the second font and so on. If the glyph is not found in all font files, the glyph won't be rendered on the screen. More...
 
void flatui::SetTextLocale (const char *locale)
 Set a locale used for the text rendering. More...
 
void flatui::SetTextDirection (const TextLayoutDirection direction)
 Override a text layout direction set by SetTextLocale() API. More...
 
void flatui::SetTextLineHeightScale (float scale)
 Set a line height scale used in the text rendering. More...
 
void flatui::SetTextKerningScale (float scale)
 Set a kerning scale used in the text rendering. More...
 
void flatui::SetTextEllipsis (const char *ellipsis)
 Set an ellipsis string used in label/edit widgets. More...
 
Event flatui::Edit (float ysize, const mathfu::vec2 &size, const char *id, EditStatus *status, std::string *string)
 Renders an edit text box as a GUI element. More...
 
Event flatui::Edit (float ysize, const mathfu::vec2 &size, TextAlignment alignment, const char *id, EditStatus *status, std::string *string)
 Render an edit text box with a text alignment. More...
 
void flatui::StartGroup (Layout layout, float spacing=0, const char *id=kDefaultGroupID)
 Create a group of elements with a given layout and intra-element spacing. More...
 
void flatui::EndGroup ()
 Clean up the Group element start by StartGroup(). More...
 
void flatui::SetMargin (const Margin &margin)
 Sets the margin for the current group. More...
 
Event flatui::CheckEvent ()
 Check for events from the current group. More...
 
Event flatui::CheckEvent (bool check_dragevent_only)
 Check for events from the current group. More...
 
void flatui::SetDefaultFocus ()
 Set the default keyboard/gamepad focus to the current element.
 
void flatui::ModalGroup ()
 Called inside of a group that that is mean to act like a popup inside of a kLayoutOverlay. More...
 
void flatui::CapturePointer (const char *element_id)
 Caputre a pointer event. More...
 
void flatui::ReleasePointer ()
 Release a pointer capture. More...
 
ssize_t flatui::GetCapturedPointerIndex ()
 Get the index of th ecaptured pointer. More...
 
void flatui::SetScrollSpeed (float scroll_speed_drag, float scroll_speed_wheel, float scroll_speed_gamepad)
 Set the scroll speed of the drag, mouse wheel, and gamepad operations. More...
 
void flatui::SetDragStartThreshold (int drag_start_threshold)
 Set a threshold value for the start of a drag operation. More...
 
void flatui::ColorBackground (const mathfu::vec4 &color)
 Set the background color for the group. More...
 
void flatui::ImageBackground (const fplbase::Texture &tex)
 Set the background texture for the group. More...
 
void flatui::ImageBackgroundNinePatch (const fplbase::Texture &tex, const mathfu::vec4 &patch_info)
 Set the background texture for the group with nine patch settings. More...
 
void flatui::StartScroll (const mathfu::vec2 &size, mathfu::vec2 *offset)
 Make the current group into a scrolling group that can display arbitrary sized elements inside a window of "size", scrolled to the current "offset" (which the caller should store somewhere that survives the current frame). More...
 
void flatui::EndScroll ()
 Ends the current scrolling group. More...
 
void flatui::StartSlider (Direction direction, float scroll_margin, float *value)
 Make the current group into a slider group that can handle basic slider behavior. The group will capture/release the pointer as necessary. More...
 
void flatui::EndSlider ()
 Ends the current slider group. More...
 
void flatui::CustomElement (const mathfu::vec2 &virtual_size, const char *id, const std::function< void(const mathfu::vec2i &pos, const mathfu::vec2i &size)> renderer)
 Create a custom element with a given size. More...
 
void flatui::RenderTexture (const fplbase::Texture &tex, const mathfu::vec2i &pos, const mathfu::vec2i &size)
 Render a Texture to a specific position with a given size. More...
 
void flatui::RenderTexture (const fplbase::Texture &tex, const mathfu::vec2i &pos, const mathfu::vec2i &size, const mathfu::vec4 &color)
 Render a Texture to a specific position with a given size and color. More...
 
void flatui::RenderTextureNinePatch (const fplbase::Texture &tex, const mathfu::vec4 &patch_info, const mathfu::vec2i &pos, const mathfu::vec2i &size)
 Render a nine-patch texture at a specific position with a given size. More...
 
void flatui::SetVirtualResolution (float virtual_resolution)
 Set the virtual resolution of the smallest dimension of the screen (the Y size in landscape mode, or X in portrait). More...
 
mathfu::vec2 flatui::GetVirtualResolution ()
 
void flatui::PositionGroup (Alignment horizontal, Alignment vertical, const mathfu::vec2 &offset)
 Position a group within the screen as a whole. More...
 
void flatui::UseExistingProjection (const mathfu::vec2i &canvas_size)
 By default, FlatUI sets up a projection matrix for all the rendering that covers the entire screen (as given by Renderer::window_size(). You can call to this function instead, to use whatever projection is in place before Run() is called (which may be a 2D or 3D projection). More...
 
void flatui::ApplyCustomTransform (const mathfu::mat4 &imvp)
 If you're rendering the UI at a location that does not correspond to the display's pixels (e.g. in 3D), this call allows you to set your a custom transform that corresponds to the inverse of your model-view- projection matrix. FlatUI will then transform all incoming (screen-space) pointer events with this, such that they are mapped to coordinates that match what was passed to UseExistingProjection. Important that the UI was rendered with object space coordinates ranging from (0,0) to canvas_size as well. Call this at the start of your UI. For an example of how to use this, see flatuisample_3d.cpp. More...
 
mathfu::vec2 flatui::GroupPosition ()
 
mathfu::vec2 flatui::GroupSize ()
 
bool flatui::IsLastEventPointerType ()
 
void flatui::SetGlobalListener (const std::function< void(HashedId id, Event event)> &callback)
 Set a global listener callback that receives all events to all interactive elements (useful for logging/debugging/analytics etc, NOT intended for normal event handling). Does not affect events in the rest of the API. Gets called for all events except None, you must do your own filtering. Call this function as the first thing inside of Run(). Callback never fires outside of Run(). Use HashId() to compare against ids of elements you may be interested in.
 
const FlatUIVersion * flatui::GetFlatUIVersion ()
 
void flatui::SetDepthTest (bool enable)
 Enables depth testing, when needed for rendering a UI in 3D. More...
 
const float * flatui::details::Animatable (HashedId id, const float *starting_values, int dimensions)
 
void flatui::details::StartAnimation (HashedId id, const float *target_values, const float *target_velocities, int dimensions, const AnimCurveDescription &description)
 
double flatui::AnimationTimeRemaining (HashedId id)
 Returns the time remaining for an animation. More...
 
double flatui::AnimationTimeRemaining (const char *id)
 Returns the time remaining for an animation. More...
 
int flatui::NumActiveSprites (HashedId id)
 This function returns the current number of sprites animating on screen. More...
 
int flatui::NumActiveSprites (const char *id)
 This function returns the current number of sprites animating on screen. More...
 
SequenceId flatui::AddSprite (const char *group_id, const std::function< bool(SequenceId seq)> &draw)
 This function adds a sprite, which will be drawn and then forgotten after it is finished firing. More...
 
void flatui::DrawSprites (const char *group_id)
 Draws all the sprites created with 'group_id' in AddSprite(). More...
 
template<typename T >
flatui::Animatable (HashedId id, const T &starting_value)
 This function creates a new Motivator if it doesn't already exist and returns the current value of it. More...
 
template<typename T >
flatui::Animatable (const char *id, const T &starting_value)
 This function creates a new animation if it doesn't already exist and returns the current value of it. More...
 
template<typename T >
void flatui::StartAnimation (HashedId id, const T &target_value, const T &target_velocity, const AnimCurveDescription &description)
 This function sets the target value and velocity to which an animation, that is identified by id, animates. More...
 
template<typename T >
void flatui::StartAnimation (const char *id, const T &target_value, const T &target_velocity, const AnimCurveDescription &description)
 This function sets the target value and velocity to which an animation, that is identified by id, animates. More...
 

Variables

static const int flatui::kMaxDimensions = 4
 
static const int flatui::kSecondsToMotiveTime = 10000
 
const char *const flatui::kDefaultGroupID = "__group_id__"
 A sentinel value for group IDs.
 
const char *const flatui::kDefaultImageID = "__image_id__"
 A sentinel value for image IDs.
 
const float flatui::FLATUI_DEFAULT_VIRTUAL_RESOLUTION = 1000.0f
 The default virtual resolution, if none is set.