Esempio n. 1
0
		internal static CanvasData Arrange(StateDisplayInfo stateDisplayInfo, Dictionary<string, List<NavigationLinkModel>> links)
		{
			var transitionModels = new List<TransitionModel>();
			var stateModels = new List<StateModel>();
			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, transitionModels);
				foreach (State state in dialog.States)
				{
					var stateModel = new StateModel(state);
					stateModels.Add(stateModel);
					stateModel.X = stateX;
					stateModel.Y = stateY;
					stateModel.H = StateHeight;
					stateModel.Page = state.Page;
					stateModel.Controller = state.Attributes["controller"];
					stateModel.ApiController = state.Attributes["apiController"];
					stateModel.Action = state.Attributes["action"];
					stateModel.Route = state.Route;
					stateModel.Theme = state.Theme;
					stateModel.Masters = state.Masters.ToList();
					if (links.ContainsKey(state.Id))
						stateModel.NavigationLinks = links[state.Id];
					if (state == StateContext.State)
					{
						stateModel.Current = state == StateContext.State;
						stateModel.Data = StateContext.Data;
						stateModel.Page = stateDisplayInfo.Page;
						stateModel.Route = stateDisplayInfo.Route;
						stateModel.Theme = stateDisplayInfo.Theme;
						stateModel.Masters = stateDisplayInfo.Masters;
					}
					stateModel.Previous = state == StateContext.PreviousState;
					stateModel.Back = 0;
					if (crumbs.ContainsKey(state))
					{
						stateModel.Back = crumbs.Count - crumbs[state].Index;
						stateModel.Data = crumbs[state].Crumb.Data;
					}
					if (stateModel.Data == null)
					{
						stateModel.Data = new NavigationData();
						foreach (string key in stateModel.State.Defaults.Keys)
							stateModel.Data[key] = stateModel.State.Defaults[key];
					}
					stateModel.W = ProcessTransitions(stateModel, transitionModels);
					stateX += stateModel.W + StateSeparation;
				}
				stateY += Top + StateHeight + depths.Count * TransitionStepHeight + FontSize;
			}
			var selected = stateModels.FirstOrDefault(s => s.Current) ?? new StateModel(new State());
			var selectedDialogTrans = transitionModels.Where(t => t.Transition.Parent.Parent == selected.State.Parent).DefaultIfEmpty();
			var lastState = stateModels.Last();
			return new CanvasData
			{
				States = stateModels,
				Transitions = transitionModels,
				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, stateModels.Max(s => s.X + s.W) + Left),
				H = Math.Max(Height, Math.Max(lastState.Y + lastState.H, transitionModels.DefaultIfEmpty().Max(t => t != null ? t.Y + t.H : 0)) + PaddingY + FontSize)
			};
		}
Esempio n. 2
0
		private static int ProcessTransitions(StateModel stateModel, List<TransitionModel> transModels)
		{
			var trans = TransByState(stateModel.State, transModels);
			var transWidth = (trans.Count() - 1) * TransitionSeparation;
			var width = StateWidth + Math.Max(0, transWidth + 2 * PaddingX - StateWidth);
			var start = stateModel.X + (width - transWidth) / 2;
			foreach (var transEl in trans)
			{
				transEl.Y = stateModel.Y + StateHeight;
				transEl.H = (transEl.Depth + 1) * TransitionStepHeight;
				transEl.SetCoords(stateModel.State, start);
				start += TransitionSeparation;
			}
			return width;
		}