Welcome to GuiCode’s documentation!

GitHub repository: https://github.com/KaixoCode/GuiCode

Documentation

class Gui

Public Functions

Gui()
template<typename T, typename ...Args>
T &AddWindow(Args... args)

Add a new Window to the Gui

Return

reference to the added Window

Template Parameters
Parameters
  • ...args: arguments to initialize T

bool Loop()

Call this in a while loop while (gui.Loop);

Return

true when Gui is running

void Close()

Close the gui.

Private Functions

void m_Init()

Private Members

std::vector<std::unique_ptr<WindowBase>> m_Windows
bool m_Running = true

Data

Vec

template<typename T>
struct Vec2

Public Functions

Vec2 operator-()
Vec2 operator-(const Vec2 &other)
Vec2 operator+(const Vec2 &other)
Vec2 operator*(const Vec2 &other)
Vec2 operator/(const Vec2 &other)
Vec2 operator*(T other)
Vec2 operator/(T other)
Vec2 operator+(T other)
Vec2 operator-(T other)
Vec2 &operator=(const Vec2 &other)
Vec2 &operator+=(const Vec2 &other)
Vec2 &operator-=(const Vec2 &other)
bool operator==(const Vec2 &other) const
bool operator!=(const Vec2 &other) const
operator glm::vec2() const
template<size_t I>
auto &get() &
template<size_t I>
auto const &get() const &
template<size_t I>
auto &&get() &&

Public Members

T width
T x
T r
T start
union Vec2::[anonymous] [anonymous]
T height
T y
T g
T end
union Vec2::[anonymous] [anonymous]
template<typename T>
struct Vec3

Public Functions

Vec3 operator-()
Vec3 operator-(const Vec3 &other)
Vec3 operator+(const Vec3 &other)
Vec3 operator*(const Vec3 &other)
Vec3 operator*(T other)
Vec3 &operator=(const Vec3 &other)
Vec3 &operator+=(const Vec3 &other)
Vec3 &operator-=(const Vec3 &other)
operator glm::vec3() const
template<size_t I>
auto &get() &
template<size_t I>
auto const &get() const &
template<size_t I>
auto &&get() &&

Public Members

T width
T x
T r
union Vec3::[anonymous] [anonymous]
T height
T y
T g
union Vec3::[anonymous] [anonymous]
T depth
T z
T b
union Vec3::[anonymous] [anonymous]
template<typename T>
struct Vec4

Public Functions

Vec4 operator-() const
Vec4 operator-(const Vec4 &other) const
Vec4 operator+(const Vec4 &other) const
Vec4 operator*(const Vec4 &other) const
Vec4 operator*(T other) const
Vec4 operator/(T other) const
Vec4 &operator=(const Vec4 &other)
Vec4 &operator+=(const Vec4 &other)
Vec4 &operator-=(const Vec4 &other)
bool operator==(const Vec4 &other) const
Vec4 Overlap(const Vec4 &o) const
Vec4 Translate(const Vec2<T> &o) const
operator glm::vec4() const
template<size_t I>
auto &get() &
template<size_t I>
auto const &get() const &
template<size_t I>
auto &&get() &&

Public Members

Vec2<T> position = {0, 0}
T x
T r
T y
T g
union Vec4::[anonymous] [anonymous]
Vec2<T> size = {0, 0}
T z
T b
T width
T w
T a
T height
union Vec4::[anonymous] [anonymous]

ui

class RightClickMenu : public ComponentFrame

Right click menu class, uses a ComponentFrame to display a Menu in a separate Window.

Public Functions

void Loop() override

Don’t worry about this, the Gui class will take care of this.

void Close()

Close the right click menu.

void Open(MenuBase *menu, bool f = false)

Open the right click menu.

Parameters
  • menu: menu to show

Public Static Functions

RightClickMenu &Get()

Get the instance (Singleton).

Return

instance

Components

class Component

Subclassed by Container, Div, MenuAccessories::Divider, MenuAccessories::VerticalDivider, ScrollbarBase

Public Functions

Component()

Constructor

Component(Vec2<int> size)

Constructor

Parameters
  • size: size

void X(int x)

Set the x-position of the Component

Parameters
  • x-position:

void Y(int y)

Set the y-position of the Component

Parameters
  • y-position:

void Position(const Vec2<int> &pos)

Set the position of the Component.

Parameters
  • pos: the position

void Size(const Vec2<int> &size)

Set the size of the Component.

Parameters
  • size: the size

void MinSize(const Vec2<int> &size)

Set the minimum size of the Component.

Parameters
  • size: the minimum size

void MaxSize(const Vec2<int> &size)

Set the maximum size of the Component.

Parameters
  • size: the maximum size

void Width(int w)

Set the width of the Component.

Parameters
  • w: the width

void Height(int h)

Set the height of the Component.

Parameters
  • h: the height

void MinWidth(int w)

Set the minimum width of the Component.

Parameters
  • w: the minimum width

void MinHeight(int h)

Set the minimum height of the Component.

Parameters
  • h: the minimum height

void MaxWidth(int w)

Set the maximum width of the Component.

Parameters
  • w: the maximum width

void MaxHeight(int h)

Set the maximum height of the Component.

Parameters
  • h: the maximum height

void Hide()

Hide the Component; same as Visible(false) .

void Show()

Show the Component; same as Visible(true) .

void Visible(bool v)

Set the visibility of the Component.

void LayoutHint(Layout::Hint h)

Set a Layout::Hint for the Component.

void Viewport(const Vec4<int> &v)

Set the viewport of the Component.

Vec4<int> Viewport() const

Get the viewport of the Component.

Vec2<int> Position() const

Get the position of the Component

Return

position

int X() const

Get the x-position of the Component

Return

x-position

int Y() const

Get the y-position of the Component

Return

y-position

Vec2<int> Size() const

Get the size of the Component

Return

size

Vec2<int> MinSize() const

Get the minimum size of the Component

Return

minimum size

Vec2<int> MaxSize() const

Get the maximum size of the Component

Return

maximum size

int Height() const

Get the height of the Component

Return

height

int Width() const

Get the width of the Component

Return

width

int MinHeight() const

Get the minimum height of the Component

Return

minimum height

int MinWidth() const

Get the minimum width of the Component

Return

minimum width

int MaxHeight() const

Get the maximum height of the Component

Return

maximum height

int MaxWidth() const

Get the maximum width of the Component

Return

maximum width

int Cursor() const

Get the cursor that will be used when hovering over the Component

Return

cursor id

bool Visible() const

Get current visibility of the Component

Return

current visibility

Layout::Hint LayoutHint() const

Get the Layout::Hint of the Component

Return

Layout::Hint

bool NeedsRedraw()

Returns true when this Component needs a redraw

Return

true when a redraw is needed

bool WithinBounds(const Vec2<int> &pos) const

Returns true when the given pos is inside the Component

Return

true when pos is inside of the bounds of this Component

Parameters
  • pos: position to check

void Render(CommandCollection &d)

Render the Component

Parameters

void Update(const Vec4<int> &viewport)

Update the Component

Parameters
  • viewport: the viewport

void AddEvent(Event &e)

Add an event to this Component

Parameters

class Container : public Component

Subclassed by ButtonBase, MenuBase, Panel, TreeItemBase, WindowBase

Public Functions

template<typename T, typename ...Args>
T &Emplace(Args&&... args)

Emplace a component to this container,

Return

reference to the emplaced component.

Template Parameters
  • T: type

Parameters
  • ...args: constructor arguments for T

template<typename T, typename ...Args>
T &Emplace(Layout::Hint h, Args&&... args)

Emplace a component to this container,

Return

reference to the emplaced component.

Template Parameters
  • T: type

Parameters
  • h: layout hint for the component

  • ...args: constructor arguments for T

void Remove(int index)

Remove a Component from this Container using its index.

Parameters
  • index:

void Clear()

Remove all components.

int Cursor() const override

Get the cursor that will be used when hovering over the Component

Return

