Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
Public Member Functions | Static Public Attributes | List of all members
gf::UI Class Reference

Context for an immediate mode graphical interface. More...

#include <gf/UI.h>

Inheritance diagram for gf::UI:
Inheritance graph
[legend]

Public Member Functions

 UI (Font &font, unsigned characterSize=DefaultCharacterSize)
 Constructor. More...
 
 ~UI ()
 Destructor. More...
 
 UI (const UI &)=delete
 Deleted copy constructor. More...
 
UIoperator= (const UI &)=delete
 Deleted copy assignment. More...
 
 UI (UI &&other)
 Move constructor. More...
 
UIoperator= (UI &&other)
 Move assignment. More...
 
void processEvent (const Event &event)
 Update the internal state with an event. More...
 
virtual void draw (RenderTarget &target, RenderStates states) override
 Draw the object to a render target. More...
 
Window
bool begin (const std::string &title, const RectF &bounds, UIWindowFlags flags=None)
 Create a window. More...
 
void end ()
 Finish a window. More...
 
Layout
void layoutRowDynamic (float height, int cols)
 Dynamic row with fixed column layout. More...
 
void layoutRowStatic (float height, int itemWidth, int cols)
 Static row with fixed column layout. More...
 
void layoutRowBegin (UILayout format, float height, int cols)
 Start an immediate mode custom column layout. More...
 
void layoutRowPush (float width)
 Specify the width of the next column. More...
 
void layoutRowEnd ()
 Finish an immediate mode custom column layout. More...
 
void layoutRow (UILayout format, float height, ArrayRef< float > ratio)
 Array-based custom column layout. More...
 
void separator (float height)
 An empty separator. More...
 
Layout: Group
bool groupBegin (const std::string &title, UIWindowFlags flags=None)
 Start a group. More...
 
void groupEnd ()
 Finish a group. More...
 
bool groupScrolledBegin (UIScroll &scroll, const std::string &title, UIWindowFlags flags=None)
 Start a scrolled group. More...
 
void groupScrolledEnd ()
 Finish a scrolled group. More...
 
Layout: Tree
bool treePush (UITree type, const std::string &title, UICollapse &state)
 Start a tree layout. More...
 
void treePop ()
 Finish a tree layout. More...
 
Widgets: Labels
void label (StringRef title, UIAlignment align=UIAlignment::Left)
 A simple label with text. More...
 
void labelColored (const Color4f &color, StringRef title, UIAlignment align=UIAlignment::Left)
 A label with colored text. More...
 
void labelWrap (StringRef title)
 A simple label that can wrap. More...
 
void labelWrapColored (const Color4f &color, StringRef title)
 A label with colored text that can wrap. More...
 
Widgets: Buttons
void buttonSetBehavior (UIButtonBehavior behavior)
 Change the behavior of buttons. More...
 
bool buttonPushBehavior (UIButtonBehavior behavior)
 Push a new behavior of buttons. More...
 
bool buttonPopBehavior ()
 Pop the previous behavior of buttons. More...
 
bool buttonLabel (StringRef title)
 A button with a centered label. More...
 
bool buttonColor (const Color4f &color)
 A button with a color. More...
 
bool buttonSymbol (UISymbol symbol)
 A button with a symbol. More...
 
bool buttonSymbolLabel (UISymbol symbol, StringRef title, UIAlignment align=UIAlignment::Left)
 A button with a symbol and a centered label. More...
 
Widgets: Checkbox
bool checkbox (StringRef title, bool &active)
 A checkbox with a title. More...
 
bool checkboxFlags (StringRef title, unsigned &flags, unsigned value)
 A checkbox with a title for flags. More...
 
Widgets: Radio
bool option (StringRef title, bool active)
 A radio button without state. More...
 
bool radio (StringRef title, bool &active)
 A radio button with a reference state. More...
 
Widgets: Selectable
bool selectableLabel (StringRef title, UIAlignment align, bool &value)
 A selectable label. More...
 
Widgets: Slider
bool sliderFloat (float min, float &val, float max, float step)
 A slider for a float value. More...
 
