Smolgui
Immediate gui library based on SFML
Loading...
Searching...
No Matches
sgui Namespace Reference

Classes

class  ObjectPool
 : implement a generic pool of objects that are stored continuously in memory without fragmentation, and is in theory thread safe More...
struct  Polygon
 Polygon is a series of N points, ranged in clock-wise order and that form a convex shape. More...
struct  Line
 Define a line with two points. More...
struct  Circle
 Define a Circle with a center and a radius. More...
class  Gui
 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...
class  ClippingLayers
 Handle clipping layers to only draw things in a given box. More...
struct  WidgetDrawOptions
 Store options for drawing widgets. More...
struct  TextDrawOptions
 Store options for drawing text. More...
class  GuiRender
 Handle rendering for the gui. More...
struct  PlotRange
 plot range for an axis More...
class  Plotter
 plot function in a given range and level of sampling. More...
class  PrimitiveShapeRender
 render primitive shapes using vertex array. More...
class  TextureMeshes
 Compute texture meshes for a given texture map. More...
struct  LayoutEntry
 Data structure stored in Layout. Its a dumb std::variant basically... More...
class  Layout
 allow to store and load Gui layou More...
class  ResourcesHolder
 load and hold resources of all kind (image, music, etc.), that can be retrieved with Identifier that are comparable. Note that Resource should implement a "bool loadFromFile" function for this holder to work. sf::Font use openFromFile, but it's handled with type test. More...
class  SoundPlayer
 Allow to play spatialized sounds. More...
class  TextContainer
 store text accessible with a string key, with option to load and store text for a given tongue, so it has simple support for localisation. More...
struct  Frames
 Store frames count and textures to ease serialization and for better interface. More...
class  TextureAtlas
 Contains texture position and sub-box of all sprites for a given sprite sheet. Animations ca be handled with the following restrictions: More...
struct  CollageOptions
 Options for collage. More...
class  TextureCollage
 Allow user to make a collage of several textures in one image. More...
struct  WidgetAspect
 Store data required to fully customize how a widget is drawn. More...
struct  Constraints
 Store constraints on position for gui panel. Alignment always precede relative position. More...
struct  Tooltip
 store tooltip in a function with its parent widget ID More...
struct  WidgetOptions
 Store widget options : tooltip, position, description. More...
struct  TextOptions
 Store text options : boxSize, centered, type, etc. More...
struct  Panel
 store panel posiiton, size and some parameters More...
struct  Window
 small struct to ease use of beginPanel and beginWindow in Gui More...
struct  FontSize
 font size container More...
struct  Style
 define gui font style and padding More...

Typedefs

using Tetragon = Polygon <4>
using Hexagon = Polygon <6>
using Octogon = Polygon <8>
using LineFloat = Line<float>
using CircleFloat = Circle<float>
using Mesh = std::array <sf::Vertex, 6>
using TextureHolder = ResourcesHolder <sf::Texture>
using ShaderHolder = ResourcesHolder <sf::Shader>
using SoundHolder = ResourcesHolder <sf::SoundBuffer>
using FontHolder = ResourcesHolder <sf::Font>
using LayoutHolder = ResourcesHolder <Layout>
using AtlasHolder = ResourcesHolder <TextureAtlas>
using TextHolder = ResourcesHolder <TextContainer>
template<typename Type>
using LookupTable = std::unordered_map <std::string, Type>

Enumerations

enum class  VerticalAlignment { Top , Center , Bottom , None }
 List all possible vertical alignment. More...
enum class  HorizontalAlignment { Left , Center , Right , None }
 List all possible horizontal alignment. More...
enum class  ItemState { Active , Hovered , Neutral , None }
 List gui elements states. More...
enum class  TextType { Footnote , Subtitle , Normal , Title }
 Text type. More...
enum class  Widget {
  Panel , Window , WindowWithCap , TextBox ,
  ItemBox , MenuBox , MenuItemBox , TitleBox ,
  Button , IconButton , TitleButton , CheckBox ,
  SliderBar , ScrollerBar , Slider , Scroller ,
  ProgressBar , ProgressFill , Separation , Image ,
  None
}
 List widget textures available in gui. More...
enum class  Slices { One , Three , Nine , Default }
 Defines number of slices for stretchable widgets. More...
enum class  TileMode { Stretch , Hide , Repeat , Rotate }
 Defines type of tiling for center part of 9-slices widgets. More...

Functions

template<typename Type>
constexpr sf::Vector2< Type > round (const sf::Vector2< Type > &value)
 Round sf::Vector2 components.
template<typename Type>
constexpr sf::Vector2< Type > round (const sf::Vector3< Type > &value)
 Round sf::Vector3 components.
