Class ReorderableListControl
Base class for custom reorderable list control.
Namespace: Unity.VisualScripting.ReorderableList
Syntax
public class ReorderableListControl
Constructors
ReorderableListControl()
Initializes a new instance of ReorderableListControl.
Declaration
public ReorderableListControl()
ReorderableListControl(ReorderableListFlags)
Initializes a new instance of ReorderableListControl.
Declaration
public ReorderableListControl(ReorderableListFlags flags)
Parameters
Type | Name | Description |
---|---|---|
ReorderableListFlags | flags | Optional flags which affect behavior of control. |
Fields
AnchorBackgroundColor
Background color of anchor list item.
Declaration
public static readonly Color AnchorBackgroundColor
Field Value
Type | Description |
---|---|
Color |
CommandClearAll
Content for "Clear All" command.
Declaration
protected static readonly GUIContent CommandClearAll
Field Value
Type | Description |
---|---|
GUIContent |
CommandDuplicate
Content for "Duplicate" command.
Declaration
protected static readonly GUIContent CommandDuplicate
Field Value
Type | Description |
---|---|
GUIContent |
CommandInsertAbove
Content for "Insert Above" command.
Declaration
protected static readonly GUIContent CommandInsertAbove
Field Value
Type | Description |
---|---|
GUIContent |
CommandInsertBelow
Content for "Insert Below" command.
Declaration
protected static readonly GUIContent CommandInsertBelow
Field Value
Type | Description |
---|---|
GUIContent |
CommandMoveToBottom
Content for "Move to Bottom" command.
Declaration
protected static readonly GUIContent CommandMoveToBottom
Field Value
Type | Description |
---|---|
GUIContent |
CommandMoveToTop
Content for "Move to Top" command.
Declaration
protected static readonly GUIContent CommandMoveToTop
Field Value
Type | Description |
---|---|
GUIContent |
CommandRemove
Content for "Remove" command.
Declaration
protected static readonly GUIContent CommandRemove
Field Value
Type | Description |
---|---|
GUIContent |
DefaultContextHandler
Default functionality to handle context command.
Declaration
protected static readonly GenericMenu.MenuFunction2 DefaultContextHandler
Field Value
Type | Description |
---|---|
GenericMenu.MenuFunction2 |
Examples
Can be used when adding custom items to the context menu:
protected override void AddItemsToMenu(GenericMenu menu, int itemIndex, IReorderableListAdaptor adaptor) {
var specialCommand = new GUIContent("Special Command");
menu.AddItem(specialCommand, false, defaultContextHandler, specialCommand);
}
function AddItemsToMenu(menu:GenericMenu, itemIndex:int, list:IReorderableListAdaptor) {
var specialCommand = new GUIContent('Special Command');
menu.AddItem(specialCommand, false, defaultContextHandler, specialCommand);
}
See Also
TargetBackgroundColor
Background color of target slot when dragging list item.
Declaration
public static readonly Color TargetBackgroundColor
Field Value
Type | Description |
---|---|
Color |
Properties
ContainerStyle
Gets or sets style used to draw background of list control.
Declaration
public GUIStyle ContainerStyle { get; set; }
Property Value
Type | Description |
---|---|
GUIStyle |
See Also
CurrentItemTotalPosition
Gets the total position of the list item that is currently being drawn.
Declaration
public static Rect CurrentItemTotalPosition { get; }
Property Value
Type | Description |
---|---|
Rect |
Remarks
The value of this property should be ignored for Layout type events when using reorderable list controls with automatic layout.
CurrentListControlID
Gets the control ID of the list that is currently being drawn.
Declaration
public static int CurrentListControlID { get; }
Property Value
Type | Description |
---|---|
Int32 |
CurrentListPosition
Gets the position of the list control that is currently being drawn.
Declaration
public static Rect CurrentListPosition { get; }
Property Value
Type | Description |
---|---|
Rect |
Remarks
The value of this property should be ignored for Layout type events when using reorderable list controls with automatic layout.
Flags
Gets or sets flags which affect behavior of control.
Declaration
public ReorderableListFlags Flags { get; set; }
Property Value
Type | Description |
---|---|
ReorderableListFlags |
FooterButtonStyle
Gets or sets style used to draw footer buttons.
Declaration
public GUIStyle FooterButtonStyle { get; set; }
Property Value
Type | Description |
---|---|
GUIStyle |
See Also
HorizontalLineAtEnd
Gets or sets a boolean value indicating whether a horizontal line should be shown below the last list item at the end of the list control.
Declaration
public bool HorizontalLineAtEnd { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
Horizontal line is not drawn for an empty list regardless of the value of this property.
HorizontalLineAtStart
Gets or sets a boolean value indicating whether a horizontal line should be shown above the first list item at the start of the list control.
Declaration
public bool HorizontalLineAtStart { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
Horizontal line is not drawn for an empty list regardless of the value of this property.
HorizontalLineColor
Gets or sets the color of the horizontal lines that appear between list items.
Declaration
public Color HorizontalLineColor { get; set; }
Property Value
Type | Description |
---|---|
Color |
ItemButtonStyle
Gets or sets style used to draw list item buttons (like the remove button).
Declaration
public GUIStyle ItemButtonStyle { get; set; }
Property Value
Type | Description |
---|---|
GUIStyle |
See Also
VerticalSpacing
Gets or sets the vertical spacing below the reorderable list control.
Declaration
public float VerticalSpacing { get; set; }
Property Value
Type | Description |
---|---|
Single |
Methods
AddItem(IReorderableListAdaptor)
Add item at end of list and raises the event ItemInserted.
Declaration
protected void AddItem(IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
AddItemsToMenu(GenericMenu, Int32, IReorderableListAdaptor)
Invoked to generate context menu for list item.
Declaration
protected virtual void AddItemsToMenu(GenericMenu menu, int itemIndex, IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
GenericMenu | menu | Menu which can be populated. |
Int32 | itemIndex | Zero-based index of item which was right-clicked. |
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
CalculateListHeight(Int32, Single)
Calculate height of list control in pixels.
Declaration
public float CalculateListHeight(int itemCount, float itemHeight)
Parameters
Type | Name | Description |
---|---|---|
Int32 | itemCount | Count of items in list. |
Single | itemHeight | Fixed height of list item. |
Returns
Type | Description |
---|---|
Single | Required list height in pixels. |
CalculateListHeight(IReorderableListAdaptor)
Calculate height of list control in pixels.
Declaration
public float CalculateListHeight(IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Returns
Type | Description |
---|---|
Single | Required list height in pixels. |
ClearAll(IReorderableListAdaptor)
Remove all items from list.
Declaration
protected bool ClearAll(IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Returns
Type | Description |
---|---|
Boolean | Returns a value of |
Remarks
The event ItemRemoving is raised for each item prior to clearing array and allows entire operation to be cancelled.
DoCommand(String, Int32, IReorderableListAdaptor)
Call to manually perform command.
Declaration
public bool DoCommand(string commandName, int itemIndex, IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
String | commandName | Name of command. This is the text shown in the context menu. |
Int32 | itemIndex | Zero-based index of item which was right-clicked. |
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Returns
Type | Description |
---|---|
Boolean | A value of |
Remarks
Warning message is logged to console if attempted to execute unknown command.
DoCommand(GUIContent, Int32, IReorderableListAdaptor)
Call to manually perform command.
Declaration
public bool DoCommand(GUIContent command, int itemIndex, IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
GUIContent | command | Content representing command. |
Int32 | itemIndex | Zero-based index of item which was right-clicked. |
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Returns
Type | Description |
---|---|
Boolean | A value of |
Remarks
Warning message is logged to console if attempted to execute unknown command.
Draw(IReorderableListAdaptor)
Declaration
public void Draw(IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor |
Draw(IReorderableListAdaptor, ReorderableListControl.DrawEmpty)
Declaration
public void Draw(IReorderableListAdaptor adaptor, ReorderableListControl.DrawEmpty drawEmpty)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor | |
ReorderableListControl.DrawEmpty | drawEmpty |
Draw(Rect, IReorderableListAdaptor)
Draw list control with absolute positioning.
Declaration
public void Draw(Rect position, IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
Rect | position | |
IReorderableListAdaptor | adaptor |
Draw(Rect, IReorderableListAdaptor, ReorderableListControl.DrawEmptyAbsolute)
Draw list control with absolute positioning.
Declaration
public void Draw(Rect position, IReorderableListAdaptor adaptor, ReorderableListControl.DrawEmptyAbsolute drawEmpty)
Parameters
Type | Name | Description |
---|---|---|
Rect | position | Position of list control in GUI. |
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
ReorderableListControl.DrawEmptyAbsolute | drawEmpty | Delegate for drawing empty list. |
DrawControlFromState(IReorderableListAdaptor, ReorderableListControl.DrawEmpty, ReorderableListFlags)
Generate and draw control from state object.
Declaration
public static void DrawControlFromState(IReorderableListAdaptor adaptor, ReorderableListControl.DrawEmpty drawEmpty, ReorderableListFlags flags)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
ReorderableListControl.DrawEmpty | drawEmpty | Delegate for drawing empty list. |
ReorderableListFlags | flags | Optional flags to pass into list field. |
DrawControlFromState(Rect, IReorderableListAdaptor, ReorderableListControl.DrawEmptyAbsolute, ReorderableListFlags)
Generate and draw control from state object.
Declaration
public static void DrawControlFromState(Rect position, IReorderableListAdaptor adaptor, ReorderableListControl.DrawEmptyAbsolute drawEmpty, ReorderableListFlags flags)
Parameters
Type | Name | Description |
---|---|---|
Rect | position | Position of control. |
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
ReorderableListControl.DrawEmptyAbsolute | drawEmpty | Delegate for drawing empty list. |
ReorderableListFlags | flags | Optional flags to pass into list field. |
DrawDropIndicator(Rect)
Draws drop insertion indicator.
Declaration
protected virtual void DrawDropIndicator(Rect position)
Parameters
Type | Name | Description |
---|---|---|
Rect | position | Position if the drop indicator. |
Remarks
This method is only ever called during repaint events.
DrawSizeField(String, IReorderableListAdaptor)
Draw list size field with automatic layout and a custom prefix label.
Declaration
public void DrawSizeField(string label, IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
String | label | Prefix label for the control. |
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
DrawSizeField(IReorderableListAdaptor)
Draw list size field with automatic layout and the default prefix label.
Declaration
public void DrawSizeField(IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
DrawSizeField(GUIContent, IReorderableListAdaptor)
Draw list size field with automatic layout and a custom prefix label.
Declaration
public void DrawSizeField(GUIContent label, IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
GUIContent | label | Prefix label for the control. |
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Remarks
Specify a value of GUIContent.none
for argument label
to omit prefix label from the drawn control.
DrawSizeField(Rect, String, IReorderableListAdaptor)
Draw list size field with absolute positioning and a custom prefix label.
Declaration
public void DrawSizeField(Rect position, string label, IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
Rect | position | Position of list control in GUI. |
String | label | Prefix label for the control. |
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
DrawSizeField(Rect, IReorderableListAdaptor)
Draw list size field with absolute positioning with the default prefix label.
Declaration
public void DrawSizeField(Rect position, IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
Rect | position | Position of list control in GUI. |
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
DrawSizeField(Rect, GUIContent, IReorderableListAdaptor)
Draw list size field with absolute positioning and a custom prefix label.
Declaration
public void DrawSizeField(Rect position, GUIContent label, IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
Rect | position | Position of list control in GUI. |
GUIContent | label | Prefix label for the control. |
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Remarks
Specify a value of GUIContent.none
for argument label
to omit prefix label from the drawn control.
DuplicateItem(IReorderableListAdaptor, Int32)
Duplicate specified item and raises the event ItemInserted.
Declaration
protected void DuplicateItem(IReorderableListAdaptor adaptor, int itemIndex)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Int32 | itemIndex | Zero-based index of item. |
HandleCommand(String, Int32, IReorderableListAdaptor)
Invoked to handle context command.
Declaration
protected virtual bool HandleCommand(string commandName, int itemIndex, IReorderableListAdaptor adaptor)
Parameters
Type | Name | Description |
---|---|---|
String | commandName | Name of command. This is the text shown in the context menu. |
Int32 | itemIndex | Zero-based index of item which was right-clicked. |
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Returns
Type | Description |
---|---|
Boolean | A value of |
Remarks
It is important to set the value of GUI.changed
to true
if any
changes are made by command handler.
Default command handling functionality can be inherited:
protected override bool HandleCommand(string commandName, int itemIndex, IReorderableListAdaptor adaptor) {
if (base.HandleCommand(itemIndex, adaptor))
return true;
// Place custom command handling code here...
switch (commandName) {
case "Your Command":
return true;
}
return false;
}
function HandleCommand(commandName:String, itemIndex:int, adaptor:IReorderableListAdaptor):boolean {
if (base.HandleCommand(itemIndex, adaptor))
return true;
// Place custom command handling code here...
switch (commandName) {
case 'Your Command':
return true;
}
return false;
}
InsertItem(IReorderableListAdaptor, Int32)
Insert item at specified index and raises the event ItemInserted.
Declaration
protected void InsertItem(IReorderableListAdaptor adaptor, int itemIndex)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Int32 | itemIndex | Zero-based index of item. |
MoveItem(IReorderableListAdaptor, Int32, Int32)
Move item from source index to destination index.
Declaration
protected void MoveItem(IReorderableListAdaptor adaptor, int sourceIndex, int destIndex)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Int32 | sourceIndex | Zero-based index of source item. |
Int32 | destIndex | Zero-based index of destination index. |
OnAddMenuClicked(AddMenuClickedEventArgs)
Raises event when add menu button is clicked.
Declaration
protected virtual void OnAddMenuClicked(AddMenuClickedEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
AddMenuClickedEventArgs | args | Event arguments. |
OnItemInserted(ItemInsertedEventArgs)
Raises event after list item is inserted or duplicated.
Declaration
protected virtual void OnItemInserted(ItemInsertedEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
ItemInsertedEventArgs | args | Event arguments. |
OnItemMoved(ItemMovedEventArgs)
Raises event after list item has been moved.
Declaration
protected virtual void OnItemMoved(ItemMovedEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
ItemMovedEventArgs | args | Event arguments. |
OnItemMoving(ItemMovingEventArgs)
Raises event immediately before list item is moved and provides oppertunity to cancel.
Declaration
protected virtual void OnItemMoving(ItemMovingEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
ItemMovingEventArgs | args | Event arguments. |
OnItemRemoving(ItemRemovingEventArgs)
Raises event before list item is removed and provides oppertunity to cancel.
Declaration
protected virtual void OnItemRemoving(ItemRemovingEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
ItemRemovingEventArgs | args | Event arguments. |
RemoveItem(IReorderableListAdaptor, Int32)
Remove specified item.
Declaration
protected bool RemoveItem(IReorderableListAdaptor adaptor, int itemIndex)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Int32 | itemIndex | Zero-based index of item. |
Returns
Type | Description |
---|---|
Boolean | Returns a value of |
Remarks
The event ItemRemoving is raised prior to removing item and allows removal to be cancelled.
ResizeList(IReorderableListAdaptor, Int32)
Set count of items in list by adding or removing items.
Declaration
protected bool ResizeList(IReorderableListAdaptor adaptor, int newCount)
Parameters
Type | Name | Description |
---|---|---|
IReorderableListAdaptor | adaptor | Reorderable list adaptor. |
Int32 | newCount | New count of items. |
Returns
Type | Description |
---|---|
Boolean | Returns a value of |
Events
AddMenuClicked
Occurs when add menu button is clicked.
Declaration
public event AddMenuClickedEventHandler AddMenuClicked
Event Type
Type | Description |
---|---|
AddMenuClickedEventHandler |
Remarks
Add menu button is only shown when there is at least one subscriber to this event.
ItemInserted
Occurs after list item is inserted or duplicated.
Declaration
public event ItemInsertedEventHandler ItemInserted
Event Type
Type | Description |
---|---|
ItemInsertedEventHandler |
ItemMoved
Occurs after list item has been moved.
Declaration
public event ItemMovedEventHandler ItemMoved
Event Type
Type | Description |
---|---|
ItemMovedEventHandler |
ItemMoving
Occurs immediately before list item is moved allowing for move operation to be cancelled.
Declaration
public event ItemMovingEventHandler ItemMoving
Event Type
Type | Description |
---|---|
ItemMovingEventHandler |
ItemRemoving
Occurs before list item is removed and allowing for remove operation to be cancelled.
Declaration
public event ItemRemovingEventHandler ItemRemoving
Event Type
Type | Description |
---|---|
ItemRemovingEventHandler |