cursor id

void Render(CommandCollection &d) override

Render the Component

Parameters

void Update(const Vec4<int> &viewport) override

Update the Component

Parameters
  • viewport: the viewport

void Erase(ComponentCollection::const_iterator &i)

Remove a Component from this Container using its iterator.

Parameters
  • iterator:

ComponentCollection &Components()

Get all components.

Return

ComponentCollection

struct Layout

Public Types

enum Type

Layout type

Values:

enumerator Grid

Simple grid layout with padding.

enumerator Stack

Vertical stack layout with padding.

enumerator SidewaysStack

Horizontal stack layout with padding.

enumerator Border

Border layout, with a North, East, South, West, and Center component.

enumerator Divs

Components are located inside divs, easily expandable and highly customizable.

enumerator Free

Free roaming layout. Practically no layout.

enum Hint

A layout hint given to components that can be used by the LayoutManager to decide the location/size.

Values:

enumerator None
enumerator North
enumerator South
enumerator East
enumerator West
enumerator Center

Public Functions

Layout(Type type)

Constructor

Parameters
  • type:

Layout(Type type, int p)

Constructor for BorderLayout

Parameters
  • type:

  • p: padding

Layout(Type type, int p, bool r)

Constructor for BorderLayout

Parameters
  • type:

  • p: padding

  • r: resizable

Layout(Type type, int p, bool a, bool b, bool c, bool d)

Constructor for BorderLayout

Parameters
  • type:

  • p: padding

  • a: north resizable

  • b: east resizable

  • c: south resizable

  • d: west resizable

Layout(Type type, int p, int p2)

Constructor for BorderLayout

Parameters
  • type:

  • p: outer padding

  • p2: inner padding

Layout(Type type, int p, int p2, bool r)

Constructor for BorderLayout

Parameters
  • type:

  • p: outer padding

  • p2: inner padding

  • r: resizable

Layout(Type type, int p, int p2, bool a, bool b, bool c, bool d)

Constructor for BorderLayout

Parameters
  • type:

  • p: outer padding

  • p2: inner padding

  • a: north resizable

  • b: east resizable

  • c: south resizable

  • d: west resizable

Layout(Type type, int c, int r, int h, int v)

Constructor for GridLayout

Parameters
  • type:

  • c: number of columns

  • r: number of rows

  • h: y padding

  • v: x padding

operator Type() const

Implicit operator to Layout::Type.

struct BorderLayout
struct GridLayout
struct StackLayout
struct LayoutManager

Each Panel contains an instance of LayoutManager and it helps with arranging the components inside the Panel.

Public Functions

LayoutManager()

Constructor

void AddEvent(Event &e)

The LayoutManager also receives events because it also manages the resizability of some layouts, and thus needs to receive mouse events.

Parameters
  • e: event

int Cursor() const

Requested cursor to be displayed, used when resizing.

Return

cursor id

template<typename TypeCollection>
void Update(const Vec4<int> &dim, TypeCollection &components)

Update the positions and sizes of the components using the given dimensions.

Parameters
  • dim: rectangle of the available space

  • components: components

::Layout Layout() const

Returns the Layout that is in use.

Return

layout

template<Layout::Type T, typename ...Args>
void Layout(Args&&... args)

Set the Layout

Template Parameters
Parameters
  • ...args: the arguments for the constructor of Layout with the given type T

Vec2<int> BiggestCoords()

The biggest coords that were seen by this LayoutManger, can be used by the Panel to automatically resize.

Return

biggest coords

Buttons

template<typename ButtonGraphics, typename ButtonType = ButtonBase>
struct Button : public ButtonBase

Templated Button class, allows fully customized behaviour and graphics.

Template Parameters
  • ButtonGraphics: a class with a static Render method that takes in the Button and the CommandCollection.

  • ButtonType: the type of button, must be a class that inherits ButtonBase.

Public Functions

void Render(CommandCollection &d) override

Render the Component

Parameters

class ButtonBase : public Container

Basis for a Button

Subclassed by Button< ButtonGraphics, ButtonType >, ButtonType::Hover, ButtonType::Normal, ButtonType::Textured< ButtonType >, ButtonType::Toggle

Public Functions

ButtonBase(const std::string &name = "Button", Key key = Key::NONE)

Constructor

Parameters
  • name: name

  • size: size

  • key: keycombo

void Enable()

Enable this Button.

void Disable()

Disable this Button.

void Active(bool a)

Activate this Button; either means pressed or toggled on depending on type.

Parameters
  • a: active

void Name(const std::string &a)

Set the name of Button.

Parameters
  • a: the new name

bool Enabled() const

True when this Button is enabled.

bool Disabled() const

True when this Button is disabled.

bool Active() const

True when this Button is active.

bool Hovering() const

True when the mouse is hovering over this Button.

Key KeyCombo() const

Returns the keycombo for ‘pressing’ this Button.

Return

keycombo

const std::string &Name() const

Returns the name of this Button.

Return

name

template<typename Enum, typename Graphics = ButtonGraphics::Normal<>, typename MenuButtonGraphics = ButtonGraphics::Menu>
class DropDown : public ButtonType::Normal

Simple DropDown button, opens a menu with options out of which you can select 1.

Public Functions

DropDown(Callback e = [](Enum v) {})

Constructor

Parameters
  • e: callback

DropDownOption<Enum, MenuButtonGraphics> &AddOption(const std::string &name, Enum value, Callback e = [](Enum v) {})

Add an option to the DropDown. It will automatically select the option if it is the first one to be added.

Parameters
  • name: name

  • value: value

  • e: callback specific for this option

void Select(Enum v)

Select the options with the given value.

Parameters
  • v: value

Enum Value()

Get the current value of this DropDown.

Return

value

void ButtonSize(const Vec2<int> &s)

Set the button size for the buttons in the menu that will be opened.

Parameters
  • s: size

void ButtonWidth(int w)

Set the button width for the buttons in the menu that will be opened.

Parameters
  • w: width

void ButtonHeight(int h)

Set the button height for the buttons in the menu that will be opened.

Parameters
  • h: height

void Clear()

Clear all options.

Menu<MenuGraphics::Vertical, MenuType::Normal> &Menu()

Get the menu.

void Update(const Vec4<int> &v) override

Update the Component

Parameters
  • viewport: the viewport

void Render(CommandCollection &d) override

Render the Component

Parameters

namespace ButtonGraphics

template<Align Hori = Align::CENTER, Align Vert = Align::CENTER>
struct ButtonGraphics::Normal

Simple normal button graphics, displays name and changes color depending on state.

Template Parameters
  • Hori: horizontal text align

  • Vert: vertical text align

Public Static Functions

void Render(ButtonBase &b, CommandCollection &d)

Render

Parameters

struct ButtonGraphics::Menu

Button graphics for a menu.

Public Static Functions

template<typename Type = ButtonBase>
void Render(Type &b, CommandCollection &d)

Render

Parameters

struct ButtonGraphics::SubMenu

Button graphics for a submenu, which is a button that, when hovered over, opens a menu.

Public Static Functions

template<typename Type = ButtonBase>
void Render(Type &b, CommandCollection &d)

Render

Parameters

template<Align Hori = Align::CENTER, Align Vert = Align::CENTER>
struct ButtonGraphics::Textured

Simple textured button graphics

Template Parameters
  • Hori: horizontal text align

  • Vert: vertical text align

Public Static Functions

template<typename Type = ButtonBase>
void Render(ButtonType::Textured<Type> &b, CommandCollection &d)

Render

Parameters

struct ButtonGraphics::TitleMenu

Button graphics used for the buttons in the title bar menu.

Public Static Functions

void Render(ButtonBase &b, CommandCollection &d)

Render

Parameters

namespace ButtonType

class ButtonType::FocusToggle : public ButtonType::Toggle

Works the same as Toggle, but becomes inactive when the button loses focus (i.e. mouse is clicked somewhere else)

Public Functions

template<typename ...Args>
FocusToggle(Args&&... a)

