gtkmm 4.19.0
Gsk::RoundedRect Class Reference

A rectangular region with rounded corners. More...

#include <gskmm/roundedrect.h>

Public Member Functions

 RoundedRect ()
 RoundedRect (const GskRoundedRect * rounded_rect)
 RoundedRect (const Gdk::Graphene::Rect & bounds, const Gdk::Graphene::Size & top_left, const Gdk::Graphene::Size & top_right, const Gdk::Graphene::Size & bottom_right, const Gdk::Graphene::Size & bottom_left)
 RoundedRect (const Gdk::Graphene::Rect & bounds, float radius)
 RoundedRect (const RoundedRect & other) noexcept
RoundedRectoperator= (const RoundedRect & other) noexcept
 RoundedRect (RoundedRect && other) noexcept
RoundedRectoperator= (RoundedRect && other) noexcept
void set (const Gdk::Graphene::Rect & bounds, const Gdk::Graphene::Size & top_left, const Gdk::Graphene::Size & top_right, const Gdk::Graphene::Size & bottom_right, const Gdk::Graphene::Size & bottom_left)
 Initializes a rounded rectangle with the given values.
void set (const Gdk::Graphene::Rect & bounds, float radius)
 Initializes a rounded rectangle to the given bounds and sets the radius of all four corners equally.
std::pair< Gdk::Graphene::Rect, std::array< Gdk::Graphene::Size, 4 > > get () const
 Get the bounding rectangle and the corner radii.
void normalize ()
 Normalizes a rounded rectangle.
void offset (float dx, float dy)
 Offsets the rounded rectangle's origin by dx and dy.
void shrink (float top, float right, float bottom, float left)
 Shrinks (or grows) a rounded rectangle by moving the 4 sides according to the offsets given.
bool is_rectilinear () const
 Checks if all corners of a rounded rectangle are right angles and the rectangle covers all of its bounds.
bool contains (const Gdk::Graphene::Point & point) const
 Checks if the given point is inside the rounded rectangle.
bool contains (const Gdk::Graphene::Rect & rect) const
 Checks if the given rectangle is contained inside the rounded rectangle.
bool intersects (const Gdk::Graphene::Rect & rect) const
 Checks if part a rectangle is contained inside the rounded rectangle.
GskRoundedRect * gobj ()
 Provides access to the underlying C GObject.
const GskRoundedRect * gobj () const
 Provides access to the underlying C GObject.

Protected Attributes

GskRoundedRect gobject_

Detailed Description

A rectangular region with rounded corners.

Application code should normalize rectangles using normalize(); this function will ensure that the bounds of the rectangle are normalized and ensure that the corner values are positive and the corners do not overlap.

All functions taking a Gsk::RoundedRect as an argument will internally operate on a normalized copy; all functions returning a Gsk::RoundedRect will always return a normalized one.

The algorithm used for normalizing corner sizes is described in the CSS specification.

Since gtkmm 4.20

Constructor & Destructor Documentation

◆ RoundedRect() [1/6]

Gsk::RoundedRect::RoundedRect ( )

◆ RoundedRect() [2/6]

Gsk::RoundedRect::RoundedRect ( const GskRoundedRect * rounded_rect)

◆ RoundedRect() [3/6]

Gsk::RoundedRect::RoundedRect ( const Gdk::Graphene::Rect & bounds,
const Gdk::Graphene::Size & top_left,
const Gdk::Graphene::Size & top_right,
const Gdk::Graphene::Size & bottom_right,
const Gdk::Graphene::Size & bottom_left )

◆ RoundedRect() [4/6]

Gsk::RoundedRect::RoundedRect ( const Gdk::Graphene::Rect & bounds,
float radius )

◆ RoundedRect() [5/6]

Gsk::RoundedRect::RoundedRect ( const RoundedRect & other)
noexcept

◆ RoundedRect() [6/6]

Gsk::RoundedRect::RoundedRect ( RoundedRect && other)
noexcept

Member Function Documentation

◆ contains() [1/2]

bool Gsk::RoundedRect::contains ( const Gdk::Graphene::Point & point) const

