TGUI  1.7
Loading...
Searching...
No Matches
tgui::Rect< T > Class Template Reference

Public Member Functions

constexpr Rect ()=default
 Default constructor.
 
template<typename U >
constexpr Rect (const Rect< U > &rect)
 Constructs the rectangle from an another Rect with a different type.
 
constexpr Rect (sf::Rect< T > rect)
 Constructs the rectangle from an sf::Rect.
 
constexpr Rect (T rectLeft, T rectTop, T rectWidth, T rectHeight)
 Constructs the rectangle from its position and size.
 
constexpr Rect (Vector2< T > position, Vector2< T > size)
 Constructs the rectangle from its position and size.
 
constexpr void setPosition (Vector2< T > position)
 Sets the position of the rectangle.
 
constexpr Vector2< T > getPosition () const
 Returns the position of the rectangle.
 
constexpr void setSize (Vector2< T > size)
 Sets the size of the rectangle.
 
constexpr Vector2< T > getSize () const
 Returns the size of the rectangle.
 
 operator sf::Rect< T > () const
 Converts the Rect to an sf::Rect.
 
constexpr bool contains (const Vector2< T > &pos) const
 Check if a point is inside the rectangle's area.
 
constexpr bool intersects (const Rect< T > &rect) const
 Check the intersection between two rectangles.
 

Public Attributes

left = 0
 Left coordinate of the rectangle.
 
top = 0
 Top coordinate of the rectangle.
 
width = 0
 Width of the rectangle.
 
height = 0
 Height of the rectangle.
 

Constructor & Destructor Documentation

◆ Rect() [1/5]

template<typename T >
tgui::Rect< T >::Rect ( )
constexprdefault

Default constructor.

Creates an empty rectangle (it is equivalent to calling Rect{0, 0, 0, 0}).

◆ Rect() [2/5]

template<typename T >
template<typename U >
tgui::Rect< T >::Rect ( const Rect< U > & rect)
inlineexplicitconstexpr

Constructs the rectangle from an another Rect with a different type.

Parameters
rectRectangle to copy

◆ Rect() [3/5]

template<typename T >
tgui::Rect< T >::Rect ( sf::Rect< T > rect)
inlineexplicitconstexpr

Constructs the rectangle from an sf::Rect.

Parameters
rectRectangle to initialize

◆ Rect() [4/5]

template<typename T >
tgui::Rect< T >::Rect ( T rectLeft,
T rectTop,
T rectWidth,
T rectHeight )
inlineconstexpr

Constructs the rectangle from its position and size.

Parameters
rectLeftLeft coordinate of the rectangle
rectTopTop coordinate of the rectangle
rectWidthWidth of the rectangle
rectHeightHeight of the rectangle

◆ Rect() [5/5]

template<typename T >
tgui::Rect< T >::Rect ( Vector2< T > position,
Vector2< T > size )
inlineconstexpr

Constructs the rectangle from its position and size.

Parameters
positionPosition of the top-left corner of the rectangle
sizeSize of the rectangle

Member Function Documentation

◆ contains()

template<typename T >
bool tgui::Rect< T >::contains ( const Vector2< T > & pos) const
inlinenodiscardconstexpr

Check if a point is inside the rectangle's area.

This check is non-inclusive. If the point lies on the edge of the rectangle, this function will return false.

Parameters
posCoordinate to test
Returns
True if the point is inside, false otherwise
Warning
This code assumes the width and height are positive.

◆ getPosition()

template<typename T >
Vector2< T > tgui::Rect< T >::getPosition ( ) const
inlinenodiscardconstexpr

Returns the position of the rectangle.

Returns
Rectangle position

◆ getSize()

template<typename T >
Vector2< T > tgui::Rect< T >::getSize ( ) const
inlinenodiscardconstexpr

Returns the size of the rectangle.

Returns
Rectangle size

◆ intersects()

template<typename T >
bool tgui::Rect< T >::intersects ( const Rect< T > & rect) const
inlinenodiscardconstexpr

Check the intersection between two rectangles.

Parameters
rectRectangle to test
Returns
True if rectangles overlap, false otherwise
Warning
This code assumes the width and height of both rectangles are positive.

◆ setPosition()

template<typename T >
void tgui::Rect< T >::setPosition ( Vector2< T > position)
inlineconstexpr

Sets the position of the rectangle.

Parameters
positionNew position for the rectangle

◆ setSize()

template<typename T >
void tgui::Rect< T >::setSize ( Vector2< T > size)
inlineconstexpr

Sets the size of the rectangle.

Parameters
sizeNew size for the rectangle

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