Beispiel #1
0
        public void CalculateVisibleIndexes(IScrollViewLayout layout, out int first, out int last)
        {
            bool horizontal         = rect.scroll.horizontal;
            var  viewPortCorrection = horizontal
                ? rect.GetComponent <RectTransform>().rect.width
                : rect.GetComponent <RectTransform>().rect.height;

            viewPortCorrection /= 2;

            var pos = rect.scrollPos.value;

            pos += horizontal ? viewPortCorrection : -viewPortCorrection;
            if (rect.scroll.horizontal)
            {
                pos = -pos;
            }

            var height = rect.scroll.RectMainSize();

            if (layout.topShift.value - pos > height || pos - layout.size.value - layout.topShift.value > 0)
            {
                first = -1;
                last  = -1;
                return;
            }

            first = layout.FirstVisibleIndexFromShift(pos);
            last  = layout.LastVisibleIndexFromShift(pos + height);
        }
Beispiel #2
0
 public IDisposable BindToLayout(IScrollViewLayout layout)
 {
     return(layout.size.MergeBind(layout.topShift, (size, pos) =>
     {
         this.rect.scroll.SetRectMainSize(size + pos + layout.settings.bottomShift);
     }));
 }
Beispiel #3
0
        public static TableConnectionsAndComponents <TView, TData> PresentWithLayout <TData, TView>(
            this IReactiveCollection <TData> data,
            RectTransform rect,
            PrefabRef <TView> prefab,
            Action <TData, TView> fillFactory,
            IScrollViewLayout layout         = null, // Linear layout is default
            TableDelegates <TView> delegates = null,
            PresentOptions options           = PresentOptions.UseChildWithSameTypeAsView) where TView : ReusableView
        {
            var components = CreateBasicTableComponents(data, rect, fillFactory, prefab: prefab,
                                                        layout: layout, delegates: delegates, options: options | PresentOptions.NeedLayout);

            components.viewPort = new AllVisibleViewPort();
            return(ControlItemVisibilityAndRecycle(components));
        }
Beispiel #4
0
        public static TableConnectionsAndComponents <TView, TData> PresentInScrollWithLayout <TData, TView>(
            this IReactiveCollection <TData> data,
            ReactiveScrollRect scroll,
            PrefabRef <TView> prefab   = default,
            Action <TData, TView> show = null,
            Func <TData, PrefabRef <TView> > prefabSelector = null,
            IScrollViewLayout layout         = null, // Linear layout is default
            TableDelegates <TView> delegates = null,
            PresentOptions options           = PresentOptions.UseChildWithSameTypeAsView
            ) where TView : ReusableView
        {
            var components = CreateBasicTableComponents(
                data,
                scroll.scroll.content,
                show,
                prefab: prefab,
                prefabSelector: prefabSelector,
                layout: layout,
                delegates: delegates,
                options: options | PresentOptions.NeedLayout);

            return(PresentInScrollWithLayout(components, scroll));
        }
Beispiel #5
0
        // Creates everithing except viewport.
        public static TableConnectionsAndComponents <TView, TData> CreateBasicTableComponents <TData, TView>(
            IReactiveCollection <TData> data,
            Transform parent,
            Action <TData, TView> show,
            IViewPool <TView, TData> pool = null,
            PrefabRef <TView> prefab      = default,
            Func <TData, PrefabRef <TView> > prefabSelector = null,
            IScrollViewLayout layout           = null, // Linear layout is default
            TableDelegates <TView> delegates   = null,
            Func <TData, IEventStream> updater = null,
            PresentOptions options             = PresentOptions.None
            ) where TView : ReusableView
        {
            var components = new TableConnectionsAndComponents <TView, TData>();

            if (pool == null)
            {
                if (prefabSelector != null)
                {
                    pool = new DistinctivePool <TView, TData>(parent, prefabSelector, options);
                }
                else
                {
                    var actualPrefab = prefab.ExtractPrefab(parent);
                    pool = new ViewPool <TView, TData>(parent, actualPrefab);
                    if (options.Has(PresentOptions.UseLoadedViews))
                    {
                        FillPoolWithChildrenViews(pool, parent, prefab, actualPrefab, options);
                    }
                }
            }

            if (updater != null)
            {
                var showCopy = show;
                Action <TData, TView> showAndSubscribe = (item, view) =>
                {
                    showCopy(item, view);
                    view.connections += updater(item).Subscribe(() => showCopy(item, view));
                };
                show = showAndSubscribe;
            }
            delegates = delegates ?? new TableDelegates <TView>();
            if (delegates.onInsert != null)
            {
                show += (d, view) =>
                {
                    if (components.animationsEnabled)
                    {
                        delegates.onInsert(view);
                    }
                }
            }
            ;
            if (options.Has(PresentOptions.PreserveSiblingOrder))
            {
                show += (d, view) => { view.tr.SetSiblingIndex(view.indexInModel); };
            }
            components.viewLoader = new LinearViewLoader <TView, TData>(pool, show, delegates.onRemove);
            components.delegates  = delegates;
            components.collection = data;

            if (options.Has(PresentOptions.NeedLayout) && layout == null)
            {
                layout = LinearLayout();
            }
            components.layout = layout;
            return(components);
        }
Beispiel #6
0
 public ScrollRectViewPort(ReactiveScrollRect rect, IScrollViewLayout layout, Action <IDisposable> connectionSink)
 {
     this.rect = rect;
     connectionSink(BindToLayout(layout));
 }
Beispiel #7
0
 public void CalculateVisibleIndexes(IScrollViewLayout layout, out int first, out int last)
 {
     first = 0;
     last  = Int32.MaxValue;
 }