See Constructor of ButtonType::Toggle

void Update(const Vec4<int> &viewport) override

Update the Component

Parameters
  • viewport: the viewport

class ButtonType::Hover : public ButtonBase

Becomes active when you hover over the button.

Public Functions

Hover(const std::string &name = "Button")

Constructor

Parameters
  • name: name

  • size: size

class ButtonType::List : public ButtonType::Normal

Only a single button all buttons of this type with the same id can be selected at a time. Works like a radio input.

Public Functions

List(Callback c = []() {}, const std::string &name = "Button", int id = 0, Key key = Key::NONE)

Constructor

Parameters
  • c: callback

  • name: name

  • id: list id

  • size: size

  • key: keycombo

void Selected(bool b)

Select or unselect this Button.

Parameters
  • b: select

bool Selected()

Returns true when this Button is selected.

Return

true when selected

Public Static Functions

int NewKey()

Generates a new unique key to be used for a new List group.

Return

unique key

template<typename Graphics, typename MenuType = MenuBase, typename ButtonType = Toggle, Align A = Align::BOTTOM>
class ButtonType::Menu : public ButtonType::Toggle

Button that also stores a Menu, has template arguments for ButtonGraphics, ButtonType and MenuType

Template Parameters
  • Graphics: button graphics

  • MenuType: type of Menu

  • ButtonType: button behaviour

  • A: alignment of the menu, either Align::BOTTOM, Align::RIGHT or Align::LEFT

Public Functions

template<typename ...Args>
Menu(Args&&... args)

See constructor of template argument ButtonType.

void Update(const Vec4<int> &viewport) override

Update the Component

Parameters
  • viewport: the viewport

template<typename T, typename ...Args>
T &Emplace(Args&&... args)

Emplace an item to the Menu

Return

reference to the emplaced item

Template Parameters
  • T: type

Parameters
  • ...args: constructor arguments for T

MenuBase &MenuBase()

Get the menu of this menu button

Return

menu

bool WithinBounds(const Vec2<int> &pos) const override

Returns true when the given pos is inside the Component

Return

true when pos is inside of the bounds of this Component

Parameters
  • pos: position to check

class ButtonType::Normal : public ButtonBase

Normal Button behaviour: press to run the Callback.

Subclassed by ButtonType::List, DropDown< Enum, Graphics, MenuButtonGraphics >

Public Functions

Normal(Callback c = []() {}, const std::string &name = "Button", Key key = Key::NONE)

Constructor

Parameters
  • c: callback

  • name: name

  • size: size

  • key: keycombo

template<typename ButtonType = ButtonBase>
class ButtonType::Textured : public ButtonBase

Button that can take on any other ButtonType, but stores 3 textures for the ButtonGraphics::Textured graphics.

Template Parameters
  • ButtonType: button behaviour

Public Functions

template<typename ...Args>
Textured(Graphics::Texture &t1, Graphics::Texture &t2, Graphics::Texture &t3, Args&&... a)

Constructor

Parameters
  • t1: texture for the idle state

  • t2: texture for the hovering state

  • t3: texture for the pressed state

  • a: arguments for the constructor of template argument ButtonType

class ButtonType::Toggle : public ButtonBase

Toggle Button behaviour, click to toggle the state.

Subclassed by ButtonType::FocusToggle, ButtonType::Menu< Graphics, MenuType, ButtonType, A >

Public Functions

Toggle(bool *a, const std::string &name = "Button", Key key = Key::NONE)

Constructor

Parameters
  • a: pointer to a bool, this button will actively read for a change in value, and when clicked change the state of this bool.

  • name: name

  • size: size

  • key: keycombo

Toggle(ToggleCallback a = [](bool &state) {}, const std::string &name = "Button", Key key = Key::NONE)

Constructor

Parameters
  • a: pointer to a bool, this button will actively read for a change in value, and when clicked change the state of this bool.

  • name: name

  • size: size

  • key: keycombo

Toggle(const std::string &name = "Button", Key key = Key::NONE)

Constructor

Parameters
  • name: name

  • size: size

  • key: keycombo

auto Active(bool a) -> void override

Activate this Button; either means pressed or toggled on depending on type.

Parameters
  • a: active

bool Active() const override

True when this Button is active.

void Update(const Vec4<int> &viewport) override

Update the Component

Parameters
  • viewport: the viewport

Panels

class Panel : public Container

A crucial building block, this component contains a layout which let’s you arrange other panels or components.

Subclassed by ComponentFramePanel, ScrollPanel, TextBox, TextDisplayer, TreePanel

Public Functions

Panel(Vec2<int> size = {40, 70})

Constructor

Parameters
  • size: size

void SmartPanel(bool s)

A smart panel only redraws whenever a component inside this panel requests a redraw. !!This feature is still a BETA and does not work entirely as intended yet!!

Parameters
  • s: enable smart panel

void Background(const Color &c)

Set the background color of this panel

Parameters
  • c: color

int Cursor() const override

Get the cursor that will be used when hovering over the Component

Return

cursor id

void Update(const Vec4<int> &viewport) override

Update the Component

Parameters
  • viewport: the viewport

void Render(CommandCollection &d) override

Render the Component

Parameters

void Background(CommandCollection &d)

Overrideable method for rendering a background.

Parameters

template<Layout::Type T, typename ...Args>
void Layout(Args&&... args)

Set the layout of this Panel

Template Parameters
Parameters
  • ...args: arguments for the layout type

void AutoResize(bool rx, bool ry)

Enable autoresizing of this panel in the x and y direction. When enabled, this Panel will retrieve the highest x and y position from its LayoutManager and automatically resize to that size.

Parameters
  • rx: auto resize in the x-axis

  • ty: auto resize in the y-axis

Vec2<bool> AutoResize() const

Retrieve the current state of the AutoResize.

Return

state of the AutoResize

bool NeedsRedraw() override

Returns true when this Component needs a redraw

Return

true when a redraw is needed

LayoutManager &LayoutManager()

Get the LayoutManager of this Panel

Return

layout manager

Div &Div()

Get the Div of this Panel. Only used when the layout is set to Layout::Divs

Return

div

class ScrollPanel : public Panel

Simple scroll panel, contains another Panel which is translated.

Subclassed by TextArea

Public Functions

ScrollPanel()

Constructor

void Update(const Vec4<int> &viewport) override

Update the Component

Parameters
  • viewport: the viewport

void Render(CommandCollection &d) override

Render the Component

Parameters

void EnableScrollbars(bool x, bool y)

Enable scrolling on the x and y axis.

Parameters
  • x: enable scroll in x-axis

  • y: enable scroll in y-axis

Vec2<int> Scrolled() const

Returns the amount scrolled in both axes.

Return

amount scrolled

::Panel &Panel() const

Retrieves the Panel inside this ScrollPanel

Return

reference to the Panel

template<typename T, typename ...Args>
T &Panel(Args&&... args)

Set the Panel in this ScrollPanel. This is templated to allow for different Panel types to be used inside a ScrollPanel.

Return

reference to the emplaced panel

Template Parameters
  • T: panel type

Parameters
  • ...args: constructor arguments for T

class TreePanel : public Panel

A TreePanel can be used to display a tree of files, using the TreeItem class.

Public Functions

TreePanel()

Constructor

void SortItems(bool reverse)

Sorts the contents of this Panel while remaining the tree hierarchy.

Parameters
  • reverse: when true it sorts in reverse alphabetical order

Scrollbars

template<typename ScrollbarGraphics, typename ScrollbarType = ScrollbarBase>
class Scrollbar : public ScrollbarBase

Templated Scrollbar class, allows fully customized behaviour and graphics.

Template Parameters

class ScrollbarBase : public Component

Basis for Scrollbar

Subclassed by Scrollbar< ScrollbarGraphics, ScrollbarType >, ScrollbarType::Horizontal, ScrollbarType::Vertical

Public Functions

ScrollbarBase()

Constructor

void Range(const Vec2<int> &r)