bool sliderInt (int min, int &val, int max, int step)
 A slider for an int value. More...
 
Widgets: Progressbar
bool progress (std::size_t &current, std::size_t max, UIProgress modifyable=UIProgress::Modifyable)
 A progress bar. More...
 
Widgets: Color picker
bool colorPicker (Color4f &color)
 A color picker. More...
 
Widgets: Property
void propertyInt (const std::string &name, int min, int &val, int max, int step, float incPerPixel)
 A property for an integer. More...
 
void propertyFloat (const std::string &name, float min, float &val, float max, float step, float incPerPixel)
 A property for a float. More...
 
void propertyDouble (const std::string &name, double min, double &val, double max, double step, float incPerPixel)
 A property for a double. More...
 
Popups
bool popupBegin (UIPopup type, const std::string &title, UIWindowFlags flags, const RectF &bounds)
 Start a popup window. More...
 
void popupClose ()
 Close a popup window. More...
 
void popupEnd ()
 Finish a popup window. More...
 
Combo box
void combobox (const std::vector< std::string > &items, int &selected, int itemHeight, Vector2f size)
 A simple combo box with a list of item. More...
 
void comboboxSeparator (const std::string &itemsSeparatedBySeparator, char separator, int &selected, int itemHeight, Vector2f size)
 A simple combo box with a string and a separator. More...
 
bool comboBeginLabel (StringRef selected, Vector2f size)
 Start a combo box with a label. More...
 
bool comboBeginColor (const Color4f &color, Vector2f size)
 Start a combo box with a color. More...
 
bool comboBeginSymbol (UISymbol symbol, Vector2f size)
 Start a combo box with a symbol. More...
 
bool comboBeginSymbolLabel (UISymbol symbol, StringRef selected, Vector2f size)
 Start a combo box with a symbol and a label. More...
 
bool comboItemLabel (StringRef title, UIAlignment align=UIAlignment::Left)
 A label inside the combo box. More...
 
bool comboItemSymbolLabel (UISymbol symbol, StringRef title, UIAlignment align=UIAlignment::Left)
 A symbol and a label inside the combo box. More...
 
void comboClose ()
 Close a combo box. More...
 
void comboEnd ()
 Finish a combo box. More...
 
Contextual
bool contextualBegin (UIWindowFlags flags, Vector2f size, const RectF &triggerBounds)
 Start a contextual window. More...
 
bool contextualItemLabel (StringRef title, UIAlignment align=UIAlignment::Left)
 A label inside the contextual window. More...
 
bool contextualItemSymbolLabel (UISymbol symbol, StringRef title, UIAlignment align=UIAlignment::Left)
 A symbol and a label inside the contextual window. More...
 
void contextualClose ()
 Close the contextual window. More...
 
void contextualEnd ()
 Finish the contextual window. More...
 
Tooltip
void tooltip (const std::string &text)
 A simple tooltip with a text. More...
 
bool tooltipBegin (float width)
 Start a tooltip. More...
 
void tooltipEnd ()
 Finish a tooltip. More...
 
Menu
void menubarBegin ()
 Start a menu bar. More...
 
void menubarEnd ()
 Finish a menu bar. More...
 
bool menuBeginLabel (StringRef title, UIAlignment align, Vector2f size)
 Start a menu with a label. More...
 
bool menuBeginSymbol (const std::string &id, UISymbol symbol, Vector2f size)
 Start a menu with a symbol. More...
 
bool menuBeginSymbolLabel (UISymbol symbol, StringRef title, UIAlignment align, Vector2f size)
 Start a menu with a symbol and a label. More...
 
bool menuItemLabel (StringRef title, UIAlignment align=UIAlignment::Left)
 A label inside the menu. More...
 
bool menuItemSymbolLabel (UISymbol symbol, StringRef title, UIAlignment align=UIAlignment::Left)
 A symbol and a label inside the menu. More...
 
void menuClose ()
 Close a menu. More...
 
void menuEnd ()
 Finish a menu. More...
 
Utilities
RectF getWidgetBounds ()
 Get the current widget bounds. More...
 
