<?xml version="1.0"?>
-<Border CornerRadius="0" Margin="0" BorderWidth="1" Width="0" Height="-1">
- <HorizontalStack Name="hstack" Margin="0" Spacing="5" Width="0" Height="-1">
- <Label Width="0" Name="labCpt" Text="{Value}" Margin="1" TextAlignment="RightCenter"/>
- <VerticalStack Spacing="1" Name="vstack">
- <Button Width="10" Height="8" MouseClick="onUp">
+<Border BorderWidth="1" Width="{Width}" Height="{Height}" Background="White">
+ <HorizontalStack Name="hstack" Margin="0" Spacing="2" Width="{Width}" Height="{Height}">
+ <Label Foreground="DimGray" Width="0" Height="{Height}" Name="labCpt"
+ Text="{Value}" Margin="1" TextAlignment="RightCenter"/>
+ <VerticalStack RowCount="2" Width="-1" Height="-1" Spacing="1" >
+ <Button Width="12" Height="8" MouseClick="onUp">
<Image Margin="1" Path="#go.Images.Icons.updown.svg" SvgSub="up"/>
</Button>
- <Button Width="10" Height="8" MouseClick="onDown">
+ <Button Width="12" Height="8" MouseClick="onDown">
<Image Margin="1" Path="#go.Images.Icons.updown.svg" SvgSub="down"/>
</Button>
</VerticalStack>
public int Spacing\r
{\r
get { return _spacing; }\r
- set { _spacing = value; }\r
+ set { \r
+ if (_spacing == value)\r
+ return;\r
+ _spacing = value; \r
+ NotifyValueChanged ("Spacing", Spacing);\r
+ }\r
}\r
[XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]\r
public virtual Orientation Orientation\r
#endregion\r
\r
#region GraphicObject Overrides\r
- //TODO: to be coherent, those overrides should be removed\r
- //I could maybe set size to fit dynamicaly in the direction of the stack\r
- [XmlAttributeAttribute()][DefaultValue(-1)]\r
- public override int Width {\r
- get { return base.Width; }\r
- set { base.Width = value; }\r
- }\r
- [XmlAttributeAttribute()][DefaultValue(-1)]\r
- public override int Height {\r
- get { return base.Height; }\r
- set { base.Height = value; }\r
- }\r
-\r
protected override Size measureRawSize ()\r
{\r
Size tmp = new Size ();\r
--- /dev/null
+using System;\r
+using System.Diagnostics;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using System.Xml.Serialization;\r
+using System.ComponentModel;\r
+\r
+namespace go\r
+{\r
+ /// <summary>\r
+ /// Simple grid container\r
+ /// Allow symetric placement of children on a grid,\r
+ /// excedental child (above grid sizing) are ignored\r
+ /// and invisible child keep their place in the grid\r
+ /// </summary>\r
+ public class Grid : Group\r
+ {\r
+ #region CTOR\r
+ public Grid()\r
+ : base()\r
+ { \r
+ }\r
+ #endregion\r
+\r
+ #region Private fields\r
+ int _spacing;\r
+ int _columnCount;\r
+ int _rowCount;\r
+ #endregion\r
+\r
+ public override T addChild<T> (T child)\r
+ {\r
+ T tmp = base.addChild (child);\r
+ this.RegisterForLayouting ((int)LayoutingType.PositionChildren);\r
+ return tmp;\r
+ }\r
+ public override void removeChild (GraphicObject child)\r
+ {\r
+ base.removeChild (child);\r
+ this.RegisterForLayouting ((int)LayoutingType.PositionChildren);\r
+ }\r
+\r
+ #region Public Properties\r
+ [XmlAttributeAttribute()][DefaultValue(2)]\r
+ public int Spacing\r
+ {\r
+ get { return _spacing; }\r
+ set { _spacing = value; }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(1)]\r
+ public virtual int ColumnCount\r
+ {\r
+ get { return _columnCount; }\r
+ set { \r
+ if (_columnCount == value)\r
+ return;\r
+\r
+ _columnCount = value; \r
+\r
+ NotifyValueChanged ("ColumnCount", ColumnCount);\r
+ this.RegisterForLayouting ((int)LayoutingType.PositionChildren);\r
+ }\r
+ }\r
+ [XmlAttributeAttribute()][DefaultValue(1)]\r
+ public virtual int RowCount\r
+ {\r
+ get { return _rowCount; }\r
+ set { \r
+ if (_rowCount == value)\r
+ return;\r
+\r
+ _rowCount = value; \r
+\r
+ NotifyValueChanged ("RowCount", RowCount);\r
+ this.RegisterForLayouting ((int)LayoutingType.PositionChildren);\r
+ }\r
+ }\r
+ public virtual int CaseWidth {\r
+ get { return (Slot.Width - (ColumnCount - 1) * Spacing) / ColumnCount; }\r
+ }\r
+ public virtual int CaseHeight {\r
+ get { return (Slot.Height - (RowCount - 1) * Spacing) / RowCount; }\r
+ }\r
+\r
+ #endregion\r
+\r
+ #region GraphicObject Overrides\r
+// protected override Size measureRawSize ()\r
+// {\r
+// Size tmp = new Size ();\r
+//\r
+// foreach (GraphicObject c in Children.Where(ch=>ch.Visible)) {\r
+// tmp.Width = Math.Max (tmp.Width, c.Slot.Width);\r
+// tmp.Height = Math.Max (tmp.Height, c.Slot.Height);\r
+// }\r
+//\r
+// tmp.Width *= (ColumnCount - 1) * Spacing / ColumnCount;;\r
+// tmp.Height *= (RowCount - 1) * Spacing / RowCount;\r
+// tmp.Width += 2 * Margin;\r
+// tmp.Height += 2 * Margin;\r
+//\r
+// return tmp;\r
+// }\r
+ public virtual void ComputeChildrenPositions()\r
+ {\r
+ int slotWidth = CaseWidth;\r
+ int slotHeight = CaseHeight;\r
+ for (int curY = 0; curY < RowCount; curY++) {\r
+ for (int curX = 0; curX < ColumnCount; curX++) {\r
+ int idx = curY * ColumnCount + curX;\r
+ if (idx >= Children.Count)\r
+ return;\r
+ GraphicObject c = Children [idx];\r
+ if (!c.Visible)\r
+ continue;\r
+ //ensure Item are not realigned\r
+ c.HorizontalAlignment = HorizontalAlignment.Left;\r
+ c.VerticalAlignment = VerticalAlignment.Top;\r
+ c.Left = curX * (slotWidth + Spacing);\r
+ c.Top = curY * (slotHeight + Spacing);\r
+ c.Width = slotWidth;\r
+ c.Height = slotHeight;\r
+ }\r
+ }\r
+ }\r
+\r
+ public override void RegisterForLayouting (int layoutType)\r
+ { \r
+ base.RegisterForLayouting (layoutType);\r
+\r
+ if ((layoutType & (int)LayoutingType.PositionChildren) > 0)\r
+ Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this); \r
+ }\r
+ public override void UpdateLayout (LayoutingType layoutType)\r
+ { \r
+ if (layoutType == LayoutingType.PositionChildren) { \r
+ ComputeChildrenPositions ();\r
+ //if no layouting remains in queue for item, registre for redraw\r
+ if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp==null)\r
+ this.RegisterForRedraw ();\r
+ }else\r
+ base.UpdateLayout(layoutType);\r
+ }\r
+ #endregion\r
+\r
+ \r
+ }\r
+}\r