Skip to content

Structure

UI element consists of a name, which should be a unique identifier. Using duplicate names may cause issues. parent, which is the name of element parent (Example: Background is a parent of Table, and Table is a parent of cells), fade out time in seconds and components, which are the properties of your element.

Components

There are multiple available components. Some are required, some are not. Rust client will use some default values when fields are needed but not defined by the UI

CuiRectTransformComponent

Position of the element

FieldTypeDescription
AnchorMaxstringthe upper right corner default: "1.0 1.0"
AnchorMinstringThe lower left corner, see UI position default: "0.0 0.0"
OffsetMaxstringUpper right corner, in pixels, relative to AnchorMin. default: "0.0 0.0"
OffsetMinstringLower left corner, in pixels, relative to AnchorMin. default: "0.0 0.0"
PivotstringPivot point for scaling and rotation. default: "0.5 0.5"
Rotationfloatrotation angle relative to pivot point. default: 0.0
SetParentstringdefine parent panel
SetTransformIndexintchange the order of a GameObject within its parent's hierarchy, default: -1
csharp
new CuiRectTransformComponent 
{ 
	AnchorMin = "0.5 0.5",  AnchorMax = "0.5 0.5", 
	OffsetMin="-100 -20", OffsetMax="100 20",
	Pivot = "0.5 0.5",
	Rotation = 0
},

CuiNeedsCursorComponent

Show a cursor that will let you click buttons and such.

FieldTypeDescription
Enabledbool?Select if component is visible or not, default: true
csharp
new CuiNeedsCursorComponent();

CuiNeedsKeyboardComponent

Keyboard input is needed for this UI.

FieldTypeDescription
Enabledbool?Select if component is visible or not, default: true
csharp
new CuiNeedsKeyboardComponent();

CuiImageComponent

Image with a sprite, material, color and cache.

FieldTypeDescription
ColorstringColor Field in RGBA format, see colors
Enabledbool?Select if component is visible or not, default: true
FadeInfloatFadein time in seconds
FillCenterbool?If true, render the center of a Tiled or Sliced image.
ImageTypeImage.Typesee Image.Type
ItemIdintItem ID, see RustHelp Item list
MaterialstringMaterial of background Material
PlaceholderParentIdstringParent Id
PngstringPng image
SkinIdulongSkin ID
SlicestringColor info for Png, see colors
Spritestringsee Image/Icon
csharp
new CuiImageComponent 
{ 
	Color = "0.30 0.30 0.30 1.0", 
	FadeIn = 0.1f,	
	Material = "assets/content/ui/uibackgroundblur.mat" 
},

CuiRawImageComponent

Raw image with a sprite, material, color, URL and cache.

FieldTypeDescription
ColorstringColor Field in RGBA format see colors
Enabledbool?Select if component is visible or not, default: true
FadeInfloatFadein time in seconds
MaterialstringMaterial of background Material
PlaceholderParentIdstringParent Id
Pngstringpng image ID
SpritestringSprite image
SteamIdstringsteam id of the avatar image
UrlstringURL of the raw image
csharp
new CuiRawImageComponent 
{ 
	Color = "0.30 0.30 0.30 1.0", 
	FadeIn = 0.1f,
	Material = "assets/content/ui/uibackgroundblur.mat"
},

CuiButtonComponent

Button with command to execute, and other atttributes.

FieldTypeDescription
ClosestringUI name to close
ColorstringColor Field in RGBA format see colors
ColorMultiplierfloatcolor multiplier
CommandstringCommand to execute when button is pressed
DisabledColorstringColor when button disabled
Enabledbool?Select if component is visible or not, default: true
FadeDurationfloatfade duration in sec, default 0.1
FadeInfloatFadein time in seconds
HighlightedColorstringColor when button highlighted
ImageTypeImage.Typesee image-type
MaterialstringMaterial of background, see Material
NormalColorstringNormal color of the button,see colors
PlaceholderParentIdstringParent Id
PressedColorstringColor when button is pressed, see colors
SelectedColorstringColor when button is selected, see colors
Spritestringsee Image/Icon
csharp
new CuiButtonComponent 
{
	Color = "0.20 0.30 0.40 1.0", 
	Command = "CommandName",
	Close = "UI.ClosePanelName",
	Material = "assets/icons/iconmaterial.mat"
},

CuiInputFieldComponent

Input field with default text attributes and command to run

