Example #1
0
 public ViewPool(Transform parent, PrefabRef <TView> prefab, PresentOptions options) : this(parent, prefab.ExtractPrefab(parent))
 {
     if ((options & PresentOptions.UseLoadedViews) != 0)
     {
         Rui.FillPoolWithChildrenViews(this, parent, prefab, this.prefab, options);
     }
 }
Example #2
0
 public static void FillPoolWithChildrenViews <TView, TData>(IViewPool <TView, TData> pool, Transform parent, PrefabRef <TView> prefabRef,
                                                             TView prefab, PresentOptions options) where TView : ReusableView
 {
     if (parent == null)
     {
         return;
     }
     foreach (var obj in parent)
     {
         var view = ((Transform)obj).GetComponent <TView>();
         if (view != null)
         {
             if (view.prefabRef != null && view.prefabRef == prefab)
             {
                 pool.AddViewToUse((TView)view.prefabRef, view);
             }
             else if (options.Has(PresentOptions.UseChildWithSameTypeAsView) && view.GetType() == prefabRef.ExtractType())
             {
                 view.prefabRef = prefab;
                 pool.AddViewToUse((TView)view.prefabRef, view);
             }
             else if (options.Has(PresentOptions.UseChildWithSameNameAsView) && view.name == prefabRef.ExtractName())
             {
                 view.prefabRef = prefab;
                 pool.AddViewToUse((TView)view.prefabRef, view);
             }
         }
     }
 }
Example #3
0
		private IPresentable CreatePresentable(IPresentable parent, Type controllerType, PresentOptions presentOptions, PresentArgs args)
		{
			Debug.Assert(controllerType != null);
			Debug.Assert(!_disposed);

			var resultType = typeof(int);
			var attrs = (ViewControllerAttribute[])controllerType.GetCustomAttributes(typeof(ViewControllerAttribute), false);
			var presentContext = new PresentResultArgs()
			{
				Id = ++_idCounter,
				ServiceProvider = _serviceProvider,
				ControllerFactory = _controllerFactory,
				ViewFactory = _viewFactory,
				ControllerType = controllerType,
				Parent = parent,
				PresentOptions = presentOptions,
				PresentArgs = args ?? PresentArgs.Default
			};

			if (attrs != null && attrs.Length > 0)
			{
				var controllerAttr = attrs[0];

				presentContext.PresentOptions |= controllerAttr.PresentOptions;
				presentContext.Layer = controllerAttr.Layer;
				presentContext.Tag = controllerAttr.Tag;
				presentContext.PrefabPath = controllerAttr.PrefabPath;
			}

			// Types inherited from IViewControllerResult<> use specific result values.
			if (IsAssignableToGenericType(controllerType, typeof(IViewControllerResult<>), out var t))
			{
				resultType = t.GenericTypeArguments[0];
			}

			// If parent is going to be dismissed, use its parent instead.
			if ((presentOptions & PresentOptions.Child) == 0)
			{
				presentContext.Parent = null;
			}
			else if ((presentOptions & PresentOptions.DismissAll) != 0)
			{
				presentContext.Parent = null;
			}
			else if ((presentOptions & PresentOptions.DismissCurrent) != 0)
			{
				presentContext.Parent = parent?.Parent;
			}

			// Instantiate the presentable.
			// https://docs.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/how-to-examine-and-instantiate-generic-types-with-reflection
			var presentResultType = typeof(PresentResult<,>).MakeGenericType(controllerType, resultType);
			var c = (IPresentable)Activator.CreateInstance(presentResultType, this, presentContext);

			AddPresentable(c);

			return c;
		}
Example #4
0
 public WindowRenderTargetProperties(
     WindowHandle window,
     Size pixelSize,
     PresentOptions options = PresentOptions.None)
 {
     _hwnd          = window;
     PixelSize      = pixelSize;
     PresentOptions = options;
 }
Example #5
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));
        }
