reckfellENGINE

NinePatchRect

Resizable textured panel with preserved border regions.

On this page
class NinePatchRectReckfellSharpInherits Control

NinePatchRect splits a texture into nine regions using four PatchMargin values: corners retain local dimensions while edges and center stretch or repeat according to AxisStretchHorizontal/Vertical. Use it for decorative frames when ordinary TextureRect stretching distorts corners.

Assign Texture, set nonnegative left, right, top and bottom border thicknesses, then size the Control. Margins use source-region pixels; their sums must fit inside that region. Leave positive center width/height for repeated areas. The setter validates Side but does not constrain the margin value itself: validate external data.

Intrinsic minimum size is (Left + Right, Top + Bottom), even without Texture. For example, horizontal borders 8/12 and vertical borders 6/10 produce minimum 20 × 16. CustomMinimumSize can increase it. PatchMargin defines texture slices rather than content padding: NinePatchRect is not a Container and does not lay out children. Add an appropriate container for layout; consider PanelContainer for a theme-based panel.

RegionRect selects a source area in pixels rather than 0…1 UVs. A zero Rect2 uses the whole texture. Stretch scales a region; Tile repeats with a potentially partial last tile; TileFit adjusts repetition scale to fit a whole number. Each axis is configured separately. DrawCenter = false only suppresses center drawing, without changing minimum size or creating a child-content area.

TextureChanged is emitted when the Texture reference changes, including clearing to null; assigning the same resource again does not emit it. Changes to the resource itself refresh drawing without emitting this NinePatchRect signal. Texture remains shared. MouseFilter defaults to Ignore so the decorative frame does not intercept mouse input.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

NinePatchRectConstructor
# NinePatchRect
C#
public NinePatchRect();

Creates a decorative frame without a texture: margins 0, DrawCenter = true, both axes Stretch, zero RegionRect, MouseFilter = Ignore.

Properties9

AxisStretchHorizontalProperty
# AxisStretchHorizontal
C#
public NinePatchRect.AxisStretchMode AxisStretchHorizontal { get; set; }

Horizontal interior-region mode: Stretch scales, Tile repeats, TileFit adjusts to a whole repeat count. Default Stretch. Does not change the PatchMargin-derived minimum.

AxisStretchVerticalProperty
# AxisStretchVertical
C#
public NinePatchRect.AxisStretchMode AxisStretchVertical { get; set; }

Vertical interior-region mode: Stretch, Tile or TileFit. Independent of the horizontal setting; PatchMargin defines top/bottom border thickness.

DrawCenterProperty
# DrawCenter
C#
public bool DrawCenter { get; set; }

Draw the center region, default true. false retains the frame and existing minimum size. Does not control children, layout or mouse hit testing.

PatchMarginBottomProperty
# PatchMarginBottom
C#
public int PatchMarginBottom { get; set; }

Bottom border thickness in source-region pixels, default 0. Contributes to minimum-size sums rather than content padding. Use a nonnegative value that fits the source area.

PatchMarginLeftProperty
# PatchMarginLeft
C#
public int PatchMarginLeft { get; set; }

Left border thickness in source-region pixels, default 0. Contributes to minimum-size sums rather than content padding. Use a nonnegative value that fits the source area.

PatchMarginRightProperty
# PatchMarginRight
C#
public int PatchMarginRight { get; set; }

Right border thickness in source-region pixels, default 0. Contributes to minimum-size sums rather than content padding. Use a nonnegative value that fits the source area.

PatchMarginTopProperty
# PatchMarginTop
C#
public int PatchMarginTop { get; set; }

Top border thickness in source-region pixels, default 0. Contributes to minimum-size sums rather than content padding. Use a nonnegative value that fits the source area.

RegionRectProperty
# RegionRect
C#
public Rect2 RegionRect { get; set; }

Source area in texture pixels rather than normalized UVs. Zero Rect2 means the whole texture. Does not change PatchMargin or Control minimum; choose an area that fits all borders.

TextureProperty
# Texture
C#
public Texture2D Texture { get; set; }

Shared Texture2D to slice. Reference replacement, including null, emits TextureChanged; assigning the same reference does not. Margins rather than texture dimensions define minimum size.

Methods12

GetHAxisStretchModeNinePatchRect.AxisStretchMode
# GetHAxisStretchMode
C#
public NinePatchRect.AxisStretchMode GetHAxisStretchMode();

Horizontal interior-region mode: Stretch scales, Tile repeats, TileFit adjusts to a whole repeat count. Default Stretch. Does not change the PatchMargin-derived minimum.

Returns NinePatchRect.AxisStretchMode

Current stored setting.

GetPatchMarginint
# GetPatchMargin
C#
public int GetPatchMargin(Side margin);

Returns selected border thickness in source-region pixels. A slicing boundary rather than child-content padding.

Parameters
NameTypeDefault
marginSide—
margin

Selected Side.Left, Top, Right or Bottom.

Returns int

