Gorgon Game Engine
Dimension Class Reference

Dimension data for components. Allows relative position and sizing. More...

Public Types

enum  Unit {
  Pixel, Percent, MilliPixel, BasisPoint,
  EM
}
 Unit for dimensions. More...
 

Public Member Functions

 Dimension (int value=0, Unit unit=Pixel)
 Constructs a new dimension or type casts integer to dimension
More...
 
int Calculate (int parentwidth, int emwidth=10) const
 Returns the calculated dimension in pixels. More...
 
float CalculateFloat (float parentwidth, float emwidth=10) const
 Returns the calculated dimension in pixels. More...
 
Unit GetUnit () const
 Returns the unit of the dimension. More...
 
int GetValue () const
 Returns the value of the dimension, should not be considered as pixels. More...
 
bool IsRelative () const
 Returns if the dimension is relative to the parentwidth. More...
 
int operator() (int parentwidth, int emwidth=10) const
 Returns the calculated dimension in pixels. More...
 
void Set (int value)
 Changes the value of the dimension without modifying the units. More...
 
void Set (int value, Unit unit)
 Changes the value and unit of the dimension. More...
 

Detailed Description

Dimension data for components. Allows relative position and sizing.

Member Enumeration Documentation

◆ Unit

enum Unit

Unit for dimensions.

Dimensions in UI system does not allow floating point numbers as floating point numbers are not precise and may cause issues. Additionally, final values always rounded, so that the symbols are always on full pixels.

Enumerator
Pixel 

Fixed pixel based dimensions.

Percent 

Dimension will be relative to the parent and given in percent.

If higher resolution is necessary use BasisPoint.

MilliPixel 

1/1000th of a pixel, there are only few places that this will be used.

Currently only rotation center use non-integer pixels

BasisPoint 

Dimension will be relative to the parent and given in 1/10000.

EM 

Dimension will be relative to the text size, given value is the percent of the width of an EM dash.

If no font information is found, 10px will be used for EM dash. Thus, 1 unit will be 0.1 pixels.

Constructor & Destructor Documentation

◆ Dimension()

Dimension ( int  value = 0,
Unit  unit = Pixel 
)

Constructs a new dimension or type casts integer to dimension

Member Function Documentation

◆ Calculate()

int Calculate ( int  parentwidth,
int  emwidth = 10 
) const

Returns the calculated dimension in pixels.

References Dimension::BasisPoint, Dimension::EM, Dimension::MilliPixel, Dimension::Percent, and Dimension::Pixel.

◆ CalculateFloat()

float CalculateFloat ( float  parentwidth,
float  emwidth = 10 
) const

Returns the calculated dimension in pixels.

References Dimension::BasisPoint, Dimension::EM, Dimension::MilliPixel, Dimension::Percent, and Dimension::Pixel.

◆ GetUnit()

Unit GetUnit ( ) const

Returns the unit of the dimension.

◆ GetValue()

int GetValue ( ) const

Returns the value of the dimension, should not be considered as pixels.

◆ IsRelative()

bool IsRelative ( ) const

Returns if the dimension is relative to the parentwidth.

References Dimension::BasisPoint, and Dimension::Percent.

◆ operator()()

int operator() ( int  parentwidth,
int  emwidth = 10 
) const

Returns the calculated dimension in pixels.

References Dimension::Calculate().

◆ Set() [1/2]

void Set ( int  value)

Changes the value of the dimension without modifying the units.

◆ Set() [2/2]

void Set ( int  value,
Unit  unit 
)

Changes the value and unit of the dimension.


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