xtd - Reference Guide 0.2.0
xtd::forms::style_sheets::length Class Reference

#include <length.h>

Definition

The xtd::forms::style_sheets::length specifies the legth and unit of many properties of the xtd::forms::style_sheets::ibox_model.

class forms_export_ length : public xtd::iequatable<length>, public xtd::object
Inheritance
xtd::objectxtd::forms::style_sheets::length
Implements
xtd::iequatable <>
Namespace
xtd::forms::style_sheets
Library
xtd.forms
Remarks
CSS has several different units for expressing a length.
Many CSS properties take "length" values, such as width, margin, padding, font-size, etc.
Length is a number followed by a length unit, such as 10px, 2em, etc.CSS has several different units for expressing a length.
Example
Set different length values, using px (pixels):
border-width: 3px;
}
border-width: 1px;
border-radius: 5px;
}
Note
A whitespace cannot appear between the number and the unit. However, if the value is 0, the unit can be omitted.
Remarks
For some CSS properties, negative lengths are allowed.
There are two types of length units: absolute and relative.
Absolute lengths
The absolute length units are fixed and a length expressed in any of these will appear as exactly that size.
Enum class value Css potfix Description
centimeters cm centimeters
millimeters  mm  millimeters
inches in inches (1in = 96px = 2.54cm)
pixels px pixels (1px = 1/96th of 1in)
points pt points (1pt = 1/72 of 1in)
picas pc picas (1pc = 12 pt)
Relative lengths
Relative length units specify a length relative to another length property. Relative length units scales better between different rendering mediums.
Enum class value Css potfix Description
element em Relative to the font-size of the element (2em means 2 times the size of the current font)
element_x_height ex Relative to the x-height of the current font (rarely used)
chase ch Relative to width of the "0" (zero)
root_element rem Relative to font-size of the root element
viewport_width vw Relative to 1% of the width of the viewport(*)
viewport_height vh Relative to 1% of the height of the viewport(*)
viewport_min vmin Relative to 1% of viewport's* smaller dimension
viewport_max vmax Relative to 1% of viewport's* larger dimension
percent % Relative to the parent element
The element(em) and root_element(rem) units are practical in creating perfectly scalable layout! (*) Viewport = the bounds of the element. If the viewport is 50cm wide, 1vw = 0.5cm.

Fields

static const length empty
 Provides a xtd::forms::style_sheets::length object with 0 pixels. More...
 

Constructors

 length ()=default
 Initializes a new instance of the xtd::forms::style_sheets::length class. More...
 
 length (double value)
 Initializes a new instance of the xtd::forms::style_sheets::length class with specifed value in pixels. More...
 
 length (double value, length_unit unit)
 Initializes a new instance of the xtd::forms::style_sheets::length class with specifed value and unit. More...
 

Peorperties

double value () const noexcept
 Gets the xtd::forms::style_sheets::length value. More...
 
void value (double value) noexcept
 Sets the xtd::forms::style_sheets::length value. More...
 
length_unit unit () const noexcept
 Gets the xtd::forms::style_sheets::length unit. More...
 
void unit (length_unit value) noexcept
 Sets the xtd::forms::style_sheets::length unit. More...
 

Methods

bool equals (const object &other) const noexcept override
 Determines whether the specified object is equal to the current object. More...
 
bool equals (const length &other) const noexcept override
 
int32_t get_pixels (const xtd::drawing::rectangle &rect) const noexcept
 Gets the legnth in pixels. More...
 
xtd::ustring to_string () const noexcept override
 Returns a sxd::ustring that represents the current object. More...
 

Additional Inherited Members

- Public Member Functions inherited from xtd::iequatable< length >
virtual bool equals (const length &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type. More...
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Constructor & Destructor Documentation

◆ length() [1/3]

xtd::forms::style_sheets::length::length ( )
default

Initializes a new instance of the xtd::forms::style_sheets::length class.

◆ length() [2/3]

xtd::forms::style_sheets::length::length ( double  value)

Initializes a new instance of the xtd::forms::style_sheets::length class with specifed value in pixels.

Parameters
valueThe number of pixels to be used for xtd::forms::style_sheets::length.

◆ length() [3/3]

xtd::forms::style_sheets::length::length ( double  value,
length_unit  unit 
)

Initializes a new instance of the xtd::forms::style_sheets::length class with specifed value and unit.

Parameters
valueThe number of unit to be used for xtd::forms::style_sheets::length.
unitOne of xtd::forms::style_sheets::legth_unit values.

Member Function Documentation

◆ equals()

bool xtd::forms::style_sheets::length::equals ( const object obj) const
overridevirtualnoexcept

Determines whether the specified object is equal to the current object.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.
Examples
The following code example compares the current instance with another object.

Reimplemented from xtd::object.

◆ get_pixels()

int32_t xtd::forms::style_sheets::length::get_pixels ( const xtd::drawing::rectangle rect) const
noexcept

Gets the legnth in pixels.

Parameters
rectThe xtd::drawing::rectangle is used to compute the length for relative length units.
Returns
The legnth in pixels.

◆ to_string()

xtd::ustring xtd::forms::style_sheets::length::to_string ( ) const
overridevirtualnoexcept

Returns a sxd::ustring that represents the current object.

Returns
A string that represents the current object.
Examples
The following code example demonstrates what to_string returns.

Reimplemented from xtd::object.

◆ unit() [1/2]

length_unit xtd::forms::style_sheets::length::unit ( ) const
noexcept

Gets the xtd::forms::style_sheets::length unit.

Returns
One of xtd::forms::style_sheets::legth_unit values.

◆ unit() [2/2]

void xtd::forms::style_sheets::length::unit ( length_unit  value)
noexcept

Sets the xtd::forms::style_sheets::length unit.

Parameters
valueOne of xtd::forms::style_sheets::legth_unit values.

◆ value() [1/2]

double xtd::forms::style_sheets::length::value ( ) const
noexcept

Gets the xtd::forms::style_sheets::length value.

Returns
The value of the xtd::forms::style_sheets::length.

◆ value() [2/2]

void xtd::forms::style_sheets::length::value ( double  value)
noexcept

Sets the xtd::forms::style_sheets::length value.

Parameters
valueThe value of the xtd::forms::style_sheets::length.

Member Data Documentation

◆ empty

const length xtd::forms::style_sheets::length::empty
static

Provides a xtd::forms::style_sheets::length object with 0 pixels.


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