Set the range of the Scrollbar.

Parameters
  • r: range

void Scroll(int s)

Scroll by s amount.

Parameters
  • s: amount

void Value(int v)

Set absolute scroll value.

Parameters
  • v: value to scroll to

void VisibleRange(int v)

Set the visible range on the screen. This is used to calculate the size of the scrollbar.

Parameters
  • v: visible range

int MinBarSize() const

The minimun scrollbar size, this value is used to limit the scrollbar size to not become infinitely small with big scrollareas.

Return

minimum bar size

int Value() const

Returns the value of this Scrollbar

Return

value

int Mouse() const

This is used by the ScrollbarGraphics and returns the x or y (depending on what type of scrollbar it is) of the mouse when it started dragging the scrollbar.

Return

x or y of mouse (depending on type of scrollbar)

int VisibleRange() const

Returns the visible range.

Return

visible range

Vec2<int> Range() const

Returns the range.

Return

range

bool NotNecessary() const

Returns true when the scrollbar is not necessary, i.e. when the visible range is lower than the range of the scrollbar.

bool Hovering() const

Returns true when the mouse is hovering over the scrollbar.

Return

true when mouse over scrollbar

bool Dragging() const = 0

Returns true when the mouse is dragging the scrollbar.

Return

true when mouse dragging

void Update(const Vec4<int> &viewport) override

Update the Component

Parameters
  • viewport: the viewport

namespace ScrollbarGraphics

struct ScrollbarGraphics::Normal

Simple normal scrollbar graphics.

Public Static Functions

template<typename ScrollbarType>
void Render(Scrollbar<Normal, ScrollbarType> &b, CommandCollection &d)

Render

Parameters

namespace ScrollbarType

class ScrollbarType::Vertical : public ScrollbarBase

Vertical scrollbar.

Public Functions

Vertical()

Constructor

bool Hovering() const override

Returns true when the mouse is hovering over the scrollbar.

Return

true when mouse over scrollbar

bool Dragging() const override

Returns true when the mouse is dragging the scrollbar.

Return

true when mouse dragging

class ScrollbarType::Horizontal : public ScrollbarBase

Horizontal scrollbar.

Public Functions

Horizontal()

Constructor

bool Hovering() const override

Returns true when the mouse is hovering over the scrollbar.

Return

true when mouse over scrollbar

bool Dragging() const override

Returns true when the mouse is dragging the scrollbar.

Return

true when mouse dragging

Text

class Selection : public Vec2<int>

Simple Selection class, practically just a Vec2<int> but with a Lowest() and Highest() method to retrieve the lowest/highest index.

Public Functions

int Lowest() const

Get the lowest value.

Return

lowest value

int Highest() const

Get the highest value.

Return

highest value

class TextContainer

Contains text, used in TextDisplayer. Tracks typing location and text selection.

Public Functions

TextContainer(const std::string &c = "", bool editable = true)

Constructor

Parameters
  • c: content

  • editable: editable

bool Editable() const

Returns true when this text container is editable.

Return

true if editable

void Editable(bool e)

Set if this container is editable.

Parameters
  • a: editable

int Length() const

Get the length of the content in this container.

Return

length

auto Selection() -> Selection&

Get the selection as indices.

Return

selection

auto SelectionString() -> std::string_view

Get the selection as a std::string_view.

Return

selection

bool Selected() const

Returns true when there is text selected (selection.start != selection.end).

Return

true if selection

void Select(const ::Selection &s)

Set a selection. This selection is automatically constrained to (0, Length()).

Parameters
  • s: selection

void Select(int pos)

Set a selection. This selection is automatically constrained to (0, Length()).

Parameters
  • pos: selection

auto Content() -> std::string&

Get the entire content of this container as a string.

Return

content

void Content(const std::string &c)

Set the content of this container.

Parameters
  • c: content

void Insert(const std::string &add)

Insert a string at the current selection, removes the selection (if there is one) and then inserts the string in its place.

Parameters
  • add: insertion

void Insert(const char &add)

Insert a characer at the current selection, removes the selection (if there is one) and then inserts the character in its place.

Parameters
  • add: insertion

void Delete()

Normal delete operation, if there is a selection it gets removed, otherwise the character that comes after the current typing index gets removed.

void Backspace()

Backspace operation, if there is a selection it gets removed, otherwise the character before the current typing index gets removed.

void RemoveSelection()

Removes the selection from the content. Automatically adjusts the typing index.

void Remove(const ::Selection &s)

Removes the given selection from the content. Does not adjust the typing index.

Parameters
  • s: selection

int CtrlLeft()

Get the index in the content 1 word to the left of the current typing index.

Return

index

int CtrlLeft(int start)

Get the index in the content 1 word to the left of the given index.

Return

index

Parameters
  • start: start index

int CtrlRight()

Get the index in the content 1 word to the right of the current typing index.

Return

index

int CtrlRight(int start)

Get the index in the content 1 word to the right of the given index.

Return

index

Parameters
  • start: start index

class TextDisplayer : public Panel

TextDisplayer displays text (wow surprising).

Public Types

enum Wrap

Wrap enum. Word wraps at words, and at character level if a word is longer than a line. Character wraps at any character. And None doesn’t wrap at all.

Values:

enumerator Word
enumerator Character
enumerator None

Public Functions

TextDisplayer()

Constructor

void Update(const Vec4<int> &v) override

Update the Component

Parameters
  • viewport: the viewport

void Render(CommandCollection &d) override

Render the Component

Parameters

auto Container() -> TextContainer&

Get the TextContainer.

Return

TextContainer

bool Dragging()

Returns true if the mouse is dragging.

Return

true if dragging

bool Focused()

Returns true if this component is focused.

Return

true if focused

int PositionToIndex(const Vec2<int> &pos)

Converts an (x, y) position on this TextDisplayer to an index in the content of the TextContainer.

Return

index

Vec2<int> IndexToPosition(int index)

Converts an index in the TextContainer to an (x, y) position on this TextDisplayer.

Return

position

void AlignLines(Align a)

Set the horizontal alignment of the lines in this TextDisplayer.

Parameters
  • a: alignment

void Content(const std::string &c)

Set the content of this container.

Parameters
  • c: content

void Editable(bool e)

Set if this container is editable.

Parameters
  • a: editable

void TextColor(Color c)

Set the text color.

Parameters
  • c: color

void SelectColor(Color c)

Set the selection color.

Parameters
  • c: color

void TextWrap(Wrap wrap)

Set the text wrap mode.

Parameters
  • wrap: wrap mode

void LineHeight(int h)

Set the line height.

Parameters
  • h: line height

void Font(int f, float size)

Set the font and font size.

Parameters
  • f: font

  • size: font size

void Padding(int p)

Set the padding around the text.

Parameters
  • p: padding

auto AlignLines() const -> Align

Get the current horizontal alignment of the text.

Return

text alignment

auto Content() -> std::string&

Get the entire content of this container as a string.

Return

content

bool Editable() const

Returns true when this text container is editable.

Return

true if editable

auto TextColor() const -> Color

Get the text color.

Return

text color

auto SelectColor() const -> Color

Get the selection color.

Return

selection color

auto TextWrap() const -> Wrap

Get the current wrap mode.

Return

wrap

int LineHeight() const

Get the current line height.

Return

line height

int Font() const

Get the current font.

Return

font

float FontSize() const

Get the current font size.

Return

font size

int Padding() const

Get the current padding around the text.

Return

padding

void Placeholder(const std::string &p)

Set a placeholder string.

Parameters
  • p: placeholder

auto Placeholder() -> std::string&

Get the placeholder string.

Return

placeholder

class TextComponent : public TextBox

Simple TextComponent for displaying a single line of non-editable text.

Public Functions

TextComponent(const std::string &t, int f = Graphics::Fonts::Gidole14, float fsize = 14)

Constructor.

Parameters
  • t: content

  • f: font

  • fsize: font size

void Content(const std::string &c)

Set the content.

Parameters
  • c: content