bool isWidgetHovered ()
 Check if the widget is hovered by the mouse. More...
 
Style
void setPredefinedStyle (UIPredefinedStyle style)
 Set a predefined style for all the windows and the widgets. More...
 
- Public Member Functions inherited from gf::Drawable
virtual ~Drawable ()
 Virtual desctructor. More...
 

Static Public Attributes

static constexpr unsigned DefaultCharacterSize = 13
 The default size for the font. More...
 

Detailed Description

Context for an immediate mode graphical interface.

When building a graphical interfaces, you have basically two choices: either the retained mode where you build a hierarchy of widgets, or the immediate mode where widgets are built from function calls. Choosing the best mode between these two may be controversial. gf offers an immediate mode graphical interface through this class.

The immediate mode graphical interface (or imgui) of gf is based on Nuklear, a C library with the same purpose. gf does not provide (yet?) all the features of Nuklear, but a fair amount of the main features. Nuklear is totally abstracted in gf so you won't see any interface from Nuklear and you won't be able to interact directly with Nuklear. If you need a feature that is not implemented yet, just ask.

This imgui library can be used to create tools for the game developpers. It's easy and quick to build a functional interface with an imgui library. You can see some examples in gf itself. You can also use this library to build in-game interfaces, even if it's not its primary purpose. If your game is heavily based on a graphical interface, it may be a good option.

Creating a context

An instance of gf::UI is a context for all the windows that will be created. You must provide a font and a character size that will be used in the interface. Generally, you create the instance of gf::UI at the beginning of your application and then you use this instance throughout your application.

gf::Font font;
if (!font.loadFromFile("font.ttf")) {
return EXIT_FAILURE;
}
gf::UI ui(font, 13);

By default, the character size is 13.

Managing events

The imgui needs to know the input events that occurred in the frame time. So when polling the events in your main loop, you must pass the events to the context so that it can be updated and take the good decision. For example, if you press on a button, the mouse event will be transmitted and the library will know that you pressed a button and act accordingly.

gf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
window.close();
break;
default:
break;
}
ui.processEvent(event); // update the imgui with input events
}

Creating a window

Then, you have to create a window. The window has a title that may appear in the titlebar. It also identifies the window so two windows must have two different titles. The window also has bounds, i.e. a position and a size, that indicates where to put the window in the screen. There is no automatic placement of windows. Finally, the window can have many properties (see gf::UIWindow) that modify the interaction with the window. They are defined at the window creation.

if (ui.begin("Title", gf::RectF(20, 20, 200, 200), gf::UIWindow::Title | gf::UIWindow::Border)) {
// content of the window
}
ui.end();

For each begin(), you have to call end() to finish the window. You can create as many windows as you want as long as they have different titles.

Determining a layout

Before drawing any widget, you have to define a layout. Think of it as a sort of specification for how to organize the following widgets. There are three types of layouts: rows, groups, trees.

Rows

Rows are the most common type of layout. The row layout is very flexible.

