gi-graphene-1.0.8: Graphene bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | None
Language | Haskell2010

GI.Graphene.Structs.Rect

Contents

- Exported types
- Methods
  - alloc
  - containsPoint
  - containsRect
  - equal
  - expand
  - free
  - getArea
  - getBottomLeft
  - getBottomRight
  - getCenter
  - getHeight
  - getTopLeft
  - getTopRight
  - getWidth
  - getX
  - getY
  - init
  - initFromRect
  - inset
  - insetR
  - interpolate
  - intersection
  - normalize
  - normalizeR
  - offset
  - offsetR
  - round
  - roundExtents
  - roundToPixel
  - scale
  - union
  - zero
- Properties
  - origin
  - size

Description

The location and size of a rectangle region.

The width and height of a `Rect` can be negative; for instance, a `Rect` with an origin of [ 0, 0 ] and a size of [ 10, 10 ] is equivalent to a `Rect` with an origin of [ 10, 10 ] and a size of [ -10, -10 ].

Application code can normalize rectangles using `rectNormalize`; this function will ensure that the width and height of a rectangle are positive values. All functions taking a `Rect` as an argument will internally operate on a normalized copy; all functions returning a `Rect` will always return a normalized rectangle.

Since: 1.0

Synopsis

- newtype Rect = Rect (ManagedPtr Rect)
- newZeroRect :: MonadIO m => m Rect
- rectAlloc :: (HasCallStack, MonadIO m) => m Rect
- rectContainsPoint :: (HasCallStack, MonadIO m) => Rect -> Point -> m Bool
- rectContainsRect :: (HasCallStack, MonadIO m) => Rect -> Rect -> m Bool
- rectEqual :: (HasCallStack, MonadIO m) => Rect -> Rect -> m Bool
- rectExpand :: (HasCallStack, MonadIO m) => Rect -> Point -> m Rect
- rectFree :: (HasCallStack, MonadIO m) => Rect -> m ()
- rectGetArea :: (HasCallStack, MonadIO m) => Rect -> m Float
- rectGetBottomLeft :: (HasCallStack, MonadIO m) => Rect -> m Point
- rectGetBottomRight :: (HasCallStack, MonadIO m) => Rect -> m Point
- rectGetCenter :: (HasCallStack, MonadIO m) => Rect -> m Point
- rectGetHeight :: (HasCallStack, MonadIO m) => Rect -> m Float
- rectGetTopLeft :: (HasCallStack, MonadIO m) => Rect -> m Point
- rectGetTopRight :: (HasCallStack, MonadIO m) => Rect -> m Point
- rectGetWidth :: (HasCallStack, MonadIO m) => Rect -> m Float
- rectGetX :: (HasCallStack, MonadIO m) => Rect -> m Float
- rectGetY :: (HasCallStack, MonadIO m) => Rect -> m Float
- rectInit :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> Float -> Float -> m Rect
- rectInitFromRect :: (HasCallStack, MonadIO m) => Rect -> Rect -> m Rect
- rectInset :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> m Rect
- rectInsetR :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> m Rect
- rectInterpolate :: (HasCallStack, MonadIO m) => Rect -> Rect -> Double -> m Rect
- rectIntersection :: (HasCallStack, MonadIO m) => Rect -> Rect -> m (Bool, Rect)
- rectNormalize :: (HasCallStack, MonadIO m) => Rect -> m Rect
- rectNormalizeR :: (HasCallStack, MonadIO m) => Rect -> m Rect
- rectOffset :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> m Rect
- rectOffsetR :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> m Rect
- rectRound :: (HasCallStack, MonadIO m) => Rect -> m Rect
- rectRoundExtents :: (HasCallStack, MonadIO m) => Rect -> m Rect
- rectRoundToPixel :: (HasCallStack, MonadIO m) => Rect -> m Rect
- rectScale :: (HasCallStack, MonadIO m) => Rect -> Float -> Float -> m Rect
- rectUnion :: (HasCallStack, MonadIO m) => Rect -> Rect -> m Rect
- rectZero :: (HasCallStack, MonadIO m) => m Rect
- getRectOrigin :: MonadIO m => Rect -> m Point
- getRectSize :: MonadIO m => Rect -> m Size

# Exported types

newtype Rect Source #

Memory-managed wrapper type.

Constructors

Rect (ManagedPtr Rect) |

#### Instances

Instances details

Eq Rect Source # |
Instance details Defined in GI.Graphene.Structs.Rect Methods (==) :: Rect -> Rect -> Bool Source # (/=) :: Rect -> Rect -> Bool Source #
GBoxed Rect Source # |
Instance details Defined in GI.Graphene.Structs.Rect
ManagedPtrNewtype Rect Source # |
Instance details Defined in GI.Graphene.Structs.Rect Methods toManagedPtr :: Rect -> ManagedPtr Rect Source #
TypedObject Rect Source # |
Instance details Defined in GI.Graphene.Structs.Rect Methods glibType :: IO GType Source #
HasParentTypes Rect Source # |
Instance details Defined in GI.Graphene.Structs.Rect
tag ~ 'AttrSet => Constructible Rect tag Source # |
Instance details Defined in GI.Graphene.Structs.Rect Methods new :: MonadIO m => (ManagedPtr Rect -> Rect) -> [AttrOp Rect tag] -> m Rect Source #
IsGValue (Maybe Rect) Source # | Convert `Rect` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.Graphene.Structs.Rect Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe Rect -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe Rect) Source #
type ParentTypes Rect Source # |
Instance details Defined in GI.Graphene.Structs.Rect type ParentTypes Rect = '[] :: [Type]