auto Content() -> std::string&

Get the content.

Return

content

void Font(int f, float size)

Set the font and font size.

Parameters
  • f: font

  • size: font size

int Font() const

Get the font.

Return

font

class TextBox : public Panel

Single line TextBox.

Subclassed by TextComponent

Public Functions

TextBox()

Constructor.

void Update(const Vec4<int> &v) override

Update the Component

Parameters
  • viewport: the viewport

void Render(CommandCollection &d) override

Render the Component

Parameters

void AlignLines(Align a)

Set the horizontal alignment of the lines in this TextDisplayer.

Parameters
  • a: alignment

void Content(const std::string &c)

Set the content of this container.

Parameters
  • c: content

void Editable(bool e)

Set if this container is editable.

Parameters
  • a: editable

void TextColor(Color c)

Set the text color.

Parameters
  • c: color

void SelectColor(Color c)

Set the selection color.

Parameters
  • c: color

void TextWrap(TextDisplayer::Wrap wrap)

Set the text wrap mode.

Parameters
  • wrap: wrap mode

void LineHeight(int h)

Set the line height.

Parameters
  • h: line height

void Font(int f, float size)

Set the font and font size.

Parameters
  • f: font

  • size: font size

void Padding(int p)

Set the padding around the text.

Parameters
  • p: padding

auto AlignLines() -> Align

Get the current horizontal alignment of the text.

Return

text alignment

auto Content() -> std::string&

Get the entire content of this container as a string.

Return

content

bool Editable()

Returns true when this text container is editable.

Return

true if editable

auto TextColor() const -> Color

Get the text color.

Return

text color

auto SelectColor() const -> Color

Get the selection color.

Return

selection color

auto TextWrap() const -> TextDisplayer::Wrap

Get the current wrap mode.

Return

wrap

int LineHeight() const

Get the current line height.

Return

line height

int Font() const

Get the current font.

Return

font

float FontSize() const

Get the current font size.

Return

font size

int Padding() const

Get the current padding around the text.

Return

padding

void Placeholder(const std::string &p)

Set a placeholder string.

Parameters
  • p: placeholder

auto Placeholder() -> std::string&

Get the placeholder string.

Return

placeholder

class TextArea : public ScrollPanel

Multiline text area with scrollbars.

Public Functions

TextArea()

Constructor.

void Update(const Vec4<int> &v) override

Update the Component

Parameters
  • viewport: the viewport

void AlignLines(Align a)

Set the horizontal alignment of the lines in this TextDisplayer.

Parameters
  • a: alignment

void Content(const std::string &c)

Set the content of this container.

Parameters
  • c: content

void Editable(bool e)

Set if this container is editable.

Parameters
  • a: editable

void TextColor(Color c)

Set the text color.

Parameters
  • c: color

void SelectColor(Color c)

Set the selection color.

Parameters
  • c: color

void TextWrap(TextDisplayer::Wrap wrap)

Set the text wrap mode.

Parameters
  • wrap: wrap mode

void LineHeight(int h)

Set the line height.

Parameters
  • h: line height

void Font(int f, float size)

Set the font and font size.

Parameters
  • f: font

  • size: font size

void Padding(int p)

Set the padding around the text.

Parameters
  • p: padding

auto AlignLines() const -> Align

Get the current horizontal alignment of the text.

Return

text alignment

auto Content() -> std::string&

Get the entire content of this container as a string.

Return

content

bool Editable() const

Returns true when this text container is editable.

Return

true if editable

auto TextColor() const -> Color

Get the text color.

Return

text color

auto SelectColor() const -> Color

Get the selection color.

Return

selection color

auto TextWrap() const -> TextDisplayer::Wrap

Get the current wrap mode.

Return

wrap

int LineHeight() const

Get the current line height.

Return

line height

int Font() const

Get the current font.

Return

font

float FontSize() const

Get the current font size.

Return

font size

int Padding() const

Get the current padding around the text.

Return

padding

void Placeholder(const std::string &p)

Set a placeholder string.

Parameters
  • p: placeholder

auto Placeholder() -> std::string&

Get the placeholder string.

Return

placeholder

TreeItems

template<typename TreeItemGraphics, typename TreeItemType = TreeItemBase>
struct TreeItem : public TreeItemBase

Templated TreeItem class, allows fully customized behaviour and graphics.

Template Parameters
  • TreeItemGraphics: a class with a static Render method that takes in the TreeItem and the CommandCollection.

  • TreeItemType: the type of tree item, must be a class that inherits TreeItemBase.

Public Functions

void Render(CommandCollection &d) override

Render the Component

Parameters

class TreeItemBase : public Container

Basis for a TreeItem

Subclassed by TreeItem< TreeItemGraphics, TreeItemType >, TreeItemType::Folder, TreeItemType::Normal

Public Functions

bool Folder() const

Returns true when this TreeItem is a folder.

Return

true if folder

bool Hovering() const

Returns true if the mouse is hovering over this TreeItem.

Return

true when mouse over

const std::string &Name() const

File/Folder name.

Return

name

const std::string &Extension() const

If it’s a file it returns the extension as an std::string.

Return

file extension

const std::filesystem::path &Path() const

Returns the path to the file/folder as an std::filesystem::path.

Return

path

namespace TreeItemGraphics

struct TreeItemGraphics::Normal

Simple normal tree item graphics

Public Static Functions

template<typename TreeItemType>
void Render(TreeItem<Normal, TreeItemType> &b, CommandCollection &d)

Render

Parameters

namespace TreeItemType

class TreeItemType::Normal : public TreeItemBase

Normal tree item.

Public Functions

Normal(const std::filesystem::path &path, Vec2<int> size = {250, 22})

Constructor

Parameters
  • path: path to file

  • size: size

class TreeItemType::Folder : public TreeItemBase

Folder tree item. Contains a sub-TreePanel for more folder and files.

Public Functions

Folder(const std::filesystem::path &path, Vec2<int> size = {250, 22})

Constructor

Parameters
  • path: path to file

  • size: size

auto Size(const Vec2<int> &size) -> void override

Set the size of the Component.

Parameters
  • size: the size

auto Width(int w) -> void override

Set the width of the Component.

Parameters
  • w: the width

auto Height(int h) -> void override

Set the height of the Component.

Parameters
  • h: the height

Vec2<int> Size() const override

Get the size of the Component

Return

size

int Height() const override

Get the height of the Component

Return

height

int Width() const override

Get the width of the Component

Return

width

int ActualHeight() const

Height is slightly adjust, this returns the actual height.

Return

actual height

bool Expanded() const

Is this folder expanded?

Return

true when folder is expanded

template<typename T, typename ...Args>
T &Emplace(Args&&... args)

Emplace TreeItem to the sub-TreePanel

Template Parameters
Parameters
  • ...args: arguments for the constructor of T

void Update(const Vec4<int> &viewport) override

Update the Component

Parameters
  • viewport: the viewport

Events

struct Event

Public Types

enum Type

Event type.

Values:

enumerator KeyTyped
enumerator KeyPressed
enumerator KeyReleased
enumerator MousePressed
enumerator MouseReleased
enumerator MouseClicked
enumerator MouseMoved
enumerator MouseDragged
enumerator MouseWheel
enumerator MouseExited
enumerator MouseEntered
enumerator Focused
enumerator Unfocused
enum MouseButton

Mouse button

Values:

enumerator NONE
enumerator LEFT
enumerator RIGHT
enumerator MIDDLE
enum Mod

Event mods

Values:

enumerator SHIFT
enumerator CONTROL
enumerator ALT
enumerator SUPER
enumerator CAPS_LOCK
enumerator NUM_LOCK
enumerator LEFT
enumerator LEFT
enumerator MIDDLE
enumerator MIDDLE
enumerator RIGHT
enumerator RIGHT

Public Functions

Event(Type t)

Constructor for Focused and Unfocused events.

Parameters
  • t: type

Event(Type t, int x, int y)