Example #6
0
 public void Clear()
 {
     autoDepthStencilFormat    = DepthFormat.Unknown;
     backBufferCount           = 0;
     backBufferFormat          = SurfaceFormat.Unknown;
     backBufferHeight          = 0;
     backBufferWidth           = 0;
     deviceWindowHandle        = IntPtr.Zero;
     enableAutoDepthStencil    = false;
     fullScreenRefreshRateInHz = 0;
     isFullScreen         = false;
     multiSampleQuality   = 0;
     multiSampleType      = MultiSampleType.None;
     presentationInterval = PresentInterval.Default;
     presentOptions       = PresentOptions.None;
     swapEffect           = SwapEffect.Default;
 }
Example #7
0
        public PresentResult(IPresenterInternal presenter, PresentResultArgs context)
        {
            Debug.Assert(presenter != null);
            Debug.Assert(context != null);

            _presenter         = presenter;
            _id                = context.Id;
            _tag               = context.Tag;
            _layer             = context.Layer;
            _parent            = context.Parent;
            _serviceProvider   = context.ServiceProvider;
            _controllerFactory = context.ControllerFactory;
            _controllerType    = context.ControllerType;
            _presentArgs       = context.PresentArgs;
            _presentOptions    = context.PresentOptions;
            _deeplinkId        = GetDeeplinkId(_controllerType);
            _prefabPath        = string.IsNullOrEmpty(context.PrefabPath) ? GetDefaultPrefabName(_controllerType) : context.PrefabPath;
        }
Example #8
0
        public static SimplePresentComponents <TView, T> Present <T, TView>(
            this IReactiveCollection <T> coll,
            Transform parent,
            PrefabRef <TView> prefab       = default,
            Action <T, TView> show         = null,
            Func <T, IEventStream> updater = null,
            Func <T, PrefabRef <TView> > prefabSelector = null,
            IViewPool <TView, T> pool        = null,
            PresentOptions options           = PresentOptions.UseChildWithSameTypeAsView,
            TableDelegates <TView> delegates = null
            ) where TView : ReusableView
        {
            var components  = CreateBasicTableComponents(coll, parent, show, pool, prefab, prefabSelector, null, delegates, updater, options);
            var viewStorage = components.viewLoader;

            components.addConnection = coll.update.Subscribe(e =>
            {
                switch (e.type)
                {
                case ReactiveCollectionEventType.Reset:
                    viewStorage.UnloadAll();
                    viewStorage.ReloadAll(e.newData);
                    break;

                case ReactiveCollectionEventType.Insert:
                    viewStorage.LoadView(e.position, e.newItem);
                    break;

                case ReactiveCollectionEventType.Remove:
                    viewStorage.UnloadView(e.position);
                    break;

                case ReactiveCollectionEventType.Set:
                    viewStorage.UnloadView(e.position);
                    viewStorage.LoadView(e.position, e.newItem);
                    break;
                }
            });
            viewStorage.ReloadAll(coll);
            // TODO think about how destroy should work
            components.addConnection     = new AnonymousDisposable(() => components.viewLoader.UnloadAll());
            components.animationsEnabled = true;
            return(components);
        }
Example #9
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));
        }
