Wt: Wt::WRectF Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Wt::WRectF Class Reference
Painting system

A value class that defines a rectangle. More...

`#include <Wt/WRectF.h>`

Inheritance diagram for Wt::WRectF:
[legend]

## Public Member Functions
| WRectF ()
| Default constructor.
| WRectF (double x, double y, double width, double height)
| Creates a rectangle.
| WRectF (const WPointF &topLeft, const WPointF &bottomRight)
| Creates a rectangle.
bool | operator== (const WRectF &rhs) const
| Comparison operator.
bool | isNull () const
| Checks for a null rectangle.
bool | isEmpty () const
| Determines whether or not this rectangle is empty.
void | setX (double x)
| Sets the X-position of the left side.
void | setY (double y)
| Sets the Y-position of the top side.
void | setWidth (double width)
| Sets the width.
void | setHeight (double height)
| Sets the Y-position of the top side.
double | x () const
| Returns the X-position (left side offset).
double | y () const
| Returns the Y-position (top side offset).
double | width () const
| Returns the width.
double | height () const
| Returns the height.
double | left () const
| Returns the X position (left side offset).
double | top () const
| Returns the Y position (top side offset).
double | right () const
| Returns the the right side offset.
double | bottom () const
| Returns the bottom side offset.
WPointF | topLeft () const
| Returns the top left point.
WPointF | topRight () const
| Returns the top right point.
WPointF | center () const
| Returns the center point.
WPointF | bottomLeft () const
| Returns the bottom left point.
WPointF | bottomRight () const
| Returns the bottom right point.
bool | contains (const WPointF &p) const
| Tests if a rectangle contains a point.
bool | contains (double x, double y) const
| Tests if a rectangle contains a point.
bool | intersects (const WRectF &other) const
| Tests if two rectangles intersect.
WRectF | united (const WRectF &other) const
| Makes the union of to rectangles.
WRectF | normalized () const
| Returns a normalized rectangle.
virtual std::string | jsValue () const override
| Returns a JavaScript representation of the value of this object.
Public Member Functions inherited from Wt::WJavaScriptExposableObject
bool | isJavaScriptBound () const
| Returns whether this object is JavaScript bound.
std::string | jsRef () const
| Returns a JavaScript reference to this object.

## Detailed Description

A value class that defines a rectangle.

The rectangle is defined by a top-left point and a width and height.

### JavaScript exposability

A WRectF is JavaScript exposable. If a WRectF is JavaScript bound, it can be accessed in your custom JavaScript code through its handle's jsRef(). A rectangle is represented in JavaScript as an array of four elements (x,y,width,height), e.g. a rectangle WRectF(10,20,30,40) will be represented in JavaScript as:

[10, 20, 30, 40]

Warning
  A WRectF that is JavaScript exposed should be modified only through its handle. Any attempt at modifying it will cause an exception to be thrown.

See also
  WPaintedWidget::createJSRect()

## Constructor & Destructor Documentation

## ◆ WRectF() [1/3]

Wt::WRectF::WRectF | ( |  | ) |

Default constructor.

Constructs a `null` rectangle.

See also
  isNull()

## ◆ WRectF() [2/3]

Wt::WRectF::WRectF | ( | double | x,
|  | double | y,
|  | double | width,
|  | double | height )

Creates a rectangle.

Constructs a rectangle with top left point (`x`, `y`) and size `width` x `height`.

## ◆ WRectF() [3/3]

Wt::WRectF::WRectF | ( | const WPointF & | topLeft,
|  | const WPointF & | bottomRight )

Creates a rectangle.

Constructs a rectangle from the two points `topLeft` and `bottomRight`.

If you want to create a rectangle from two arbitrary corner points, you can use this constructor too, but should call normalized() afterwords.

## Member Function Documentation

## ◆ bottom()

double Wt::WRectF::bottom | ( |  | ) | const

Returns the bottom side offset.

See also
  top()

## ◆ bottomLeft()

WPointF Wt::WRectF::bottomLeft | ( |  | ) | const

Returns the bottom left point.

See also
  left(), bottom()

## ◆ bottomRight()

