Coordinate - Horizon-NTH/HorizonGUI GitHub Wiki
These classes are designed to enable users to position widgets and elements within the graphical interface and define
their sizes. They incorporate responsive units, allowing developers to create applications that adapt
to different screen sizes and resolutions. You can find these classes in the header file Coordinate.hpp
.
Important: These classes are primarily designed to allow a certain level of responsiveness and not to perform calculations or create repetitive updates, as this can lead to undefined behaviour and latency in the application. To perform any of these operations, you need to refer to these
vectors
.
Notes:
- Check the available typedefs.
- Many of the constructors and functions of the following classes are implemented for multiple template parameters to avoid implicit
conversion
warning.
The EM
class provides a flexible type for expressing responsive design units, based on a reference size.
It is equipped with support for common arithmetic operators, making it a powerful tool for building a responsive application.
-
T
: Type of the elements.
-
EM() noexcept
: Default constructor. -
explicit EM(T value) noexcept
: Constructor with an initial value. -
EM(const EM& em) noexcept
: Copy constructor. -
EM(EM&& em) noexcept
: Move constructor.
-
EM& operator=(const EM& em) noexcept
: Copy assignment operator. -
EM& operator=(EM&& em) noexcept
: Move assignment operator.
-
T get_width_value() const
: Returns the EM value relative to the width of the reference size. -
T get_height_value() const
: Returns the EM value relative to the height of the reference size. -
void set_reference(const reference& ref) noexcept
: Set thereference
of the EM. -
const reference& get_reference() const noexcept
: Return thereference
currently used. -
void set_base_value(T baseValue) noexcept
: Set the base value of the EM. -
T get_base_value() const noexcept
: Return the base value of the EM.
Various operators are overloaded for this class as follows:
- You can add
+
, subtract-
, multiply*
or divide/
EM between them. - You can add
+
, subtract-
, multiply*
or divide/
it with a scalar. - You can negate his value with
-
. - You can stream the EM in an
std::ostream
.
Literal operator are overloaded allowing you to easily create percentages in your application.
-
EM<HGUI_PRECISION> operator""_em(unsigned long long value)
. -
EM<HGUI_PRECISION> operator""_em(long double value)
.
Note: HGUI_PRECISION is generally either a float or a double, to have more information read this.
// Perform operations
hgui::kernel::EM<float> em = 10.0f_em + 5.0f - 3.0f_em * 2.0f;
// Get the value based on it's width
std::cout << em.get_width_value() << std::endl;e
The Coordinate
class is a generic class template used to represents coordinates in the application.
It provides essential functionality working along with EM
to allow you to easily create a responsive application.
-
T
: Type of the elements.
-
Coordinate() noexcept
: Default constructor. -
explicit Coordinate(T bothCoord) noexcept
: Constructor that initializes both coordinates with a specified value. -
explicit Coordinate(const EM<T>& bothCoord) noexcept
: Constructor that initializes both coordinates with a specifiedEM
. -
Coordinate(const Coordinate& coords) noexcept
: Copy constructor. -
Coordinate(Coordinate&& coords) noexcept
: Move constructor. -
Coordinate(T x, T y) noexcept
: Constructor with x and y components as value. -
Coordinate(const EM<T>& x, const EM<T>& y) noexcept
: Constructor with x and y components with anEM
. -
Coordinate(const EM<T>& x, T y) noexcept
: Constructor with x component with anEM
and y component as value. -
Coordinate(T x, const EM<T>& y) noexcept
: Constructor with x component as value and y component with anEM
. -
explicit Coordinate(const std::pair<EM<T>, EM<T>>& coords) noexcept
: Copy constructor using anstd::pair
ofEM
. -
explicit Coordinate(std::pair<EM<T>, EM<T>>&& coords) noexcept
: Move constructor using anstd::pair
ofEM
. -
explicit Coordinate(const std::array<EM<T>, 2>& coords) noexcept
: Copy constructor using anstd::array
ofEM
. -
explicit Coordinate(std::array<EM<T>, 2>&& coords) noexcept
: Move constructor using anstd::array
ofEM
. -
explicit Coordinate(const Vector<T, 2>& coords) noexcept
: Copy constructor using anvector
. -
explicit Coordinate(const GLSLvec2<T>& coords) noexcept
: Copy constructor using anGLSLvec2
. -
explicit Coordinate(const glm::vec<2, T>& coords) noexcept
: Copy constructor using anglm::vec<2, T>
.
-
Coordinate& operator=(const Coordinate& coords) noexcept
: Copy assignment operator. -
Coordinate& operator=(Coordinate&& coords) noexcept
: Move assignment operator. -
Coordinate& operator=(const Vector<T, 2>& coords) noexcept
: Copy assignment operator using anvector
. -
Coordinate& operator=(const std::pair<EM<T>, EM<T>>& coords) noexcept
: Copy assignment operator using anstd::pair
ofEM
. -
Coordinate& operator=(const GLSLvec2<T>& coords) noexcept
: Copy assignment operator using anGLSLvec2
. -
Coordinate& operator=(const glm::vec<2, T>& coords) noexcept
: Copy assignment operator using anglm::vec<2, T>
.
-
Coordinate& set_reference(const reference& newReference) noexcept
: Set thereference
of the coordinate. -
const EM<T>& get_first_coord() const noexcept
: Retrieves the second component of the coordinate as anEM
-
void set_first_coord(const EM<T>& em) noexcept
: Set the second component of the coordinate with anEM
. -
const EM<T>& get_first_coord() const noexcept
: Retrieves the second component of the coordinate as anEM
-
void set_second_coord(const EM<T>& em) noexcept
: Setthe second component of the coordinate with anEM
. -
virtual void update()
: Used to update coordinates so that they can be recalculated in the event of a change, for example in the size of the window, according to the values set withEM
. -
Coordinate& undo_responsivness() noexcept
: Disable all the added responsiveness implemented thus far to improve efficiency.
This function is useful after a long serie of calcul when the responsiveness is not useful.
Various operators are overloaded for this class as follows:
- You can add
+
or subtract-
coordinates between them. - You can multiply
*
or divide/
a coordinate with a scalar. - You can stream the vector in an
std::ostream
.
-
explicit operator Vector<T, 2>() const noexcept
: Convert the coordinate into avector
. -
explicit operator glm::vec<2, T>() const noexcept
: Convert the coordinate into aglm::vec<2, T>
.
#include <hgui/header/Coordinate.hpp>
// Example Usage of Coordinate
hgui::kernel::Coordinate<float> vec(45, 50_em * 1.25f + 3.);
// Perform operations
auto scaledCoord = 3 * vec;
auto newCoord = scaledCoord - hgui::kernel::Coordinate<float>(3);
// See the result
std::cout << newCoord << std::endl;
The Point
class represents a 2-dimensional point in space. This class is designed for working with point coordinates
and simplifies operations on 2D points. This class inherits from Coordinate
.
-
T
: Type of the elements.
-
Point() noexcept
: Default constructor. -
explicit Point(T xy) noexcept
: Constructor that initializes both coordinates with a specified value. -
explicit Point(const EM<T>& xy) noexcept
: Constructor that initializes both coordinates with a specifiedEM
. -
Point(const Point& point) noexcept
: Copy constructor. -
Point(Point&& point) noexcept
: Move constructor. -
explicit Point(const Coordinate<T>& point) noexcept
: Copy constructor from aCoordinate
. -
explicit Point(Coordinate<T>&& point) noexcept
: Move constructor from aCoordinate
. -
Point(T x, T y) noexcept
: Constructor with x and y components as value. -
Point(const EM<T>& x, const EM<T>& y) noexcept
: Constructor with x and y components with anEM
. -
Point(const EM<T>& x, T y) noexcept
: Constructor with x component with anEM
and y component as value. -
Point(T x, const EM<T>& y) noexcept
: Constructor with x component as value and y component with anEM
. -
explicit Point(const Vector<T, 2>& point) noexcept
: Copy constructor using anvector
. -
explicit Point(const GLSLvec2<T>& point) noexcept
: Copy constructor using anGLSLvec2
. -
explicit Point(const glm::vec<2, T>& point) noexcept
: Copy constructor using anglm::vec<2, T>
.
-
Point& operator=(const Point& coords) noexcept
: Copy assignment operator. -
Point& operator=(Point&& coords) noexcept
: Move assignment operator.
This class have the same operators that from its base class.
-
const T& x
: Represents the x-coordinate of the point. -
const T& y
: Represents the y-coordinate of the point.
Note: These are read-only and if you want to perform any modifications please use the following variables but do not forget to call the
update
function after. And remember not to add too many elements, or you'll cause latency.
-
EM<T>& em_x
:EM
that represents the x-coordinate of the point. -
EM<T>& em_y
:EM
that represents the y-coordinate of the point.
#include <hgui/header/Coordinate.hpp>
// Example Usage of Point
hgui::kernel::Point<float> point1(50_em), point2(256.f, 8_em / 3 + 452.);
// Perform operations
hgui::kernel::Point<float> point = 3 * (point1 / 2 + point2);
// See the result
std::cout << point << std::endl;
The Size
class represents a size. This class is designed for working with widgets
and simplifies operations on their size. This class inherits from Coordinate
.
-
T
: Type of the elements.
-
Size() noexcept
: Default constructor. -
explicit Size(T widthAndHeight) noexcept
: Constructor that initializes both coordinates with a specified value. -
explicit Size(const EM<T>& widthAndHeight) noexcept
: Constructor that initializes both coordinates with a specifiedEM
. -
Size(const Size& size) noexcept
: Copy constructor. -
Size(Size&& size) noexcept
: Move constructor. -
explicit Size(const Coordinate<T>& size) noexcept
: Copy constructor from aCoordinate
. -
explicit Size(Coordinate<T>&& size) noexcept
: Move constructor from aCoordinate
. -
Size(T width, T height) noexcept
: Constructor with width and height components as value. -
Size(const EM<T>& width, const EM<T>& height) noexcept
: Constructor with width and height components with anEM
. -
Size(const EM<T>& width, T height) noexcept
: Constructor with width component with anEM
and height component as value. -
Size(T width, const EM<T>& height) noexcept
: Constructor with width component as value and height component with anEM
. -
explicit Size(const Vector<T, 2>& size) noexcept
: Copy constructor using anvector
. -
explicit Size(const GLSLvec2<T>& size) noexcept
: Copy constructor using anGLSLvec2
. -
explicit Size(const glm::vec<2, T>& size) noexcept
: Copy constructor using anglm::vec<2, T>
.
-
Size& operator=(const Size& coords) noexcept
: Copy assignment operator. -
Size& operator=(Size&& coords) noexcept
: Move assignment operator.
This class have the same operators that from its base class.
-
const T& width
: Represents the width of the size. -
const T& height
: Represents the height of the size.
Note: These are read-only and if you want to perform any modifications please use the following variables but do not forget to call the
update
function after. And remember not to add too many elements, or you'll cause latency.
-
EM<T>& em_x
:EM
that represents the width of the size. -
EM<T>& em_y
:EM
that represents the height of the size.
#include <hgui/header/Coordinate.hpp>
// Example Usage of Size
hgui::kernel::Size<float> size1(50_em), size2(256.f, 8_em / 3 + 452.);
// Perform operations
hgui::kernel::Size<float> size = 3 * (size1 / 2 + size2);
// See the result
std::cout << size << std::endl;