newZeroRect :: MonadIO m => m Rect Source #

Construct a `Rect` struct initialized to zero.

# Methods

### Click to display all available methods, including inherited ones

Expand

#### Methods

containsPoint, containsRect, equal, expand, free, init, initFromRect, inset, insetR, interpolate, intersection, normalize, normalizeR, offset, offsetR, round, roundExtents, roundToPixel, scale, union.

#### Getters

getArea, getBottomLeft, getBottomRight, getCenter, getHeight, getTopLeft, getTopRight, getWidth, getX, getY.

#### Setters

None.

## alloc

rectAlloc Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> m Rect | Returns: the newly allocated rectangle

Allocates a new `Rect`.

The contents of the returned rectangle are undefined.

Since: 1.0

## containsPoint

rectContainsPoint Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> Point | `p`: a `Point`
-> m Bool | Returns: `true` if the rectangle contains the point

Checks whether a `Rect` contains the given coordinates.

Since: 1.0

## containsRect

rectContainsRect Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `a`: a `Rect`
-> Rect | `b`: a `Rect`
-> m Bool | Returns: `true` if the rectangle `a` fully contains `b`

Checks whether a `Rect` fully contains the given rectangle.

Since: 1.0

## equal

rectEqual Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `a`: a `Rect`
-> Rect | `b`: a `Rect`
-> m Bool | Returns: `true` if the rectangles are equal

Checks whether the two given rectangle are equal.

Since: 1.0

## expand

rectExpand Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> Point | `p`: a `Point`
-> m Rect |

Expands a `Rect` to contain the given `Point`.

Since: 1.4

## free

rectFree Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m () |

Frees the resources allocated by `rectAlloc`.

Since: 1.0

## getArea

rectGetArea Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Float | Returns: the area of the normalized rectangle

Compute the area of given normalized rectangle.

Since: 1.10

## getBottomLeft

rectGetBottomLeft Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Point |

Retrieves the coordinates of the bottom-left corner of the given rectangle.

Since: 1.0

## getBottomRight

rectGetBottomRight Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Point |

Retrieves the coordinates of the bottom-right corner of the given rectangle.

Since: 1.0

## getCenter

rectGetCenter Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Point |

Retrieves the coordinates of the center of the given rectangle.

Since: 1.0

## getHeight

rectGetHeight Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Float | Returns: the normalized height of the rectangle

Retrieves the normalized height of the given rectangle.

Since: 1.0

## getTopLeft

rectGetTopLeft Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Point |

Retrieves the coordinates of the top-left corner of the given rectangle.

Since: 1.0

## getTopRight

rectGetTopRight Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Point |

Retrieves the coordinates of the top-right corner of the given rectangle.

Since: 1.0

## getWidth

rectGetWidth Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Float | Returns: the normalized width of the rectangle

Retrieves the normalized width of the given rectangle.

Since: 1.0

## getX

rectGetX Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Float | Returns: the normalized X coordinate of the rectangle

Retrieves the normalized X coordinate of the origin of the given rectangle.

Since: 1.0

## getY

rectGetY Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Float | Returns: the normalized Y coordinate of the rectangle

Retrieves the normalized Y coordinate of the origin of the given rectangle.

Since: 1.0

## init

rectInit Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> Float | `x`: the X coordinate of the `grapheneRectT`.origin
-> Float | `y`: the Y coordinate of the `grapheneRectT`.origin
-> Float | `width`: the width of the `grapheneRectT`.size
-> Float | `height`: the height of the `grapheneRectT`.size
-> m Rect | Returns: the initialized rectangle

Initializes the given `Rect` with the given values.

This function will implicitly normalize the `Rect` before returning.

Since: 1.0

## initFromRect

rectInitFromRect Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> Rect | `src`: a `Rect`
-> m Rect | Returns: the initialized rectangle

Initializes `r` using the given `src` rectangle.

This function will implicitly normalize the `Rect` before returning.

Since: 1.0

## inset

rectInset Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> Float | `dX`: the horizontal inset
-> Float | `dY`: the vertical inset
-> m Rect | Returns: the inset rectangle

Changes the given rectangle to be smaller, or larger depending on the given inset parameters.

To create an inset rectangle, use positive `dX` or `dY` values; to create a larger, encompassing rectangle, use negative `dX` or `dY` values.

The origin of the rectangle is offset by `dX` and `dY`, while the size is adjusted by `(2 * @d_x, 2 * @d_y)`. If `dX` and `dY` are positive values, the size of the rectangle is decreased; if `dX` and `dY` are negative values, the size of the rectangle is increased.

If the size of the resulting inset rectangle has a negative width or height then the size will be set to zero.

