Esempio n. 1
0
        public void RemoveListItem(IObservableList list, object item, string listName)
        {
            var dataTableElement = GetDataTable(list.guid);

            if (dataTableElement == null)
            {
                return;
            }

            dataTableElement.RemoveRowMVVM(list.GetGUID(item));
        }
Esempio n. 2
0
        /// <summary>
        /// Render a new list item element
        /// </summary>
        /// <param name="itemData"></param>
        /// <param name="dataSource"></param>
        /// <param name="itemTemplate"></param>
        /// <param name="list"></param>
        internal void RenderListItem(object itemData, string dataSource, XmlElement itemTemplate, IObservableList list)
        {
            // Create the new item based on the item template for this list
            var element = (XmlElement)GameObject.Instantiate(itemTemplate);
            var parent  = currentListElement.listElement;

            // Add the new item to the list container
            parent.AddChildElement(element);

            // The template will be inactive by default, we need to make it active
            element.SetAttribute("active", "true");

            // Get/Add the List Item component and add it to the element
            var listItemComponent = element.gameObject.GetComponent <XmlLayoutListItem>() ?? element.gameObject.AddComponent <XmlLayoutListItem>();

            listItemComponent.guid = list.GetGUID(itemData);

            // Add this list item to the list's item collection
            var index = list.IndexOf(itemData);

            currentListElement.listItems.Insert(index, listItemComponent);

            // Load the data from 'itemData' and apply it to our new list element
            ApplyViewModelData(element, itemData, dataSource, itemTemplate, list, null, true, true);

            // apply our attributes (especially necessary for things like event handlers and the like)
            element.Initialise(currentXmlLayoutInstance, element.rectTransform, element.tagHandler);
            element.ApplyAttributes();

            element.AnimationDuration = currentListElement.itemAnimationDuration;
            element.ShowAnimation     = currentListElement.itemShowAnimation;
            element.HideAnimation     = currentListElement.itemHideAnimation;

            if (element.ShowAnimation != "None")
            {
                element.Show();
            }

            // Rebuild the layout at the end of the frame
            XmlLayoutTimer.AtEndOfFrame(() => LayoutRebuilder.MarkLayoutForRebuild(element.rectTransform), element);

#if UNITY_5_4
            // Due to differences in how 5.4 and 5.5 handle layout rebuilds, we sometimes have to manually notify child TableLayouts to update
            XmlLayoutTimer.DelayedCall(0.05f, () =>
            {
                var tableLayouts = element.GetComponentsInChildren <UI.Tables.TableLayout>();
                foreach (var tableLayout in tableLayouts)
                {
                    tableLayout.UpdateLayout();
                }
            }, element);
#endif
        }
Esempio n. 3
0
        public void RemoveListItem(IObservableList list, object item, string listName)
        {
            var listElement = ListElements[list.guid];

            var itemGuid    = list.GetGUID(item);
            var itemElement = listElement.listItems.FirstOrDefault(f => f.guid == itemGuid);

            if (itemElement != null)
            {
                itemElement.xmlElement.Hide(false, () => _RemoveListItem(listElement, itemElement));
            }
        }
Esempio n. 4
0
        public void UpdateListItem(IObservableList list, int index, object item, string listName, string changedField = null)
        {
            //Debug.Log("DataTable::UpdateListItem:: " + listName + " :: " + changedField ?? "all");

            var dataTableElement = GetDataTable(list.guid);

            if (dataTableElement == null)
            {
                return;
            }

            dataTableElement.UpdateRowMVVM(list.GetGUID(item), item, changedField);
        }
Esempio n. 5
0
        public void UpdateListItem(IObservableList list, int index, object item, string listName, string changedField = null)
        {
            var listElement = ListElements[list.guid];
            var itemGuid    = list.GetGUID(item);
            var itemElement = listElement.listItems.FirstOrDefault(f => f.guid == itemGuid);

            this.SetInstance(itemElement.xmlElement.rectTransform, itemElement.xmlElement.xmlLayoutInstance);
            this.ApplyViewModelData(itemElement.xmlElement, item, listElement.DataSource, listElement.itemTemplate, list, changedField);

            XmlLayoutTimer.AtEndOfFrame(() =>
            {
                UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(listElement.rectTransform);
            }, listElement);
        }
        internal XmlLayoutDataTableRow AddRowMVVM(IObservableList list, object rowData, Type type)
        {
            TableRow row;

            if (type == typeof(Dictionary <string, string>))
            {
                row = RenderDataRow(rowData as Dictionary <string, string>);
            }
            else
            {
                row = RenderDataRow(ExtractRowData(rowData, type));
            }

            var tracker = row.gameObject.AddComponent <XmlLayoutDataTableRow>();

            tracker.guid = list.GetGUID(rowData);

            mvvmRows.Add(tracker);

            XmlLayoutTimer.AtEndOfFrame(table.CalculateLayoutInputHorizontal, this);

            return(tracker);
        }