Checks if the given point is inside the rounded rectangle.

Parameters
pointThe point to check.
Returns
True if the point is inside the rounded rectangle.

◆ contains() [2/2]

bool Gsk::RoundedRect::contains ( const Gdk::Graphene::Rect & rect) const

Checks if the given rectangle is contained inside the rounded rectangle.

Parameters
rectThe rectangle to check.
Returns
True if the rect is fully contained inside the rounded rectangle.

◆ get()

std::pair< Gdk::Graphene::Rect, std::array< Gdk::Graphene::Size, 4 > > Gsk::RoundedRect::get ( ) const

Get the bounding rectangle and the corner radii.

You can use the Gsk::Corner enum to select a corner.

auto [bounds, corners] = rounded_rect.get();
auto top_right = corners[Gsk::Corner::TOP_RIGHT];
Returns
{bounds, corners} The bounding rectangle and the corner radii.

◆ gobj() [1/2]

GskRoundedRect * Gsk::RoundedRect::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GskRoundedRect * Gsk::RoundedRect::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ intersects()

bool Gsk::RoundedRect::intersects ( const Gdk::Graphene::Rect & rect) const

Checks if part a rectangle is contained inside the rounded rectangle.

Parameters
rectThe rectangle to check.
Returns
True if the rect intersects with the rounded rectangle.

◆ is_rectilinear()

bool Gsk::RoundedRect::is_rectilinear ( ) const

Checks if all corners of a rounded rectangle are right angles and the rectangle covers all of its bounds.

This information can be used to decide if Gsk::ClipNode::new() or Gsk::RoundedClipNode::new() should be called.

Returns
True if the rounded rectangle is rectilinear.

◆ normalize()

void Gsk::RoundedRect::normalize ( )

Normalizes a rounded rectangle.

This function will ensure that the bounds of the rounded rectangle are normalized and ensure that the corner values are positive and the corners do not overlap.

◆ offset()

void Gsk::RoundedRect::offset ( float dx,
float dy )

Offsets the rounded rectangle's origin by dx and dy.

The size and corners of the rounded rectangle are unchanged.

Parameters
dxThe horizontal offset.
dyThe vertical offset.

◆ operator=() [1/2]

RoundedRect & Gsk::RoundedRect::operator= ( const RoundedRect & other)
noexcept

◆ operator=() [2/2]

RoundedRect & Gsk::RoundedRect::operator= ( RoundedRect && other)
noexcept

◆ set() [1/2]

void Gsk::RoundedRect::set ( const Gdk::Graphene::Rect & bounds,
const Gdk::Graphene::Size & top_left,
const Gdk::Graphene::Size & top_right,
const Gdk::Graphene::Size & bottom_right,
const Gdk::Graphene::Size & bottom_left )

Initializes a rounded rectangle with the given values.

This function will implicitly normalize the rounded rectangle before returning.

Parameters
boundsA graphene_rect_t describing the bounds.
top_leftThe rounding radius of the top left corner.
top_rightThe rounding radius of the top right corner.
bottom_rightThe rounding radius of the bottom right corner.
bottom_leftThe rounding radius of the bottom left corner.

◆ set() [2/2]

void Gsk::RoundedRect::set ( const Gdk::Graphene::Rect & bounds,
float radius )

Initializes a rounded rectangle to the given bounds and sets the radius of all four corners equally.

Parameters
boundsA graphene_rect_t.
radiusThe border radius.

◆ shrink()

void Gsk::RoundedRect::shrink ( float top,
float right,
float bottom,
float left )

Shrinks (or grows) a rounded rectangle by moving the 4 sides according to the offsets given.

The corner radii will be changed in a way that tries to keep the center of the corner circle intact. This emulates CSS behavior.

This function also works for growing rounded rectangles if you pass negative values for the top, right, bottom or left.

Parameters
topHow far to move the top side downwards.
rightHow far to move the right side to the left.
bottomHow far to move the bottom side upwards.
leftHow far to move the left side to the right.

Member Data Documentation

◆ gobject_

GskRoundedRect Gsk::RoundedRect::gobject_
protected