WPointF Wt::WRectF::bottomRight | ( |  | ) | const

Returns the bottom right point.

See also
  right(), bottom()

## ◆ contains() [1/2]

bool Wt::WRectF::contains | ( | const WPointF & | p | ) | const

Tests if a rectangle contains a point.

Note
  This method is not supported if this rectangle isJavaScriptBound()

## ◆ contains() [2/2]

bool Wt::WRectF::contains | ( | double | x,
|  | double | y ) const

Tests if a rectangle contains a point.

Note
  This method is not supported if this rectangle isJavaScriptBound()

## ◆ height()

double Wt::WRectF::height | ( |  | ) | const

Returns the height.

See also
  width()

## ◆ isEmpty()

bool Wt::WRectF::isEmpty | ( |  | ) | const

Determines whether or not this rectangle is empty.

A rectangle is empty if its width and height are zero.

A rectangle that isJavaScriptBound() is JavaScript bound is never empty.

## ◆ isNull()

bool Wt::WRectF::isNull | ( |  | ) | const

Checks for a null rectangle.

A rectangle that isJavaScriptBound() is never null.

See also
  WRectF()

## ◆ jsValue()

virtual std::string Wt::WRectF::jsValue | ( |  | ) | const
| overridevirtual

Returns a JavaScript representation of the value of this object.

Note
  The value returned will reflect the current server side value of the object. If this object is JavaScript bound, this value may not reflect the actual client side value. If you need access to the client side value, use jsRef() intead.

Implements Wt::WJavaScriptExposableObject.

## ◆ left()

double Wt::WRectF::left | ( |  | ) | const

Returns the X position (left side offset).

See also
  x(), right()

## ◆ normalized()

WRectF Wt::WRectF::normalized | ( |  | ) | const

Returns a normalized rectangle.

A normalized rectangle has a positive width and height.

This method supports JavaScript bound rectangles.

## ◆ right()

double Wt::WRectF::right | ( |  | ) | const

Returns the the right side offset.

See also
  left()

## ◆ setHeight()

void Wt::WRectF::setHeight | ( | double | height | ) |

Sets the Y-position of the top side.

The bottom side of the rectangle may move, but this does not affect the Y position of the top side.

Exceptions

  WException | if the rectangle is JavaScript bound

## ◆ setWidth()

void Wt::WRectF::setWidth | ( | double | width | ) |

Sets the width.

The right side of the rectangle may move, but this does not affect the left side.

Exceptions

  WException | if the rectangle is JavaScript bound

## ◆ setX()

void Wt::WRectF::setX | ( | double | x | ) |

Sets the X-position of the left side.

The right side of the rectangle does not move, and as a result, the rectangle may be resized.

Exceptions

  WException | if the rectangle is JavaScript bound

## ◆ setY()

void Wt::WRectF::setY | ( | double | y | ) |

Sets the Y-position of the top side.

The bottom side of the rectangle does not move, and as a result, the rectangle may be resized.

Exceptions

  WException | if the rectangle is JavaScript bound

## ◆ top()

double Wt::WRectF::top | ( |  | ) | const

Returns the Y position (top side offset).

See also
  y(), bottom()

## ◆ topLeft()

WPointF Wt::WRectF::topLeft | ( |  | ) | const

Returns the top left point.

See also
  left(), top()

## ◆ topRight()

WPointF Wt::WRectF::topRight | ( |  | ) | const

Returns the top right point.

See also
  right(), top()

## ◆ united()

WRectF Wt::WRectF::united | ( | const WRectF & | other | ) | const

Makes the union of to rectangles.

Note
  This method is not supported if this rectangle is JavaScript bound.

## ◆ width()

double Wt::WRectF::width | ( |  | ) | const

Returns the width.

See also
  height()

## ◆ x()

double Wt::WRectF::x | ( |  | ) | const

Returns the X-position (left side offset).

This is equivalent to left().

See also
  y(), left()

## ◆ y()

double Wt::WRectF::y | ( |  | ) | const

Returns the Y-position (top side offset).

This is equivalent to top().

See also
  x(), top()