Example #10
0
		IPresentResult IPresenterInternal.PresentAsync(IPresentable presentable, Type controllerType, PresentOptions presentOptions, Transform parent, PresentArgs args)
		{
			return PresentInternal(presentable, controllerType, presentOptions, parent, args);
		}
 /// <summary>
 /// Presents a controller of the specified type.
 /// </summary>
 /// <typeparam name="TController">Type of the controller to instantiate.</typeparam>
 /// <param name="presenter">The presenter.</param>
 /// <param name="options">Present options.</param>
 /// <param name="args">Controller arguments.</param>
 /// <returns>An object that can be used to track the operation progress.</returns>
 /// <exception cref="ArgumentException">Thrown if <typeparamref name="TController"/> cannot be used to instantiate the controller (for instance it is abstract type).</exception>
 /// <exception cref="ObjectDisposedException">Thrown if the presenter is disposed.</exception>
 public static Task PresentAsync <TController>(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController
 {
     return(presenter.Present(typeof(TController), args, options, null).Task);
 }
Example #12
0
 public static bool Has(this PresentOptions self, PresentOptions option)
 {
     return((self & option) == option);
 }
 /// <summary>
 /// Presents a controller of the specified type.
 /// </summary>
 /// <param name="presenter">The presenter.</param>
 /// <param name="controllerType">Type of the view controller to present.</param>
 /// <param name="options">Present options.</param>
 /// <param name="args">Controller arguments.</param>
 /// <returns>An object that can be used to track the operation progress.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="controllerType"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentException">Thrown if <paramref name="controllerType"/> cannot be used to instantiate the controller (for instance it is abstract type).</exception>
 /// <exception cref="ObjectDisposedException">Thrown if the presenter is disposed.</exception>
 /// <seealso cref="Present(Type)"/>
 public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentArgs args, PresentOptions options)
 {
     return(presenter.Present(controllerType, args, options, null).Task);
 }
 /// <summary>
 /// Presents a controller of the specified type.
 /// </summary>
 /// <param name="presenter">The presenter.</param>
 /// <param name="controllerType">Type of the view controller to present.</param>
 /// <param name="options">Present options.</param>
 /// <param name="transform">Parent transform of the controller view.</param>
 /// <returns>An object that can be used to track the operation progress.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="controllerType"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentException">Thrown if <paramref name="controllerType"/> cannot be used to instantiate the controller (for instance it is abstract type).</exception>
 /// <exception cref="ObjectDisposedException">Thrown if the presenter is disposed.</exception>
 /// <seealso cref="Present(Type)"/>
 public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentOptions options, Transform transform)
 {
     return(presenter.Present(controllerType, null, options, transform));
 }
Example #15
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);
        }
