Smolgui
Immediate gui library based on SFML
Loading...
Searching...
No Matches
sgui::Gui Class Reference

implement gui following the immediate gui principles, like dear-imgui, but with more control over the textures used for widgets, sounds effects and animations. More...

#include <Gui.h>

Inheritance diagram for sgui::Gui:
[legend]

Public Member Functions

 Gui ()
 load fontawesome and initialize window size.
 Gui (sf::Font &font, sf::Texture &widgetTexture, const TextureAtlas &widgetAtlas, const sf::RenderWindow &window)
 load fontawesome and call initialize
void initialize (sf::Font &font, sf::Texture &widgetTexture, const TextureAtlas &widgetAtlas, const sf::RenderWindow &window)
 initialize window size and all required resources this need to be called once before beginFrame/endFrame
void setResources (sf::Font &font, sf::Texture &widgetTexture)
 set resources
void setTextureAtlas (const TextureAtlas &widgetAtlas)
 set texture atlas
void setSounds (SoundHolder &sounds)
 this must be called once if user want to have sound effects
void setStyle (const Style &newStyle, const bool defaultPadding=true)
 to change font size, color and item padding.
void setPadding (const sf::Vector2f &padding={0.5f, 0.125f})
 set padding of widgets
void setPixelsPerScroll (const float amount)
 set scroll wheel strength (should be ~ 20.f)
void setView (const sf::View &view)
 to set gui view
void beginFrame ()
 this function must be called at the start of every loop.
void endFrame (const float tooltipDelay=0.5f)
 this function must be called at the end of every loop.
void update (const sf::RenderWindow &window, const std::optional< sf::Event > &event)
 set-up inputs for gui interaction.
void setScreenSize (const sf::Vector2f &size)
 set screen size, its required for panel and window to call it if no Gui::update was called
void updateTimer ()
 to allow apparition of tooltip and animation to occur.
Stylestyle ()
 get current style of the gui
const Stylestyle () const
 get current style of the gui
sf::Vector2f textSize (const std::string &text, const TextType type=TextType::Normal) const
 get normal size of text in gui
float textHeight (const TextType type=TextType::Normal) const
 to have standard height size across gui code
sf::Vector2f activePanelSize () const
 get active panel or window size
sf::Vector2f normalizeSize (const sf::Vector2f &panelSize) const
 normalize size of a panel Return panel size in fraction
sf::Vector2f denormalizeSize (const sf::Vector2f &panelSize) const
 denormalize size of a panel Return panel size in pixels
sf::Vector2f lastSpacing () const
 get spacing generated by the last widget Return last spacing
void addSpacing (const sf::Vector2f &amount)
 add spacing
void addLastSpacing (const float amount=1.f)
 to add (amount > 0) or remove (amount < 0) last widget spacing
void setAnchor (const std::string &key="")
 register a position at which you can go back with backToAnchor.
void backToAnchor (const std::string &key="")
 go back to the last setAnchor position set.
sf::Vector2f cursorPosition () const
 get current cursor position of the gui
void sameLine ()
 go back to previous line/column, next to the last widget
bool isActive () const
 to know if some part of the gui are active or hovered. It must be called before endFrame.
sf::Vector2f parentGroupSize ()
 to get size of the active parent group
sf::Vector2f textureSize (const std::string &texture) const
 to get texture size as stored in the uv mapper
bool beginWindow (Panel &settings, const Constraints &constraint={}, const WidgetOptions &options={})
 windows in which widgets will be arranged, their position are automatically computed. Return true if it is not reduced or closed.
bool beginWindow (Window &window, const TextContainer &texts={})
 build a window using window.panel.title as a key in texts.
void endWindow ()
 enWindow need to be called to clean state after beginWindow.
void beginPanel (Panel &settings, const Constraints &constraint={}, const WidgetOptions &options={})
 static box in which widget will be arranged.
void beginPanel (Window &window)
 build a panel.
