本文整理汇总了C#中IReorderableListAdaptor类的典型用法代码示例。如果您正苦于以下问题:C# IReorderableListAdaptor类的具体用法?C# IReorderableListAdaptor怎么用?C# IReorderableListAdaptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IReorderableListAdaptor类属于命名空间,在下文中一共展示了IReorderableListAdaptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItemRemovingEventArgs
/// <summary>
/// Initializes a new instance of <see cref="ItemRemovingEventArgs"/>.
/// </summary>
/// <param name="adaptor">Reorderable list adaptor.</param>
/// <param name="itemIndex">Zero-based index of item.</param>
public ItemRemovingEventArgs(IReorderableListAdaptor adaptor, int itemIndex) {
this.Adaptor = adaptor;
this.ItemIndex = itemIndex;
}
示例2: DrawFloatingListItem
private void DrawFloatingListItem(EventType eventType, IReorderableListAdaptor adaptor, float targetSlotPosition) {
if (eventType == EventType.Repaint) {
Color restoreColor = GUI.color;
// Fill background of target area.
Rect targetPosition = s_DragItemPosition;
targetPosition.y = targetSlotPosition - 1;
targetPosition.height = 1;
GUIHelper.DrawTexture(targetPosition, ReorderableListResources.texItemSplitter);
--targetPosition.x;
++targetPosition.y;
targetPosition.width += 2;
targetPosition.height = s_DragItemPosition.height - 1;
GUI.color = TargetBackgroundColor;
GUIHelper.DrawTexture(targetPosition, EditorGUIUtility.whiteTexture);
// Fill background of item which is being dragged.
--s_DragItemPosition.x;
s_DragItemPosition.width += 2;
--s_DragItemPosition.height;
GUI.color = AnchorBackgroundColor;
GUIHelper.DrawTexture(s_DragItemPosition, EditorGUIUtility.whiteTexture);
++s_DragItemPosition.x;
s_DragItemPosition.width -= 2;
++s_DragItemPosition.height;
// Draw horizontal splitter above and below.
GUI.color = new Color(0f, 0f, 0f, 0.6f);
targetPosition.y = s_DragItemPosition.y - 1;
targetPosition.height = 1;
GUIHelper.DrawTexture(targetPosition, EditorGUIUtility.whiteTexture);
targetPosition.y += s_DragItemPosition.height;
GUIHelper.DrawTexture(targetPosition, EditorGUIUtility.whiteTexture);
GUI.color = restoreColor;
}
DrawListItem(eventType, s_DragItemPosition, adaptor, s_AnchorIndex);
}
示例3: AcceptReorderDrag
/// <summary>
/// Accept reordering.
/// </summary>
/// <param name="adaptor">Reorderable list adaptor.</param>
private void AcceptReorderDrag(IReorderableListAdaptor adaptor) {
try {
// Reorder list as needed!
s_TargetIndex = Mathf.Clamp(s_TargetIndex, 0, adaptor.Count + 1);
if (s_TargetIndex != s_AnchorIndex && s_TargetIndex != s_AnchorIndex + 1)
MoveItem(adaptor, s_AnchorIndex, s_TargetIndex);
}
finally {
StopTrackingReorderDrag();
}
}
示例4: PrepareState
/// <summary>
/// Prepare initial state for list control.
/// </summary>
/// <param name="controlID">Unique ID of list control.</param>
/// <param name="adaptor">Reorderable list adaptor.</param>
private void PrepareState(int controlID, IReorderableListAdaptor adaptor) {
_controlID = controlID;
_visibleRect = GUIHelper.VisibleRect();
if ((Flags & ReorderableListFlags.ShowIndices) != 0) {
int digitCount = Mathf.Max(2, Mathf.CeilToInt(Mathf.Log10((float)adaptor.Count)));
_indexLabelWidth = digitCount * 8 + 8;
}
else {
_indexLabelWidth = 0;
}
_tracking = IsTrackingControl(controlID);
_allowReordering = (Flags & ReorderableListFlags.DisableReordering) == 0;
}
示例5: AddMenuClickedEventArgs
/// <summary>
/// Initializes a new instance of <see cref="ItemMovedEventArgs"/>.
/// </summary>
/// <param name="adaptor">Reorderable list adaptor.</param>
/// <param name="buttonPosition">Position of the add menu button.</param>
public AddMenuClickedEventArgs(IReorderableListAdaptor adaptor, Rect buttonPosition) {
this.Adaptor = adaptor;
this.ButtonPosition = buttonPosition;
}
示例6: ClearAll
/// <summary>
/// Remove all items from list.
/// </summary>
/// <remarks>
/// <para>The event <see cref="ItemRemoving"/> is raised for each item prior to
/// clearing array and allows entire operation to be cancelled.</para>
/// </remarks>
/// <param name="adaptor">Reorderable list adaptor.</param>
/// <returns>
/// Returns a value of <c>false</c> if operation was cancelled.
/// </returns>
protected bool ClearAll(IReorderableListAdaptor adaptor) {
if (adaptor.Count == 0)
return true;
var args = new ItemRemovingEventArgs(adaptor, 0);
int count = adaptor.Count;
for (int i = 0; i < count; ++i) {
args.ItemIndex = i;
OnItemRemoving(args);
if (args.Cancel)
return false;
}
adaptor.Clear();
GUI.changed = true;
ReorderableListGUI.IndexOfChangedItem = -1;
return true;
}
示例7: DuplicateItem
/// <summary>
/// Duplicate specified item and raises the event <see cref="ItemInserted"/>.
/// </summary>
/// <param name="adaptor">Reorderable list adaptor.</param>
/// <param name="itemIndex">Zero-based index of item.</param>
protected void DuplicateItem(IReorderableListAdaptor adaptor, int itemIndex) {
adaptor.Duplicate(itemIndex);
AutoFocusItem(s_ContextControlID, itemIndex + 1);
GUI.changed = true;
ReorderableListGUI.IndexOfChangedItem = -1;
var args = new ItemInsertedEventArgs(adaptor, itemIndex + 1, true);
OnItemInserted(args);
}
示例8: Draw
/// <inheritdoc cref="Draw(Rect, IReorderableListAdaptor, DrawEmptyAbsolute)"/>
public void Draw(Rect position, IReorderableListAdaptor adaptor) {
int controlID = GUIUtility.GetControlID(FocusType.Passive);
Draw(position, controlID, adaptor, null);
}
示例9: DrawLayoutListField
/// <summary>
/// Do layout version of list field.
/// </summary>
/// <param name="controlID">Unique ID of list control.</param>
/// <param name="adaptor">Reorderable list adaptor.</param>
/// <returns>
/// Position of list container area in GUI (excludes footer area).
/// </returns>
private Rect DrawLayoutListField(int controlID, IReorderableListAdaptor adaptor) {
float totalHeight;
// Calculate position of list field using layout engine.
if (Event.current.type == EventType.Layout) {
totalHeight = CalculateListHeight(adaptor);
s_ContainerHeightCache[controlID] = totalHeight;
}
else {
totalHeight = s_ContainerHeightCache.ContainsKey(controlID)
? s_ContainerHeightCache[controlID]
: 0;
}
Rect position = GUILayoutUtility.GetRect(GUIContent.none, ContainerStyle, GUILayout.Height(totalHeight));
// Make room for footer buttons?
if (HasFooterButtons)
position.height -= FooterButtonStyle.fixedHeight;
// Draw list as normal.
DrawListContainerAndItems(position, controlID, adaptor);
CheckForAutoFocusControl(controlID);
return position;
}
示例10: DrawFooterControls
/// <summary>
/// Draw additional controls below list control and highlight drop target.
/// </summary>
/// <param name="position">Position of list control in GUI.</param>
/// <param name="controlID">Unique ID of list control.</param>
/// <param name="adaptor">Reorderable list adaptor.</param>
private void DrawFooterControls(Rect position, int controlID, IReorderableListAdaptor adaptor) {
if (HasFooterButtons) {
Rect buttonPosition = new Rect(position.xMax - 30, position.yMax - 1, 30, FooterButtonStyle.fixedHeight);
Rect menuButtonPosition = buttonPosition;
var menuIconNormal = ReorderableListResources.GetTexture(ReorderableListTexture.Icon_AddMenu_Normal);
var menuIconActive = ReorderableListResources.GetTexture(ReorderableListTexture.Icon_AddMenu_Active);
if (HasAddButton) {
// Draw add menu drop-down button.
if (HasAddMenuButton) {
menuButtonPosition.x = buttonPosition.xMax - 14;
menuButtonPosition.xMax = buttonPosition.xMax;
menuIconNormal = ReorderableListResources.GetTexture(ReorderableListTexture.Icon_Menu_Normal);
menuIconActive = ReorderableListResources.GetTexture(ReorderableListTexture.Icon_Menu_Active);
buttonPosition.width -= 5;
buttonPosition.x = menuButtonPosition.x - buttonPosition.width + 1;
}
// Draw add item button.
var iconNormal = ReorderableListResources.GetTexture(ReorderableListTexture.Icon_Add_Normal);
var iconActive = ReorderableListResources.GetTexture(ReorderableListTexture.Icon_Add_Active);
if (GUIHelper.IconButton(buttonPosition, true, iconNormal, iconActive, FooterButtonStyle)) {
// Append item to list.
GUIUtility.keyboardControl = 0;
AddItem(adaptor);
}
}
if (HasAddMenuButton) {
// Draw add menu drop-down button.
if (GUIHelper.IconButton(menuButtonPosition, true, menuIconNormal, menuIconActive, FooterButtonStyle)) {
GUIUtility.keyboardControl = 0;
Rect totalAddButtonPosition = buttonPosition;
totalAddButtonPosition.xMax = position.xMax;
OnAddMenuClicked(new AddMenuClickedEventArgs(adaptor, totalAddButtonPosition));
// This will be helpful in many circumstances; including by default!
GUIUtility.ExitGUI();
}
}
}
}
示例11: MoveItem
/// <summary>
/// Move item from source index to destination index.
/// </summary>
/// <param name="adaptor">Reorderable list adaptor.</param>
/// <param name="sourceIndex">Zero-based index of source item.</param>
/// <param name="destIndex">Zero-based index of destination index.</param>
protected void MoveItem(IReorderableListAdaptor adaptor, int sourceIndex, int destIndex) {
// Raise event before moving item so that the operation can be cancelled.
var movingEventArgs = new ItemMovingEventArgs(adaptor, sourceIndex, destIndex);
OnItemMoving(movingEventArgs);
if (!movingEventArgs.Cancel) {
adaptor.Move(sourceIndex, destIndex);
// Item was actually moved!
int newIndex = destIndex;
if (newIndex > sourceIndex)
--newIndex;
OnItemMoved(new ItemMovedEventArgs(adaptor, sourceIndex, newIndex));
GUI.changed = true;
}
ReorderableListGUI.IndexOfChangedItem = -1;
}
示例12: AddItem
/// <summary>
/// Add item at end of list and raises the event <see cref="ItemInserted"/>.
/// </summary>
/// <param name="adaptor">Reorderable list adaptor.</param>
protected void AddItem(IReorderableListAdaptor adaptor) {
adaptor.Add();
AutoFocusItem(s_ContextControlID, adaptor.Count - 1);
GUI.changed = true;
ReorderableListGUI.IndexOfChangedItem = -1;
var args = new ItemInsertedEventArgs(adaptor, adaptor.Count - 1, false);
OnItemInserted(args);
}
示例13: ShowContextMenu
private void ShowContextMenu(int controlID, int itemIndex, IReorderableListAdaptor adaptor) {
GenericMenu menu = new GenericMenu();
s_ContextControlID = controlID;
s_ContextItemIndex = itemIndex;
AddItemsToMenu(menu, itemIndex, adaptor);
if (menu.GetItemCount() > 0)
menu.ShowAsContext();
}
示例14: RemoveItem
/// <summary>
/// Remove specified item.
/// </summary>
/// <remarks>
/// <para>The event <see cref="ItemRemoving"/> is raised prior to removing item
/// and allows removal to be cancelled.</para>
/// </remarks>
/// <param name="adaptor">Reorderable list adaptor.</param>
/// <param name="itemIndex">Zero-based index of item.</param>
/// <returns>
/// Returns a value of <c>false</c> if operation was cancelled.
/// </returns>
protected bool RemoveItem(IReorderableListAdaptor adaptor, int itemIndex) {
var args = new ItemRemovingEventArgs(adaptor, itemIndex);
OnItemRemoving(args);
if (args.Cancel)
return false;
adaptor.Remove(itemIndex);
GUI.changed = true;
ReorderableListGUI.IndexOfChangedItem = -1;
return true;
}
示例15: AddItemsToMenu
/// <summary>
/// Invoked to generate context menu for list item.
/// </summary>
/// <param name="menu">Menu which can be populated.</param>
/// <param name="itemIndex">Zero-based index of item which was right-clicked.</param>
/// <param name="adaptor">Reorderable list adaptor.</param>
protected virtual void AddItemsToMenu(GenericMenu menu, int itemIndex, IReorderableListAdaptor adaptor) {
if ((Flags & ReorderableListFlags.DisableReordering) == 0) {
if (itemIndex > 0)
menu.AddItem(CommandMoveToTop, false, DefaultContextHandler, CommandMoveToTop);
else
menu.AddDisabledItem(CommandMoveToTop);
if (itemIndex + 1 < adaptor.Count)
menu.AddItem(CommandMoveToBottom, false, DefaultContextHandler, CommandMoveToBottom);
else
menu.AddDisabledItem(CommandMoveToBottom);
if (HasAddButton) {
menu.AddSeparator("");
menu.AddItem(CommandInsertAbove, false, DefaultContextHandler, CommandInsertAbove);
menu.AddItem(CommandInsertBelow, false, DefaultContextHandler, CommandInsertBelow);
if ((Flags & ReorderableListFlags.DisableDuplicateCommand) == 0)
menu.AddItem(CommandDuplicate, false, DefaultContextHandler, CommandDuplicate);
}
}
if (HasRemoveButtons) {
if (menu.GetItemCount() > 0)
menu.AddSeparator("");
menu.AddItem(CommandRemove, false, DefaultContextHandler, CommandRemove);
menu.AddSeparator("");
menu.AddItem(CommandClearAll, false, DefaultContextHandler, CommandClearAll);
}
}