public MaxScore_LayoutQuery Clone(MaxScore_LayoutQuery returnType) { MaxScore_LayoutQuery clone = new MaxScore_LayoutQuery(); clone.CopyFrom(this); return(clone); }
public override LayoutQuery OptimizedUsingExample(SpecificLayout example) { MaxScore_LayoutQuery result = this; if (this.MinScore.CompareTo(example.Score) < 0) { result = this.Clone((MaxScore_LayoutQuery)null); result.setMinScore(example.Score); } return(result); }
public override LayoutQuery OptimizedPastDimensions(LayoutDimensions example) { MaxScore_LayoutQuery result = this; LayoutScore minScore = example.Score.Plus(LayoutScore.Tiny); if (this.MinScore.CompareTo(minScore) < 0) { result = this.Clone((MaxScore_LayoutQuery)null); result.setMinScore(minScore); if (!result.Accepts(result.ProposedSolution_ForDebugging)) { result.ProposedSolution_ForDebugging = null; } } return(result); }
// tests that the layout satisfies all of the queries consistently public void DebugCheck(LayoutChoice_Set layout) { int i, j; int maxWidth, maxHeight; maxWidth = 127; maxHeight = 127; LayoutDimensions[,] maxScore_dimensions = new LayoutDimensions[maxWidth, maxHeight]; LayoutDimensions[,] minWidth_dimensions = new LayoutDimensions[maxWidth, maxHeight]; LayoutDimensions[,] minHeight_dimensions = new LayoutDimensions[maxWidth, maxHeight]; for (i = 0; i < maxWidth; i++) { System.Diagnostics.Debug.WriteLine(i.ToString() + " of " + maxWidth.ToString()); for (j = 0; j < maxHeight; j++) { int width = i + 29; int height = j; // find the maximum score of all layouts that fit in these dimensions LayoutQuery maxScoreQuery = new MaxScore_LayoutQuery(width, height, LayoutScore.Minimum, this.visualDefaults.LayoutDefaults); SpecificLayout maxScore_layout = layout.GetBestLayout(maxScoreQuery); maxScore_dimensions[i, j] = maxScore_layout.Dimensions; // find the layout of minimum width having at least this score LayoutQuery minWidthQuery = new MinWidth_LayoutQuery(width, height, maxScore_layout.Score, this.visualDefaults.LayoutDefaults); SpecificLayout minWidth_layout = layout.GetBestLayout(minWidthQuery); if (minWidth_layout != null) { minWidth_dimensions[i, j] = minWidth_layout.Dimensions; } // find the layout of minimum height having at least this score LayoutQuery minHeightQuery = new MinHeight_LayoutQuery(width, height, maxScore_layout.Score, this.visualDefaults.LayoutDefaults); SpecificLayout minHeight_layout = layout.GetBestLayout(minHeightQuery); if (minHeight_layout != null) { minHeight_dimensions[i, j] = minHeight_layout.Dimensions; } if (i > 0) { if (maxScore_dimensions[i, j].Score.CompareTo(maxScore_dimensions[i - 1, j].Score) < 0) { System.Diagnostics.Debug.WriteLine("Error: inconsistency between (" + i.ToString() + ", " + j.ToString() + ") and (" + (i - 1).ToString() + ", " + j.ToString() + ")"); } } if (j > 0) { if (maxScore_dimensions[i, j].Score.CompareTo(maxScore_dimensions[i, j - 1].Score) < 0) { System.Diagnostics.Debug.WriteLine("Error: inconsistency between (" + i.ToString() + ", " + j.ToString() + ") and (" + i.ToString() + ", " + (j - 1).ToString() + ")"); } } if ((width == 0 || height == 0) && maxScore_dimensions[i, j].Score.CompareTo(LayoutScore.Zero) > 0) { System.Diagnostics.Debug.WriteLine("Error: clipping not noticed at (" + i.ToString() + ", " + j.ToString() + ")"); } if (minWidth_dimensions[i, j] == null) { System.Diagnostics.Debug.WriteLine("Error: minWidth query for (" + i.ToString() + ", " + j.ToString() + ") returned null"); minWidthQuery.Debug = true; layout.GetBestLayout(minWidthQuery.Clone()); } if (minHeight_dimensions[i, j] == null) { System.Diagnostics.Debug.WriteLine("Error: minHeight query for (" + i.ToString() + ", " + j.ToString() + ") returned null"); } if (i > 0 && minWidth_dimensions[i, j] != null && minWidth_dimensions[i, j] != null) { if (minWidth_dimensions[i, j].Score.CompareTo(minWidth_dimensions[i - 1, j].Score) == 0) { if (minWidth_dimensions[i, j].Width != minWidth_dimensions[i - 1, j].Width) { System.Diagnostics.Debug.WriteLine("Error: width is wrong in minWidth query between (" + i.ToString() + ", " + j.ToString() + ") and (" + (i - 1).ToString() + ", " + j.ToString() + ")"); } } } if (j > 0 && minHeight_dimensions[i, j] != null && minHeight_dimensions[i, j] != null) { if (minHeight_dimensions[i, j].Score.CompareTo(minHeight_dimensions[i, j - 1].Score) == 0) { if (minHeight_dimensions[i, j].Height != minHeight_dimensions[i, j - 1].Height) { System.Diagnostics.Debug.WriteLine("Error: height is wrong in minHeight query between (" + i.ToString() + ", " + j.ToString() + ") and (" + i.ToString() + ", " + (j - 1).ToString() + ")"); minHeightQuery.Debug = true; layout.GetBestLayout(minHeightQuery.Clone()); } } } } } System.Diagnostics.Debug.WriteLine("done with debugCheck"); /* * System.Diagnostics.Debug.WriteLine("checking minWidth queries"); * for (i = 1; i < maxWidth; i++) * { * for (j = 1; j < maxHeight; j++) * { * if (maxScore_dimensions[i, j].Score.CompareTo(maxScore_dimensions[i - 1, j] < 0)) * System.Diagnostics.Debug.WriteLine("Error: inconsistency between (" + i.ToString() + ", " + j.ToString() + ") and (" + (i - 1).ToString() + ", " + j.ToString()); * if (maxScore_dimensions[i, j].Score.CompareTo(maxScore_dimensions[i, j - 1] < 0)) * System.Diagnostics.Debug.WriteLine("Error: inconsistency between (" + i.ToString() + ", " + j.ToString() + ") and (" + i.ToString() + ", " + (j - 1).ToString()); * } * }*/ }
// redoes the layout private void DoLayout() { this.needsRelayout = false; // determine which views are currently focused so we can re-focus them after redoing the layout List <View> focusedViews = new List <View>(); if (this.specificLayout != null) { foreach (SpecificLayout layout in this.specificLayout.GetDescendents()) { if (layout.View != null && layout.View.IsFocused && layout.GetParticipatingChildren().Count() < 1) { focusedViews.Add(layout.View); } } } // check some data in preparation for computing stats int num_grid_preComputations = GridLayout.NumComputations; DateTime startTime = DateTime.Now; // record the parent of each view before the relayout, to help us know which parents to disconnect Dictionary <View, SpecificLayout> preParents = this.findAncestors(this.specificLayout); // recompute the new desired layout // generally we expect the overall score to be positive, so we start by hypothesizing // that there exists a layout with positive score, and only checking negative-scoring layouts if no positive-scoring layout is found LayoutQuery query = new MaxScore_LayoutQuery(this.displaySize.Width, this.displaySize.Height, LayoutScore.Zero, this.visualDefaults.LayoutDefaults); DateTime getBestLayout_startDate = DateTime.Now; this.specificLayout = this.GetSublayout().GetBestLayout(query); if (this.specificLayout == null) { query = query.WithScore(LayoutScore.Minimum); this.specificLayout = this.GetSublayout().GetBestLayout(query); } DateTime getBestLayout_endDate = DateTime.Now; // find the parent of each view after the relayout, to help us know which parents to disconnect Dictionary <View, SpecificLayout> postParents = this.findAncestors(this.specificLayout); // disconnect any parents that are no longer the same foreach (View view in preParents.Keys) { SpecificLayout preLayout = preParents[view]; if (preLayout != null) { SpecificLayout postLayout = this.DictionaryGet(postParents, view); if (postLayout == null || preLayout.View != postLayout.View) { // The parent of <view> has changed. // Disconnect it from the previous parent. preLayout.Remove_VisualDescendent(view); } } } // record that our layout is up-to-date (so any future updates will trigger a relayout) this.Reset_ChangeAnnouncement(); // update our actual view this.mainView.Content = this.specificLayout.DoLayout(displaySize, this.visualDefaults.ViewDefaults); // Inform each layout whose view was reattached, in case they need to restore any state that can only be restored after being reattached (most likely because the view system would overwrite it) foreach (SpecificLayout layout in postParents.Values) { layout.AfterLayoutAttached(); } // display stats DateTime endTime = DateTime.Now; TimeSpan duration = endTime.Subtract(startTime); System.Diagnostics.Debug.WriteLine("ViewManager DoLayout finished in " + duration + " (" + query.Cost + ") queries"); System.Diagnostics.Debug.WriteLine("Text formatting time = " + TextLayout.TextTime + " for " + TextLayout.NumMeasures + " measures"); int num_grid_postComputations = GridLayout.NumComputations; System.Diagnostics.Debug.WriteLine("Num grid computations = " + (num_grid_postComputations - num_grid_preComputations)); TextLayout.NumMeasures = 0; TextLayout.TextTime = new TimeSpan(); // refocus the previously focused views foreach (View view in focusedViews) { if (postParents.ContainsKey(view)) { view.Focus(); } } System.Diagnostics.Debug.WriteLine("ViewManager completed layout at " + DateTime.Now); if (this.LayoutCompleted != null) { ViewManager_LayoutStats stats = new ViewManager_LayoutStats(); stats.ViewManager_LayoutDuration = duration; stats.ViewManager_getBestLayout_Duration = getBestLayout_endDate.Subtract(getBestLayout_startDate); this.LayoutCompleted.Invoke(stats); } }