Example #16
0
		private IPresentResult PresentInternal(IPresentable presentable, Type controllerType, PresentOptions presentOptions, Transform transform, PresentArgs args)
		{
			ThrowIfDisposed();
			ThrowIfInvalidControllerType(controllerType);

			var result = CreatePresentable(presentable, controllerType, presentOptions, args);
			PresentInternal(result, presentable, transform);
			return result;
		}
 /// <summary>
 /// Presents a controller of the specified type.
 /// </summary>
 /// <typeparam name="TController">Type of the controller to instantiate.</typeparam>
 /// <param name="presenter">The presenter.</param>
 /// <param name="options">Present options.</param>
 /// <param name="args">Controller arguments.</param>
 /// <returns>An object that can be used to track the operation progress.</returns>
 /// <exception cref="ArgumentException">Thrown if <typeparamref name="TController"/> cannot be used to instantiate the controller (for instance it is abstract type).</exception>
 /// <exception cref="ObjectDisposedException">Thrown if the presenter is disposed.</exception>
 public static IPresentResultOf <TController> Present <TController>(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController
 {
     return((IPresentResultOf <TController>)presenter.Present(typeof(TController), args, options, null));
 }
Example #18
0
 static bool Has(this PresentOptions self, PresentOptions option)
 {
     return((self & option) != 0);
 }
 /// <summary>
 /// Presents a controller of the specified type.
 /// </summary>
 /// <typeparam name="TController">Type of the controller to instantiate.</typeparam>
 /// <param name="presenter">The presenter.</param>
 /// <param name="options">Present options.</param>
 /// <param name="transform">Parent transform of the controller view.</param>
 /// <returns>An object that can be used to track the operation progress.</returns>
 /// <exception cref="ArgumentException">Thrown if <typeparamref name="TController"/> cannot be used to instantiate the controller (for instance it is abstract type).</exception>
 /// <exception cref="ObjectDisposedException">Thrown if the presenter is disposed.</exception>
 public static IPresentResultOf <TController> Present <TController>(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController
 {
     return((IPresentResultOf <TController>)presenter.Present(typeof(TController), null, options, transform));
 }
 /// <summary>
 /// Presents a controller of the specified type.
 /// </summary>
 /// <param name="presenter">The presenter.</param>
 /// <param name="controllerType">Type of the view controller to present.</param>
 /// <param name="options">Present options.</param>
 /// <param name="args">Controller arguments.</param>
 /// <returns>An object that can be used to track the operation progress.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="controllerType"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentException">Thrown if <paramref name="controllerType"/> cannot be used to instantiate the controller (for instance it is abstract type).</exception>
 /// <exception cref="ObjectDisposedException">Thrown if the presenter is disposed.</exception>
 /// <seealso cref="Present(Type)"/>
 public static IPresentResult Present(this IPresenter presenter, Type controllerType, PresentArgs args, PresentOptions options)
 {
     return(presenter.Present(controllerType, args, options, null));
 }
 /// <summary>
 /// Presents a controller of the specified type.
 /// </summary>
 /// <typeparam name="TController">Type of the controller to instantiate.</typeparam>
 /// <typeparam name="TResult">Type of the controller result value.</typeparam>
 /// <param name="presenter">The presenter.</param>
 /// <param name="options">Present options.</param>
 /// <param name="transform">Parent transform of the controller view.</param>
 /// <returns>An object that can be used to track the operation progress.</returns>
 /// <exception cref="ArgumentException">Thrown if <typeparamref name="TController"/> cannot be used to instantiate the controller (for instance it is abstract type).</exception>
 /// <exception cref="InvalidCastException">Thrown if the <typeparamref name="TResult"/> does not match result type of the <typeparamref name="TController"/>.</exception>
 /// <exception cref="ObjectDisposedException">Thrown if the presenter is disposed.</exception>
 public static Task <TResult> PresentAsync <TController, TResult>(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult <TResult>
 {
     return(((IPresentResultOf <TController, TResult>)presenter.Present(typeof(TController), null, options, transform)).Task);
 }
 /// <summary>
 /// Presents a controller of the specified type.
 /// </summary>
 /// <typeparam name="TController">Type of the controller to instantiate.</typeparam>
 /// <typeparam name="TResult">Type of the controller result value.</typeparam>
 /// <param name="presenter">The presenter.</param>
 /// <param name="options">Present options.</param>
 /// <param name="transform">Parent transform of the controller view.</param>
 /// <param name="args">Controller arguments.</param>
 /// <returns>An object that can be used to track the operation progress.</returns>
 /// <exception cref="ArgumentException">Thrown if <typeparamref name="TController"/> cannot be used to instantiate the controller (for instance it is abstract type).</exception>
 /// <exception cref="InvalidCastException">Thrown if the <typeparamref name="TResult"/> does not match result type of the <typeparamref name="TController"/>.</exception>
 /// <exception cref="ObjectDisposedException">Thrown if the presenter is disposed.</exception>
 public static IPresentResultOf <TController, TResult> Present <TController, TResult>(this IPresenter presenter, PresentArgs args, PresentOptions options, Transform transform) where TController : IViewController, IViewControllerResult <TResult>
 {
     return((IPresentResultOf <TController, TResult>)presenter.Present(typeof(TController), args, options, transform));
 }
 /// <summary>
 /// Presents a controller of the specified type.
 /// </summary>
 /// <typeparam name="TController">Type of the controller to instantiate.</typeparam>
 /// <typeparam name="TResult">Type of the controller result value.</typeparam>
 /// <param name="presenter">The presenter.</param>
 /// <param name="args">Controller arguments.</param>
 /// <param name="options">Present options.</param>
 /// <returns>An object that can be used to track the operation progress.</returns>
 /// <exception cref="ArgumentException">Thrown if <typeparamref name="TController"/> cannot be used to instantiate the controller (for instance it is abstract type).</exception>
 /// <exception cref="InvalidCastException">Thrown if the <typeparamref name="TResult"/> does not match result type of the <typeparamref name="TController"/>.</exception>
 /// <exception cref="ObjectDisposedException">Thrown if the presenter is disposed.</exception>
 public static Task <TResult> PresentAsync <TController, TResult>(this IPresenter presenter, PresentArgs args, PresentOptions options) where TController : IViewController, IViewControllerResult <TResult>
 {
     return(((IPresentResultOf <TController, TResult>)presenter.Present(typeof(TController), args, options, null)).Task);
 }
 /// <summary>
 /// Presents a controller of the specified type.
 /// </summary>
 /// <typeparam name="TController">Type of the controller to instantiate.</typeparam>
 /// <param name="presenter">The presenter.</param>
 /// <param name="options">Present options.</param>
 /// <param name="transform">Parent transform of the controller view.</param>
 /// <returns>An object that can be used to track the operation progress.</returns>
 /// <exception cref="ArgumentException">Thrown if <typeparamref name="TController"/> cannot be used to instantiate the controller (for instance it is abstract type).</exception>
 /// <exception cref="ObjectDisposedException">Thrown if the presenter is disposed.</exception>
 public static Task PresentAsync <TController>(this IPresenter presenter, PresentOptions options, Transform transform) where TController : IViewController
 {
     return(presenter.Present(typeof(TController), null, options, transform).Task);
 }
Example #25
0
		public IPresentResult Present(Type controllerType, PresentArgs args, PresentOptions presentOptions, Transform parent)
		{
			return PresentInternal(null, controllerType, presentOptions, parent, args);
		}
Example #26
0
 public SimpleViewPool(Transform parent, PrefabRef <TView> prefab, PresentOptions options) : base(parent, prefab, options)
 {
 }
Example #27
0
 public DistinctivePool(Transform parent, Func <TData, PrefabRef <TView> > prefabSelector, PresentOptions options)
 {
     this.prefabSelector = prefabSelector;
     this.parent         = parent;
     this.options        = options;
 }
 /// <summary>
 /// Presents a controller of the specified type.
 /// </summary>
 /// <param name="presenter">The presenter.</param>
 /// <param name="controllerType">Type of the view controller to present.</param>
 /// <param name="options">Present options.</param>
 /// <param name="transform">Parent transform of the controller view.</param>
 /// <returns>An object that can be used to track the operation progress.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="controllerType"/> is <see langword="null"/>.</exception>
 /// <exception cref="ArgumentException">Thrown if <paramref name="controllerType"/> cannot be used to instantiate the controller (for instance it is abstract type).</exception>
 /// <exception cref="ObjectDisposedException">Thrown if the presenter is disposed.</exception>
 /// <seealso cref="Present(Type)"/>
 public static Task PresentAsync(this IPresenter presenter, Type controllerType, PresentOptions options, Transform transform)
 {
     return(presenter.Present(controllerType, null, options, transform).Task);
 }
 public void Clear()
 {
     autoDepthStencilFormat = DepthFormat.Unknown;
     backBufferCount = 0;
     backBufferFormat = SurfaceFormat.Unknown;
     backBufferHeight = 0;
     backBufferWidth = 0;
     deviceWindowHandle = IntPtr.Zero;
     enableAutoDepthStencil = false;
     fullScreenRefreshRateInHz = 0;
     isFullScreen = false;
     multiSampleQuality = 0;
     multiSampleType = MultiSampleType.None;
     presentationInterval = PresentInterval.Default;
     presentOptions = PresentOptions.None;
     swapEffect = SwapEffect.Default;
 }
Example #30
0
        public Task <IView> CreateViewAsync(string prefabPath, int layer, int zIndex, PresentOptions options, Transform parent)
        {
            switch (prefabPath)
            {
            case "MessageBox":
                return(Task.FromResult <IView>(new MessageBoxView()));
            }

            return(Task.FromResult <IView>(new DefaultView()));
        }