TGUI  1.6.1
Loading...
Searching...
No Matches
Global.hpp
1
2//
3// TGUI - Texus' Graphical User Interface
4// Copyright (C) 2012-2024 Bruno Van de Velde (vdv_b@tgui.eu)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#ifndef TGUI_GLOBAL_HPP
26#define TGUI_GLOBAL_HPP
27
29
30#include <TGUI/Config.hpp>
31#include <TGUI/Exception.hpp>
32#include <TGUI/Duration.hpp>
33#include <TGUI/Font.hpp>
34#include <TGUI/String.hpp>
35#include <TGUI/Filesystem.hpp>
36
37#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
38 #include <cstdint>
39 #include <string>
40 #include <memory>
41
42 #ifdef TGUI_DEBUG
43 #include <iostream>
44 #endif
45#endif
46
48
50TGUI_MODULE_EXPORT namespace tgui
51{
55#if defined(__cpp_lib_smart_ptr_for_overwrite) && (__cpp_lib_smart_ptr_for_overwrite >= 202002L)
56 template <typename T>
57 const auto MakeUniqueForOverwrite = std::make_unique_for_overwrite<T>;
58#else
59 template <typename T>
60 TGUI_NODISCARD std::unique_ptr<T> MakeUniqueForOverwrite(const std::size_t size)
61 {
62 return std::unique_ptr<T>(new typename std::remove_extent_t<T>[size]);
63 }
64#endif
65
69 template <typename T>
70 TGUI_NODISCARD constexpr const T& clamp(const T& v, const T& lo, const T& hi)
71 {
72 return (v < lo) ? lo : (hi < v) ? hi : v;
73 }
74
78 TGUI_API void setGlobalTextSize(unsigned int textSize);
79
83 TGUI_NODISCARD TGUI_API unsigned int getGlobalTextSize();
84
88 TGUI_API void setDoubleClickTime(Duration duration);
89
93 TGUI_NODISCARD TGUI_API Duration getDoubleClickTime();
94
102 TGUI_API void setResourcePath(const Filesystem::Path& path);
103
111 TGUI_API void setResourcePath(const String& path);
112
120 TGUI_NODISCARD TGUI_API const Filesystem::Path& getResourcePath();
121
125 TGUI_API void setEditCursorBlinkRate(Duration blinkRate);
126
130 TGUI_NODISCARD TGUI_API Duration getEditCursorBlinkRate();
131
142 TGUI_NODISCARD TGUI_API std::unique_ptr<std::uint8_t[]> readFileToMemory(const String& filename, std::size_t& fileSize);
143
152 TGUI_API bool writeFile(const String& filename, const std::stringstream& textToWrite);
153
162 TGUI_API bool writeFile(const String& filename, CharStringView textToWrite);
163
165}
166
168
169#endif // TGUI_GLOBAL_HPP
170
Wrapper for durations.
Definition Duration.hpp:55
Object to represent paths on a filesystem.
Definition Filesystem.hpp:58
Wrapper class to store strings.
Definition String.hpp:96
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:38
TGUI_API void setDoubleClickTime(Duration duration)
Sets the double-click time for the mouse.
TGUI_API const Filesystem::Path & getResourcePath()
Returns the resource path.
TGUI_API void setGlobalTextSize(unsigned int textSize)
Sets the default text size for all widgets created after calling the function.
TGUI_API void setEditCursorBlinkRate(Duration blinkRate)
Changes the blink rate of the cursor in edit fields such as EditBox and TextArea.
TGUI_API void setResourcePath(const Filesystem::Path &path)
Sets a new resource path.
constexpr const T & clamp(const T &v, const T &lo, const T &hi)
Clamps a value between two boundries. This function exists because std::clamp was only added with c++...
Definition Global.hpp:70
TGUI_API Duration getDoubleClickTime()
Retrieves the double-click time for the mouse.
TGUI_API std::unique_ptr< std::uint8_t[]> readFileToMemory(const String &filename, std::size_t &fileSize)
Opens a file and reads its contents into memory.
TGUI_API Duration getEditCursorBlinkRate()
Returns the blink rate of the cursor in edit fields such as EditBox and TextArea.
std::unique_ptr< T > MakeUniqueForOverwrite(const std::size_t size)
Create a unique_ptr containing an uninitialized array.
Definition Global.hpp:60
TGUI_API bool writeFile(const String &filename, const std::stringstream &textToWrite)
Opens a file and writes the given contents to it.
TGUI_API unsigned int getGlobalTextSize()
Retrieves the default text size used for all new widgets.