Class RoundedRect
- All Implemented Interfaces:
Proxy
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 GskRoundedRect as an argument will internally
operate on a normalized copy; all functions returning a GskRoundedRect
will always return a normalized one.
The algorithm used for normalizing corner sizes is described in the CSS specification.
-
Constructor Summary
ConstructorsConstructorDescriptionAllocate a new RoundedRect.RoundedRect(Arena arena) Allocate a new RoundedRect.RoundedRect(MemorySegment address) Create a RoundedRect proxy instance for the provided memory address.RoundedRect(Rect bounds, Size[] corner) Allocate a new RoundedRect with the fields set to the provided values.RoundedRect(Rect bounds, Size[] corner, Arena arena) Allocate a new RoundedRect with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsPoint(Point point) Checks if the given point is inside the rounded rectangle.booleancontainsRect(Rect rect) Checks if the given rectangle is contained inside the rounded rectangle.static MemoryLayoutThe memory layout of the native struct.Initializes a rounded rectangle with the given values.initCopy(RoundedRect src) Initializes a rounded rectangle with a copy.initFromRect(Rect bounds, float radius) Initializes a rounded rectangle to the given bounds and sets the radius of all four corners equally.booleanintersectsRect(Rect rect) Checks if part a rectangle is contained inside the rounded rectangle.booleanChecks if all corners of a rounded rectangle are right angles and the rectangle covers all of its bounds.Normalizes a rounded rectangle.offset(float dx, float dy) Offsets the rounded rectangle's origin bydxanddy.@Nullable RectRead the value of the fieldbounds.@Nullable Size @Nullable []Read the value of the fieldcorner.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.voidwriteBounds(@Nullable Rect bounds) Write a value in the fieldbounds.voidwriteCorner(@Nullable Size @Nullable [] corner, Arena _arena) Write a value in the fieldcorner.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
RoundedRect
Create a RoundedRect proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
RoundedRect
Allocate a new RoundedRect.- Parameters:
arena- to control the memory allocation scope
-
RoundedRect
public RoundedRect()Allocate a new RoundedRect. The memory is allocated withArena.ofAuto(). -
RoundedRect
-
RoundedRect
Allocate a new RoundedRect with the fields set to the provided values. The memory is allocated withArena.ofAuto().- Parameters:
bounds- value for the fieldboundscorner- value for the fieldcorner
-
-
Method Details
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readBounds
Read the value of the fieldbounds.- Returns:
- The value of the field
bounds
-
writeBounds
Write a value in the fieldbounds.- Parameters:
bounds- The new value for the fieldbounds
-
readCorner
Read the value of the fieldcorner.- Returns:
- The value of the field
corner
-
writeCorner
-
containsPoint
Checks if the given point is inside the rounded rectangle.- Parameters:
point- the point to check- Returns:
- true if the point is inside the rounded rectangle
-
containsRect
Checks if the given rectangle is contained inside the rounded rectangle.- Parameters:
rect- the rectangle to check- Returns:
- true if the
rectis fully contained inside the rounded rectangle
-
init
public RoundedRect init(Rect bounds, Size topLeft, Size topRight, Size bottomRight, Size bottomLeft) Initializes a rounded rectangle with the given values.This function will implicitly normalize the rounded rectangle before returning.
- Parameters:
bounds- agraphene_rect_tdescribing the boundstopLeft- the rounding radius of the top left cornertopRight- the rounding radius of the top right cornerbottomRight- the rounding radius of the bottom right cornerbottomLeft- the rounding radius of the bottom left corner- Returns:
- the initialized rounded rectangle
-
initCopy
Initializes a rounded rectangle with a copy.This function will not normalize the rounded rectangle, so make sure the source is normalized.
- Parameters:
src- another rounded rectangle- Returns:
- the initialized rounded rectangle
-
initFromRect
Initializes a rounded rectangle to the given bounds and sets the radius of all four corners equally.- Parameters:
bounds- agraphene_rect_tradius- the border radius- Returns:
- the initialized rounded rectangle
-
intersectsRect
Checks if part a rectangle is contained inside the rounded rectangle.- Parameters:
rect- the rectangle to check- Returns:
- true if the
rectintersects with the rounded rectangle
-
isRectilinear
public boolean isRectilinear()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
ClipNode(org.gnome.gsk.RenderNode, org.gnome.graphene.Rect)orRoundedClipNode(org.gnome.gsk.RenderNode, org.gnome.gsk.RoundedRect)should be called.- Returns:
- true if the rounded rectangle is rectilinear
-
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.
- Returns:
- the normalized rounded rectangle
-
offset
Offsets the rounded rectangle's origin bydxanddy.The size and corners of the rounded rectangle are unchanged.
- Parameters:
dx- the horizontal offsetdy- the vertical offset- Returns:
- the offset rounded rectangle
-
shrink
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,bottomorleft.- Parameters:
top- how far to move the top side downwardsright- how far to move the right side to the leftbottom- how far to move the bottom side upwardsleft- how far to move the left side to the right- Returns:
- the resized rounded rectangle
-