void endPanel ()
 endPanel need to be called to clean state after beginPanel.
void beginMenu ()
 menu bar in which menu item can be arranged. Note that it need to be called in a window or box with hasMenu set to true
void endMenu ()
 endMenu need to be called to clean state after beginMenu.
bool menuItem (const std::string &text, const WidgetOptions &options={})
 menu item are clickable button aligned along menu bar. It need to be enclosed in a beginMenu; { menuItem } endMenu;
void separation (const float thickness=0.75f)
 draw a simple line that span the current group width
void image (const std::string &textureId, const sf::Vector2f &size={}, const WidgetOptions &options={})
 draw an image
bool clickable (const sf::Vector2f &size, const WidgetOptions &options={})
 display a clickable button that return true if pressed
bool button (const std::string &text, const WidgetOptions &options={})
 button with a text displayed over it
bool icon (const std::string &iconName, const WidgetOptions &options={})
 clickable icon that work like a button
bool checkBox (bool &checked, const WidgetOptions &options={})
 display textured box that can be checked
void text (const std::string &text, const TextOptions &textOptions={}, const WidgetOptions &options={})
 display text, if a box size is given it will be formatted to fit in
void fontawesome (const std::string &iconName, const TextType type=TextType::Normal)
 display a fontawesome icon
template<typename Type>
void inputNumber (Type &number, const WidgetOptions &options={}, const Type min=0, const Type max=0, const std::string &label="", const bool fixedWidth=false)
 modify a number value through text
template<typename Type>
void inputVector2 (sf::Vector2< Type > &vector, const WidgetOptions &options={}, const sf::Vector2< Type > &min={}, const sf::Vector2< Type > &max={})
 modify a vector2 value through text, using two inputNumber call
template<typename Type>
void inputVector3 (sf::Vector3< Type > &vector, const WidgetOptions &options={}, const sf::Vector3< Type > &min={}, const sf::Vector3< Type > &max={})
 modify a vector3 value through text, using three inputNumber call
void inputColor (sf::Color &color, const WidgetOptions &options={})
 modify a color value through text
void inputText (std::string &text, const TextOptions &textOptions={}, const WidgetOptions &options={})
 modify text on one or multiple line
void inputKey (char &key, const WidgetOptions &options={})
 modify a specific character
void progressBar (const float progress, const WidgetOptions &options={})
 display advancement of a value between 0 and 1
std::string comboBox (const std::vector< std::string > &list, const WidgetOptions &options={})
 display selected item and all others selectables items when clicked
template<typename Type>
void slider (Type &value, const Type min, const Type max, const WidgetOptions &options={})
 slider to vary value between min and max
void setPlotRange (const PlotRange xRange, const PlotRange yRange)
 set plot range and number of points sampled
void setSample (const uint32_t sample)
void setPlotBound (const sf::Vector2f &bound)
 set plot size. This depend on the context of use. In a window/panel, plot bound will be limited to the window/panel width and height. Also a 16:9 ratio is enforced when there are no bound set.
void unsetPlotBound ()
 remove plot bound.
void plot (const std::function< float(float)> &slope, const float thickness=1.f, const sf::Color &lineColor=sf::Color::White)
 plot a function R -> R. The data is cached and not recomputed until user request an update with forcePlotUpdate.
void plot (const std::function< sf::Vector2f(float)> &slope, const float thickness=1.f, const sf::Color &lineColor=sf::Color::White)
 plot a function R -> R², i.e. a set of points. The data is cached and not recomputed until user request an update with forcePlotUpdate.
void plot (const std::vector< sf::Vector2f > &points, const float thickness=1.f, const sf::Color &lineColor=sf::Color::White)
 plot a set of points.
void forcePlotUpdate ()
 force cache update

Detailed Description

implement gui following the immediate gui principles, like dear-imgui, but with more control over the textures used for widgets, sounds effects and animations.

Constructor & Destructor Documentation