Constructor for MouseMoved, MouseEntered, MouseExited, and KeyReleased events.

Parameters
  • t: type

  • x: x or key

  • y: y or keymod

Event(Type t, int key, int keymod, int repeat)

Constructor for KeyPressed events.

Parameters
  • t: type

  • key: key

  • keymod: keymod

  • repeat: repeat

Event(Type t, char c, int keymod, int coded)

Constructor for KeyTyped events.

Parameters
  • t: type

  • c: char

  • keymod: keymod

Event(Type t, int x, int y, MouseButton b)

Constructor for MouseDragged events.

Parameters
  • t: type

  • x: x

  • y: y

  • b: mouse button

Event(Type t, int x, int y, MouseButton b, int m)

Constructor for MousePressed, MouseReleased, and MouseClicked events.

Parameters
  • t: type

  • x: x

  • y: y

  • b: mouse button

  • m: event mods

Event(Type t, int x, int y, int a, int m)

Constructor for MouseWheel events.

Parameters
  • t: type

  • x: x

  • y: y

  • a: amount scrolled

  • m: event mods

struct Focused
struct KeyPressed
struct KeyReleased
struct KeyTyped
struct MouseClicked
struct MouseDragged
struct MouseEntered
struct MouseExited
struct MouseMoved
struct MousePressed
struct MouseReleased
struct MouseWheel
struct Unfocused
class Key

Public Types

enum Value

Type of key combo

Values:

enumerator NONE
enumerator CTRL_A
enumerator CTRL_B
enumerator CTRL_C
enumerator CTRL_D
enumerator CTRL_E
enumerator CTRL_F
enumerator CTRL_G
enumerator CTRL_H
enumerator CTRL_I
enumerator CTRL_J
enumerator CTRL_K
enumerator CTRL_L
enumerator CTRL_M
enumerator CTRL_N
enumerator CTRL_O
enumerator CTRL_P
enumerator CTRL_Q
enumerator CTRL_R
enumerator CTRL_S
enumerator CTRL_T
enumerator CTRL_U
enumerator CTRL_V
enumerator CTRL_W
enumerator CTRL_X
enumerator CTRL_Y
enumerator CTRL_Z
enumerator CTRL_COMMA
enumerator CTRL_SHIFT_S
enumerator CTRL_SHIFT_W
enumerator ALT_F4
enumerator CTRL_F4
enumerator BACKSPACE
enumerator TAB
enumerator DEL
enumerator ENTER
enumerator LEFT
enumerator RIGHT
enumerator UP
enumerator DOWN
enumerator SHIFT

Public Functions

Key()

Constructor

Key(Key::Value v)

Constructor

Parameters
  • v: value

Key(Event::KeyPressed v)

Constructor v keypressed event, automatically converted to a key combo

bool operator==(Key::Value a) const
bool operator!=(Key::Value a) const
bool operator<(Key::Value a) const
bool operator>(Key::Value a) const
bool operator<=(Key::Value a) const
bool operator>=(Key::Value a) const
operator int() const
operator Value() const
const std::string &ToString()

Convert the key combo to a string.

class EventListener

Public Types

template<typename T>
using Callback = std::function<void(T&)>

Public Functions

void AddCallback(Callback<Event> c)
void AddCallback(Callback<Event::KeyPressed> c)
void AddCallback(Callback<Event::KeyTyped> c)
void AddCallback(Callback<Event::KeyReleased> c)
void AddCallback(Callback<Event::MousePressed> c)
void AddCallback(Callback<Event::MouseReleased> c)
void AddCallback(Callback<Event::MouseClicked> c)
void AddCallback(Callback<Event::MouseMoved> c)
void AddCallback(Callback<Event::MouseDragged> c)
void AddCallback(Callback<Event::MouseWheel> c)
void AddCallback(Callback<Event::MouseEntered> c)
void AddCallback(Callback<Event::MouseExited> c)
void AddCallback(Callback<Event::Focused> c)
void AddCallback(Callback<Event::Unfocused> c)
void AddEvent(Event &e)

Add an event.

Parameters
  • e: event

void AddEvent(Event::KeyPressed &e)
void AddEvent(Event::KeyTyped &e)
void AddEvent(Event::KeyReleased &e)
void AddEvent(Event::MousePressed &e)
void AddEvent(Event::MouseReleased &e)
void AddEvent(Event::MouseClicked &e)
void AddEvent(Event::MouseMoved &e)
void AddEvent(Event::MouseDragged &e)
void AddEvent(Event::MouseWheel &e)
void AddEvent(Event::MouseEntered &e)
void AddEvent(Event::MouseExited &e)
void AddEvent(Event::Focused &e)
void AddEvent(Event::Unfocused &e)
template<typename T>
void operator+=(T t)
void Clear()

Graphics

namespace Graphics

Enums

enum Type

Command Type.

Values:

enumerator Fill
enumerator Stroke
enumerator StrokeWeight
enumerator FontSize
enumerator Font
enumerator TextAlign
enumerator Clip
enumerator PopClip
enumerator ClearClip
enumerator Translate
enumerator PushMatrix
enumerator PopMatrix
enumerator Scale
enumerator Viewport
enumerator Text
enumerator TextView
enumerator Line
enumerator Quad
enumerator TexturedQuad
enumerator Ellipse
enumerator Triangle
enumerator Point
enumerator FrameBuffer
enumerator FrameBufferEnd

Functions

void SetProjection(const glm::mat4 &proj)
bool WindowFocused()
void WindowFocused(bool a)
void CurrentWindow(int a)
void Scaling(float scale)
void RunCommands(const ::CommandCollection&)
Image LoadImageFile(const std::string &path)
void FreeImage(const Image &image)
int LoadFont(const std::string &path)
int LoadFont(const std::string &path, unsigned int size)
int StringWidth(const std::string&, int font, int size = -1)
int StringWidth(const std::string_view&, int font, int size = -1)
int CharWidth(const char&, int font, int size = -1)
void Init()
struct CommandBase
#include <Command.hpp>

Basis for a Command.

Subclassed by Graphics::Command< T >

template<Type T>
struct Command : public Graphics::CommandBase
struct Image
struct Texture
struct Textures
namespace Fonts

Variables

int Gidole
int Gidole14
int Gidole16
class CommandCollection

A collection of Graphics::Command.

Public Functions

template<Graphics::Type T, typename ...Args>
void Command(Args... args)

Emplace a Graphics::Command.

Template Parameters
  • T: type

Parameters
  • ...args: arguments for the constructor of T

const std::vector<Graphics::CommandBase> &Get() const

Returns the vector of Graphics::CommandBase.

Return

all commands

void Clear()

Empties the collection.

class Shader

Public Functions

Shader(const std::string &vertex, const std::string &frag, const std::string &geo = "")
void Clean() const
void Use() const
void SetBool(const char *n, bool v) const
void SetInt(const char *n, int v) const
void SetFloat(const char *n, float v) const
void SetFloatA(const char *n, const float *v, const unsigned int a) const
void SetIntA(const char *n, const int *v, const unsigned int a) const
void SetVec2(const char *n, const glm::vec2 &v) const
void SetVec3(const char *n, const glm::vec3 &v) const
void SetVec4(const char *n, const glm::vec4 &v) const
void SetVec4(const char *n, const Color &v) const
void SetMat2(const char *n, const glm::mat2 &m) const
void SetMat3(const char *n, const glm::mat3 &m) const
void SetMat4(const char *n, const glm::mat4 &m) const

Public Members

unsigned int ID

Windows

struct Window : public WindowType

Basic window, inherits a WindowType depending on OS.

Subclassed by ComponentFrame, Frame, SmallFrame

Public Functions

Window(const std::string &name, int width, int height, bool hideonclose = false, bool show = true, bool resizable = true, bool decorated = true)

Constructor

Parameters
  • name: name

  • width: width

  • height: height

  • resizable: resizable

  • decorated: decorated

class WindowBase : protected Container

Base for a window

Subclassed by WindowsWindow

