Coordinate - Horizon-NTH/HorizonGUI GitHub Wiki

Introduction

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.

Table of Contents


Overview

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.

Template Parameters

  • T: Type of the elements.

Constructors

  • 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.

Assignment Operators

  • EM& operator=(const EM& em) noexcept: Copy assignment operator.
  • EM& operator=(EM&& em) noexcept: Move assignment operator.

Member Functions

  • 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 the reference of the EM.

  • const reference& get_reference() const noexcept: Return the reference 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.

Operator

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 Operators

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.

Example Usage

// 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

Overview

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.

Template Parameters

  • T: Type of the elements.

Constructors

  • 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 specified EM.
  • 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 an EM.
  • Coordinate(const EM<T>& x, T y) noexcept: Constructor with x component with an EM and y component as value.
  • Coordinate(T x, const EM<T>& y) noexcept: Constructor with x component as value and y component with an EM.
  • explicit Coordinate(const std::pair<EM<T>, EM<T>>& coords) noexcept: Copy constructor using an std::pair of EM.
  • explicit Coordinate(std::pair<EM<T>, EM<T>>&& coords) noexcept: Move constructor using an std::pair of EM.
  • explicit Coordinate(const std::array<EM<T>, 2>& coords) noexcept: Copy constructor using an std::array of EM.
  • explicit Coordinate(std::array<EM<T>, 2>&& coords) noexcept: Move constructor using an std::array of EM.
  • explicit Coordinate(const Vector<T, 2>& coords) noexcept: Copy constructor using an vector.
  • explicit Coordinate(const GLSLvec2<T>& coords) noexcept: Copy constructor using an GLSLvec2.
  • explicit Coordinate(const glm::vec<2, T>& coords) noexcept: Copy constructor using an glm::vec<2, T>.

Assignment Operators

  • 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 an vector.
  • Coordinate& operator=(const std::pair<EM<T>, EM<T>>& coords) noexcept: Copy assignment operator using an std::pair of EM.
  • Coordinate& operator=(const GLSLvec2<T>& coords) noexcept: Copy assignment operator using an GLSLvec2.
  • Coordinate& operator=(const glm::vec<2, T>& coords) noexcept: Copy assignment operator using an glm::vec<2, T>.

Member Functions

  • Coordinate& set_reference(const reference& newReference) noexcept: Set the reference of the coordinate.

  • const EM<T>& get_first_coord() const noexcept: Retrieves the second component of the coordinate as an EM

  • void set_first_coord(const EM<T>& em) noexcept: Set the second component of the coordinate with an EM.

  • const EM<T>& get_first_coord() const noexcept: Retrieves the second component of the coordinate as an EM

  • void set_second_coord(const EM<T>& em) noexcept: Setthe second component of the coordinate with an EM.

  • 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 with EM.

  • 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.

Operator

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.

Conversion Operator

  • explicit operator Vector<T, 2>() const noexcept: Convert the coordinate into a vector.
  • explicit operator glm::vec<2, T>() const noexcept: Convert the coordinate into a glm::vec<2, T>.

Example Usage

#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;

Overview

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.

Template Parameters

  • T: Type of the elements.

Constructors

  • 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 specified EM.
  • Point(const Point& point) noexcept: Copy constructor.
  • Point(Point&& point) noexcept: Move constructor.
  • explicit Point(const Coordinate<T>& point) noexcept: Copy constructor from a Coordinate.
  • explicit Point(Coordinate<T>&& point) noexcept: Move constructor from a Coordinate.
  • 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 an EM.
  • Point(const EM<T>& x, T y) noexcept: Constructor with x component with an EM and y component as value.
  • Point(T x, const EM<T>& y) noexcept: Constructor with x component as value and y component with an EM.
  • explicit Point(const Vector<T, 2>& point) noexcept: Copy constructor using an vector.
  • explicit Point(const GLSLvec2<T>& point) noexcept: Copy constructor using an GLSLvec2.
  • explicit Point(const glm::vec<2, T>& point) noexcept: Copy constructor using an glm::vec<2, T>.

Assignment Operators

  • Point& operator=(const Point& coords) noexcept: Copy assignment operator.
  • Point& operator=(Point&& coords) noexcept: Move assignment operator.

Operator

This class have the same operators that from its base class.

Public Variables

  • 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.

Example Usage

#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;

Overview

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.

Template Parameters

  • T: Type of the elements.

Constructors

  • 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 specified EM.
  • Size(const Size& size) noexcept: Copy constructor.
  • Size(Size&& size) noexcept: Move constructor.
  • explicit Size(const Coordinate<T>& size) noexcept: Copy constructor from a Coordinate.
  • explicit Size(Coordinate<T>&& size) noexcept: Move constructor from a Coordinate.
  • 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 an EM.
  • Size(const EM<T>& width, T height) noexcept: Constructor with width component with an EM and height component as value.
  • Size(T width, const EM<T>& height) noexcept: Constructor with width component as value and height component with an EM.
  • explicit Size(const Vector<T, 2>& size) noexcept: Copy constructor using an vector.
  • explicit Size(const GLSLvec2<T>& size) noexcept: Copy constructor using an GLSLvec2.
  • explicit Size(const glm::vec<2, T>& size) noexcept: Copy constructor using an glm::vec<2, T>.

Assignment Operators

  • Size& operator=(const Size& coords) noexcept: Copy assignment operator.
  • Size& operator=(Size&& coords) noexcept: Move assignment operator.

Operator

This class have the same operators that from its base class.

Public Variables

  • 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.

Example Usage

#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;
⚠️ **GitHub.com Fallback** ⚠️