◆ Gui() [1/2]

sgui::Gui::Gui ( )

load fontawesome and initialize window size.

◆ Gui() [2/2]

sgui::Gui::Gui ( sf::Font & font,
sf::Texture & widgetTexture,
const TextureAtlas & widgetAtlas,
const sf::RenderWindow & window )

load fontawesome and call initialize

Member Function Documentation

◆ activePanelSize()

sf::Vector2f sgui::Gui::activePanelSize ( ) const

get active panel or window size

◆ addLastSpacing()

void sgui::Gui::addLastSpacing ( const float amount = 1.f)

to add (amount > 0) or remove (amount < 0) last widget spacing

◆ addSpacing()

void sgui::Gui::addSpacing ( const sf::Vector2f & amount)

add spacing

Parameters
amountmultiply this vector by the normal font size and add it to (x, y)

◆ backToAnchor()

void sgui::Gui::backToAnchor ( const std::string & key = "")

go back to the last setAnchor position set.

◆ beginFrame()

void sgui::Gui::beginFrame ( )

this function must be called at the start of every loop.

◆ beginMenu()

void sgui::Gui::beginMenu ( )

menu bar in which menu item can be arranged. Note that it need to be called in a window or box with hasMenu set to true

◆ beginPanel() [1/2]

void sgui::Gui::beginPanel ( Panel & settings,
const Constraints & constraint = {},
const WidgetOptions & options = {} )

static box in which widget will be arranged.

Parameters
settingsstore panel size, position and properties
constraintstore panel's constraints on position
optionsstore special information (tooltip, horizontal)

◆ beginPanel() [2/2]

void sgui::Gui::beginPanel ( Window & window)

build a panel.

Parameters
windowcontains settings, constraints and options.

◆ beginWindow() [1/2]

bool sgui::Gui::beginWindow ( Panel & settings,
const Constraints & constraint = {},
const WidgetOptions & options = {} )

windows in which widgets will be arranged, their position are automatically computed. Return true if it is not reduced or closed.

Parameters
settingsstore panel size, position and properties
constraintstore panel's constraints on position
optionsstore special information (tooltip, horizontal)

◆ beginWindow() [2/2]

bool sgui::Gui::beginWindow ( Window & window,
const TextContainer & texts = {} )

build a window using window.panel.title as a key in texts.

Parameters
windowcontains settings, constraints and options.
textscontains window title

◆ button()

bool sgui::Gui::button ( const std::string & text,
const WidgetOptions & options = {} )

button with a text displayed over it

◆ checkBox()

bool sgui::Gui::checkBox ( bool & checked,
const WidgetOptions & options = {} )

display textured box that can be checked

◆ clickable()

bool sgui::Gui::clickable ( const sf::Vector2f & size,
const WidgetOptions & options = {} )

display a clickable button that return true if pressed

◆ comboBox()

std::string sgui::Gui::comboBox ( const std::vector< std::string > & list,
const WidgetOptions & options = {} )

display selected item and all others selectables items when clicked

◆ cursorPosition()

sf::Vector2f sgui::Gui::cursorPosition ( ) const

get current cursor position of the gui

◆ denormalizeSize()

sf::Vector2f sgui::Gui::denormalizeSize ( const sf::Vector2f & panelSize) const

denormalize size of a panel Return panel size in pixels

◆ endFrame()

void sgui::Gui::endFrame ( const float tooltipDelay = 0.5f)

this function must be called at the end of every loop.

Parameters
tooltipDelaydelay before apparition of tooltip.

◆ endMenu()

void sgui::Gui::endMenu ( )

endMenu need to be called to clean state after beginMenu.

◆ endPanel()

void sgui::Gui::endPanel ( )

endPanel need to be called to clean state after beginPanel.

◆ endWindow()

void sgui::Gui::endWindow ( )

enWindow need to be called to clean state after beginWindow.

◆ fontawesome()