Current stored setting.

GetRegionRectRect2
# GetRegionRect
C#
public Rect2 GetRegionRect();

Source area in texture pixels rather than normalized UVs. Zero Rect2 means the whole texture. Does not change PatchMargin or Control minimum; choose an area that fits all borders.

Returns Rect2

Current stored setting.

GetTextureTexture2D
# GetTexture
C#
public Texture2D GetTexture();

Shared Texture2D to slice. Reference replacement, including null, emits TextureChanged; assigning the same reference does not. Margins rather than texture dimensions define minimum size.

Returns Texture2D

Current shared Texture2D reference, or null.

GetVAxisStretchModeNinePatchRect.AxisStretchMode
# GetVAxisStretchMode
C#
public NinePatchRect.AxisStretchMode GetVAxisStretchMode();

Vertical interior-region mode: Stretch, Tile or TileFit. Independent of the horizontal setting; PatchMargin defines top/bottom border thickness.

Returns NinePatchRect.AxisStretchMode

Current stored setting.

IsDrawCenterEnabledbool
# IsDrawCenterEnabled
C#
public bool IsDrawCenterEnabled();

Draw the center region, default true. false retains the frame and existing minimum size. Does not control children, layout or mouse hit testing.

Returns bool

Current stored setting.

SetDrawCentervoid
# SetDrawCenter
C#
public void SetDrawCenter(bool drawCenter);

Draw the center region, default true. false retains the frame and existing minimum size. Does not control children, layout or mouse hit testing.

Parameters
NameTypeDefault
drawCenterbool—
drawCenter

Draw the center region, default true. false retains the frame and existing minimum size. Does not control children, layout or mouse hit testing.

SetHAxisStretchModevoid
# SetHAxisStretchMode
C#
public void SetHAxisStretchMode(NinePatchRect.AxisStretchMode mode);

Horizontal interior-region mode: Stretch scales, Tile repeats, TileFit adjusts to a whole repeat count. Default Stretch. Does not change the PatchMargin-derived minimum.

Parameters
NameTypeDefault
modeNinePatchRect.AxisStretchMode—
mode

Horizontal interior-region mode: Stretch scales, Tile repeats, TileFit adjusts to a whole repeat count. Default Stretch. Does not change the PatchMargin-derived minimum.

SetPatchMarginvoid
# SetPatchMargin
C#
public void SetPatchMargin(Side margin, int value);

Sets selected border thickness in pixels and refreshes minimum size. Side must be valid; negative/excessive sizes are not automatically constrained. Keep border sums within the source region.

Parameters
NameTypeDefault
marginSide—
valueint—
margin

Selected Side.Left, Top, Right or Bottom.

value

Nonnegative border thickness in source-region pixels; validate opposite-border sums.

SetRegionRectvoid
# SetRegionRect
C#
public void SetRegionRect(Rect2 rect);

Source area in texture pixels rather than normalized UVs. Zero Rect2 means the whole texture. Does not change PatchMargin or Control minimum; choose an area that fits all borders.

Parameters
NameTypeDefault
rectRect2—
rect

Source area in texture pixels rather than normalized UVs. Zero Rect2 means the whole texture. Does not change PatchMargin or Control minimum; choose an area that fits all borders.

SetTexturevoid
# SetTexture
C#
public void SetTexture(Texture2D texture);

Shared Texture2D to slice. Reference replacement, including null, emits TextureChanged; assigning the same reference does not. Margins rather than texture dimensions define minimum size.

Parameters
NameTypeDefault
textureTexture2D—
texture

Shared Texture2D, or null to clear drawing.

SetVAxisStretchModevoid
# SetVAxisStretchMode
C#
public void SetVAxisStretchMode(NinePatchRect.AxisStretchMode mode);

Vertical interior-region mode: Stretch, Tile or TileFit. Independent of the horizontal setting; PatchMargin defines top/bottom border thickness.

Parameters
NameTypeDefault
modeNinePatchRect.AxisStretchMode—
mode

Vertical interior-region mode: Stretch, Tile or TileFit. Independent of the horizontal setting; PatchMargin defines top/bottom border thickness.

Signals and events1

TextureChangedEvent
# TextureChanged
C#
public event Action TextureChanged;

Texture reference changed, including null. Not emitted for same-resource reassignment or the resource’s own Changed. Observe the resource’s signal for internal changes.

NinePatchRect.AxisStretchMode

ValueDescription
Stretch = 0

Stretches the center texture across the NinePatchRect. This may cause the texture to be distorted.

Tile = 1

Repeats the center texture across the NinePatchRect. This won't cause any visible distortion. The texture must be seamless for this to work without displaying artifacts between edges.

TileFit = 2

Repeats the center texture across the NinePatchRect, but will also stretch the texture to make sure each tile is visible in full. This may cause the texture to be distorted, but less than NinePatchRect.AxisStretchMode.Stretch. The texture must be seamless for this to work without displaying artifacts between edges.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.