FieldTypeDescription
AlignTextAnchorsee Align
Autofocusboolset input focus mode
CharsLimitintmaximum number of char, 0 = infinite
ColorstringColor Field in RGBA format see colors
CommandstringCommand to execute when button is pressed
Enabledbool?Select if component is visible or not, default: true
FadeInfloatFadein time in seconds
Fontstringsee fonts
FontSizeintSize of font
HudMenuInputboolblocks keyboard input like NeedsKeyboard but is used for UI in the inventory/crafting
IsPasswordboolpassword mode, hide input
LineTypeInputField.LineTypesee InputField.LineType
NeedsKeyboardboolblocks or allow keyboard input
PlaceholderIdstringId to identify this component
PlaceholderParentIdstringId to identify parent of this component
ReadOnlyboolSet the InputField to be read only
Textstringcurrent value of the input field
csharp
new CuiInputFieldComponent 
{
	Align = TextAnchor.MiddleCenter, 
	CharsLimit = 300, 
	Command = "CommandName", 
	FontSize = 20, 
	IsPassword = false, 
	Text = "Input field" 
},

CuiTextComponent

Text with value, font size, font, text align and color.

FieldTypeDescription
AlignTextAnchorsee Align, default: TextAnchor.UpperLef
ColorstringColor Field in RGBA string format, see colors
Enabledbool?Select if component is visible or not, default: true
FadeInfloatFadein time in seconds
Fontstringsee fonts, default: RobotoCondensed-Bold.ttf
FontSizeintSize of font , defalut: 14
TextstringText to display
VerticalOverflowVerticalWrapModesee VerticalWrapMode
csharp
new CuiTextComponent 
{ 
	Text = "Workbench view", 
	FontSize = 24, 
	Align = TextAnchor.MiddleCenter, 
	Color ="1 0 0 1" 
},

CuiOutlineComponent

Outline for an element with parameters.

FieldTypeDescription
ColorstringColor Field in RGBA format see colors
DistancestringNumber of pixels for outline size
Enabledbool?Select if component is visible or not, default: true
UseGraphicAlphaboolif present, use graphic alpha
csharp
new CuiOutlineComponent 
{ 
	Distance = "1.0 1.0", 
	Color = "1 1 1 1",
	UseGraphicAlpha = true
},

CuiCountdownComponent

Countdown that send a command at the end of count

FieldTypeDescription
CommandstringCommand to execute when countdown terminates
DestroyIfDoneboolIf present, the component will auto destroy
Enabledbool?Select if component is visible or not, default: true
EndTimefloatEnd time of the countter
FadeInfloatFadein time in seconds
Intervalfloattimer update interval. Min interval is 0.02 ( 50 times per sec )
NumberFormatstringformat, default is "0.####"
StartTimefloatInitial time of the counter
StepfloatValue to increase/decrement the counter
TimerFormatTimerFormatDefault: None, see TimerFormat
csharp
CuiCountdownComponent Countdown = new CuiCountdownComponent
{
	TimerFormat = TimerFormat.HoursMinutesSeconds,
	Step = 1, EndTime = 0f, StartTime = 100f, Interval = 1f, FadeIn=2.0f,
	Command = "Cmd.CountdownUi " + player.userID.ToString()
};

elements.Add(new CuiElement
{
	Name = "NameOfElement", 
	Parent = "NameOfPanel", 
	FadeOut = 1.0f,
	Components =
	{
	new CuiTextComponent{Text="Time left : %TIME_LEFT%", FontSize=14, Font="RobotoCondensed-Bold.ttf", Align=TextAnchor.MiddleCenter, Color="1.0 1.0 1.0 1.0" },
	Countdown
	}
});

CuiScrollViewComponent

Scroll component with parametrization