Public Functions

WindowBase(const std::string &name, int width, int height, bool hideonclose = false)

Constructor

Parameters
  • name: name

  • width: width

  • height: height

auto Size(int w, int h) -> void
auto Size(Vec2<int> s) -> void = 0
auto Location(Vec2<int> s) -> void = 0
auto Maximize() -> void = 0
auto Restore() -> void = 0
auto Iconify() -> void = 0
auto Close() -> void = 0
auto Show() -> void = 0

Show the Component; same as Visible(true) .

auto Hide() -> void = 0

Hide the Component; same as Visible(false) .

auto Visible(bool b) -> void

Set the visibility of the Component.

auto ShouldClose(bool b) -> void = 0
auto Loop() -> void = 0
auto Scale(float) -> void = 0
Vec2<int> Size() const = 0

Get the size of the Component

Return

size

Vec2<int> Location() const = 0
Vec2<int> CursorPos() const = 0
int Width() const = 0

Get the width of the Component

Return

width

int Height() const = 0

Get the height of the Component

Return

height

bool Maximized() const = 0
bool Visible() const = 0

Get current visibility of the Component

Return

current visibility

bool ShouldClose() const = 0
bool HideOnClose() const
class Frame : public Window

A window with a menu and standard close/maximize/minimize buttons. Also has a base Panel to put content on.

Public Functions

Frame(const std::string &name, const int width, const int height, bool hideonclose = false, bool show = true, bool r = true)

Constructor

Parameters
  • name: name

  • width: width

  • height: height

  • hideonclose: when true this window will not exit the program but simply hide the window when closed.

  • r: resizeable

MenuBase &Menu()

Returns the menu.

Return

menu

::Panel &Panel()

Returns the base panel.

Return

panel

class SmallFrame : public Window

Smaller version of Frame, only has a close button and no menu.

Public Functions

SmallFrame(const std::string &name, const int width, const int height, bool hideonclose = false, bool show = false, bool r = true)

Constructor

Parameters
  • name: name

  • width: width

  • height: height

  • hideonclose: when true this window will not exit the program but simply hide the window when closed.

  • r: resizeable

::Panel &Panel()

Returns the base panel.

Return

panel

class ComponentFramePanel : public Panel

Panel used by the ComponentFrame.

Public Functions

ComponentFramePanel()

Constructor

void Update(const Vec4<int> &viewport) override

Update the Component

Parameters
  • viewport: the viewport

void Render(CommandCollection &d) override

Render the Component

Parameters

auto Component(::Component *c) -> void

Set the component of this ComponentFramePanel.

Parameters
  • c: component

class ComponentFrame : public Window

A frame to display a single component, used by the RightClickMenu.

Subclassed by Dragging, RightClickMenu

Public Functions

ComponentFrame(const std::string &name, const int width, const int height)

Constructor

Parameters
  • name: name

  • width: width

  • height: height

::Panel &Panel()

Returns the base panel.

Return

panel

void Component(::Component *c)

Set the component of this ComponentFrame.

Parameters
  • c: component

::Component *Component() const

Returns a pointer to the component.

Return

pointer to the component

Examples

Simple Window with a Menu

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <GuiCode/Gui.hpp>
#include <GuiCode/ui/window/Frame.hpp>
#include <GuiCode/ui/components/buttons/Button.hpp>
#include <GuiCode/ui/components/buttons/ButtonType.hpp>
#include <GuiCode/ui/components/buttons/ButtonGraphics.hpp>
#include <GuiCode/ui/components/menus/Menu.hpp>
#include <GuiCode/ui/components/menus/MenuGraphics.hpp>
#include <GuiCode/ui/components/menus/MenuType.hpp>
#include <GuiCode/ui/components/menus/MenuAccessories.hpp>

int main()
{
    // Create a Gui instance, this will take care of all the looping.
    Gui _gui;

    // Add a window to the gui.
    auto& _frame = _gui.AddWindow<Frame>("Frame Name", 400, 400);

    // Retrieve the menu from this Frame
    auto& _frameMenu = _frame.Menu();

    // Shorten the namespaces, otherwise lines will become really long.
    namespace BG = ButtonGraphics; namespace BT = ButtonType; 
    namespace MG = MenuGraphics; namespace MT = MenuType;
    
    // A TitleMenuButton is of type Menu, in this case it will be a Vertical menu, with 
    // Normal behaviour. The button type is FocusToggle, meaning it will toggle, but 
    // switch off when it loses focus (i.e. mouse is clicked somewhere else or 
    // the window loses focus)
    using TitleMenuButton = 
        Button<BG::TitleMenu, BT::Menu<MG::Vertical, MT::Normal, BT::FocusToggle>>;
    
    // A MenuButton is simply a Normal button with Menu graphics
    using MenuButton = Button<BG::Menu, BT::Normal>;

    // A SubMenuButton is of type Menu, here we use a Vertical menu, it is a normal menu, 
    // so no special behaviour, and this SubMenuButton behaves as Hover, meaning it will
    // activate when you hover over it. We will also align the submenu on the right of this
    // button.
    using SubMenuButton = 
        Button<BG::SubMenu, BT::Menu<MG::Vertical, MT::Normal, BT::Hover, Align::RIGHT>>;

    // A list button works as a radio select, you can select a single button within a
    // certain group.
    using ListButton = Button<BG::Menu, BT::List>;

    // A toggle button works like a normal button, but the active state toggles 
    // when clicked.
    using ToggleButton = Button<BG::Menu, BT::Toggle>;

    // Define a simple callback we will use for demo purposes here.
    auto _callback = [] { std::cout << "Callback!" << std::endl; };

    // Add the TitleMenuButton to the menu in the Frame. Because it is of ButtonType Menu 
    // it will contain a submenu in which we can add MenuButtons. 
    auto& _fileMenu = _frameMenu.Emplace<TitleMenuButton>("File");
    _fileMenu.Size({ 40, 32 });
    _fileMenu.MenuBase().ButtonSize({ 140, 18 });
    _fileMenu.Emplace<MenuButton>(_callback, "Button Name");
    _fileMenu.Emplace<MenuButton>(_callback, "Another button");
    _fileMenu.Emplace<MenuButton>(_callback, "More buttons!");

    // Now we add a SubMenuButton, meaning it contains another submenu to add buttons to
    auto& _subMenu = _fileMenu.Emplace<SubMenuButton>("Sub menu!");
    _subMenu.MenuBase().ButtonSize({ 170, 18 });
    _subMenu.Emplace<MenuButton>(_callback, "This is a submenu!").Disable(); // We disable this button so we can use it as a title.
    _subMenu.Emplace<MenuAccessories::Divider>(170, 1, 0, 2); // We can also add dividers!

    // Now we will create a group of ListButtons.
    int _id = BT::List::NewKey(); // Generate a new unique key for this button group.
    _subMenu.Emplace<ListButton>(_callback, "Select me!", _id);
    _subMenu.Emplace<ListButton>(_callback, "Or me!", _id);
    _subMenu.Emplace<ListButton>(_callback, "But not two at once!", _id);

    // Now we will continue adding to the file menu.
    _fileMenu.Emplace<MenuAccessories::Divider>(140, 1, 0, 2);
 
    // Here are some examples of a toggle button, you can either link it to a bool
    // or have a toggle callback which will take in its state as a bool.
    bool _link = false; // The toggle button will be linked to this bool.
    _fileMenu.Emplace<ToggleButton>(&_link, "Toggle me!");
    _fileMenu.Emplace<ToggleButton>([](bool state) { std::cout << state << std::endl; }, 
        "Toggle me as well!");

    // Infinite loop, this will automatically stop when the gui closes.
    while (_gui.Loop());
}