Since: 1.0

## insetR

rectInsetR Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> Float | `dX`: the horizontal inset
-> Float | `dY`: the vertical inset
-> m Rect |

Changes the given rectangle to be smaller, or larger depending on the given inset parameters.

To create an inset rectangle, use positive `dX` or `dY` values; to create a larger, encompassing rectangle, use negative `dX` or `dY` values.

The origin of the rectangle is offset by `dX` and `dY`, while the size is adjusted by `(2 * @d_x, 2 * @d_y)`. If `dX` and `dY` are positive values, the size of the rectangle is decreased; if `dX` and `dY` are negative values, the size of the rectangle is increased.

If the size of the resulting inset rectangle has a negative width or height then the size will be set to zero.

Since: 1.4

## interpolate

rectInterpolate Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `a`: a `Rect`
-> Rect | `b`: a `Rect`
-> Double | `factor`: the linear interpolation factor
-> m Rect |

Linearly interpolates the origin and size of the two given rectangles.

Since: 1.0

## intersection

rectIntersection Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `a`: a `Rect`
-> Rect | `b`: a `Rect`
-> m (Bool, Rect) | Returns: `true` if the two rectangles intersect

Computes the intersection of the two given rectangles.

The intersection in the image above is the blue outline.

If the two rectangles do not intersect, `res` will contain a degenerate rectangle with origin in (0, 0) and a size of 0.

Since: 1.0

## normalize

rectNormalize Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Rect | Returns: the normalized rectangle

Normalizes the passed rectangle.

This function ensures that the size of the rectangle is made of positive values, and that the origin is the top-left corner of the rectangle.

Since: 1.0

## normalizeR

rectNormalizeR Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Rect |

Normalizes the passed rectangle.

This function ensures that the size of the rectangle is made of positive values, and that the origin is in the top-left corner of the rectangle.

Since: 1.4

## offset

rectOffset Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> Float | `dX`: the horizontal offset
-> Float | `dY`: the vertical offset
-> m Rect | Returns: the offset rectangle

Offsets the origin by `dX` and `dY`.

The size of the rectangle is unchanged.

Since: 1.0

## offsetR

rectOffsetR Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> Float | `dX`: the horizontal offset
-> Float | `dY`: the vertical offset
-> m Rect |

Offsets the origin of the given rectangle by `dX` and `dY`.

The size of the rectangle is left unchanged.

Since: 1.4

## round

rectRound Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Rect |

Deprecated: (Since version 1.10)Use `rectRoundExtents` instead

Rounds the origin and size of the given rectangle to their nearest integer values; the rounding is guaranteed to be large enough to have an area bigger or equal to the original rectangle, but might not fully contain its extents. Use `rectRoundExtents` in case you need to round to a rectangle that covers fully the original one.

This function is the equivalent of calling `floor` on the coordinates of the origin, and `ceil` on the size.

Since: 1.4

## roundExtents

rectRoundExtents Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Rect |

Rounds the origin of the given rectangle to its nearest integer value and and recompute the size so that the rectangle is large enough to contain all the conrners of the original rectangle.

This function is the equivalent of calling `floor` on the coordinates of the origin, and recomputing the size calling `ceil` on the bottom-right coordinates.

If you want to be sure that the rounded rectangle completely covers the area that was covered by the original rectangle — i.e. you want to cover the area including all its corners — this function will make sure that the size is recomputed taking into account the ceiling of the coordinates of the bottom-right corner. If the difference between the original coordinates and the coordinates of the rounded rectangle is greater than the difference between the original size and and the rounded size, then the move of the origin would not be compensated by a move in the anti-origin, leaving the corners of the original rectangle outside the rounded one.

Since: 1.10

## roundToPixel

rectRoundToPixel Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> m Rect | Returns: the pixel-aligned rectangle.

Deprecated: (Since version 1.4)Use `rectRound` instead

Rounds the origin and the size of the given rectangle to their nearest integer values; the rounding is guaranteed to be large enough to contain the original rectangle.

Since: 1.0

## scale

rectScale Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `r`: a `Rect`
-> Float | `sH`: horizontal scale factor
-> Float | `sV`: vertical scale factor
-> m Rect |

Scales the size and origin of a rectangle horizontaly by `sH`, and vertically by `sV`. The result `res` is normalized.

Since: 1.10

## union

rectUnion Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Rect | `a`: a `Rect`
-> Rect | `b`: a `Rect`
-> m Rect |

Computes the union of the two given rectangles.

The union in the image above is the blue outline.

Since: 1.0

## zero

rectZero Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> m Rect | Returns: a fixed rectangle

Returns a degenerate rectangle with origin fixed at (0, 0) and a size of 0, 0.

Since: 1.4

# Properties

## origin

the coordinates of the origin of the rectangle

getRectOrigin :: MonadIO m => Rect -> m Point Source #

Get the value of the “`origin`” field. When overloading is enabled, this is equivalent to

    get rect #origin

## size

the size of the rectangle

getRectSize :: MonadIO m => Rect -> m Size Source #

Get the value of the “`size`” field. When overloading is enabled, this is equivalent to

    get rect #size