template<typename Type>
constexpr Type lerp (const Type &min, const Type &max, const float value)
 Linear interpolation between min and max if value belong to [0, 1], with extrapolation otherwise (see clampedLerp).
sf::Color lerp (const sf::Color &a, const sf::Color &b, const float value)
 Interpolate between two color, value is clamped to [0, 1].
template<typename Type>
constexpr Type clamp (const Type min, const Type max, const Type value)
 Clamp value between min and max.
template<typename Type>
constexpr Type clampedLerp (const Type &min, const Type &max, const float value)
 Clamped linear interpolation, it always return a value in [min, max] regardless of if value is in [0, 1] or not.
template<typename Type>
constexpr float inverseLerp (const Type &min, const Type &max, const Type &value)
 Inverse linear interpolation. Return in [0, 1] range if value is in [min, max].
template<typename InputType, typename OutputType>
constexpr OutputType remap (const InputType &minInput, const InputType &maxInput, const OutputType &minOutput, const OutputType &maxOutput, const InputType &value)
 Remap a value from [minInput, maxInput] range to [minOutput, maxOutput], depending on where value is in [minInput, maxInput].
template<size_t N>
Polygon< N > makeRegularPolygon (const sf::Vector2f &center, const float size)
 make a regular polygon, like hexagon or octogon, around a center
template<size_t N>
constexpr sf::Vector2f centroid (const Polygon< N > &polygon)
 Return center of polygon.
template<size_t N>
constexpr sf::FloatRect boundingBox (const Polygon< N > &polygon)
 Return a box that bounds polygon.
template<typename Type>
constexpr sf::Vector2f centroid (const std::vector< sf::Vector2< Type > > &vertices)
 Return center of a set of points.
void computeMesh (Mesh &mesh, const sf::FloatRect &box)
 Compute mesh quad coordinates.
void computeMeshTexture (Mesh &Mesh, const sf::IntRect &textureRect)
 compute texture coordinates from a rect
void rotateMeshTexture (Mesh &mesh)
 Rotate a mesh texture by 90°
template<typename LayoutData>
constexpr std::string layoutTypeName ()
 return special prefix to avoid name collision and to infer type from file
void saveInFile (const json &out, const std::string &file, const bool compact=false)
 save json to file
json loadFromFile (const std::string &file)
 load json from file
bool loadFromFile (Layout &layout, const std::string &file)
void saveInFile (const Layout &layout, const std::string &file, const bool compact)
template<typename Key, typename Type>
bool loadFromFile (std::unordered_map< Key, Type > &table, const std::string &file)
template<typename Key, typename Type>
void saveInFile (const std::unordered_map< Key, Type > &table, const std::string &file, const bool compact=false)
bool loadFromFile (TextureAtlas &atlas, const std::string &file)
void saveInFile (const TextureAtlas &atlas, const std::string &file, const bool compact)
 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT (Frames, count, texture)
