TGUI  1.6.1
Loading...
Searching...
No Matches

Base class for the Gui. More...

#include <TGUI/Backend/Window/BackendGui.hpp>

Inheritance diagram for tgui::BackendGui:
tgui::BackendGuiGLFW tgui::BackendGuiRaylib tgui::BackendGuiSDL tgui::BackendGuiSFML tgui::GLFW_GLES2::Gui tgui::GLFW_OPENGL3::Gui tgui::RAYLIB::Gui tgui::SDL_GLES2::Gui tgui::SDL_OPENGL3::Gui tgui::SDL_RENDERER::Gui tgui::SDL_TTF_GLES2::Gui tgui::SDL_TTF_OPENGL3::Gui tgui::SFML_GRAPHICS::Gui tgui::SFML_OPENGL3::Gui

Public Member Functions

 BackendGui ()
 Default constructor.
 
 BackendGui (const BackendGui &copy)=delete
 
BackendGuioperator= (const BackendGui &right)=delete
 
void setAbsoluteViewport (const FloatRect &viewport)
 Sets the part of the screen to which the gui will render in pixels.
 
void setRelativeViewport (const FloatRect &viewport)
 Sets the part of the screen to which the gui will render as a ratio relative to the window size.
 
RelFloatRect getViewport () const
 Returns to which part of the screen the gui will render.
 
void setAbsoluteView (const FloatRect &view)
 Sets the part of the gui that will be used to fill the viewport in pixels.
 
void setRelativeView (const FloatRect &view)
 Sets the part of the gui that will be used to fill the viewport.
 
RelFloatRect getView () const
 Returns the part of the gui that will be used to fill the viewport.
 
bool handleEvent (Event event)
 Passes the event to the widgets.
 
void setTabKeyUsageEnabled (bool enabled)
 When the tab key usage is enabled, pressing tab will focus another widget.
 
bool isTabKeyUsageEnabled () const
 Returns whether the tab key usage is enabled (if so, pressing tab will focus another widget)
 
virtual void draw ()
 Draws all the widgets that were added to the gui.
 
RootContainer::Ptr getContainer () const
 Returns the internal container of the Gui.
 
std::shared_ptr< BackendRenderTargetgetBackendRenderTarget () const
 Returns the backend render target that is assigned to the gui.
 
void setFont (const Font &font)
 Changes the global font.
 
Font getFont () const
 Returns the global font for this gui.
 
const std::vector< Widget::Ptr > & getWidgets () const
 Returns a list of all the widgets.
 
void add (const Widget::Ptr &widgetPtr, const String &widgetName="")
 Adds a widget to the container.
 
Widget::Ptr get (const String &widgetName) const
 Returns a pointer to an earlier created widget.
 
template<class WidgetType >
WidgetType::Ptr get (const String &widgetName) const
 Returns a pointer to an earlier created widget.
 
bool remove (const Widget::Ptr &widget)
 Removes a single widget that was added to the container.
 
void removeAllWidgets ()
 Removes all widgets that were added to the container.
 
Widget::Ptr getFocusedChild () const
 Returns the child widget that is focused inside this container.
 
Widget::Ptr getFocusedLeaf () const
 Returns the leaf child widget that is focused inside this container.
 
Widget::Ptr getWidgetAtPosition (Vector2f pos) const
 Returns the leaf child widget that is located at the given position.
 
Widget::Ptr getWidgetAtPos (Vector2f pos, bool recursive) const
 Returns the widget that is located at the given position.
 
Widget::Ptr getWidgetBelowMouseCursor (Vector2i mousePos) const
 Returns the leaf child widget below the mouse.
 
Widget::Ptr getWidgetBelowMouseCursor (Vector2i mousePos, bool recursive) const
 Returns the widget below the mouse.
 
bool focusNextWidget (bool recursive=true)
 Focuses the next widget in the gui.
 
bool focusPreviousWidget (bool recursive=true)
 Focuses the previous widget in the gui.
 
void unfocusAllWidgets ()
 Unfocus all the widgets.
 
void moveWidgetToFront (const Widget::Ptr &widget)
 Places a widget before all other widgets, to the front of the z-order.
 