Form with Text Boxes

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <GuiCode/Gui.hpp>
#include <GuiCode/ui/window/Frame.hpp>
#include <GuiCode/ui/components/buttons/Button.hpp>
#include <GuiCode/ui/components/buttons/ButtonType.hpp>
#include <GuiCode/ui/components/buttons/ButtonGraphics.hpp>
#include <GuiCode/ui/components/text/TextDisplayer.hpp>
#include <GuiCode/ui/components/text/TextArea.hpp>
#include <GuiCode/ui/components/text/TextBox.hpp>
#include <GuiCode/ui/components/text/TextComponent.hpp>
#include <GuiCode/ui/components/buttons/DropDown.hpp>

int main()
{
    // Create a Gui instance, this will take care of all the looping.
    Gui _gui;

    // Add a window to the gui.
    auto& _frame = _gui.AddWindow<Frame>("Frame Name", 400, 400);

    // Retrieve the panel from the frame.
    auto& _panel = _frame.Panel();

    // Set the layout to Divs for fully custom layout. Also set divider color.
    _panel.Layout<Layout::Divs>();
    _panel.LayoutManager().DividerColor({ 128, 128, 128, 255 });
    auto& _div = _panel.Div();

    // Some colors
    Color _textColor{ 255, 255, 255, 255 }, _fieldColor{ 255, 255, 255, 10 },
        _selectColor{ 128, 128, 128, 50 };

    // Emplace all the components to the panel: 

    // The title of the page
    auto& _titleText = _panel.Emplace<TextComponent>("Order Pizza", Graphics::Fonts::Gidole, 24.0f);

    // Name field
    auto& _nameText = _panel.Emplace<TextComponent>("Name", Graphics::Fonts::Gidole14, 14.0f);
    auto& _nameField = _panel.Emplace<TextBox>();
    _nameField.Placeholder("Name");
    _nameField.TextColor(_textColor);
    _nameField.SelectColor(_selectColor);
    _nameField.Background(_fieldColor);

    // Address field
    auto& _addressText = _panel.Emplace<TextComponent>("Address", Graphics::Fonts::Gidole14, 14.0f);
    auto& _addressField = _panel.Emplace<TextBox>();
    _addressField.Placeholder("Address");
    _addressField.TextColor(_textColor);
    _addressField.SelectColor(_selectColor);
    _addressField.Background(_fieldColor);

    // Pizza sizing: 3 radio buttons with text besides them
    using ListButton = Button<ButtonGraphics::Menu, ButtonType::List>;
    auto& _sizeText = _panel.Emplace<TextComponent>("Size");
    auto key = ButtonType::List::NewKey();
    auto& _size1Box = _panel.Emplace<ListButton>([] {}, "", key);
    _size1Box.Size({ 16, 16 });
    _size1Box.Selected(true);
    auto& _size1Text = _panel.Emplace<TextComponent>("8-inch");
    auto& _size2Box = _panel.Emplace<ListButton>([] {}, "", key);
    _size2Box.Size({ 16, 16 });
    auto& _size2Text = _panel.Emplace<TextComponent>("10-inch");
    auto& _size3Box = _panel.Emplace<ListButton>([] {}, "", key);
    _size3Box.Size({ 16, 16 });
    auto& _size3Text = _panel.Emplace<TextComponent>("12-inch");

    // Pizza type: DropDown
    enum class PizzaTopping { Margarita, FourCheese, Vegetarian, Hawaiian, Length };
    std::string _topName[]{ "Margarita", "Four Cheese", "Vegetarian", "Hawaiian"};
    auto& _topText = _panel.Emplace<TextComponent>("Topping", Graphics::Fonts::Gidole14, 14.0f);
    auto& _topDrop = _panel.Emplace<DropDown<PizzaTopping, ButtonGraphics::Dropdown>>();
    for (int i = 0; i < (int)PizzaTopping::Length; i++)
        _topDrop.AddOption(_topName[i], (PizzaTopping)i);

    // Additional instructions: TextArea
    auto& _instrText = _panel.Emplace<TextComponent>("Additional Instructions");
    auto& _instrField = _panel.Emplace<TextArea>();
    _instrField.TextColor(_textColor);
    _instrField.SelectColor(_selectColor);
    _instrField.Background(_fieldColor);

    // The layout for the page:

    // Divide main div in 2 divs, vertically aligned, with 16 pixels of padding, and dividers.
    _div = { 2, Div::Alignment::Vertical, 16, true };

    // First div contains the title text
    _div[1] = { _titleText, Div::Alignment::Center, 48 };

    // The 2nd div divides into 5 vertically aligned divs with 2 pixels padding, no dividers.
    auto& _form = _div[0] = { 5, Div::Alignment::Vertical, 2, false };

    // The top one contains the name field, horizontally aligned, 0 padding, no
    // dividers and the div height is 28 (height because parent div is vertical)
    // The _nameField has size: Div::AUTO, meaning the div will equally divide
    // the space, or in this case just give the remaining space to the field. And the 
    // last 'true' means the object inside the div will be resized to the div size.
    auto& _name = _form[4] = { 2, Div::Alignment::Horizontal, 0, false, 28 };
    _name[0] = { _nameText, Div::Alignment::Left, 70, true };
    _name[1] = { _nameField, Div::Alignment::Left, Div::AUTO, true };

    // The end one contains the address field, horizontally aligned, 0 padding, no
    // dividers and the div height is 28 (height because parent div is vertical)
    auto& _addr = _form[3] = { 2, Div::Alignment::Horizontal, 0, false, 28 };
    _addr[0] = { _addressText, Div::Alignment::Left, 70, true };
    _addr[1] = { _addressField, Div::Alignment::Left, Div::AUTO, true };

    // Below that are the size radio buttons, first divide horizontally like the
    // previous 2, height also 28 pixels and no dividers/padding
    auto& _size = _form[2] = { 2, Div::Alignment::Horizontal, 0, false, 28 };
    _size[0] = { _sizeText, Div::Alignment::Left, 70, true };

    // Then divide the left div in 3 horizontal divs with 0 padding and no divider
    auto& _sizeBoxes = _size[1] = { 3, Div::Alignment::Horizontal, 0, false };

    // For each size button/text divide the div in 2 and but the radio button
    // of the left, and immediately besides it the text. All divs are Div::AUTO
    // so all 3 will be equally spaced out.
    _sizeBoxes[0] = { 2, Div::Alignment::Horizontal, 0, false, Div::AUTO };
    _sizeBoxes[0][0] = { _size1Box, Div::Alignment::Left, 20, false };
    _sizeBoxes[0][1] = { _size1Text, Div::Alignment::Left, Div::AUTO, true };
    _sizeBoxes[1] = { 2, Div::Alignment::Horizontal, 0, false, Div::AUTO };
    _sizeBoxes[1][0] = { _size2Box, Div::Alignment::Left, 20, false };
    _sizeBoxes[1][1] = { _size2Text, Div::Alignment::Left, Div::AUTO, true };
    _sizeBoxes[2] = { 2, Div::Alignment::Horizontal, 0, false, Div::AUTO };
    _sizeBoxes[2][0] = { _size3Box, Div::Alignment::Left, 20, false };
    _sizeBoxes[2][1] = { _size3Text, Div::Alignment::Left, Div::AUTO, true };

    // Then the next one is the topping dropdown, works the same as the name/address
    // ones, except now it's a dropdown button instead of a textbox
    auto& _topping = _form[1] = { 2, Div::Alignment::Horizontal, 0, false, 28 };
    _topping[0] = { _topText, Div::Alignment::Left, 70, true };
    _topping[1] = { _topDrop, Div::Alignment::Left, Div::AUTO, true };

    // For the final one we will give it the remaining space (Div::AUTO) and put the
    // text on top (vertical alignment) with height 28, and the textarea below that
    // with auto resize enabled, meaning the textarea will fill the remaining space.
    auto& _instr = _form[0] = { 2, Div::Alignment::Vertical, 0, false, Div::AUTO };
    _instr[1] = { _instrText, Div::Alignment::Left, 28, true };
    _instr[0] = { _instrField, Div::Alignment::Left, Div::AUTO, true };

    // Infinite loop, this will automatically stop when the gui closes.
    while (_gui.Loop());
}