template<typename Key, typename Type>
void to_json (json &j, const std::unordered_map< Key, Type > &table)
template<typename Key, typename Type>
void from_json (const json &j, std::unordered_map< Key, Type > &table)
template<typename Object, typename ObjectId>
void to_json (json &j, const ObjectPool< Object, ObjectId > &pool)
template<typename Object, typename ObjectId>
void from_json (const json &j, ObjectPool< Object, ObjectId > &pool)
 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT (FontSize, normal, title, subtitle, footnote)
 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT (Style, fontSize, fontColor, itemSpacing)
 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT (Panel, movable, visible, closable, hasHeader, size, position, title)
 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT (Constraints, vertical, horizontal, relativePosition)
 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT (Window, panel, constraints)
 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT (LayoutEntry, panel, position, constraints, window)
 NLOHMANN_JSON_SERIALIZE_ENUM (VerticalAlignment, { {VerticalAlignment::None, "VerticalAlignment::None"}, {VerticalAlignment::Top, "VerticalAlignment::Top"}, {VerticalAlignment::Bottom, "VerticalAlignment::Bottom"}, {VerticalAlignment::Center, "VerticalAlignment::Center"}, }) NLOHMANN_JSON_SERIALIZE_ENUM(HorizontalAlignment

Variables

constexpr float Pi = 3.14159265359f
constexpr float PiRad = 3.14159265359f / 180.f
const std::string DefaultFont = SguiContentsDir"/Luciole-Regular.ttf"
const std::string DefaultBoldFont = SguiContentsDir"/Luciole-Bold.ttf"
const std::string DefaultTexture = SguiContentsDir"/widgets.png"
const std::string DefaultAtlas = SguiContentsDir"/atlas.json"

Typedef Documentation

◆ AtlasHolder

◆ CircleFloat

using sgui::CircleFloat = Circle<float>

◆ FontHolder

using sgui::FontHolder = ResourcesHolder <sf::Font>

◆ Hexagon

using sgui::Hexagon = Polygon <6>

◆ LayoutHolder

◆ LineFloat

using sgui::LineFloat = Line<float>

◆ LookupTable

template<typename Type>
using sgui::LookupTable = std::unordered_map <std::string, Type>

◆ Mesh

typedef std::array< sf::Vertex, 6 > sgui::Mesh = std::array <sf::Vertex, 6>

◆ Octogon

using sgui::Octogon = Polygon <8>

◆ ShaderHolder

using sgui::ShaderHolder = ResourcesHolder <sf::Shader>

◆ SoundHolder

using sgui::SoundHolder = ResourcesHolder <sf::SoundBuffer>

◆ Tetragon

using sgui::Tetragon = Polygon <4>

◆ TextHolder

◆ TextureHolder

using sgui::TextureHolder = ResourcesHolder <sf::Texture>

Enumeration Type Documentation

◆ HorizontalAlignment

enum class sgui::HorizontalAlignment
strong

List all possible horizontal alignment.

Enumerator
Left 
Center 
Right 
None 

◆ ItemState

enum class sgui::ItemState
strong

List gui elements states.

Enumerator
Active 
Hovered 
Neutral 
None 

◆ Slices

enum class sgui::Slices
strong

Defines number of slices for stretchable widgets.

Enumerator
One 
Three 
Nine 
Default 

◆ TextType

enum class sgui::TextType
strong

Text type.

Enumerator
Footnote 
Subtitle 
Normal 
Title 

◆ TileMode

enum class sgui::TileMode
strong

Defines type of tiling for center part of 9-slices widgets.

Enumerator
Stretch 
Hide 
Repeat 
Rotate 

◆ VerticalAlignment

enum class sgui::VerticalAlignment
strong

List all possible vertical alignment.

Enumerator
Top 
Center 
Bottom 
None 

◆ Widget

enum class sgui::Widget
strong

List widget textures available in gui.

Enumerator
Panel 
Window 
WindowWithCap 
TextBox 
ItemBox 
MenuBox 
MenuItemBox 
TitleBox 
Button 
IconButton 
TitleButton 
CheckBox 
SliderBar 
ScrollerBar 
Slider 
Scroller 
ProgressBar 
ProgressFill 
Separation 
Image 
None 

Function Documentation

◆ boundingBox()

template<size_t N>
sf::FloatRect sgui::boundingBox ( const Polygon< N > & polygon)
constexpr

Return a box that bounds polygon.

◆ centroid() [1/2]

template<size_t N>
sf::Vector2f sgui::centroid ( const Polygon< N > & polygon)
constexpr

Return center of polygon.

◆ centroid() [2/2]

template<typename Type>
sf::Vector2f sgui::centroid ( const std::vector< sf::Vector2< Type > > & vertices)
constexpr

Return center of a set of points.

◆ clamp()

template<typename Type>
Type sgui::clamp ( const Type min,
const Type max,
const Type value )
constexpr

Clamp value between min and max.

◆ clampedLerp()

template<typename Type>
Type sgui::clampedLerp ( const Type & min,
const Type & max,
const float value )
constexpr

Clamped linear interpolation, it always return a value in [min, max] regardless of if value is in [0, 1] or not.

◆ computeMesh()

void sgui::computeMesh ( Mesh & mesh,
const sf::FloatRect & box )

Compute mesh quad coordinates.

◆ computeMeshTexture()

void sgui::computeMeshTexture ( Mesh & mesh,
const sf::IntRect & textureBox )

compute texture coordinates from a rect

◆ from_json() [1/2]

template<typename Object, typename ObjectId>
void sgui::from_json ( const json & j,
ObjectPool< Object, ObjectId > & pool )

◆ from_json() [2/2]

template<typename Key, typename Type>
void sgui::from_json ( const json & j,
std::unordered_map< Key, Type > & table )

◆ inverseLerp()

template<typename Type>
float sgui::inverseLerp ( const Type & min,
const Type & max,
const Type & value )
constexpr

Inverse linear interpolation. Return in [0, 1] range if value is in [min, max].

◆ layoutTypeName()

template<typename LayoutData>
std::string sgui::layoutTypeName ( )
constexpr

return special prefix to avoid name collision and to infer type from file

◆ lerp() [1/2]

sf::Color sgui::lerp ( const sf::Color & a,
const sf::Color & b,
const float value )

Interpolate between two color, value is clamped to [0, 1].

◆ lerp() [2/2]

template<typename Type>
Type sgui::lerp ( const Type & min,
const Type & max,
const float value )
constexpr

Linear interpolation between min and max if value belong to [0, 1], with extrapolation otherwise (see clampedLerp).

◆ loadFromFile() [1/4]

json sgui::loadFromFile ( const std::string & file)

load json from file

◆ loadFromFile() [2/4]

bool sgui::loadFromFile ( Layout & layout,
const std::string & file )

save/load GuiLayout in json

◆ loadFromFile() [3/4]

template<typename Key, typename Type>
bool sgui::loadFromFile ( std::unordered_map< Key, Type > & table,
const std::string & file )

save/load look-up table from file

◆ loadFromFile() [4/4]

bool sgui::loadFromFile ( TextureAtlas & atlas,
const std::string & file )

save/load sprite Atlas

◆ makeRegularPolygon()

template<size_t N>
Polygon< N > sgui::makeRegularPolygon ( const sf::Vector2f & center,
const float size )

make a regular polygon, like hexagon or octogon, around a center

◆ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT() [1/7]

sgui::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT ( Constraints ,
vertical ,
horizontal ,
relativePosition  )

◆ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT() [2/7]

sgui::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT ( FontSize ,
normal ,
title ,
subtitle ,
footnote  )

Fontsize

◆ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT() [3/7]

sgui::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT ( Frames ,
count ,
texture  )

Convert Frames to/from json

◆ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT() [4/7]

sgui::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT ( LayoutEntry ,
panel ,
position ,
constraints ,
window  )

◆ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT() [5/7]

sgui::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT ( Panel ,
movable ,
visible ,
closable ,
hasHeader ,
size ,
position ,
title  )

◆ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT() [6/7]

sgui::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT ( Style ,
fontSize ,
fontColor ,
itemSpacing  )

◆ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT() [7/7]

sgui::NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT ( Window ,
panel ,
constraints  )

◆ NLOHMANN_JSON_SERIALIZE_ENUM()

sgui::NLOHMANN_JSON_SERIALIZE_ENUM ( VerticalAlignment ,
{ {VerticalAlignment::None, "VerticalAlignment::None"}, {VerticalAlignment::Top, "VerticalAlignment::Top"}, {VerticalAlignment::Bottom, "VerticalAlignment::Bottom"}, {VerticalAlignment::Center, "VerticalAlignment::Center"}, }  )

convert VerticalAlignment to/from json convert HOrizontalAlignment to/from json

◆ remap()

template<typename InputType, typename OutputType>
OutputType sgui::remap ( const InputType & minInput,
const InputType & maxInput,
const OutputType & minOutput,
const OutputType & maxOutput,
const InputType & value )
constexpr

Remap a value from [minInput, maxInput] range to [minOutput, maxOutput], depending on where value is in [minInput, maxInput].

◆ rotateMeshTexture()

void sgui::rotateMeshTexture ( Mesh & mesh)

Rotate a mesh texture by 90°

◆ round() [1/2]

template<typename Type>
sf::Vector2< Type > sgui::round ( const sf::Vector2< Type > & value)
constexpr

Round sf::Vector2 components.

◆ round() [2/2]

template<typename Type>
sf::Vector2< Type > sgui::round ( const sf::Vector3< Type > & value)
constexpr

Round sf::Vector3 components.

◆ saveInFile() [1/4]

void sgui::saveInFile ( const json & out,
const std::string & file,
const bool compact )

save json to file

◆ saveInFile() [2/4]

void sgui::saveInFile ( const Layout & layout,
const std::string & file,
const bool compact )

◆ saveInFile() [3/4]

template<typename Key, typename Type>
void sgui::saveInFile ( const std::unordered_map< Key, Type > & table,
const std::string & file,
const bool compact = false )

◆ saveInFile() [4/4]

void sgui::saveInFile ( const TextureAtlas & atlas,
const std::string & file,
const bool compact )

◆ to_json() [1/2]

template<typename Object, typename ObjectId>
void sgui::to_json ( json & j,
const ObjectPool< Object, ObjectId > & pool )

convert object pool to/from json

◆ to_json() [2/2]

template<typename Key, typename Type>
void sgui::to_json ( json & j,
const std::unordered_map< Key, Type > & table )

convert unordered_map to/from json

Variable Documentation

◆ DefaultAtlas

const std::string sgui::DefaultAtlas = SguiContentsDir"/atlas.json"

◆ DefaultBoldFont

const std::string sgui::DefaultBoldFont = SguiContentsDir"/Luciole-Bold.ttf"

◆ DefaultFont

const std::string sgui::DefaultFont = SguiContentsDir"/Luciole-Regular.ttf"

Default fonts files

◆ DefaultTexture

const std::string sgui::DefaultTexture = SguiContentsDir"/widgets.png"

Default texture and atlas file for widgets

◆ Pi

float sgui::Pi = 3.14159265359f
constexpr

◆ PiRad

float sgui::PiRad = 3.14159265359f / 180.f
constexpr