FieldTypeDescription
ContentTransformCuiRectTransformRectangle definition of the window
DecelerationRatefloatDeceleration rate
ElasticityfloatElasticity
Enabledbool?Select if component is visible or not, default: true
HorizontalboolEnable horizontal scrollbar
horizontalNormalizedPositionfloathorizontal scroll position as a value between 0.0 and 1.0, Default: 0, Left
HorizontalScrollbarCuiScrollbarParameters to define the scrollbar see CuiScrollbar
Inertiaboolflag to enable/disable Inertia
MovementTypeScrollRect. MovementTypesee ScrollRect. MovementType
ScrollSensitivityfloatScroll Sensitivity
VerticalboolEnable vertical scrollbar
verticalNormalizedPositionfloatvertical scroll position as a value between 0.0 and 1.0, Default: 1, top
VerticalScrollbarCuiScrollbarParameters to define the scrollbar, see CuiScrollbar
csharp
CuiElementContainer createScrollUI()
{
	CuiElementContainer elements = new CuiElementContainer();

	string mainpanel = elements.Add(new CuiPanel
	{
		Image = { Color = "0.3 0.3 0.6 0.8" },
		RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-200 -300", OffsetMax = "200 300" },
	}, "Overlay", UIScrollName, UIScrollName);

	elements.Add(new CuiElement
	{
		Name = "panel1",
		Parent = UIScrollName,
		Components =
			{
				new CuiRawImageComponent { Sprite = "assets/content/effects/crossbreed/fx gradient skewed.png", Color = "0.1 0.1 0.1 1.0" },
				new CuiRectTransformComponent { AnchorMin = "0.015 0.015", AnchorMax = "0.985 0.985" }
			}
	});

	elements.Add(new CuiElement
	{
		Parent = "panel1",
		Components =
			{
				new CuiTextComponent { Text = "Scroll example", FontSize=12, Align=TextAnchor.MiddleCenter },
				new CuiRectTransformComponent { AnchorMin = "0 1", AnchorMax = "1 1", OffsetMin = "0 -50", OffsetMax = "0 0" }                    
			}
	});

	elements.Add(new CuiButton
	{
		Button = { Color = "0.8 0.2 0.2 0.8", Command = "closescroll" },
		RectTransform = { AnchorMin = "0.91 0.93", AnchorMax = "0.98 0.98" },
		Text = { Text = "Close", FontSize = 8, Align = TextAnchor.MiddleCenter }
	}, mainpanel);

	CuiScrollViewComponent scrollUI = new CuiScrollViewComponent
	{
		ContentTransform = new CuiRectTransform { AnchorMin = "0 0.9", AnchorMax = "1 0.9", OffsetMin = "0 -1200", OffsetMax = "0 0" },
		Vertical = true,
		Horizontal = false,
		MovementType = ScrollRect.MovementType.Clamped,
		Elasticity = 0.25f,
		Inertia = true,
		DecelerationRate = 0.3f,
		ScrollSensitivity = 24f,
		VerticalScrollbar = new CuiScrollbar { AutoHide = true, Size = 20 },
		HorizontalScrollbar = new CuiScrollbar { AutoHide = true, Size = 20 },
	};

	elements.Add(new CuiElement
	{
		Name = "Scroller",
		Parent = "panel1",
		Components =
			{
			new CuiRawImageComponent { Sprite = "assets/content/effects/crossbreed/fx gradient skewed.png", Color = "0.15 0.25 0.25 0.8" },
			scrollUI,
			new CuiRectTransformComponent {AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 -50" },
			new CuiNeedsCursorComponent()
			}
		});

	int scrollSpacing = 28;
	int scrollSize = 24;
  
	for ( int i=0; i<40; i++) 
	{
		Puts($"OffsetMin =  {-i * scrollSpacing} /  OffsetMax =  {-i * scrollSpacing - scrollSize}");
		elements.Add(new CuiElement
		{
			Name = "Text_" + i,
			Parent = "Scroller",
			Components =
			{
			new CuiRawImageComponent { Color = "0.2 0.2 0.2 1.0", Sprite = "Assets/Content/UI/UI.Background.Tile.psd" },
			new CuiRectTransformComponent { AnchorMin = "0.03 0.97", AnchorMax = "0.75 0.97", OffsetMin = $"0 {-i*scrollSpacing-scrollSize}", OffsetMax = $"0 {-i*scrollSpacing}"},
			new CuiOutlineComponent { Distance= "2 2", Color= "0 0 0 0.06" },
			new CuiOutlineComponent { Distance= "4 4", Color= "0 0 0 0.025" },
			}
		});

		elements.Add(new CuiElement
		{
			Parent = "Text_" + i,
			Components =
			{
			new CuiTextComponent { Text = $"Item #{i+1}", Color = "0.95 0.95 0.95 1.0", FontSize = 10, Align = TextAnchor.MiddleLeft },          
			}
		});

		elements.Add(new CuiElement
		{
			Name = "Button_" + i,
			Parent = "Scroller",
			Components =
			{
			new CuiRawImageComponent { Color = "0.2 0.2 0.2 1.0", Sprite = "Assets/Content/UI/UI.Background.Tile.psd" },
			new CuiRectTransformComponent { AnchorMin = "0.77 0.97", AnchorMax = "0.97 0.97", OffsetMin = $"0 {-i*scrollSpacing-scrollSize}", OffsetMax = $"0 {-i*scrollSpacing}"},
			new CuiOutlineComponent { Distance= "2 2", Color= "0 0 0 0.06" }
			}
		});

		elements.Add(new CuiElement
		{
			Name = "ButtonText_" + i,
			Parent = "Button_" + i,
			Components =
			{
			new CuiTextComponent { Text = $"Button#{i+1}", Color = "0.95 0.95 0.95 1.0", FontSize = 10, Align = TextAnchor.MiddleCenter },
			new CuiRectTransformComponent { AnchorMin = "0.02 0.02", AnchorMax = "0.98 0.98"},
			}
		});

		elements.Add(new CuiElement
		{
			Name = "TheButton_" + i,
			Parent = "ButtonText_" + i,
			Components =
			{
				new CuiButtonComponent { Color = "0.8 0.2 0.2 0.8", Command = "ui.testscrollui "+ (i+1), ImageType= Image.Type.Tiled },
				new CuiRectTransformComponent { AnchorMin = "0.02 0.02", AnchorMax = "0.98 0.98" },
				new CuiOutlineComponent { Distance= "2 2", Color= "0 0 0 0.50" },
			}
		});

	}
	return elements;
}

CuiDraggableComponent

To create a draggable object

FieldTypeDescription
AllowSwappingbool?if true the draggable can be swapped with other draggables if dragged ontop of eachother
AnchorOffsetstringoffset from the draggable's initial position
DragAlphafloatif the alpha of the draggable's graphics should be lowered while being dragged.
DropAnywherebool?if false, the draggable will return to its last valid position (its initial position by default) unless swapped or attached to a slot
Enabledbool?Select if component is visible or not, default: true
Filterstringthe filter string this draggable should carry. work with CuiSlotComponent
KeepOnTopbool?if true the draggable will stay detached from its parent, reccomended for unrestricted draggables
LimitToParentbool?Limit the draggable to the parent
MaxDistancefloatHow far can you drag the object from its parent
MoveToAnchorboolif field present, move to anchor
ParentLimitIndexintif limitToParent is true, this index allows you to specify how many non slot parents it should traverse before finding the limit. If the slot has no filter, any draggable can be inserted. if the slot has a filter it only allows Draggables with a matching filter property.
ParentPaddingstringif limitToParent is true, specifies additional padding that the draggable should be contained. can be negative to allow the draggable to slightly travel outside the parent
PositionRPCPositionSendTypehow the position should be processed before being sent via RPCs. see PositionSendType
RebuildAnchorboolif field present, rebuild anchor

Depending on other settings the default value for the positionRPC field may change.

  • if maxDistance is used, the default will be RelativeAnchor
  • if limitToParent is used, the default will be NormalizedParent

Note: There are two hooks related to DraggableComponents. OnCuiDraggableDrag and OnCuiDraggableDrop

csharp
new CuiDraggableComponent 
{ 
	LimitToParent = false, 
	MaxDistance = -1f,
	AllowSwapping = false,
	DropAnywhere = true,
	DragAlpha = 1f,
	ParentLimitIndex = 1,
	Filter = "filter string",
	ParentPadding = "0 0",
	AnchorOffset = "0 0",
	KeepOnTop = false,
	PositionRPC = CommunityEntity.DraggablePositionSendType.Relative,
	MoveToAnchor = true,
	RebuildAnchor = true
},

CuiSlotComponent

To Define a filter component for the draggable objects

Slots use a filter system that allows to specify what draggables can be attached.

  • A slot with no filter allow any draggable to be inserted.
  • A slot with a filter only allows Draggables with a matching filter property.
FieldTypeDescription
Enabledbool?Select if component is visible or not, default: true
Filterstringthe filter string associated to this component.
csharp
new CuiSlotComponent 
{ 
	Filter = "filter string",
},

CuiLayoutGroupComponent

FieldTypeDescription
ChildAlignmentTextAnchorsee Align
ChildControlHeightbool?if true, child will control height of elements
ChildControlWidthbool?if true, child will control width of elements
ChildForceExpandHeightbool?if true, force height expansion
ChildForceExpandWidthbool?if true, force width expansion
ChildScaleHeightbool?if true, scale height
ChildScaleWidthbool?if true, scale width
Enabledbool?Select if component is visible or not, default: true
PaddingstringShorthand "padding" field: "l t r b" (or a single "x" to apply to all sides)
SpacingfloatDistance between elements
csharp
new CuiHorizontalLayoutGroupComponent 
{ 
	ChildAlignment = TextAnchor.UpperLeft,
	ChildControlHeight = true,
	ChildControlWidth = true,
	ChildForceExpandHeight = true,
	ChildForceExpandWidth = true,
	ChildScaleHeight = false,
	ChildScaleWidth = false,
	Padding = "x",
	Spacing = 0f,
},

CuiHorizontalLayoutGroupComponent

same elements as CuiLayoutGroupComponent, see CuiLayoutGroupComponent

CuiVerticalLayoutGroupComponent

same elements as CuiLayoutGroupComponent, see CuiLayoutGroupComponent

CuiGridLayoutGroupComponent

FieldTypeDescription
CellsizestringSize of the cell, default "100 100"
ChildAlignmentTextAnchorsee Align, default UpperLeft
ConstraintGridLayoutGroup.Constraintsee Constraint, default Flexible
ConstraintCountint32number of constraint
Enabledbool?Select if component is visible or not, default: true
PaddingstringShorthand "padding" field: "l t r b" (or a single "x" to apply to all sides)
Spacingstringspacing between cells, default "0 0"
StartAxisGridLayoutGroup.Axissee Axis, default Horizontal
StartCornerGridLayoutGroup.Cornersee Corner, default UpperLeft
csharp
new CuiGridLayoutGroupComponent 
{ 
	CellSize = "100 100",
	ChildAlignment = TextAnchor.UpperLeft,
	Constraint = GridLayoutGroup.Constraint.Flexible,
	ConstraintCount = 1,	
	Padding = "x",
	Spacing = "0 0",
	StartAxis = GridLayoutGroup.Axis.Horizontal,
	StartCorner = GridLayoutGroup.Corner.UpperLeft
},

CuiContentSizeFitterComponent

FieldTypeDescription
Enabledbool?Select if component is visible or not, default: true
HorizontalFitContentSizeFitter.FitModeFit mode, see FitMode, default Unconstrained
VerticalFitContentSizeFitter.FitModeFit mode, see FitMode, default Unconstrained
csharp
new CuiContentSizeFitterComponent 
{ 
	HorizontalFit = ContentSizeFitter.FitMode.Unconstrained,
	VerticalFit = ContentSizeFitter.FitMode.Unconstrained,
},

CuiLayoutElementComponent

FieldTypeDescription
Enabledbool?Select if component is visible or not, default: true
FlexibleHeightfloatadditional height space, if available, default 0.0
FlexibleWidthfloatadditional horizontal space, if available, default 0.0
IgnoreLayoutbool?number of constraint
MinHeightfloatMinimum required height
MinWidthfloatMinimum required width
PreferredHeightfloatpreferred Height, if space is available
PreferredWidthfloatpreferred Width, if space is available
csharp
new CuiLayoutElementComponent 
{ 
	FlexibleHeight = 0f,
	FlexibleWidth = 0f,
	IgnoreLayout = false,	
	MinHeight = -1f,
	MinWidth = -1f,
	PreferredHeight = 0f,
	PreferredWidth = 0f,
},

Element presets

Oxide provides you with a few presets for elements with predefined components, such as:

CuiElement

CuiElement is an assembly of single or multiple components. The CuiElement member will be defined through the elements.Add member.

FieldTypeDescription
ActivateSelfboolFlag to activate/deactivate this CuiElement without a complete resend
ComponentsList<ICuiComponent>a list of components to define the element
DestroyUIstringName of the UI to auto destroy
FadeOutfloatFade out time in seconds
NamestringName of the element.
ParentstringParent name of this element
UpdateboolUpdate flag
csharp
new CuiElement
{
	Name = "NameOfElement",
	Parent = "NameOfParent",
	Components =
		{
		new CuiRectTransformComponent {AnchorMin = "0 0", AnchorMax = "1 1", OffsetMax = "0 -50" },
		new CuiNeedsCursorComponent(),
		...
	}
},

CuiPanel

to show images or draw a nice background.

FieldTypeDescription
CursorEnabledboolCursor enabled for this UI
FadeOutfloatFade out time in seconds
ImageCuiImageComponentBackground image, required
KeyboardEnabledboolKeyboard input enabled for this UI
RawImageCuiRawImageComponentRaw image
RectTransformCuiRectTransformComponentRectangle for the panel, required
csharp
new CuiPanel
{
	Image = { Color = "0.3 0.3 0.3 0.8" },
	RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-200 -300", OffsetMax = "200 300" },
},

CuiButton

to create a button.

FieldTypeDescription
ButtonCuiButtonComponentButton to execute command, required
FadeOutfloatFade out time in seconds
RectTransformCuiRectTransformComponentRectangle for the button, required
TextCuiTextComponentText to display on the button, required
csharp
new CuiButton
{
	Button = {  },
	Text = { },
	RectTransform = { AnchorMin = "0.5 0.5", AnchorMax = "0.5 0.5", OffsetMin = "-100 -100", OffsetMax = "100 100" },
	FadeOut = 1f
},

CuiLabel

to show text.

FieldTypeDescription
FadeOutfloatFade out time in seconds
RectTransformCuiRectTransformComponentRectangle to display text, required
TextCuiTextComponentText to display, required
csharp
new CuiLabel 
{ 
	FadeOut = 0.5f,
	RectTransform = { AnchorMin = "0.5 0.5",  AnchorMax = "0.5 0.5" },
	Text = { Color = "1 0.5 0 1", FontSize = 18, Align = TextAnchor.MiddleCenter, Text = "Some text" },
};

CuiRectTransform

to define a rectangle

FieldTypeDescription
AnchorMaxstringUpper right corner
AnchorMinstringLower left corner see UI position
OffsetMaxstringUpper right corner, in pixels, relative to AnchorMin
OffsetMinstringLower left corner, in pixels, relative to AnchorMin
PivotstringPivot point. default: "0.5 0.5"
Rotationfloatrotation angle. default: 0.0
SetParentstringdefine parent panel
SetTransformIndexintchange the order of a GameObject within its parent's hierarchy, default: -1
csharp
new CuiRectTransform 
{ 
	AnchorMin = "0.5 0.5",  AnchorMax = "0.5 0.5", 
	OffsetMin="-100 -20", OffsetMax="100 20",
	Pivot = "0.5 0.5",
	Rotation = 0
},

CuiScrollbar

To draw a scrollbar

FieldTypeDescription
AutoHideboolAuto hides the scroller
Enabledbool?Select if component is visible or not, default: true
HandleColorstringColor of handle see colors
HandleSpritestringSprite of handle
HighlightColorstringColor when highlighted handle, see colors
InvertboolInvert action of scroller
PressedColorstringColor when pressed handle, see colors
Sizefloatsize of the scrollbar
TrackColorstringcolor of the track, see colors
TrackSpritestringSprite of the track
csharp
new CuiScrollbar
{
	AutoHide = true,
	Size = 20,
	HandleColor = "0.23 0.23 0.49 1.0",
	HighlightColor = "0.23 0.23 0.69 1.0",
	PressedColor = "0.23 0.23 0.99 1.0",
	TrackColor = "0.5 0.5 0.5 1.0",
};

They can be used to have predefined fields in case you want to modify them without casting ICuiComponent to the needed type, and to simplify UI creation.

CuiHelper

Adding UI

You made a few buttons and a nice background. To send them you have to create a container first, which is CuiElementContainer:

csharp
var container = new CuiElementContainer();
var NameOfElement = container.Add(myBackground, "Overlay", "NameOfElement");
container.Add(myCuiComponent);

There are multiple Add methods - one is for presets, which lets you set the parent and name. If you do not specify a name, a random GUID will be used. Name will also be returned. However, if you have a CuiElement, it works as just a List<CuiElement> so you have to manually specify parent and name.

In order to send UI to the player, use the AddUi method:

csharp
CuiHelper.AddUi(basePlayer, container);

or

csharp
CuiHelper.AddUi(basePlayer, jsonString);

where jsonString is the Json formatted string of the UI, generated by the Json conversion of the CuiElementContainer.

Destroying UI

If you want to remove your UI, you should call DestroyUi and specify element ID (name) to remove like that :

csharp
CuiHelper.DestroyUi(basePlayer, NameOfElement);

GetColor

Convert a string formatted ICuiColor "R G B A", to a type Color RGBA {color.r, color.g, color.b, color.a}

SetColor

Convert a type Color RGBA to a string formatted ICuiColor "R G B A"

GetGuid

Generate a new unique Guid string.

CuiElementContainer

CuiElementContainer is the top object to create an UI. It will contain multiple elements Once the container is created, we add a CuiPanel and a CuiElement with multiple component in the CuiElement Finally, the CuiHelper.AddUi will send the UI to a player for display.

But in the following example, we use the TechTree layer so the UI will only be visible when opening workbench. You can have a look at layer visibility for proper layer to use.

csharp
private const string UI_WORKBENCHOVERLAY = "UI_WorkbenchOverlay";
private void WorkbenchUi(BasePlayer player)
{
 CuiElementContainer elements = new CuiElementContainer();
 
 string panel = elements.Add(new CuiPanel
 {
  Image = { Color = "0 0 0 0.63", Sprite = "assets/content/materials/highlight.png", Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat" },
  RectTransform = { AnchorMin = "0.1 0.7", AnchorMax = "0.9 0.8" }
 }, "TechTree", UI_WORKBENCHOVERLAY);

 elements.Add(new CuiLabel
 {
  Text = {
  Text = "Message to overlay in workbench",
  FontSize = 14, Align = TextAnchor.MiddleCenter, Color = "1 1 1 1" },
  RectTransform = { AnchorMin = "0.02 0.5", AnchorMax = "0.98 0.98" }
 }, panel);

 elements.Add(new CuiElement
 {
  Parent = panel,
  Components =
  {
   new CuiTextComponent { Text = "Workbench view", FontSize = 24, Align = TextAnchor.MiddleCenter, Color ="1 0 0 1" },
   new CuiOutlineComponent { Distance = "0.5 0.5", Color = "1 1 1 1" },
   new CuiRectTransformComponent { AnchorMin = "0.02 0.02",  AnchorMax = "0.98 0.5" },
  }
 });
 CuiHelper.AddUi(player, elements);
}

Cache

If you are using a URL, client will download the image from the link you specify every time, and its quality might be changed depending on the quality settings. To avoid both issues, you can use "cache" a.k.a. Png option.

Game provides you with a Png option for UI, which is the image ID on the server. You have to store the image server-side first, for example you could use Image Library. After doing so you provide your client with the ID of this image, and client will download it from the server and store in its cache.

UI position

There are two types of positions - Anchor and Offset. Both have Min and Max. Min value is the bottom left corner position, and Max is the top right one. Both Min and Max have X and Y values and are such string: "X Y".

Anchors are numbers that represent width and height in percents (%) from 0.0 (0%) to 1.0 (100%).

Offsets are accurate values that are width and height, in pixels, relative to a 1280x720 resolution. Example: You made a 100x100 box for 1280x720 and if you switch to 2560x1440, it will be 200x200 pixels.

Anchors are applied before offsets. If you want offsets to be relative to the screen center, make all anchors 0.5 0.5 so that both corners are in the center. Then to make a 100x100 box you should use offsets -50 -50 for bottom left corner and 50 50 for top right one.

Colors

Rust UI is using normalized RGBA colors. It means that this nice red color (R255 G102 B102 A255) would be 1.0 0.4 0.4 1.0.

The fourth and last number is normalized Alpha (transparency), 0.0 is completely transparent and 1.0 is 100% opaque, like in the example above.

Fonts

All available fonts are:

  • DroidSansMono.ttf
  • PermanentMarker.ttf
  • RobotoCondensed-Bold.ttf(Default)
  • RobotoCondensed-Regular.ttf

Material

  • assets/content/ui/ui.saturation.shader
  • assets/content/ui/ui.thresholdcolor.shader
  • assets/content/ui/uibackgroundblur-ingamemenu.mat
  • assets/content/ui/uibackgroundblur-mainmenu.mat
  • assets/content/ui/uibackgroundblur-notice.mat
  • assets/content/ui/uibackgroundblur.mat
  • assets/content/ui/uibackgroundblur.shader
  • assets/content/image effects/darkclamp/darknessclamp.mat
  • assets/content/image effects/linear fog/linearfog.mat
  • assets/content/image effects/scope/defaultscope.mat
  • assets/content/materials/cable.mat
  • assets/content/materials/collider_mesh.mat
  • assets/content/materials/collider_mesh_convex.mat
  • assets/content/materials/collider_trigger.mat
  • assets/content/materials/deployable/deployable_acceptable.mat
  • assets/content/materials/deployable/deployable_denied.mat
  • assets/content/materials/displacement/foliagedisplace_circle.mat
  • assets/content/materials/displacement/foliagedisplace_square.mat
  • assets/content/materials/gradient.mat
  • assets/content/materials/ground.mat
  • assets/content/materials/guide_bad.mat
  • assets/content/materials/guide_good.mat
  • assets/content/materials/guide_highlight.mat
  • assets/content/materials/guide_neutral.mat
  • assets/content/materials/itemmaterial.mat
  • assets/content/materials/male.material.mat
  • assets/content/shaders/gl/gl opaque.mat
  • assets/content/shaders/gl/gl transparent.mat
  • assets/content/ui/binocular_overlay.mat
  • assets/content/ui/goggle_overlay.mat
  • assets/content/ui/helmet_slit_overlay.mat
  • assets/content/ui/ingame/compass/compassstrip.mat
  • assets/content/ui/namefontmaterial.mat
  • assets/content/ui/playerpreviewglow.mat
  • assets/content/ui/playerpreviewremovesegments.mat
  • assets/content/ui/playerpreviewsegments.mat
  • assets/content/ui/scope_1.mat
  • assets/content/ui/scope_2.mat
  • assets/content/ui/ui.maskclear.mat
  • assets/content/ui/uibackgroundblur-ingamemenu.mat
  • assets/content/ui/uibackgroundblur-notice.mat
  • assets/content/ui/uibackgroundblur.mat
  • assets/icons/fogofwar.mat
  • assets/icons/greyout.mat
  • assets/icons/iconmaterial.mat (Default)

UI data types

Align

  • TextAnchor.UpperLeft
  • TextAnchor.UpperCenter
  • TextAnchor.UpperRight
  • TextAnchor.MiddleLeft
  • TextAnchor.MiddleCenter
  • TextAnchor.MiddleRight
  • TextAnchor.LowerLeft
  • TextAnchor.LowerCenter
  • TextAnchor.LowerRight

Image.Type

  • Image.Type.Simple
  • Image.Type.Sliced
  • Image.Type.Tiled
  • Image.Type.Filled

InputField.LineType

  • TextAnchor.SingleLine
  • TextAnchor.MultiLineSubmit
  • TextAnchor.MultiLineNewline

VerticalWrapMode

  • VerticalWrapMode.Truncate
  • VerticalWrapMode.Overflow

Constraint

  • GridLayoutGroup.Constraint.Flexible
  • GridLayoutGroup.Constraint.FixedColumnCount
  • GridLayoutGroup.Constraint.FixedRowCount

Axis

  • GridLayoutGroup.Axis.Horizontal
  • GridLayoutGroup.Axis.Vertical

Corner

  • GridLayoutGroup.Corner.UpperLeft
  • GridLayoutGroup.Corner.UpperRight
  • GridLayoutGroup.Corner.LowerLeft
  • GridLayoutGroup.Corner.LowerRight

TimerFormat

  • None
  • SecondsHundreth
  • MinutesSeconds
  • MinutesSecondsHundreth
  • HoursMinutes
  • HoursMinutesSeconds
  • HoursMinutesSecondsMilliseconds
  • HoursMinutesSecondsTenths
  • DaysHoursMinutes
  • DaysHoursMinutesSeconds

ScrollRect.MovementType

  • Unrestricted
  • Elastic
  • Clamped

PositionSendType

  • CommunityEntity.DraggablePositionSendType.NormalizedScreen
      the Position normalized to the Screen resolution
  • CommunityEntity.DraggablePositionSendType.NormalizedParent
      the Position normalized to the panel's limitParent, even if the setting is not used
  • CommunityEntity.DraggablePositionSendType.Relative
      the offset from the Draggable's last position
  • CommunityEntity.DraggablePositionSendType.RelativeAnchor
      the offset from the anchor

FitMode

  • ContentSizeFitter.FitMode.Unconstrained
  • ContentSizeFitter.FitMode.MinSize
  • ContentSizeFitter.FitMode.PreferredSize

Layers

You can use these specific "layers" as parents for your UI, because they are always present:

  • Overall the top most layer in front of all of Rust's UI
  • Overlay top layer in front of most of Rust's UI
  • OverlayNonScaled Like Overlay, scale to resolution but not to client UI scale setting
  • Hud.Menu the layer where rust positions menus like your inventory
  • Hud the layer where Rust stores most HUD elements like your status bar
  • Under the lowermost layer, your UI will appear behind all of Rust's UI
  • UnderNonScaled like Under, scale to resolution but not to client UI scale setting

For the other layers, UI will only be visible in the respective view.

  • Inventory
  • Crafting
  • Contacts
  • Clans
  • TechTree
  • Map

Layers visibility

LayerNormalInventoryCraftingContactsClansTechTreeMap
OverallXXXXXXX
OverlayXXXXXXX
Overlay Non ScaledXXXXXXX
Hud.MenuXXXXXXX
HudX11111X
UnderX11111
Under Non ScaledX11111
InventoryX
CraftingX
ContactsX
ClansX
TechTreeX
MapX
  1. Visible but blurred, under the view background.

Released under the MIT License.