public override object ReadJson (Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { object instance; JContainer container; if (reader.TokenType == JsonToken.Null) { return null; } if (reader.TokenType == JsonToken.StartArray) { container = JArray.Load (reader); if (objectType == typeof(DynamicRow)) { var dynamicRow = new DynamicRow (); instance = dynamicRow; serializer.Populate (container.CreateReader (), dynamicRow.Items); } else if (objectType == typeof(DynamicItem)) { var dynamicTable = new DynamicTable (); instance = dynamicTable; serializer.Populate (container.CreateReader (), dynamicTable.Rows); } else throw new EtoException("Invalid object graph"); } else { container = JObject.Load (reader); if (container["$type"] == null) { if (container["Rows"] != null) instance = new DynamicTable (); else if (container["Control"] != null) instance = new DynamicControl (); else throw new EtoException("Could not infer the type of object to create"); serializer.Populate(container.CreateReader(), instance); } else { var type = Type.GetType ((string)container ["$type"]); if (!typeof(DynamicItem).IsAssignableFrom (type)) { var dynamicControl = new DynamicControl (); dynamicControl.Control = serializer.Deserialize (container.CreateReader ()) as Control; instance = dynamicControl; } else { instance = serializer.Deserialize (container.CreateReader ()); } } } if (objectType == typeof(DynamicRow) && instance.GetType () != typeof(DynamicRow)) { var row = new DynamicRow(); row.Items.Add (instance as DynamicItem); return row; } return instance; }
/// <summary> /// Add the control with the optional scaling /// </summary> /// <remarks> /// This will add either horizontally or vertically depending on whether <see cref="BeginVertical(Padding?,Size?,bool?,bool?)"/> or /// <see cref="BeginHorizontal"/> was called last. /// /// The x/y scaling specified applies either to the entire column or row in the parent table that the control /// was added to, not just this individual control. /// </remarks> /// <param name="control">Control to add, or null to add blank space</param> /// <param name="xscale">Xscale for this control and any in the same column</param> /// <param name="yscale">Yscale for this control and any in the same row</param> public DynamicControl Add(Control control, bool?xscale = null, bool?yscale = null) { if (xscale == null && currentItem.CurrentRow != null && control == null) { xscale = true; } yscale = yscale ?? this.yscale; if (yscale == null && currentItem.CurrentRow == null && control == null) { yscale = true; } var dynamicControl = new DynamicControl { Control = control, XScale = xscale, YScale = yscale }; currentItem.Add(dynamicControl); return(dynamicControl); }
public DynamicControl Add(Control control, bool?xscale = null, bool?yscale = null) { if (Generated) { throw new AlreadyGeneratedException(); } if (xscale == null && currentItem.CurrentRow != null && control == null) { xscale = true; } yscale = yscale ?? this.yscale; if (yscale == null && currentItem.CurrentRow == null && control == null) { yscale = true; } var dynamicControl = new DynamicControl { Control = control, XScale = xscale, YScale = yscale }; currentItem.Add(dynamicControl); return(dynamicControl); }
public DynamicControl Add(Control control, bool? xscale = null, bool? yscale = null) { if (xscale == null && currentItem.CurrentRow != null && control == null) xscale = true; yscale = yscale ?? this.yscale; if (yscale == null && currentItem.CurrentRow == null && control == null) yscale = true; var dynamicControl = new DynamicControl { Control = control, XScale = xscale, YScale = yscale }; currentItem.Add(dynamicControl); return dynamicControl; }
public override Control Generate(DynamicLayout layout) { if (rows.Count == 0) { return(null); } int cols = rows.Where(r => r != null).Max(r => r.Items.Count); this.Table = new TableLayout(cols, rows.Count); var tableLayout = this.Table; var padding = this.Padding ?? layout.DefaultPadding; if (padding != null) { tableLayout.Padding = padding.Value; } var spacing = this.Spacing ?? layout.DefaultSpacing; if (spacing != null) { tableLayout.Spacing = spacing.Value; } var scalingRow = new DynamicRow(); scalingRow.Items.Add(new DynamicControl { YScale = true }); for (int cy = 0; cy < rows.Count; cy++) { var row = rows[cy]; if (row == null) { row = scalingRow; } for (int cx = 0; cx < row.Items.Count; cx++) { var item = row.Items[cx]; if (item == null) { item = new DynamicControl { XScale = true } } ; item.Generate(layout, tableLayout, cx, cy); } } return(Table); } void ISupportInitialize.BeginInit() { } void ISupportInitialize.EndInit() { foreach (var row in rows) { row.Table = this; } } }
public override Control Generate(DynamicLayout layout) { if (rows.Count == 0) { return(null); } int cols = rows.Where(r => r != null).Max(r => r.Items.Count); if (Container == null) { Container = new Panel(); this.Layout = new TableLayout(Container, cols, rows.Count); } else { this.Layout = new TableLayout(null, cols, rows.Count); layout.SetBaseInnerLayout(); } var tableLayout = this.Layout; var padding = this.Padding ?? layout.DefaultPadding; if (padding != null) { tableLayout.Padding = padding.Value; } var spacing = this.Spacing ?? layout.DefaultSpacing; if (spacing != null) { tableLayout.Spacing = spacing.Value; } var scalingRow = new DynamicRow(); scalingRow.Items.Add(new DynamicControl { YScale = true }); for (int cy = 0; cy < rows.Count; cy++) { var row = rows[cy]; if (row == null) { row = scalingRow; } for (int cx = 0; cx < row.Items.Count; cx++) { var item = row.Items[cx]; if (item == null) { item = new DynamicControl { XScale = true } } ; item.Generate(layout, tableLayout, cx, cy); } } return(Container); } }
public override Control Generate (DynamicLayout layout) { if (rows.Count == 0) return null; int cols = rows.Where (r => r != null).Max (r => r.Items.Count); this.Table = new TableLayout (cols, rows.Count); var tableLayout = this.Table; var padding = this.Padding ?? layout.DefaultPadding; if (padding != null) tableLayout.Padding = padding.Value; var spacing = this.Spacing ?? layout.DefaultSpacing; if (spacing != null) tableLayout.Spacing = spacing.Value; var scalingRow = new DynamicRow (); scalingRow.Items.Add (new DynamicControl{ YScale = true }); for (int cy = 0; cy < rows.Count; cy++) { var row = rows[cy]; if (row == null) row = scalingRow; for (int cx = 0; cx < row.Items.Count; cx++) { var item = row.Items[cx]; if (item == null) item = new DynamicControl { XScale = true }; item.Generate (layout, tableLayout, cx, cy); } } return Table; }