void sgui::Gui::fontawesome ( const std::string & iconName,
const TextType type = TextType::Normal )

display a fontawesome icon

◆ forcePlotUpdate()

void sgui::Gui::forcePlotUpdate ( )

force cache update

◆ icon()

bool sgui::Gui::icon ( const std::string & iconName,
const WidgetOptions & options = {} )

clickable icon that work like a button

◆ image()

void sgui::Gui::image ( const std::string & textureId,
const sf::Vector2f & size = {},
const WidgetOptions & options = {} )

draw an image

◆ initialize()

void sgui::Gui::initialize ( sf::Font & font,
sf::Texture & widgetTexture,
const TextureAtlas & widgetAtlas,
const sf::RenderWindow & window )

initialize window size and all required resources this need to be called once before beginFrame/endFrame

◆ inputColor()

void sgui::Gui::inputColor ( sf::Color & color,
const WidgetOptions & options = {} )

modify a color value through text

◆ inputKey()

void sgui::Gui::inputKey ( char & key,
const WidgetOptions & options = {} )

modify a specific character

◆ inputNumber()

template<typename Type>
void sgui::Gui::inputNumber ( Type & number,
const WidgetOptions & options = {},
const Type min = 0,
const Type max = 0,
const std::string & label = "",
const bool fixedWidth = false )

modify a number value through text

Parameters
optionscontains displacement and description
minand max are used to clamb number, but only if they are both different from 0.
labelis a text that appear in the number text box [ label: number ]
fixedWidthif true, the box will have the width to fit label + "10000" in it.

◆ inputText()

void sgui::Gui::inputText ( std::string & text,
const TextOptions & textOptions = {},
const WidgetOptions & options = {} )

modify text on one or multiple line

◆ inputVector2()

template<typename Type>
void sgui::Gui::inputVector2 ( sf::Vector2< Type > & vector,
const WidgetOptions & options = {},
const sf::Vector2< Type > & min = {},
const sf::Vector2< Type > & max = {} )

modify a vector2 value through text, using two inputNumber call

◆ inputVector3()

template<typename Type>
void sgui::Gui::inputVector3 ( sf::Vector3< Type > & vector,
const WidgetOptions & options = {},
const sf::Vector3< Type > & min = {},
const sf::Vector3< Type > & max = {} )

modify a vector3 value through text, using three inputNumber call

◆ isActive()

bool sgui::Gui::isActive ( ) const

to know if some part of the gui are active or hovered. It must be called before endFrame.

◆ lastSpacing()

sf::Vector2f sgui::Gui::lastSpacing ( ) const

get spacing generated by the last widget Return last spacing

◆ menuItem()

bool sgui::Gui::menuItem ( const std::string & text,
const WidgetOptions & options = {} )

menu item are clickable button aligned along menu bar. It need to be enclosed in a beginMenu; { menuItem } endMenu;

Parameters
textprinted on the menu item.
infooptional tooltip.

◆ normalizeSize()

sf::Vector2f sgui::Gui::normalizeSize ( const sf::Vector2f & panelSize) const

normalize size of a panel Return panel size in fraction

◆ parentGroupSize()

sf::Vector2f sgui::Gui::parentGroupSize ( )

to get size of the active parent group

◆ plot() [1/3]

void sgui::Gui::plot ( const std::function< float(float)> & slope,
const float thickness = 1.f,
const sf::Color & lineColor = sf::Color::White )

plot a function R -> R. The data is cached and not recomputed until user request an update with forcePlotUpdate.

◆ plot() [2/3]

void sgui::Gui::plot ( const std::function< sf::Vector2f(float)> & slope,
const float thickness = 1.f,
const sf::Color & lineColor = sf::Color::White )

plot a function R -> R², i.e. a set of points. The data is cached and not recomputed until user request an update with forcePlotUpdate.

◆ plot() [3/3]

void sgui::Gui::plot ( const std::vector< sf::Vector2f > & points,
const float thickness = 1.f,
const sf::Color & lineColor = sf::Color::White )

plot a set of points.

◆ progressBar()

void sgui::Gui::progressBar ( const float progress,
const WidgetOptions & options = {} )

display advancement of a value between 0 and 1

◆ sameLine()

void sgui::Gui::sameLine ( )

go back to previous line/column, next to the last widget

◆ separation()

void sgui::Gui::separation ( const float thickness = 0.75f)

draw a simple line that span the current group width

◆ setAnchor()

void sgui::Gui::setAnchor ( const std::string & key = "")

register a position at which you can go back with backToAnchor.

◆ setPadding()

void sgui::Gui::setPadding ( const sf::Vector2f & padding = {0.5f, 0.125f})

set padding of widgets

◆ setPixelsPerScroll()

void sgui::Gui::setPixelsPerScroll ( const float amount)

set scroll wheel strength (should be ~ 20.f)

◆ setPlotBound()

void sgui::Gui::setPlotBound ( const sf::Vector2f & bound)

set plot size. This depend on the context of use. In a window/panel, plot bound will be limited to the window/panel width and height. Also a 16:9 ratio is enforced when there are no bound set.

◆ setPlotRange()

void sgui::Gui::setPlotRange ( const PlotRange xRange,
const PlotRange yRange )

set plot range and number of points sampled

◆ setResources()

void sgui::Gui::setResources ( sf::Font & font,
sf::Texture & widgetTexture )

set resources

◆ setSample()

void sgui::Gui::setSample ( const uint32_t sample)

◆ setScreenSize()

void sgui::Gui::setScreenSize ( const sf::Vector2f & size)

set screen size, its required for panel and window to call it if no Gui::update was called

◆ setSounds()

void sgui::Gui::setSounds ( SoundHolder & sounds)

this must be called once if user want to have sound effects

◆ setStyle()

void sgui::Gui::setStyle ( const Style & newStyle,
const bool defaultPadding = true )

to change font size, color and item padding.

◆ setTextureAtlas()

void sgui::Gui::setTextureAtlas ( const TextureAtlas & widgetAtlas)

set texture atlas

◆ setView()

void sgui::Gui::setView ( const sf::View & view)

to set gui view

◆ slider()

template<typename Type>
void sgui::Gui::slider ( Type & value,
const Type min,
const Type max,
const WidgetOptions & options = {} )

slider to vary value between min and max

◆ style() [1/2]

Style & sgui::Gui::style ( )

get current style of the gui

◆ style() [2/2]

const Style & sgui::Gui::style ( ) const

get current style of the gui

◆ text()

void sgui::Gui::text ( const std::string & text,
const TextOptions & textOptions = {},
const WidgetOptions & options = {} )

display text, if a box size is given it will be formatted to fit in

◆ textHeight()

float sgui::Gui::textHeight ( const TextType type = TextType::Normal) const

to have standard height size across gui code

◆ textSize()

sf::Vector2f sgui::Gui::textSize ( const std::string & text,
const TextType type = TextType::Normal ) const

get normal size of text in gui

◆ textureSize()

sf::Vector2f sgui::Gui::textureSize ( const std::string & texture) const

to get texture size as stored in the uv mapper

◆ unsetPlotBound()

void sgui::Gui::unsetPlotBound ( )

remove plot bound.

◆ update()

void sgui::Gui::update ( const sf::RenderWindow & window,
const std::optional< sf::Event > & event )

set-up inputs for gui interaction.

Parameters
windowwindow on which gui is drawn.
eventobtained through pollEvent.

◆ updateTimer()

void sgui::Gui::updateTimer ( )

to allow apparition of tooltip and animation to occur.

Parameters
deltaTis the current time of the frame

The documentation for this class was generated from the following files:
  • /github/workspace/src/sgui/Gui.h
  • /github/workspace/src/sgui/Gui.cpp