|
Smolgui
Immediate gui library based on SFML
|
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>
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. | |
| Style & | style () |
| get current style of the gui | |
| const Style & | style () 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 | |
implement gui following the immediate gui principles, like dear-imgui, but with more control over the textures used for widgets, sounds effects and animations.
| sgui::Gui::Gui | ( | ) |
load fontawesome and initialize window size.
| sgui::Gui::Gui | ( | sf::Font & | font, |
| sf::Texture & | widgetTexture, | ||
| const TextureAtlas & | widgetAtlas, | ||
| const sf::RenderWindow & | window ) |
load fontawesome and call initialize
| sf::Vector2f sgui::Gui::activePanelSize | ( | ) | const |
get active panel or window size
| void sgui::Gui::addLastSpacing | ( | const float | amount = 1.f | ) |
to add (amount > 0) or remove (amount < 0) last widget spacing
| void sgui::Gui::addSpacing | ( | const sf::Vector2f & | amount | ) |
add spacing
| amount | multiply this vector by the normal font size and add it to (x, y) |
| void sgui::Gui::backToAnchor | ( | const std::string & | key = "" | ) |
go back to the last setAnchor position set.
| void sgui::Gui::beginFrame | ( | ) |
this function must be called at the start of every loop.
| 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
| void sgui::Gui::beginPanel | ( | Panel & | settings, |
| const Constraints & | constraint = {}, | ||
| const WidgetOptions & | options = {} ) |
static box in which widget will be arranged.
| settings | store panel size, position and properties |
| constraint | store panel's constraints on position |
| options | store special information (tooltip, horizontal) |
| void sgui::Gui::beginPanel | ( | Window & | window | ) |
build a panel.
| window | contains settings, constraints and options. |
| 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.
| settings | store panel size, position and properties |
| constraint | store panel's constraints on position |
| options | store special information (tooltip, horizontal) |
| bool sgui::Gui::beginWindow | ( | Window & | window, |
| const TextContainer & | texts = {} ) |
build a window using window.panel.title as a key in texts.
| window | contains settings, constraints and options. |
| texts | contains window title |
| bool sgui::Gui::button | ( | const std::string & | text, |
| const WidgetOptions & | options = {} ) |
button with a text displayed over it
| bool sgui::Gui::checkBox | ( | bool & | checked, |
| const WidgetOptions & | options = {} ) |
display textured box that can be checked
| bool sgui::Gui::clickable | ( | const sf::Vector2f & | size, |
| const WidgetOptions & | options = {} ) |
display a clickable button that return true if pressed
| std::string sgui::Gui::comboBox | ( | const std::vector< std::string > & | list, |
| const WidgetOptions & | options = {} ) |
display selected item and all others selectables items when clicked
| sf::Vector2f sgui::Gui::cursorPosition | ( | ) | const |
get current cursor position of the gui
| sf::Vector2f sgui::Gui::denormalizeSize | ( | const sf::Vector2f & | panelSize | ) | const |
denormalize size of a panel Return panel size in pixels
| void sgui::Gui::endFrame | ( | const float | tooltipDelay = 0.5f | ) |
this function must be called at the end of every loop.
| tooltipDelay | delay before apparition of tooltip. |
| void sgui::Gui::endMenu | ( | ) |
endMenu need to be called to clean state after beginMenu.
| void sgui::Gui::endPanel | ( | ) |
endPanel need to be called to clean state after beginPanel.
| void sgui::Gui::endWindow | ( | ) |
enWindow need to be called to clean state after beginWindow.
| void sgui::Gui::fontawesome | ( | const std::string & | iconName, |
| const TextType | type = TextType::Normal ) |
display a fontawesome icon
| void sgui::Gui::forcePlotUpdate | ( | ) |
force cache update
| bool sgui::Gui::icon | ( | const std::string & | iconName, |
| const WidgetOptions & | options = {} ) |
clickable icon that work like a button
| void sgui::Gui::image | ( | const std::string & | textureId, |
| const sf::Vector2f & | size = {}, | ||
| const WidgetOptions & | options = {} ) |
draw an image
| 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
| void sgui::Gui::inputColor | ( | sf::Color & | color, |
| const WidgetOptions & | options = {} ) |
modify a color value through text
| void sgui::Gui::inputKey | ( | char & | key, |
| const WidgetOptions & | options = {} ) |
modify a specific character
| 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
| options | contains displacement and description |
| min | and max are used to clamb number, but only if they are both different from 0. |
| label | is a text that appear in the number text box [ label: number ] |
| fixedWidth | if true, the box will have the width to fit label + "10000" in it. |
| void sgui::Gui::inputText | ( | std::string & | text, |
| const TextOptions & | textOptions = {}, | ||
| const WidgetOptions & | options = {} ) |
modify text on one or multiple line
| 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
| 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
| bool sgui::Gui::isActive | ( | ) | const |
to know if some part of the gui are active or hovered. It must be called before endFrame.
| sf::Vector2f sgui::Gui::lastSpacing | ( | ) | const |
get spacing generated by the last widget Return last spacing
| 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;
| text | printed on the menu item. |
| info | optional tooltip. |
| sf::Vector2f sgui::Gui::normalizeSize | ( | const sf::Vector2f & | panelSize | ) | const |
normalize size of a panel Return panel size in fraction
| sf::Vector2f sgui::Gui::parentGroupSize | ( | ) |
to get size of the active parent group
| 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.
| 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.
| 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.
| void sgui::Gui::progressBar | ( | const float | progress, |
| const WidgetOptions & | options = {} ) |
display advancement of a value between 0 and 1
| void sgui::Gui::sameLine | ( | ) |
go back to previous line/column, next to the last widget
| void sgui::Gui::separation | ( | const float | thickness = 0.75f | ) |
draw a simple line that span the current group width
| void sgui::Gui::setAnchor | ( | const std::string & | key = "" | ) |
register a position at which you can go back with backToAnchor.
| void sgui::Gui::setPadding | ( | const sf::Vector2f & | padding = {0.5f, 0.125f} | ) |
set padding of widgets
| void sgui::Gui::setPixelsPerScroll | ( | const float | amount | ) |
set scroll wheel strength (should be ~ 20.f)
| 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.
set plot range and number of points sampled
| void sgui::Gui::setResources | ( | sf::Font & | font, |
| sf::Texture & | widgetTexture ) |
set resources
| void sgui::Gui::setSample | ( | const uint32_t | sample | ) |
| 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
| void sgui::Gui::setSounds | ( | SoundHolder & | sounds | ) |
this must be called once if user want to have sound effects
| void sgui::Gui::setStyle | ( | const Style & | newStyle, |
| const bool | defaultPadding = true ) |
to change font size, color and item padding.
| void sgui::Gui::setTextureAtlas | ( | const TextureAtlas & | widgetAtlas | ) |
set texture atlas
| void sgui::Gui::setView | ( | const sf::View & | view | ) |
to set gui view
| void sgui::Gui::slider | ( | Type & | value, |
| const Type | min, | ||
| const Type | max, | ||
| const WidgetOptions & | options = {} ) |
slider to vary value between min and max
| Style & sgui::Gui::style | ( | ) |
get current style of the gui
| const Style & sgui::Gui::style | ( | ) | const |
get current style of the gui
| 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
| float sgui::Gui::textHeight | ( | const TextType | type = TextType::Normal | ) | const |
to have standard height size across gui code
| sf::Vector2f sgui::Gui::textSize | ( | const std::string & | text, |
| const TextType | type = TextType::Normal ) const |
get normal size of text in gui
| sf::Vector2f sgui::Gui::textureSize | ( | const std::string & | texture | ) | const |
to get texture size as stored in the uv mapper
| void sgui::Gui::unsetPlotBound | ( | ) |
remove plot bound.
| void sgui::Gui::update | ( | const sf::RenderWindow & | window, |
| const std::optional< sf::Event > & | event ) |
set-up inputs for gui interaction.
| window | window on which gui is drawn. |
| event | obtained through pollEvent. |
| void sgui::Gui::updateTimer | ( | ) |
to allow apparition of tooltip and animation to occur.
| deltaT | is the current time of the frame |