public override void CalcPositionsRecursive(int left, int top, int width, int height) { int xpos, ypos; //compute client size, that is the size children can reside in int clientwidth = width - Margin.Horizontal; int clientheight = height - Margin.Vertical; //if we have a physical driver object, we start over at x,y=0,0 otherwise we continue //to build on current x,y DriverCompositeWidget dw = DriverObject as DriverCompositeWidget; Margin decorations = Margin.Empty; if (dw == null) { //no physical driver object xpos = left + Margin.Left; ypos = top + Margin.Top; } else { Margin m = DecorationSize; decorations = dw.GetDecorationSize(); clientwidth -= decorations.Horizontal; clientheight -= decorations.Vertical; Point2i orig = dw.GetClientOrigin(); xpos = orig.X + Margin.Left; ypos = orig.Y + Margin.Top; } //compute how much space we have left for exapnsion in x and y int expandx = Math.Max(0, width - LayoutInfo.Size.Width /* clientwidth - (LayoutInfo.Size.Width+Math.Max(spans.NumColumns - 1, 0) * Gap + Margin.Horizontal)*/); int expandy = Math.Max(0, height - LayoutInfo.Size.Height /*clientheight - (LayoutInfo.Size.Height+Math.Max(spans.NumRows - 1, 0) * Gap + Margin.Vertical)*/); int numexpandx = spans.NumExpandingColumns; int numexpandy = spans.NumExpandingRows; //recompute the cells of table taking expansion into account for (int row = 0; row < spans.NumRows; row++) { int curx = xpos; for (int col = 0; col < spans.NumColumns; col++) { Widget w = WidgetAt(row, col); if (w == null) { continue; } int cellwidth = spans.ColumnWidth(col) + (w.LayoutInfo.ExpandX ? GetExpand(expandx, numexpandx, col) : 0); int cellheight = spans.RowHeight(row) + (w.LayoutInfo.ExpandY ? GetExpand(expandy, numexpandy, row) : 0); spans.GrowFinalSize(row, col, cellwidth, cellheight); } } //finally, actually place the controls int cury = ypos; for (int row = 0; row < spans.NumRows; row++) { int curx = xpos; int rowheight = spans.FinalRowHeight(row); for (int col = 0; col < spans.NumColumns; col++) { Widget w = WidgetAt(row, col); if (w == null) { continue; } int colwidth = spans.FinalColumnWidth(col); int ctrlwidth = w.LayoutInfo.ExpandX ? colwidth : w.LayoutInfo.Size.Width; int ctrlheight = w.LayoutInfo.ExpandY ? rowheight : w.LayoutInfo.Size.Height; int ctrlx, ctrly; ComputeXYUsingAlign(w.LayoutInfo.Align, ctrlwidth, ctrlheight, curx, cury, colwidth, rowheight, out ctrlx, out ctrly); w.CalcPositionsRecursive(ctrlx, ctrly, ctrlwidth, ctrlheight); curx += colwidth + Gap; } cury += rowheight + Gap; } if (!(this is Window)) //dont alter window object sizes here { base.CalcPositionsRecursive(left, top, width, height); } }
public override void CalcPositionsRecursive(int left, int top, int width, int height) { int xpos, ypos; //compute client size, that is the size children can reside in int clientwidth = width - Margin.Horizontal; int clientheight = height - Margin.Vertical; int numrows = NumRows; int numcols = NumColumns; //if we have a physical driver object, we start over at x,y=0,0 otherwise we continue //to build on current x,y DriverCompositeWidget dw = DriverObject as DriverCompositeWidget; Margin decorations = Margin.Empty; if (dw == null) { //no physical driver object xpos = left + Margin.Left; ypos = top + Margin.Top; } else { Margin m = DecorationSize; decorations = dw.GetDecorationSize(); clientwidth -= decorations.Horizontal; clientheight -= decorations.Vertical; Point orig = dw.GetClientOrigin(); xpos = orig.X + Margin.Left; ypos = orig.Y + Margin.Top; } //compute how much space we have for expansion to expandsizex/y //by subtracting the (natural size of) highest column from available height //an widest row from available width int[] natural_rowwidth = new int[numrows]; int[] natural_colheight = new int[numcols]; int[] natural_rowheight = new int[numrows]; int[] natural_colwidth = new int[numcols]; int[] xexpanding = new int[numrows]; int[] yexpanding = new int[numcols]; int expandsizex = clientwidth, expandsizey = clientheight; int numexpandingx = 0, numexpandingy = 0; expandsizex -= Math.Max(0, numcols - 1) * Gap; expandsizey -= Math.Max(0, numrows - 1) * Gap; for (int row = 0; row < numrows; row++) { for (int col = 0; col < numcols; col++) { Widget child = ControlAt(col, row); if (child == null) { continue; } natural_rowwidth[row] += child.LayoutInfo.Size.Width; natural_colheight[col] += child.LayoutInfo.Size.Height; natural_rowheight[row] = Math.Max(child.LayoutInfo.Size.Height, natural_rowheight[row]); natural_colwidth[col] = Math.Max(child.LayoutInfo.Size.Width, natural_colwidth[col]); if (child.LayoutInfo.ExpandX) { xexpanding[row]++; } if (child.LayoutInfo.ExpandY) { yexpanding[col]++; } } } int maxrowwidth = 0, maxcolheight = 0; maxrowwidth = MaxInt(natural_rowwidth); maxcolheight = MaxInt(natural_colheight); numexpandingx = MaxInt(xexpanding); numexpandingy = MaxInt(yexpanding); expandsizex -= maxrowwidth; expandsizey -= maxcolheight; if (expandsizex < 0) { expandsizex = 0; } if (expandsizey < 0) { expandsizey = 0; } //compute the final width and height off all rows and columns int[] colwidth = new int[numcols]; int[] rowheight = new int[numrows]; for (int row = 0; row < numrows; row++) { int oldnumexpandingy = numexpandingy; //so we can restyore it after loop int oldexpandsizey = expandsizey; for (int col = 0; col < numcols; col++) { Widget child = ControlAt(col, row); if (child == null) { continue; } int childwidth = natural_colwidth[col]; // child.LayoutInfo.Size.Width; if (child.LayoutInfo.ExpandX) { childwidth += GetExpand(expandsizex, numexpandingx, col); } //childwidth += expandsizex / numexpandingx; int childheight = natural_rowheight[row]; // child.LayoutInfo.Size.Height; if (child.LayoutInfo.ExpandY) { childheight += GetExpand(expandsizey, numexpandingy, row); } colwidth[col] = Math.Max(childwidth, colwidth[col]); rowheight[row] = Math.Max(childheight, rowheight[row]); } numexpandingy = oldnumexpandingy; expandsizey = oldexpandsizey; } int cx = xpos, cy = ypos; for (int row = 0; row < numrows; row++) { for (int col = 0; col < numcols; col++) { Widget child = ControlAt(col, row); if (child == null) { continue; } int childwidth = child.LayoutInfo.ExpandX ? colwidth[col] : child.LayoutInfo.Size.Width; int childheight = child.LayoutInfo.ExpandY ? rowheight[row] : child.LayoutInfo.Size.Height; int ctrlx, ctrly; ComputeXYUsingAlign(child.LayoutInfo.Align, childwidth, childheight, cx, cy, colwidth[col], rowheight[row], out ctrlx, out ctrly); child.CalcPositionsRecursive(ctrlx, ctrly, childwidth, childheight); cx += colwidth[col] + Gap; // colsizes[col] + Gap; } cx = xpos; cy += rowheight[row] + Gap; } //layout each child, taking expansion and align into account /* foreach (Widget child in Children) * { * int childheight = Math.Max( * child.LayoutInfo.Size.Height, * child.LayoutInfo.ExpandY ? clientheight : child.LayoutInfo.Size.Height * ); * * int childwidth = child.LayoutInfo.Size.Width; * if (child.LayoutInfo.ExpandX) * childwidth += expandsize / numexpanding; * * int aligned_ypos = ypos; * if (child.LayoutInfo.Align == GuppyEx.LayoutAlign.Center) * aligned_ypos = ypos + clientheight / 2 - childheight / 2; * else if (child.LayoutInfo.Align == GuppyEx.LayoutAlign.Bottom) * aligned_ypos = ypos + clientheight - childheight; * * child.CalcPositionsRecursive(xpos, aligned_ypos, childwidth, childheight); * xpos += childwidth + Gap; * }*/ //base.CalcPositionsRecursive(left, top, width, height); }
public override void CalcPositionsRecursive(int left, int top, int width, int height) { int xpos, ypos; //compute client size, that is the size children can reside in int clientwidth = width - Margin.Horizontal; int clientheight = height - Margin.Vertical; //if we have a physical driver object, we start over at x,y=0,0 otherwise we continue //to build on current x,y DriverCompositeWidget dw = DriverObject as DriverCompositeWidget; Margin decorations = Margin.Empty; if (dw == null) { //no physical driver object xpos = left + Margin.Left; ypos = top + Margin.Top; } else { Margin m = DecorationSize; decorations = dw.GetDecorationSize(); clientwidth -= decorations.Horizontal; clientheight -= decorations.Vertical; Point orig = dw.GetClientOrigin(); xpos = orig.X + Margin.Left; ypos = orig.Y + Margin.Top; } //compute how much space we have for expansion to expandsize int expandsize = clientwidth; int numexpanding = 0; expandsize -= Math.Max(0, Children.Count - 1) * Gap; foreach (Widget child in Children) { expandsize -= child.LayoutInfo.Size.Width; if (child.LayoutInfo.ExpandX) { numexpanding++; } } if (expandsize < 0) { expandsize = 0; } //layout each child, taking expansion and align into account foreach (Widget child in Children) { int childheight = Math.Max( child.LayoutInfo.Size.Height, child.LayoutInfo.ExpandY ? clientheight : child.LayoutInfo.Size.Height ); int childwidth = child.LayoutInfo.Size.Width; if (child.LayoutInfo.ExpandX) { childwidth += expandsize / numexpanding; } int aligned_ypos = ypos; if (child.LayoutInfo.Align == GuppyEx.LayoutAlign.Center) { aligned_ypos = ypos + clientheight / 2 - childheight / 2; } else if (child.LayoutInfo.Align == GuppyEx.LayoutAlign.Bottom) { aligned_ypos = ypos + clientheight - childheight; } child.CalcPositionsRecursive(xpos, aligned_ypos, childwidth, childheight); xpos += childwidth + Gap; } //NEVER CALL BASE CLASS POSITIONER FROM HBOX! /*if (!(this is Window)) //dont place window objects here * base.CalcPositionsRecursive(left, top, width, height);*/ }