void moveWidgetToBack (const Widget::Ptr &widget)
 Places a widget behind all other widgets, to the back of the z-order.
 
std::size_t moveWidgetForward (const Widget::Ptr &widget)
 Places a widget one step forward in the z-order.
 
std::size_t moveWidgetBackward (const Widget::Ptr &widget)
 Places a widget one step backward in the z-order.
 
bool setWidgetIndex (const Widget::Ptr &widget, std::size_t index)
 Changes the index of a widget in this container.
 
int getWidgetIndex (const Widget::Ptr &widget) const
 Returns the current index of a widget in this container.
 
void setOpacity (float opacity)
 Changes the opacity of all widgets.
 
float getOpacity () const
 Returns the opacity of all the widgets.
 
void setTextSize (unsigned int size)
 Changes the character size of all existing and future child widgets.
 
unsigned int getTextSize () const
 Returns the character size for future child widgets (and for existing widgets where the size wasn't changed)
 
void loadWidgetsFromFile (const String &filename, bool replaceExisting=true)
 Loads the child widgets from a text file.
 
void saveWidgetsToFile (const String &filename)
 Saves the child widgets to a text file.
 
void loadWidgetsFromStream (std::stringstream &stream, bool replaceExisting=true)
 Loads the child widgets from a string stream.
 
void loadWidgetsFromStream (std::stringstream &&stream, bool replaceExisting=true)
 Loads the child widgets from a string stream.
 
void saveWidgetsToStream (std::stringstream &stream) const
 Saves this the child widgets to a text file.
 
void setOverrideMouseCursor (Cursor::Type type)
 Overrides which cursor gets shown.
 
void restoreOverrideMouseCursor ()
 Undoes the effect of the last call to setOverrideCursor.
 
void requestMouseCursor (Cursor::Type type)
 Function that is used by widgets to change the mouse cursor.
 
void setDrawingUpdatesTime (bool drawUpdatesTime)
 Sets whether drawing the gui will automatically update the internal clock or whether the user does it manually.
 
bool updateTime ()
 Updates the internal clock (for timers, animations and blinking edit cursors)
 
bool updateTime (Duration elapsedTime)
 
Vector2f mapPixelToCoords (Vector2i pixel) const
 Converts the pixel coordinate to a position within the view.
 
Vector2f mapCoordsToPixel (Vector2f coord) const
 Converts a position within the view to the corresponding pixel coordinate.
 
virtual void mainLoop (Color clearColor={240, 240, 240})=0
 Give the gui control over the main loop.
 
virtual void startTextInput (FloatRect inputRect)
 This function is called by TGUI when focusing a text field (EditBox or TextArea). It may result in the software keyboard being opened.
 
virtual void stopTextInput ()
 This function is called by TGUI when unfocusing a text field (EditBox or TextArea). It may result in the software keyboard being closed.
 
virtual void updateTextCursorPosition (FloatRect inputRect, Vector2f caretPos)
 This function is called by TGUI when the position of the caret changes in a text field (EditBox or TextArea). If an IME is used then this function may move the IME candidate list to the text cursor position.
 
virtual bool isKeyboardModifierPressed (Event::KeyModifier modifierKey) const
 Checks the state for one of the modifier keys.
 
void setKeyboardNavigationEnabled (bool enabled)
 Changes whether using the arrow keys can be used to navigate between widgets.
 
bool isKeyboardNavigationEnabled () const
 Returns whether using the arrow keys can be used to navigate between widgets.
 

Public Attributes

SignalFloatRect onViewChange = {"ViewChanged"}
 The view was changed. Optional parameter: new view rectangle.
 
Signal onWindowFocus = {"WindowFocused"}
 The window sent a GainedFocus event.
 
Signal onWindowUnfocus = {"WindowUnfocused"}
 The window sent a LostFocus event.
 

Protected Member Functions

bool handleTwoFingerScroll (bool wasAlreadyScrolling)
 
virtual void updateContainerSize ()
 
Event::KeyboardKey translateKeypadKey (Event::KeyboardKey key)
 

Protected Attributes

std::chrono::steady_clock::time_point m_lastUpdateTime
 
bool m_windowFocused = true
 
RootContainer::Ptr m_container = std::make_shared<RootContainer>()
 
Widget::Ptr m_visibleToolTip = nullptr
 
Duration m_tooltipTime
 
bool m_tooltipPossible = false
 
Vector2f m_toolTipRelativePos
 
Vector2i m_lastMousePos
 
TwoFingerScrollDetect m_twoFingerScroll
 
Vector2i m_framebufferSize
 
RelFloatRect m_viewport {RelativeValue{0}, RelativeValue{0}, RelativeValue{1}, RelativeValue{1}}
 
RelFloatRect m_view {RelativeValue{0}, RelativeValue{0}, RelativeValue{1}, RelativeValue{1}}
 
FloatRect m_lastView
 
bool m_drawUpdatesTime = true
 
bool m_tabKeyUsageEnabled = true
 
bool m_keyboardNavigationEnabled = false
 
Cursor::Type m_requestedMouseCursor = Cursor::Type::Arrow
 
std::stack< Cursor::Typem_overrideMouseCursors
 
std::shared_ptr< BackendRenderTargetm_backendRenderTarget = nullptr
 

Detailed Description

Base class for the Gui.

Member Function Documentation

◆ add()

void tgui::BackendGui::add ( const Widget::Ptr & widgetPtr,
const String & widgetName = "" )

Adds a widget to the container.

Parameters
widgetPtrPointer to the widget you would like to add
widgetNameIf you want to access the widget later then you must do this with this name
Warning
Widgets should be named as if they are C++ variables, i.e. names must not include any whitespace, or most symbols (e.g.: +, -, *, /, ., &), and should not start with a number. If you do not follow these rules, layout expressions may give unexpected results. Alphanumeric characters and underscores are safe to use, and widgets are permitted to have no name.

◆ focusNextWidget()

bool tgui::BackendGui::focusNextWidget ( bool recursive = true)

Focuses the next widget in the gui.

Parameters
recursiveIf the focused widget is a container, should the next widget inside it be focused instead of focusing the sibling of the container?
Returns
Whether a new widget was focused

◆ focusPreviousWidget()

bool tgui::BackendGui::focusPreviousWidget ( bool recursive = true)

Focuses the previous widget in the gui.

Parameters
recursiveIf the focused widget is a container, should the next widget inside it be focused instead of focusing the sibling of the container?
Returns
Whether a new widget was focused

◆ get() [1/2]

Widget::Ptr tgui::BackendGui::get ( const String & widgetName) const
nodiscard

Returns a pointer to an earlier created widget.

Parameters
widgetNameThe name that was given to the widget when it was added to the container
Returns
Pointer to the earlier created widget

The gui will first search for widgets that are direct children of it, but when none of the child widgets match the given name, a recursive search will be performed.

Warning
This function will return nullptr when an unknown widget name was passed

◆ get() [2/2]

template<class WidgetType >
WidgetType::Ptr tgui::BackendGui::get ( const String & widgetName) const
inlinenodiscard

Returns a pointer to an earlier created widget.

Parameters
widgetNameThe name that was given to the widget when it was added to the container
Returns
Pointer to the earlier created widget. The pointer will already be casted to the desired type

The gui will first search for widgets that are direct children of it, but when none of the child widgets match the given name, a recursive search will be performed.

Warning
This function will return nullptr when an unknown widget name was passed

◆ getBackendRenderTarget()

std::shared_ptr< BackendRenderTarget > tgui::BackendGui::getBackendRenderTarget ( ) const
nodiscard

Returns the backend render target that is assigned to the gui.

Returns
Render target that was created when a window was passed to the gui, or nullptr if it hasn't been created yet

◆ getContainer()

RootContainer::Ptr tgui::BackendGui::getContainer ( ) const
nodiscard

Returns the internal container of the Gui.

This could be useful when having a function that should accept both the gui and e.g. a child window as parameter.

Warning
Not all functions in the Container class make sense for the Gui (which is the reason that the Gui does not inherit from Container), so calling some functions (e.g. setSize) on the container will have no effect.
Returns
Reference to the internal Container class

◆ getFocusedChild()

Widget::Ptr tgui::BackendGui::getFocusedChild ( ) const
nodiscard

Returns the child widget that is focused inside this container.

Returns
Focused child widget or nullptr if none of the widgets are currently focused

If the focused widget is a container then a pointer to that container is returned. If you want to know which widget is focused inside that container (recursively) then you should use the getFocusedLeaf() function.

◆ getFocusedLeaf()

Widget::Ptr tgui::BackendGui::getFocusedLeaf ( ) const
nodiscard

Returns the leaf child widget that is focused inside this container.

Returns
Focused leaf child widget or nullptr if none of the widgets are currently focused

If the focused widget is a container then the getFocusedLeaf() is recursively called on that container. If you want to limit the search to only direct children of this container then you should use the getFocusedChild() function.

◆ getFont()

Font tgui::BackendGui::getFont ( ) const
nodiscard

Returns the global font for this gui.

Returns
Font for widgets in the gui

◆ getOpacity()

float tgui::BackendGui::getOpacity ( ) const
nodiscard

Returns the opacity of all the widgets.

Returns
The opacity of the widgets. 0 means completely transparent, while 1 (default) means fully opaque

◆ getTextSize()

unsigned int tgui::BackendGui::getTextSize ( ) const
nodiscard

Returns the character size for future child widgets (and for existing widgets where the size wasn't changed)

Returns
The current text size or 0 when no size was explicitly set in this gui

◆ getView()

RelFloatRect tgui::BackendGui::getView ( ) const
nodiscard

Returns the part of the gui that will be used to fill the viewport.

Returns

By default the view will have the same size as the viewport.

◆ getViewport()

RelFloatRect tgui::BackendGui::getViewport ( ) const
nodiscard

Returns to which part of the screen the gui will render.

Returns
Rect of the window to which the gui will draw

By default the viewport will fill the entire screen.

◆ getWidgetAtPos()

Widget::Ptr tgui::BackendGui::getWidgetAtPos ( Vector2f pos,
bool recursive ) const
nodiscard

Returns the widget that is located at the given position.

Parameters
posThe location where the widget will be searched, relative to the gui view
recursiveIf the widget at the position is a container, should the search continue inside it instead of just returning the container? The child container may still be returned when recursive is true, but only if none of its children are located at the searched position.
Returns
Widget at the queried position, or nullptr when there is no widget at that location
See also
getWidgetBelowMouseCursor
Since
TGUI 1.2

◆ getWidgetAtPosition()

Widget::Ptr tgui::BackendGui::getWidgetAtPosition ( Vector2f pos) const
nodiscard

Returns the leaf child widget that is located at the given position.

Parameters
posThe location where the widget will be searched, relative to the gui view
Returns
Widget at the queried position, or nullptr when there is no widget at that location
Deprecated
Replaced by getWidgetAtPos in TGUI 1.2

◆ getWidgetBelowMouseCursor() [1/2]

Widget::Ptr tgui::BackendGui::getWidgetBelowMouseCursor ( Vector2i mousePos) const
nodiscard

Returns the leaf child widget below the mouse.

Parameters
mousePosPosition of the mouse, in pixel coordinates, relative the the window
Returns
Widget below the mouse, or nullptr when the mouse isn't on top of any widgets
Deprecated
Replaced by getWidgetBelowMouseCursor overload with additional recursive parameter in TGUI 1.2

◆ getWidgetBelowMouseCursor() [2/2]

Widget::Ptr tgui::BackendGui::getWidgetBelowMouseCursor ( Vector2i mousePos,
bool recursive ) const
nodiscard

Returns the widget below the mouse.

Parameters
mousePosPosition of the mouse, in pixel coordinates, relative the the window
recursiveIf the widget below the mouse is a container, should the search continue inside it instead of just returning the container? The child container may still be returned when recursive is true, but only if none of its children are located at the mouse position.
Returns
Widget below the mouse, or nullptr when the mouse isn't on top of any widgets
See also
getWidgetAtPos
Since
TGUI 1.2

◆ getWidgetIndex()

int tgui::BackendGui::getWidgetIndex ( const Widget::Ptr & widget) const
nodiscard

Returns the current index of a widget in this container.

Returns
Index of the widget, or -1 if the widget wasn't found in this container

◆ getWidgets()

const std::vector< Widget::Ptr > & tgui::BackendGui::getWidgets ( ) const
nodiscard

Returns a list of all the widgets.

Returns
Vector of all widget pointers

◆ handleEvent()

bool tgui::BackendGui::handleEvent ( Event event)

Passes the event to the widgets.

Parameters
eventThe event that was polled from the window
Returns
Has the event been consumed? When this function returns false, then the event was ignored by all widgets.

◆ isKeyboardModifierPressed()

virtual bool tgui::BackendGui::isKeyboardModifierPressed ( Event::KeyModifier modifierKey) const
nodiscardvirtual

Checks the state for one of the modifier keys.

Parameters
modifierKeyThe modifier key of which the state is being queried
Returns
Whether queries modifier key is being pressed

Reimplemented in tgui::BackendGuiGLFW, tgui::BackendGuiRaylib, tgui::BackendGuiSDL, and tgui::BackendGuiSFML.

◆ isKeyboardNavigationEnabled()

bool tgui::BackendGui::isKeyboardNavigationEnabled ( ) const
nodiscard

Returns whether using the arrow keys can be used to navigate between widgets.

Returns
Should keyboard navigation be enabled?
See also
setKeyboardNavigationEnabled
Since
TGUI 1.1

◆ loadWidgetsFromFile()

void tgui::BackendGui::loadWidgetsFromFile ( const String & filename,
bool replaceExisting = true )

Loads the child widgets from a text file.

Parameters
filenameFilename of the widget file
replaceExistingRemove existing widgets first if there are any

◆ loadWidgetsFromStream() [1/2]

void tgui::BackendGui::loadWidgetsFromStream ( std::stringstream && stream,
bool replaceExisting = true )

Loads the child widgets from a string stream.

Parameters
streamstringstream that contains the widget file
replaceExistingRemove existing widgets first if there are any

◆ loadWidgetsFromStream() [2/2]

void tgui::BackendGui::loadWidgetsFromStream ( std::stringstream & stream,
bool replaceExisting = true )

Loads the child widgets from a string stream.

Parameters
streamstringstream that contains the widget file
replaceExistingRemove existing widgets first if there are any

◆ mainLoop()

virtual void tgui::BackendGui::mainLoop ( Color clearColor = {240, 240, 240})
pure virtual

Give the gui control over the main loop.

Parameters
clearColorbackground color of the window

This function is only intended in cases where your program only needs to respond to gui events. For multimedia applications, games, or other programs where you want a high framerate or do a lot of processing in the main loop, you should use your own main loop.

Implemented in tgui::BackendGuiGLFW, tgui::BackendGuiRaylib, tgui::BackendGuiSDL, and tgui::BackendGuiSFML.

◆ mapCoordsToPixel()

Vector2f tgui::BackendGui::mapCoordsToPixel ( Vector2f coord) const
nodiscard

Converts a position within the view to the corresponding pixel coordinate.

Parameters
coordposition within the coordinate system that is used by the widgets
Returns
Pixel coordinate where the point would end up on the screen

◆ mapPixelToCoords()

Vector2f tgui::BackendGui::mapPixelToCoords ( Vector2i pixel) const
nodiscard

Converts the pixel coordinate to a position within the view.

Parameters
pixelcoordinate on the window
Returns
Transformed coordinate within the coordinate system that is used by the widgets

◆ moveWidgetBackward()

std::size_t tgui::BackendGui::moveWidgetBackward ( const Widget::Ptr & widget)

Places a widget one step backward in the z-order.

Parameters
widgetThe widget that should be moved one step backward
Returns
New index in the widgets list (one lower than the old index or the same if the widget was already at back), or getWidgets().size() if the widget was never added to this container.
See also
moveWidgetToBack

◆ moveWidgetForward()

std::size_t tgui::BackendGui::moveWidgetForward ( const Widget::Ptr & widget)

Places a widget one step forward in the z-order.

Parameters
widgetThe widget that should be moved one step forward
Returns
New index in the widgets list (one higher than the old index or the same if the widget was already in front), or getWidgets().size() if the widget was never added to this container.
See also
moveWidgetToFront

◆ moveWidgetToBack()

void tgui::BackendGui::moveWidgetToBack ( const Widget::Ptr & widget)

Places a widget behind all other widgets, to the back of the z-order.

Parameters
widgetThe widget that should be moved to the back

◆ moveWidgetToFront()

void tgui::BackendGui::moveWidgetToFront ( const Widget::Ptr & widget)

Places a widget before all other widgets, to the front of the z-order.

Parameters
widgetThe widget that should be moved to the front

◆ remove()

bool tgui::BackendGui::remove ( const Widget::Ptr & widget)

Removes a single widget that was added to the container.

Parameters
widgetPointer to the widget to remove

◆ requestMouseCursor()

void tgui::BackendGui::requestMouseCursor ( Cursor::Type type)

Function that is used by widgets to change the mouse cursor.

Parameters
typeThe requested cursor

This function is used to change the mouse cursor when the mouse enters or leaves a widget. If you want to choose a cursor that doesn't get changed when moving the mouse then use setOverrideMouseCursor. If an override cursor is already set then this function won't be able to change the cursor. When all overrides are removed with restoreOverrideMouseCursor then the mouse cursor will be changed to what was last requested here.

◆ restoreOverrideMouseCursor()

void tgui::BackendGui::restoreOverrideMouseCursor ( )

Undoes the effect of the last call to setOverrideCursor.

This function has to be called for each call to setOverrideCursor. If the stack of overriden cursors becomes empty then widgets will be able to change the cursor again.

◆ saveWidgetsToFile()

void tgui::BackendGui::saveWidgetsToFile ( const String & filename)

Saves the child widgets to a text file.

Parameters
filenameFilename of the widget file
Exceptions
Exceptionwhen file could not be opened for writing

◆ saveWidgetsToStream()

void tgui::BackendGui::saveWidgetsToStream ( std::stringstream & stream) const

Saves this the child widgets to a text file.

Parameters
streamstringstream to which the widget file will be added

◆ setAbsoluteView()

void tgui::BackendGui::setAbsoluteView ( const FloatRect & view)

Sets the part of the gui that will be used to fill the viewport in pixels.

Parameters
viewRect of the gui that will be stretched to fill the viewport

No stretching will occur when the view has the same size as the viewport (default).

Example code to use the contents of the gui container from top-left (200,100) to bottom-right (600, 400) and stetch it to fill the viewport (which equals the entire window by default):

gui.setAbsoluteView({200, 100, 400, 300});

◆ setAbsoluteViewport()

void tgui::BackendGui::setAbsoluteViewport ( const FloatRect & viewport)

Sets the part of the screen to which the gui will render in pixels.

Parameters
viewportRect of the window to which the gui should draw

Example code to render the gui on only the right side of an 800x600 window:

gui.setAbsoluteViewport({400, 0, 400, 600});

◆ setDrawingUpdatesTime()

void tgui::BackendGui::setDrawingUpdatesTime ( bool drawUpdatesTime)

Sets whether drawing the gui will automatically update the internal clock or whether the user does it manually.

Parameters
drawUpdatesTimeTrue if gui.draw() updates the clock (default), false if gui.updateTime() has to be called

◆ setFont()

void tgui::BackendGui::setFont ( const Font & font)

Changes the global font.

Parameters
fontFont to use

◆ setKeyboardNavigationEnabled()

void tgui::BackendGui::setKeyboardNavigationEnabled ( bool enabled)

Changes whether using the arrow keys can be used to navigate between widgets.

Parameters
enabledShould keyboard navigation be enabled?

Even when enabled, you may still need to tell widgets where they need to navigate to when an arrow key is pressed. Kayboard navigation is disabled by default.

Note that this option affects the return value of handleEvent for key press events. Normally all key events are marked as handled, but by enabling this option handleEvent will only return true if the key was actually handled.

Since
TGUI 1.1

◆ setOpacity()

void tgui::BackendGui::setOpacity ( float opacity)

Changes the opacity of all widgets.

Parameters
opacityThe opacity of the widgets. 0 means completely transparent, while 1 (default) means fully opaque

◆ setOverrideMouseCursor()

void tgui::BackendGui::setOverrideMouseCursor ( Cursor::Type type)

Overrides which cursor gets shown.

Parameters
typeWhich cursor to show
Warning
You must call restoreOverrideCursor() for every call to setOverrideCursor.

Until restoreOverrideCursor is called, the cursor will no longer be changed by widgets. If setOverrideCursor is called multiple times, the cursors are stacked and calling restoreOverrideCursor will only pop the last added cursor from the stack.

◆ setRelativeView()

void tgui::BackendGui::setRelativeView ( const FloatRect & view)

Sets the part of the gui that will be used to fill the viewport.

Parameters
viewRect of the gui that will be stretched to fill the viewport, relative to the viewport size

The default view is (0, 0, 1, 1) so that no scaling happens even when the viewport is changed.

Example code to zoom in on the gui and display everything at 2x the size:

gui.setRelativeView({0, 0, 0.5f, 0.5f});

◆ setRelativeViewport()

void tgui::BackendGui::setRelativeViewport ( const FloatRect & viewport)

Sets the part of the screen to which the gui will render as a ratio relative to the window size.

Parameters
viewportRect of the window to which the gui should draw, relative to the window size

The default viewport is set to (0, 0, 1, 1) so that it fills the entire window.

Example code to render the gui on only the right side of window:

gui.setRelativeViewport({0.5f, 0, 0.5f, 1});

◆ setTextSize()

void tgui::BackendGui::setTextSize ( unsigned int size)

Changes the character size of all existing and future child widgets.

Parameters
sizeThe new text size

The text size specified in this function overrides the global text size property. By default, the gui does not pass any text size to the widgets and the widgets will use the global text size as default value.

◆ setWidgetIndex()

bool tgui::BackendGui::setWidgetIndex ( const Widget::Ptr & widget,
std::size_t index )

Changes the index of a widget in this container.

Widgets are drawn in the order of the list, so overlapping widgets with a higher index will appear on top of others.

Parameters
widgetWidget that is to be moved to a different index
indexNew index of the widget, corresponding to the widget position after the widget has been moved
Returns
True when the index was changed, false if widget wasn't found in the container or index was too high

◆ startTextInput()

virtual void tgui::BackendGui::startTextInput ( FloatRect inputRect)
virtual

This function is called by TGUI when focusing a text field (EditBox or TextArea). It may result in the software keyboard being opened.

Parameters
inputRectThe rectangle where text is being inputted

Reimplemented in tgui::BackendGuiSDL, and tgui::BackendGuiSFML.

◆ stopTextInput()

virtual void tgui::BackendGui::stopTextInput ( )
virtual

This function is called by TGUI when unfocusing a text field (EditBox or TextArea). It may result in the software keyboard being closed.

Reimplemented in tgui::BackendGuiSDL, and tgui::BackendGuiSFML.

◆ updateTextCursorPosition()

virtual void tgui::BackendGui::updateTextCursorPosition ( FloatRect inputRect,
Vector2f caretPos )
virtual

This function is called by TGUI when the position of the caret changes in a text field (EditBox or TextArea). If an IME is used then this function may move the IME candidate list to the text cursor position.

Parameters
inputRectThe rectangle where text is being inputted
caretPosLocation of the text cursor, relative to the gui view

Reimplemented in tgui::BackendGuiGLFW, tgui::BackendGuiRaylib, tgui::BackendGuiSDL, and tgui::BackendGuiSFML.

◆ updateTime()

bool tgui::BackendGui::updateTime ( )

Updates the internal clock (for timers, animations and blinking edit cursors)

Returns
True if the the contents of the screen changed, false if nothing changed

You do not need to call this function unless you set DrawingUpdatesTime to false (it is true by default).

Member Data Documentation

◆ onWindowFocus

Signal tgui::BackendGui::onWindowFocus = {"WindowFocused"}

The window sent a GainedFocus event.

Since
TGUI 1.3

◆ onWindowUnfocus

Signal tgui::BackendGui::onWindowUnfocus = {"WindowUnfocused"}

The window sent a LostFocus event.

Since
TGUI 1.3

The documentation for this class was generated from the following file: