lecui 1.0.0-alpha.20
lecui C++ user interface library
Public Types | Public Member Functions | List of all members
liblec::lecui::rect Class Reference

Rectangle class. More...

#include <lecui.h>

Public Types

enum class  snap_type {
  bottom_left , bottom , bottom_right , top_left ,
  top , top_right , right_top , right ,
  right_bottom , left_top , left , left_bottom
}
 Snap type, used to position a rectangle next to another (reference) rectangle. More...
 

Public Member Functions

 rect ()
 Rectangle constructor. Makes a zero size rectangle with zero width and height.
 
 rect (const lecui::size size)
 Rectangle constructor. More...
 
 rect (const float left, const float right, const float top, const float bottom)
 Rectangle constructor. More...
 
float & left ()
 Get or set the left coordinate. More...
 
float get_left () const
 Get the left coordinate. More...
 
rectleft (const float &left)
 Set the left coordinate. More...
 
float & right ()
 Get or set the right coordinate. More...
 
float get_right () const
 Get the right coordinate. More...
 
rectright (const float &right)
 Set the right coordinate. More...
 
float & top ()
 Get or set the top coordinate. More...
 
float get_top () const
 Get the top coordinate. More...
 
recttop (const float &top)
 Set the top coordinate. More...
 
float & bottom ()
 Get or set the bottom coordinate. More...
 
float get_bottom () const
 Get the bottom coordinate. More...
 
rectbottom (const float &bottom)
 Set the bottom coordinate. More...
 
float width () const
 Get the rectangle's width. More...
 
float height () const
 Get the rectangle's height. More...
 
size size () const
 Get the rectangle's size. More...
 
rectwidth (float width)
 Set the rectangle's width. More...
 
rectheight (float height)
 Set the rectangle's height. More...
 
rectsize (lecui::size size)
 Set the rectangle's size (both width and height). More...
 
rectsize (float width, float height)
 Set the rectangle's size (both width and height). More...
 
rectset (float x, float y, float cx, float cy)
 Set the rectangle dimensions and position. More...
 
rectmove (float x, float y)
 Move the rectangle using it's top left corner. More...
 
rectplace (const rect &rect_reference, const float &perc_h, const float &perc_v)
 Place this rectangle within or over another. More...
 
rectsnap_to (const rect &rect_reference, snap_type type, const float &clearance)
 Snap this rectangle to another, for quick positioning. More...
 
rectclip_to (const rect &rect_reference, const float &clearance)
 Clip a rectangle within another, to prevent a rectangle going beyond stipulated confines. More...
 
bool operator== (const rect &param)
 Check whether two rectangles are equal. All properties are considered. More...
 
bool operator!= (const rect &param)
 Check whether two rectangles are NOT equal. All properties are considered. More...
 

Detailed Description

Rectangle class.

Member Enumeration Documentation

◆ snap_type

enum class liblec::lecui::rect::snap_type
strong

Snap type, used to position a rectangle next to another (reference) rectangle.

Enumerator
bottom_left 

Snap rectangle to the bottom, with its left side aligned to the reference's left.

bottom 

Snap rectangle to the bottom, with its horizontal center aligned to the reference's horizontal center.

bottom_right 

Snap rectangle to the bottom, with its right side aligned to the reference's right.

top_left 

Snap rectangle to the top, with its left side aligned to the reference's left.

top 

Snap rectangle to the top, with its horizontal center aligned to the reference's horizontal center.

top_right 

Snap rectangle to the top, with its right side aligned to the reference's right.

right_top 

Snap rectangle to the right, with its top side aligned to the reference's top.

right 

Snap rectangle to the right, with its vertical center aligned to the reference's vertical center.

right_bottom 

Snap rectangle to the right, with its bottom aligned to the reference's bottom.

left_top 

Snap rectangle to the left, with its top aligned to the reference's top.

left 

Snap rectangle to the left, with its vertical center aligned to the reference's vertical center.

left_bottom 

Snap rectangle to the left, with its bottom aligned to the reference's bottom.

Constructor & Destructor Documentation

◆ rect() [1/2]

liblec::lecui::rect::rect ( const lecui::size  size)

Rectangle constructor.

Parameters
sizeThe size of the rectangle, in pixels.

◆ rect() [2/2]

liblec::lecui::rect::rect ( const float  left,
const float  right,
const float  top,
const float  bottom 
)

Rectangle constructor.

Parameters
leftThe left coordinate, in pixels.
rightThe right coordinate, in pixels.
topThe top coordinate, in pixels.
bottomThe bottom coordinate, in pixels.

Member Function Documentation

◆ bottom() [1/2]

float & liblec::lecui::rect::bottom ( )

Get or set the bottom coordinate.

Returns
A reference to the bottom coordinate, in pixels.

◆ bottom() [2/2]

rect & liblec::lecui::rect::bottom ( const float &  bottom)

Set the bottom coordinate.

Parameters
bottomThe bottom coordinate, in pixels.
Returns
A reference to the modified object.

◆ clip_to()

rect & liblec::lecui::rect::clip_to ( const rect rect_reference,
const float &  clearance 
)

Clip a rectangle within another, to prevent a rectangle going beyond stipulated confines.

Parameters
rect_referenceThe rectangle to clip to.
clearanceThe clearance to use in the clipping operation.
Returns
A reference to the modified object.

This is a handy method for simpler failsafe coding. Note that if any clipping occurs the dimensions of the rectangle will get smaller.

◆ get_bottom()

float liblec::lecui::rect::get_bottom ( ) const

Get the bottom coordinate.

Returns
The bottom coordinate, in pixels.

◆ get_left()

float liblec::lecui::rect::get_left ( ) const

Get the left coordinate.

Returns
The left coordinate, in pixels.

◆ get_right()

float liblec::lecui::rect::get_right ( ) const

Get the right coordinate.

Returns
The right coordinate, in pixels.

◆ get_top()

float liblec::lecui::rect::get_top ( ) const

Get the top coordinate.

Returns
The top coordinate, in pixels.

◆ height() [1/2]

float liblec::lecui::rect::height ( ) const

Get the rectangle's height.

Returns
The height.

◆ height() [2/2]

rect & liblec::lecui::rect::height ( float  height)

Set the rectangle's height.

Parameters
heightThe height to set it to.
Returns
A reference to the modified object.

The top left corner is used as an anchor.

◆ left() [1/2]

float & liblec::lecui::rect::left ( )

Get or set the left coordinate.

Returns
A reference to the left coordinate, in pixels.

◆ left() [2/2]

rect & liblec::lecui::rect::left ( const float &  left)

Set the left coordinate.

Parameters
leftThe left coordinate, in pixels.
Returns
A reference to the modified object.

◆ move()

rect & liblec::lecui::rect::move ( float  x,
float  y 
)

Move the rectangle using it's top left corner.

Parameters
xThe new x-coordinate of the top-left corner.
yThe new y-coordinate of the top-left corner.
Returns
A reference to the modified object.

The size of the rectangle remains unchanged. The rectangle is effectively translated to the new coodinates.

◆ operator!=()

bool liblec::lecui::rect::operator!= ( const rect param)

Check whether two rectangles are NOT equal. All properties are considered.

Parameters
paramThe rectangle to compare to.
Returns
Returns true if the rectangles are NOT equal, else false.

◆ operator==()

bool liblec::lecui::rect::operator== ( const rect param)

Check whether two rectangles are equal. All properties are considered.

Parameters
paramThe rectangle to compare to.
Returns
Returns true if the rectangles are equal, else false.

◆ place()

rect & liblec::lecui::rect::place ( const rect rect_reference,
const float &  perc_h,
const float &  perc_v 
)

Place this rectangle within or over another.

Parameters
rect_referenceThe rectangle to place it on or over.
perc_hHow far along vertically to place it, as a percentage. 50% means this rectangle will be centered vertically.
perc_vHow far along horizontally to place it, as a percentage. 50% means this rectangle will be centered horizontally.
Returns
A reference to the modified object.

This is a handy method for faster coding and easier maintenance.

◆ right() [1/2]

float & liblec::lecui::rect::right ( )

Get or set the right coordinate.

Returns
A reference to the right coordinate, in pixels.

◆ right() [2/2]

rect & liblec::lecui::rect::right ( const float &  right)

Set the right coordinate.

Parameters
rightThe right coordinate, in pixels.
Returns
A reference to the modified object.

◆ set()

rect & liblec::lecui::rect::set ( float  x,
float  y,
float  cx,
float  cy 
)

Set the rectangle dimensions and position.

Parameters
xThe x-coordinate.
yThe y-coordinate.
cxThe width.
cyThe height.
Returns
A reference to the modified object.

◆ size() [1/3]

size liblec::lecui::rect::size ( ) const

Get the rectangle's size.

Returns
The size.

◆ size() [2/3]

rect & liblec::lecui::rect::size ( float  width,
float  height 
)

Set the rectangle's size (both width and height).

Parameters
widthThe width to set.
heightThe height to set.
Returns
A reference to the modified object.

The top left corner is used as an anchor.

◆ size() [3/3]

rect & liblec::lecui::rect::size ( lecui::size  size)

Set the rectangle's size (both width and height).

Parameters
sizeThe size to set it to.
Returns
A reference to the modified object.

The top left corner is used as an anchor.

◆ snap_to()

rect & liblec::lecui::rect::snap_to ( const rect rect_reference,
snap_type  type,
const float &  clearance 
)

Snap this rectangle to another, for quick positioning.

Parameters
rect_referenceThe rectangle to snap to.
typeThe snap type.
clearanceThe clearance to use in the snapping operation.
Returns
A reference to the modified object.

This is a handy method for faster coding and easier maintenance.

◆ top() [1/2]

float & liblec::lecui::rect::top ( )

Get or set the top coordinate.

Returns
A reference to the top coordinate, in pixels.

◆ top() [2/2]

rect & liblec::lecui::rect::top ( const float &  top)

Set the top coordinate.

Parameters
topThe top coordinate, in pixels.
Returns
A reference to the modified object.

◆ width() [1/2]

float liblec::lecui::rect::width ( ) const

Get the rectangle's width.

Returns
The width.

◆ width() [2/2]

rect & liblec::lecui::rect::width ( float  width)

Set the rectangle's width.

Parameters
widthThe width to set it to.
Returns
A reference to the modified object.

The top left corner is used as an anchor.


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