예제 #1
0
        public override object GetData(ITabContext context)
        {
            var request = context.GetRequestContext <HttpContextBase>();
            var mobile  = request.Request["n0"] == null?request.GetOverriddenBrowser().IsMobileDevice:
                          request.Request["n0"].StartsWith("Mobile", StringComparison.Ordinal);

            var stateDisplayInfo = new StateDisplayInfo();

            if (StateContext.State != null)
            {
                stateDisplayInfo.Page    = GetCurrentPage(context, mobile);
                stateDisplayInfo.Route   = GetCurrentRoute(mobile);
                stateDisplayInfo.Theme   = GetCurrentTheme(context, mobile);
                stateDisplayInfo.Masters = GetCurrentMasters(context, mobile);
            }
            return(Canvas.Arrange(stateDisplayInfo));
        }
예제 #2
0
        internal static CanvasData Arrange(StateDisplayInfo stateDisplayInfo)
        {
            var transitionElements = new List <TransitionElement>();
            var stateElements      = new List <StateElement>();
            var stateX             = Left;
            var stateY             = Top;
            var crumbs             = StateController.Crumbs.Select((c, i) => new { Crumb = c, Index = i })
                                     .ToDictionary(c => c.Crumb.State, c => new { Crumb = c.Crumb, c.Index });

            foreach (Dialog dialog in StateInfoConfig.Dialogs)
            {
                stateX = Left;
                var depths = CalculateDepths(dialog, transitionElements);
                foreach (State state in dialog.States)
                {
                    var stateElement = new StateElement(state);
                    stateElements.Add(stateElement);
                    stateElement.X       = stateX;
                    stateElement.Y       = stateY;
                    stateElement.H       = StateHeight;
                    stateElement.Page    = state.Page;
                    stateElement.Route   = state.Route;
                    stateElement.Theme   = state.Theme;
                    stateElement.Masters = state.Masters.ToList();
                    if (state == StateContext.State)
                    {
                        stateElement.Current = state == StateContext.State;
                        stateElement.Data    = StateContext.Data;
                        stateElement.Page    = stateDisplayInfo.Page;
                        stateElement.Route   = stateDisplayInfo.Route;
                        stateElement.Theme   = stateDisplayInfo.Theme;
                        stateElement.Masters = stateDisplayInfo.Masters;
                    }
                    stateElement.Previous = state == StateContext.PreviousState;
                    stateElement.Back     = 0;
                    if (crumbs.ContainsKey(state))
                    {
                        stateElement.Back = crumbs.Count - crumbs[state].Index;
                        stateElement.Data = crumbs[state].Crumb.Data;
                    }
                    if (stateElement.Data == null)
                    {
                        stateElement.Data = new NavigationData();
                        foreach (string key in stateElement.State.Defaults.Keys)
                        {
                            stateElement.Data[key] = stateElement.State.Defaults[key];
                        }
                    }
                    stateElement.W = ProcessTransitions(stateElement, transitionElements);
                    stateX        += stateElement.W + StateSeparation;
                }
                stateY += Top + StateHeight + depths.Count * TransitionStepHeight + FontSize;
            }
            var selected            = stateElements.FirstOrDefault(s => s.Current) ?? new StateElement(new State());
            var selectedDialogTrans = transitionElements.Where(t => t.Transition.Parent.Parent == selected.State.Parent).DefaultIfEmpty();
            var lastState           = stateElements.Last();

            return(new CanvasData
            {
                States = stateElements,
                Transitions = transitionElements,
                X = Math.Min(0, Width - Math.Min(selected.X + selected.W + Left, selected.X + Width - Left)),
                Y = Math.Min(0, Height - Math.Min(Math.Max(selected.Y + selected.H, selectedDialogTrans.Max(t => t != null ? t.Y + t.H : 0)) + PaddingY + FontSize, selected.Y + Height - Top)),
                W = Math.Max(Width, stateElements.Max(s => s.X + s.W) + Left),
                H = Math.Max(Height, Math.Max(lastState.Y + lastState.H, transitionElements.DefaultIfEmpty().Max(t => t != null ? t.Y + t.H : 0)) + PaddingY + FontSize)
            });
        }