A row can be either static (it does not adapt to the width of the window) of dynamic (it adapts to the width of the window). It can be fixed (all columns have the same width) or custom (columns' widths are specified, either relatively or absolutely), and in the latter case the specification can be global or in immediate mode. Here is a summary of the functions to use in each case:

Trees

A tree is a tree-like layout. It can be collapsed to hide its content except its title. There are two types of trees: tabs and nodes (see gf::UITree). A tab tree is generally put at the root of the tree, it is represented with a border around the title. A node tree is generally the son of a tab tree or another node tree. It is represented without any border.

In both cases, you need a variable of type gf::UICollapse to handle the current state of the tree: minimized or maximized.

static gf::UICollapse rootCollapsed = gf::UICollapse::Minimized;
if (ui.treePush(gf::UITree::Tab, "Root", rootCollapsed)) {
static gf::UICollapse childCollapsed = gf::UICollapse::Maximized;
if (ui.treePush(gf::UITree::Node, "Child", childCollapsed)) {
// content of the child node
ui.treePop();
}
// next content of the root node
ui.treePop();
}

Groups

A group is a kind of window inside a window. It can have a title, a border and a scrollbar. However, a group needs to be put in a row. See groupBegin() and groupEnd().

ui.layoutRowStatic(groupHeight, groupWidth, 2);
if (ui.groupBegin("Group", gf::UIWindow::Title | gf::UIWindow::Border)) {
// content of the group
ui.groupEnd();
}

Adding widgets and more

The library offers common kinds of widgets:

Widgets often manipulate a reference to a user-provided variable that represents the state of the widget. This way, you can pass directly your model variables to the graphical interface without duplicating the data. Some widgets return a boolean that indicates a state change. For example, a button returns true if it has been pressed.

The library also offers common graphical interface elements:

Many of these elements have a begin/end API. The end part must be called if the begin part succeeded, i.e. returned true. Some elements offer a simplified version without begin/end for common cases.

Constructor & Destructor Documentation

gf::UI::UI ( Font font,
unsigned  characterSize = DefaultCharacterSize 
)

Constructor.

Parameters
fontThe font used in the interface
characterSizeThe size of the font used in the interface
gf::UI::~UI ( )

Destructor.

gf::UI::UI ( const UI )
delete

Deleted copy constructor.

gf::UI::UI ( UI &&  other)

Move constructor.

Member Function Documentation

bool gf::UI::begin ( const std::string &  title,
const RectF bounds,
UIWindowFlags  flags = None 
)

Create a window.

if (ui.begin("Title", gf::RectF(20, 20, 200, 200), gf::UIWindow::Title | gf::UIWindow::Border)) {
// content of the window
}
ui.end();
Parameters
titleThe title of the window
boundsThe area of the window
flagsThe properties of the window
Returns
True is the content of the window is visible
See also
end(), gf::UIWindow
bool gf::UI::buttonColor ( const Color4f color)

A button with a color.

Parameters
colorThe color of the button
Returns
True if the button was pressed
See also
buttonLabel(), buttonSymbol(), buttonSymbolLabel()
bool gf::UI::buttonLabel ( StringRef  title)

A button with a centered label.

Parameters
titleThe title of the button
Returns
True if the button was pressed
See also
buttonColor(), buttonSymbol(), buttonSymbolLabel()
bool gf::UI::buttonPopBehavior ( )

Pop the previous behavior of buttons.

See also
buttonSetBehavior(), buttonPushBehavior()
bool gf::UI::buttonPushBehavior ( UIButtonBehavior  behavior)

Push a new behavior of buttons.

Parameters
behaviorThe new behavior of buttons
See also
buttonSetBehavior(), buttonPopBehavior()
void gf::UI::buttonSetBehavior ( UIButtonBehavior  behavior)

Change the behavior of buttons.

Parameters
behaviorThe new behavior of buttons
See also
buttonPushBehavior(), buttonPopBehavior()
bool gf::UI::buttonSymbol ( UISymbol  symbol)

A button with a symbol.

Parameters
symbolA symbol
Returns
True if the button was pressed
See also
buttonLabel(), buttonColor(), buttonSymbolLabel()
bool gf::UI::buttonSymbolLabel ( UISymbol  symbol,
StringRef  title,
UIAlignment  align = UIAlignment::Left 
)

A button with a symbol and a centered label.

Parameters
symbolA symbol
titleThe title of the button
alignThe alignment of the symbol
Returns
True if the button was pressed
See also
buttonLabel(), buttonColor(), buttonSymbol()
bool gf::UI::checkbox ( StringRef  title,
bool &  active 
)

A checkbox with a title.

Parameters
titleThe title of the checkbox
activeA reference to a boolean that indicates the state of the checkbox
Returns
True if the checkbox has changed its state
See also
checkboxFlags()
bool gf::UI::checkboxFlags ( StringRef  title,
unsigned &  flags,
unsigned  value 
)

A checkbox with a title for flags.

Parameters
titleThe title of the checkbox
flagsA reference to the state of flags
valueThe flag value for this checkbox
Returns
True if the checkbox has changed its state
See also
checkbox()
bool gf::UI::colorPicker ( Color4f color)

A color picker.

Parameters
colorA reference to the state of the color picker, i.e. the current color
Returns
True if the color has changed
bool gf::UI::comboBeginColor ( const Color4f color,
Vector2f  size 
)

Start a combo box with a color.

Parameters
colorThe color that appears in the combo box
sizeThe size of the combo box
Returns
True if the combo box is open
See also
comboClose(), comboEnd()
bool gf::UI::comboBeginLabel ( StringRef  selected,
Vector2f  size 
)

Start a combo box with a label.

Parameters
selectedThe selected item that appears in the combo box
sizeThe size of the combo box
Returns
True if the combo box is open
See also
comboClose(), comboEnd()
bool gf::UI::comboBeginSymbol ( UISymbol  symbol,
Vector2f  size 
)

Start a combo box with a symbol.

Parameters
symbolThe symbol that appears in the combo box
sizeThe size of the combo box
Returns
True if the combo box is open
See also
comboClose(), comboEnd()
bool gf::UI::comboBeginSymbolLabel ( UISymbol  symbol,
StringRef  selected,
Vector2f  size 
)

Start a combo box with a symbol and a label.

Parameters
symbolThe symbol that appears in the combo box
selectedThe selected item that appears in the combo box
sizeThe size of the combo box
Returns
True if the combo box is open
See also
comboClose(), comboEnd()
void gf::UI::combobox ( const std::vector< std::string > &  items,
int &  selected,
int  itemHeight,
Vector2f  size 
)

A simple combo box with a list of item.

Parameters
itemsThe list of items in the combo box
selectedA reference to the selected item in the combo box
itemHeightThe height of the items in the list
sizeThe size of the combo box
See also
comboboxSeparator()
void gf::UI::comboboxSeparator ( const std::string &  itemsSeparatedBySeparator,
char  separator,
int &  selected,
int  itemHeight,
Vector2f  size 
)

A simple combo box with a string and a separator.

Parameters
itemsSeparatedBySeparatorA string with all the items separated by a separator
separatorThe separator used in the string
selectedA reference to the selected item in the combo box
itemHeightThe height of the items in the list
sizeThe size of the combo box
See also
combobox()
void gf::UI::comboClose ( )

Close a combo box.

See also
comboEnd()
void gf::UI::comboEnd ( )
bool gf::UI::comboItemLabel ( StringRef  title,
UIAlignment  align = UIAlignment::Left 
)

A label inside the combo box.

Parameters
titleThe title of the label
alignThe alignment of the text in the label
Returns
True if the item is selected
bool gf::UI::comboItemSymbolLabel ( UISymbol  symbol,
StringRef  title,
UIAlignment  align = UIAlignment::Left 
)

A symbol and a label inside the combo box.

Parameters
symbolThe symbol of the item
titleThe title of the label
alignThe alignment of the text in the label
Returns
True if the item is selected
bool gf::UI::contextualBegin ( UIWindowFlags  flags,
Vector2f  size,
const RectF triggerBounds 
)

Start a contextual window.

Parameters
flagsThe properties of the contextual window
sizeThe size of the contextual window
triggerBoundsThe bounds when the contextual should appear
Returns
True if the contextual is open
See also
contextualClose(), contextualEnd()
void gf::UI::contextualClose ( )

Close the contextual window.

See also
contextualBegin(), contextualEnd()
void gf::UI::contextualEnd ( )

Finish the contextual window.

See also
contextualBegin(), contextualClose()
bool gf::UI::contextualItemLabel ( StringRef  title,
UIAlignment  align = UIAlignment::Left 
)

A label inside the contextual window.

Parameters
titleThe title of the label
alignThe alignment of the text in the label
Returns
True if the item is selected
bool gf::UI::contextualItemSymbolLabel ( UISymbol  symbol,
StringRef  title,
UIAlignment  align = UIAlignment::Left 
)

A symbol and a label inside the contextual window.

Parameters
symbolThe symbol of the item
titleThe title of the label
alignThe alignment of the text in the label
Returns
True if the item is selected
virtual void gf::UI::draw ( RenderTarget target,
RenderStates  states 
)
overridevirtual

Draw the object to a render target.

This is a pure virtual function that has to be implemented by the derived class to define how the drawable should be drawn.

Parameters
targetRender target to draw to
statesCurrent render states

Implements gf::Drawable.

void gf::UI::end ( )

Finish a window.

if (ui.begin("Title", gf::RectF(20, 20, 200, 200), gf::UIWindow::Title | gf::UIWindow::Border)) {
// content of the window
}
ui.end();
See also
begin()
RectF gf::UI::getWidgetBounds ( )

Get the current widget bounds.

Returns
The bounds of the widget
bool gf::UI::groupBegin ( const std::string &  title,
UIWindowFlags  flags = None 
)

Start a group.

The only allowed flags are UIWindow::Title, UIWindow::Border, UIWindow::NoScrollbar.

ui.layoutRowStatic(groupHeight, groupWidth, 2);
if (ui.groupBegin("Group", gf::UIWindow::Title | gf::UIWindow::Border)) {
// content of the group
ui.groupEnd();
}
Parameters
titleThe title of the group
flagsThe properties of the group
Returns
True if the group is visible
See also
groupEnd()
void gf::UI::groupEnd ( )

Finish a group.

ui.layoutRowStatic(groupHeight, groupWidth, 2);
if (ui.groupBegin("Group", gf::UIWindow::Title | gf::UIWindow::Border)) {
// content of the group
ui.groupEnd();
}
See also
groupBegin()
bool gf::UI::groupScrolledBegin ( UIScroll scroll,
const std::string &  title,
UIWindowFlags  flags = None 
)

Start a scrolled group.

The only allowed flags are UIWindow::Title, UIWindow::Border, UIWindow::NoScrollbar.

Parameters
scrollA state for representing the scroll
titleThe title of the group
flagsThe properties of the group
Returns
True if the group is visible
See also
groupScrolledEnd()
void gf::UI::groupScrolledEnd ( )

Finish a scrolled group.

See also
groupScrolledBegin()
bool gf::UI::isWidgetHovered ( )

Check if the widget is hovered by the mouse.

You must do this check just after the layout specification

Returns
True if the mouse hovers the widget
void gf::UI::label ( StringRef  title,
UIAlignment  align = UIAlignment::Left 
)

A simple label with text.

Parameters
titleThe title of the label
alignThe alignment of the text in the label
See also
labelColored()
void gf::UI::labelColored ( const Color4f color,
StringRef  title,
UIAlignment  align = UIAlignment::Left 
)

A label with colored text.

Parameters
colorThe color of the text
titleThe title of the label
alignThe alignment of the text in the label
See also
label()
void gf::UI::labelWrap ( StringRef  title)

A simple label that can wrap.

Parameters
titleThe title of the label
See also
labelWrapColored()
void gf::UI::labelWrapColored ( const Color4f color,
StringRef  title 
)

A label with colored text that can wrap.

Parameters
colorThe color of the text
titleThe title of the label
See also
labelWrap()
void gf::UI::layoutRow ( UILayout  format,
float  height,
ArrayRef< float >  ratio 
)

Array-based custom column layout.

Parameters
formatThe format of the row: static or dynamic
heightThe height of the row
ratioA reference to an array of ratios for the columns
void gf::UI::layoutRowBegin ( UILayout  format,
float  height,
int  cols 
)

Start an immediate mode custom column layout.

Parameters
formatThe format of the row: static or dynamic
heightThe height of the row
colsThe number of columns in the row
See also
layoutRowPush(), layoutRowEnd()
void gf::UI::layoutRowDynamic ( float  height,
int  cols 
)

Dynamic row with fixed column layout.

Parameters
heightThe height of the row
colsThe number of columns in the row
See also
layoutRowStatic()
void gf::UI::layoutRowEnd ( )

Finish an immediate mode custom column layout.

See also
layoutRowBegin(), layoutRowPush()
void gf::UI::layoutRowPush ( float  width)

Specify the width of the next column.

Parameters
widthThe width of the next column
See also
layoutRowBegin(), layoutRowEnd()
void gf::UI::layoutRowStatic ( float  height,
int  itemWidth,
int  cols 
)

Static row with fixed column layout.

Parameters
heightThe height of the row
itemWidthThe width of each item in the row
colsThe number of columns in the row
See also
layoutRowDynamic()
void gf::UI::menubarBegin ( )

Start a menu bar.

See also
menubarEnd()
void gf::UI::menubarEnd ( )

Finish a menu bar.

See also
menubarBegin()
bool gf::UI::menuBeginLabel ( StringRef  title,
UIAlignment  align,
Vector2f  size 
)

Start a menu with a label.

Parameters
titleThe title of the label
alignThe alignment of the text in the label
sizeThe size of the menu
Returns
True if the menu is open
See also
menuClose(), menuEnd()
bool gf::UI::menuBeginSymbol ( const std::string &  id,
UISymbol  symbol,
Vector2f  size 
)

Start a menu with a symbol.

Parameters
idA unique identifier for the menu
symbolA symbol for the menu
sizeThe size of the menu
Returns
True if the menu is open
See also
menuClose(), menuEnd()
bool gf::UI::menuBeginSymbolLabel ( UISymbol  symbol,
StringRef  title,
UIAlignment  align,
Vector2f  size 
)

Start a menu with a symbol and a label.

Parameters
symbolA symbol for the menu
titleThe title of the label
alignThe alignment of the text in the label
sizeThe size of the menu
Returns
True if the menu is open
See also
menuClose(), menuEnd()
void gf::UI::menuClose ( )

Close a menu.

See also
menuEnd()
void gf::UI::menuEnd ( )
bool gf::UI::menuItemLabel ( StringRef  title,
UIAlignment  align = UIAlignment::Left 
)

A label inside the menu.

Parameters
titleThe title of the label
alignThe alignment of the text in the label
Returns
True if the item is selected
bool gf::UI::menuItemSymbolLabel ( UISymbol  symbol,
StringRef  title,
UIAlignment  align = UIAlignment::Left 
)

A symbol and a label inside the menu.

Parameters
symbolThe symbol of the item
titleThe title of the label
alignThe alignment of the text in the label
Returns
True if the item is selected
UI& gf::UI::operator= ( const UI )
delete

Deleted copy assignment.

UI& gf::UI::operator= ( UI &&  other)

Move assignment.

bool gf::UI::option ( StringRef  title,
bool  active 
)

A radio button without state.

Parameters
titleThe title of the radio button
activeA boolean that indicates if the radio is chosen
Returns
True if the radio is pressed
See also
radio()
bool gf::UI::popupBegin ( UIPopup  type,
const std::string &  title,
UIWindowFlags  flags,
const RectF bounds 
)

Start a popup window.

Parameters
typeThe type of popup (static or dynamic)
titleThe title of the popup
flagsThe properties of the popup window
boundsThe area of the popup window
Returns
True if the popup is open
See also
popupClose(), popupEnd()
void gf::UI::popupClose ( )

Close a popup window.

See also
popupBegin(), popupEnd()
void gf::UI::popupEnd ( )

Finish a popup window.

See also
popupBegin(), popupClose()
void gf::UI::processEvent ( const Event event)

Update the internal state with an event.

This function must be called for every event that occur in a frame.

Parameters
eventAn event
bool gf::UI::progress ( std::size_t &  current,
std::size_t  max,
UIProgress  modifyable = UIProgress::Modifyable 
)

A progress bar.

Parameters
currentA reference to the state of the progress bar
maxThe maximum of the progress bar (the minimum is zero)
modifyableA property to indicate if the progress bar can be modified by the user or not
Returns
True if the progress bar has changed
void gf::UI::propertyDouble ( const std::string &  name,
double  min,
double &  val,
double  max,
double  step,
float  incPerPixel 
)

A property for a double.

Parameters
nameThe name of the property
minThe minimum for the value
valA reference to the value
maxThe maximum for the value
stepA step when changing the value
incPerPixelA step when modifying the value with the mouse
See also
propertyInt(), propertyFloat()
void gf::UI::propertyFloat ( const std::string &  name,
float  min,
float &  val,
float  max,
float  step,
float  incPerPixel 
)

A property for a float.

Parameters
nameThe name of the property
minThe minimum for the value
valA reference to the value
maxThe maximum for the value
stepA step when changing the value
incPerPixelA step when modifying the value with the mouse
See also
propertyInt(), propertyDouble()
void gf::UI::propertyInt ( const std::string &  name,
int  min,
int &  val,
int  max,
int  step,
float  incPerPixel 
)

A property for an integer.

Parameters
nameThe name of the property
minThe minimum for the value
valA reference to the value
maxThe maximum for the value
stepA step when changing the value
incPerPixelA step when modifying the value with the mouse
See also
propertyFloat(), propertyDouble()
bool gf::UI::radio ( StringRef  title,
bool &  active 
)

A radio button with a reference state.

Parameters
titleThe title of the radio button
activeA reference to the state of the radio
Returns
True if the radio is pressed
See also
option()
bool gf::UI::selectableLabel ( StringRef  title,
UIAlignment  align,
bool &  value 
)

A selectable label.

Parameters
titleThe title of the label
alignThe alignment of the text in the label
valueA reference to the state of the selection
Returns
True if the state has changed
See also
label()
void gf::UI::separator ( float  height)

An empty separator.

This function creates an empty row so you have to specify a new row.

Parameters
heightThe height of the row
void gf::UI::setPredefinedStyle ( UIPredefinedStyle  style)

Set a predefined style for all the windows and the widgets.

Parameters
styleThe predefined style
See also
gf::UIPredefinedStyle
bool gf::UI::sliderFloat ( float  min,
float &  val,
float  max,
float  step 
)

A slider for a float value.

Parameters
minThe minimum for the value
valA reference to the value
maxThe maximum for the value
stepA step when changing the value
Returns
True if the slider has changed
See also
sliderInt()
bool gf::UI::sliderInt ( int  min,
int &  val,
int  max,
int  step 
)

A slider for an int value.

Parameters
minThe minimum for the value
valA reference to the value
maxThe maximum for the value
stepA step when changing the value
Returns
True if the slider has changed
See also
sliderFloat()
void gf::UI::tooltip ( const std::string &  text)

A simple tooltip with a text.

Parameters
textThe text of the tooltip
bool gf::UI::tooltipBegin ( float  width)

Start a tooltip.

Parameters
widthThe with of the tooltip
Returns
True if the tooltip is open
See also
tooltipEnd()
void gf::UI::tooltipEnd ( )

Finish a tooltip.

See also
tooltipBegin()
void gf::UI::treePop ( )

Finish a tree layout.

static gf::UICollapse rootCollapsed = gf::UICollapse::Minimized;
if (ui.treePush(gf::UITree::Tab, "Root", rootCollapsed)) {
static gf::UICollapse childCollapsed = gf::UICollapse::Maximized;
if (ui.treePush(gf::UITree::Node, "Child", childCollapsed)) {
// content of the child node
ui.treePop();
}
// next content of the root node
ui.treePop();
}
See also
treePush()
bool gf::UI::treePush ( UITree  type,
const std::string &  title,
UICollapse state 
)

Start a tree layout.

static gf::UICollapse rootCollapsed = gf::UICollapse::Minimized;
if (ui.treePush(gf::UITree::Tab, "Root", rootCollapsed)) {
static gf::UICollapse childCollapsed = gf::UICollapse::Maximized;
if (ui.treePush(gf::UITree::Node, "Child", childCollapsed)) {
// content of the child node
ui.treePop();
}
// next content of the root node
ui.treePop();
}
Parameters
typeThe type of tree: tab or node
titleThe title of the tree
stateThe collapse state
Returns
True if the tree is maximized
See also
treePop()

Member Data Documentation

constexpr unsigned gf::UI::DefaultCharacterSize = 13
static

The default size for the font.