WidgetSize IWidgetSurface.GetPreferredWidth() { if (widthCached) { return(width); } else { if (!Application.EngineBackend.HandlesSizeNegotiation) { widthCached = true; } if (minWidth != -1 && naturalWidth != -1) { return(new WidgetSize(minWidth, naturalWidth)); } width = OnGetPreferredWidth() + Margin.HorizontalSpacing; if (naturalWidth != -1) { width.NaturalSize = naturalWidth; } if (minWidth != -1) { width.MinSize = minWidth; } if (width.NaturalSize < width.MinSize) { width.NaturalSize = width.MinSize; } return(width); } }
WidgetSize IWidgetSurface.GetPreferredHeightForWidth(double width) { if (heightCached) { return(height); } else { if (!Application.EngineBackend.HandlesSizeNegotiation) { heightCached = true; } if (minHeight != -1 && naturalHeight != -1) { return(new WidgetSize(minHeight, naturalHeight)); } // Horizontal margin is substracted here because that's space which // can't really be used to render the widget width = Math.Max(width - Margin.HorizontalSpacing, 0); height = OnGetPreferredHeightForWidth(width) + Margin.VerticalSpacing; if (naturalHeight != -1) { height.NaturalSize = naturalHeight; } if (minHeight != -1) { height.MinSize = minHeight; } if (height.NaturalSize < height.MinSize) { height.NaturalSize = height.MinSize; } return(height); } }
WidgetSize IWidgetSurface.GetPreferredWidthForHeight(double height) { if (widthCached) { return(width); } else { if (!Application.EngineBackend.HandlesSizeNegotiation) { widthCached = true; } if (minWidth != -1 && naturalWidth != -1) { return(new WidgetSize(minWidth, naturalWidth)); } // Vertical margin is substracted here because that's space which // can't really be used to render the widget height = Math.Max(height - Margin.VerticalSpacing, 0); width = OnGetPreferredWidthForHeight(height) + Margin.HorizontalSpacing; if (naturalWidth != -1) { width.NaturalSize = naturalWidth; } if (minWidth != -1) { width.MinSize = minWidth; } if (width.NaturalSize < width.MinSize) { width.NaturalSize = width.MinSize; } return(width); } }
protected override WidgetSize OnGetPreferredHeight() { WidgetSize s = new WidgetSize(); if (direction == Orientation.Vertical) { int count = 0; foreach (var cw in Children.Where(b => b.Visible)) { s += cw.Surface.GetPreferredHeight(); count++; } if (count > 0) { s += spacing * (double)(count - 1); } } else { foreach (var cw in Children.Where(b => b.Visible)) { s = s.UnionWith(cw.Surface.GetPreferredHeight()); } } return(s); }
WidgetSize GetPreferredLengthForSize(SizeRequestMode mode, double width) { WidgetSize s = new WidgetSize(); if ((direction == Orientation.Horizontal && mode == SizeRequestMode.HeightForWidth) || (direction == Orientation.Vertical && mode == SizeRequestMode.WidthForHeight)) { CalcDefaultSizes(mode, width, -1); foreach (var bp in children.Where(b => b.Child.Visible)) { s = s.UnionWith(GetPreferredLengthForSize(mode, bp.Child, bp.NextSize)); } } else { int count = 0; foreach (var bp in children.Where(b => b.Child.Visible)) { s += GetPreferredLengthForSize(mode, bp.Child, width); count++; } if (count > 0) { s += spacing * (double)(count - 1); } } return(s); }
WidgetSize IWidgetSurface.GetPreferredHeight() { if (heightCached) { return(height); } else { if (!Application.EngineBackend.HandlesSizeNegotiation) { heightCached = true; } if (minHeight != -1 && naturalHeight != -1) { return(new WidgetSize(minHeight, naturalHeight)); } height = OnGetPreferredHeight() + Margin.VerticalSpacing; if (naturalHeight != -1) { height.NaturalSize = naturalHeight; } if (minHeight != -1) { height.MinSize = minHeight; } if (height.NaturalSize < height.MinSize) { height.NaturalSize = height.MinSize; } return(height); } }
protected override WidgetSize OnGetPreferredWidthForHeight(double height) { WidgetSize s = new WidgetSize(); if (child != null) { s += child.Surface.GetPreferredWidthForHeight(height); } return(s); }
protected override WidgetSize OnGetPreferredHeightForWidth(double width) { WidgetSize s = new WidgetSize(); if (child != null) { s += child.Surface.GetPreferredHeightForWidth(width); } return(s); }
protected override WidgetSize OnGetPreferredWidth() { WidgetSize s = new WidgetSize(); if (child != null) { s += child.Surface.GetPreferredWidth(); } return(s); }
public override bool Equals(object obj) { if (!(obj is WidgetSize)) { return(false); } WidgetSize s = (WidgetSize)obj; return(s.MinSize == MinSize && s.NaturalSize == NaturalSize); }
public void UnionWith(WidgetSize s2) { if (s2.MinSize > MinSize) { MinSize = s2.MinSize; } if (s2.NaturalSize > NaturalSize) { NaturalSize = s2.NaturalSize; } }
public WidgetSize GetPreferredHeight() { var h = GetNaturalSize().Height; var s = new Xwt.WidgetSize(h, h); if (minHeight != -1 && s.MinSize > minHeight) { s.MinSize = minHeight; } return(s); }
public WidgetSize GetPreferredHeight() { double h = Widget.WidgetHeight() + frontend.Margin.VerticalSpacing; var s = new Xwt.WidgetSize(h, h); if (minHeight != -1 && s.MinSize > minHeight) { s.MinSize = minHeight; } return(s); }
protected override WidgetSize OnGetPreferredHeight() { WidgetSize s = new WidgetSize(); if (child != null) { s += child.Surface.GetPreferredHeight(); s += Margin.VerticalSpacing; } return(s); }
public WidgetSize GetPreferredWidth() { var w = GetNaturalSize().Width; var s = new Xwt.WidgetSize(w, w); if (minWidth != -1 && s.MinSize > minWidth) { s.MinSize = minWidth; } return(s); }
public WidgetSize GetPreferredWidth() { double w = Widget.WidgetWidth() + frontend.Margin.HorizontalSpacing; var s = new Xwt.WidgetSize(w, w); if (minWidth != -1 && s.MinSize > minWidth) { s.MinSize = minWidth; } return(s); }
protected override WidgetSize OnGetPreferredWidth() { WidgetSize s = new WidgetSize(); if (child != null) { s += child.Surface.GetPreferredWidth(); s += Margin.HorizontalSpacing; } return(s); }
WidgetSize IWidgetSurface.GetPreferredWidth() { if (widthCached) { return(width); } else { widthCached = true; return(width = OnGetPreferredWidth()); } }
WidgetSize IWidgetSurface.GetPreferredHeightForWidth(double width) { if (heightCached) { return(height); } else { heightCached = true; return(height = OnGetPreferredHeightForWidth(width)); } }
WidgetSize IWidgetSurface.GetPreferredWidthForHeight(double height) { if (widthCached) { return(width); } else { widthCached = true; return(width = OnGetPreferredWidthForHeight(height)); } }
WidgetSize IWidgetSurface.GetPreferredHeight() { if (heightCached) { return(height); } else { heightCached = true; return(height = OnGetPreferredHeight()); } }
WidgetSize CalcSize(SizeRequestMode mode, bool calcHeights) { TablePlacement[] visibleChildren; Dictionary <int, WidgetSize> fixedSizesByCell; HashSet <int> cellsWithExpand; WidgetSize[] sizes; double spacing; CalcDefaultSizes(mode, calcHeights, out visibleChildren, out fixedSizesByCell, out cellsWithExpand, out sizes, out spacing); WidgetSize size = new WidgetSize(spacing); foreach (var s in fixedSizesByCell.Values) { size += s; } return(size); }
protected override WidgetSize OnGetPreferredWidth() { WidgetSize s = new WidgetSize(); if (direction == Orientation.Horizontal) { int count = 0; foreach (IWidgetSurface cw in Children.Where(b => b.Visible)) { s += cw.GetPreferredWidth(); count++; } s += spacing * (double)(count - 1); } else { foreach (IWidgetSurface cw in Children.Where(b => b.Visible)) { s.UnionWith(cw.GetPreferredWidth()); } } return(s); }
WidgetSize IWidgetSurface.GetPreferredHeight() { if (heightCached) return height; else { if (!Application.EngineBackend.HandlesSizeNegotiation) heightCached = true; if (minHeight != -1 && naturalHeight != -1) return new WidgetSize (minHeight, naturalHeight); height = OnGetPreferredHeight () + Margin.VerticalSpacing; if (naturalHeight != -1) height.NaturalSize = naturalHeight; if (minHeight != -1) height.MinSize = minHeight; if (height.NaturalSize < height.MinSize) height.NaturalSize = height.MinSize; return height; } }
public virtual WidgetSize GetPreferredWidthForHeight(double height) { bool oldFlag = doubleSizeRequestCheckSupported; try { gettingPreferredSize = true; doubleSizeRequestCheckSupported = false; var s = new WidgetSize (Widget.SizeRequest ().Width); if (minSizeSet && Frontend.MinWidth != -1) s.MinSize = Frontend.MinWidth; return s; } finally { gettingPreferredSize = false; doubleSizeRequestCheckSupported = oldFlag; } }
public virtual WidgetSize GetPreferredHeightForWidth(double width) { try { gettingPreferredSize = true; var s = new WidgetSize (Widget.SizeRequest ().Height); if (minSizeSet && Frontend.MinHeight != -1) s.MinSize = Frontend.MinHeight; return s; } finally { gettingPreferredSize = false; } }
WidgetSize IWidgetSurface.GetPreferredHeightForWidth(double width) { if (heightCached) return height; else { if (!Application.EngineBackend.HandlesSizeNegotiation) heightCached = true; if (minHeight != -1 && naturalHeight != -1) return new WidgetSize (minHeight, naturalHeight); // Horizontal margin is substracted here because that's space which // can't really be used to render the widget width = Math.Max (width - Margin.HorizontalSpacing, 0); height = OnGetPreferredHeightForWidth (width) + Margin.VerticalSpacing; if (naturalHeight != -1) height.NaturalSize = naturalHeight; if (minHeight != -1) height.MinSize = minHeight; if (height.NaturalSize < height.MinSize) height.NaturalSize = height.MinSize; return height; } }
WidgetSize IWidgetSurface.GetPreferredWidthForHeight(double height) { if (widthCached) return width; else { if (!Application.EngineBackend.HandlesSizeNegotiation) widthCached = true; if (minWidth != -1 && naturalWidth != -1) return new WidgetSize (minWidth, naturalWidth); // Vertical margin is substracted here because that's space which // can't really be used to render the widget height = Math.Max (height - Margin.VerticalSpacing, 0); width = OnGetPreferredWidthForHeight (height) + Margin.HorizontalSpacing; if (naturalWidth != -1) width.NaturalSize = naturalWidth; if (minWidth != -1) width.MinSize = minWidth; if (width.NaturalSize < width.MinSize) width.NaturalSize = width.MinSize; return width; } }
protected override WidgetSize OnGetPreferredWidthForHeight(double height) { WidgetSize s = new WidgetSize (); if (child != null) { s += child.Surface.GetPreferredWidthForHeight (height); s += Margin.HorizontalSpacing; } return s; }
void CalcDefaultSizes(SizeRequestMode mode, bool calcHeights, out TablePlacement[] visibleChildren, out Dictionary <int, WidgetSize> fixedSizesByCell, out HashSet <int> cellsWithExpand, out WidgetSize[] sizes, out double spacing) { bool useLengthConstraint = mode == SizeRequestMode.HeightForWidth && calcHeights || mode == SizeRequestMode.WidthForHeight && !calcHeights; visibleChildren = children.Where(b => b.Child.Visible).ToArray(); int lastCell = 0; fixedSizesByCell = new Dictionary <int, WidgetSize> (); cellsWithExpand = new HashSet <int> (); HashSet <int> cellsWithWidget = new HashSet <int> (); sizes = new WidgetSize [visibleChildren.Length]; // Get the size of each widget and store the fixed sizes for widgets which don't span more than one cell for (int n = 0; n < visibleChildren.Length; n++) { var bp = visibleChildren[n]; int start = GetStartAttach(bp, calcHeights); int end = GetEndAttach(bp, calcHeights); if (end > lastCell) { lastCell = end; } // Check if the cell is expandable and store the value AttachOptions ops = calcHeights ? bp.YOptions : bp.XOptions; for (int i = start; i < end; i++) { cellsWithWidget.Add(i); if ((ops & AttachOptions.Expand) != 0) { cellsWithExpand.Add(i); } } WidgetSize s; if (useLengthConstraint) { s = GetPreferredLengthForSize(mode, bp.Child, calcHeights ? bp.NextWidth : bp.NextHeight); } else { s = GetPreferredSize(calcHeights, bp.Child); } sizes [n] = s; if (end == start + 1) { // The widget only takes one cell. Store its size if it is the biggest bool changed = false; WidgetSize fs; fixedSizesByCell.TryGetValue(start, out fs); if (s.MinSize > fs.MinSize) { fs.MinSize = s.MinSize; changed = true; } if (s.NaturalSize > fs.NaturalSize) { fs.NaturalSize = s.NaturalSize; changed = true; } if (changed) { fixedSizesByCell [start] = fs; } } } // For widgets that span more than one cell, calculate the floating size, that is, the size // which is not taken by other fixed size widgets List <TablePlacement> widgetsToAdjust = new List <TablePlacement> (); Dictionary <TablePlacement, WidgetSize[]> growSizes = new Dictionary <TablePlacement, WidgetSize[]> (); for (int n = 0; n < visibleChildren.Length; n++) { var bp = visibleChildren[n]; int start = GetStartAttach(bp, calcHeights); int end = GetEndAttach(bp, calcHeights); if (end == start + 1) { continue; } widgetsToAdjust.Add(bp); WidgetSize fixedSize = new WidgetSize(0); // We are going to calculate the spacing included in the widget's span of cells // (there is spacing between each cell) double spanSpacing = 0; for (int c = start; c < end; c++) { WidgetSize fs; fixedSizesByCell.TryGetValue(c, out fs); fixedSize += fs; if (c != start && c != end) { spanSpacing += GetSpacing(c, calcHeights); } } // sizeToGrow is the size that the whole cell span has to grow in order to fit // this widget. We substract the spacing between cells because that space will // be used by the widget, so we don't need to allocate more size for it WidgetSize sizeToGrow = sizes [n] - fixedSize - new WidgetSize(spanSpacing); WidgetSize sizeToGrowPart = new WidgetSize(sizeToGrow.MinSize / (end - start), sizeToGrow.NaturalSize / (end - start)); // Split the size to grow between the cells of the widget. We need to know how much size the widget // requires for each cell it covers. WidgetSize[] widgetGrowSizes = new WidgetSize [end - start]; for (int i = 0; i < widgetGrowSizes.Length; i++) { widgetGrowSizes [i] = sizeToGrowPart; } growSizes[bp] = widgetGrowSizes; } // Now size-to-grow values have to be adjusted. For example, let's say widget A requires 100px for column 1 and 100px for column 2, and widget B requires // 60px for column 2 and 60px for column 3. So the widgets are overlapping at column 2. Since A requires at least 100px in column 2, it means that B can assume // that it will have 100px available in column 2, which means 40px more than it requested. Those extra 40px can then be substracted from the 60px that // it required for column 3. foreach (var n in cellsWithWidget) { // Get a list of all widgets that cover this cell var colCells = widgetsToAdjust.Where(bp => GetStartAttach(bp, calcHeights) <= n && GetEndAttach(bp, calcHeights) > n).ToArray(); WidgetSize maxv = new WidgetSize(0); TablePlacement maxtMin = null; TablePlacement maxtNatural = null; // Find the widget that requires the maximum size for this cell foreach (var bp in colCells) { WidgetSize cv = growSizes[bp][n - GetStartAttach(bp, calcHeights)]; if (cv.MinSize > maxv.MinSize) { maxv.MinSize = cv.MinSize; maxtMin = bp; } if (cv.NaturalSize > maxv.NaturalSize) { maxv.NaturalSize = cv.NaturalSize; maxtNatural = bp; } } // Adjust the required size of all widgets of the cell (excluding the widget with the max size) foreach (var bp in colCells) { WidgetSize[] widgetGrows = growSizes[bp]; int cellIndex = n - GetStartAttach(bp, calcHeights); if (bp != maxtMin) { double cv = widgetGrows[cellIndex].MinSize; // splitExtraSpace is the additional space that the widget can take from this cell (because there is a widget // that is requiring more space), split among all other cells of the widget double splitExtraSpace = (maxv.MinSize - cv) / (widgetGrows.Length - 1); for (int i = 0; i < widgetGrows.Length; i++) { widgetGrows[i].MinSize -= splitExtraSpace; } } if (bp != maxtNatural) { double cv = widgetGrows[cellIndex].NaturalSize; double splitExtraSpace = (maxv.NaturalSize - cv) / (widgetGrows.Length - 1); for (int i = 0; i < widgetGrows.Length; i++) { widgetGrows[i].NaturalSize -= splitExtraSpace; } } } } // Find the maximum size-to-grow for each cell Dictionary <int, WidgetSize> finalGrowTable = new Dictionary <int, WidgetSize> (); foreach (var bp in widgetsToAdjust) { int start = GetStartAttach(bp, calcHeights); int end = GetEndAttach(bp, calcHeights); WidgetSize[] widgetGrows = growSizes[bp]; for (int n = start; n < end; n++) { WidgetSize curGrow; finalGrowTable.TryGetValue(n, out curGrow); var val = widgetGrows [n - start]; if (val.MinSize > curGrow.MinSize) { curGrow.MinSize = val.MinSize; } if (val.NaturalSize > curGrow.NaturalSize) { curGrow.NaturalSize = val.NaturalSize; } finalGrowTable [n] = curGrow; } } // Add the final size-to-grow to the fixed sizes calculated at the begining foreach (var it in finalGrowTable) { WidgetSize ws; fixedSizesByCell.TryGetValue(it.Key, out ws); fixedSizesByCell [it.Key] = it.Value + ws; } spacing = 0; for (int n = 1; n < lastCell; n++) { if (cellsWithWidget.Contains(n)) { spacing += GetSpacing(n, calcHeights); } } }
WidgetSize IWidgetSurface.GetPreferredHeightForWidth(double width) { if (heightCached) return height; else { heightCached = true; return height = OnGetPreferredHeightForWidth (width); } }
protected override WidgetSize OnGetPreferredHeight() { WidgetSize s = new WidgetSize (); if (child != null) { s += child.Surface.GetPreferredHeight (); s += Margin.VerticalSpacing; } return s; }
public void UnionWith(WidgetSize s2) { if (s2.MinSize > MinSize) MinSize = s2.MinSize; if (s2.NaturalSize > NaturalSize) NaturalSize = s2.NaturalSize; }
WidgetSize IWidgetSurface.GetPreferredWidth() { if (widthCached) return width; else { if (!Application.EngineBackend.HandlesSizeNegotiation) widthCached = true; if (minWidth != -1 && naturalWidth != -1) return new WidgetSize (minWidth, naturalWidth); width = OnGetPreferredWidth () + Margin.HorizontalSpacing; if (naturalWidth != -1) width.NaturalSize = naturalWidth; if (minWidth != -1) width.MinSize = minWidth; if (width.NaturalSize < width.MinSize) width.NaturalSize = width.MinSize; return width; } }
void CalcDefaultSizes(SizeRequestMode mode, double totalSize, double lengthConstraint) { bool calcHeights = direction == Orientation.Vertical; bool useLengthConstraint = mode == SizeRequestMode.HeightForWidth && calcHeights || mode == SizeRequestMode.WidthForHeight && !calcHeights; int nexpands = 0; double naturalSize = 0; var visibleChildren = children.Where(b => b.Child.Visible).ToArray(); var sizes = new Dictionary <BoxPlacement, WidgetSize> (); // Get the natural size of each child foreach (var bp in visibleChildren) { WidgetSize s; if (useLengthConstraint) { s = GetPreferredLengthForSize(mode, bp.Child, lengthConstraint); } else { s = GetPreferredSize(calcHeights, bp.Child); } sizes [bp] = s; naturalSize += s.NaturalSize; bp.NextSize = s.NaturalSize; if ((bp.BoxMode & BoxMode.Expand) != 0) { nexpands++; } } double remaining = totalSize - naturalSize - (spacing * (double)(visibleChildren.Length - 1)); if (remaining < 0) { // The box is not big enough to fit the widgets using its natural size. // We have to shrink the widgets. // List of widgets that we have to shrink var toShrink = new List <BoxPlacement> (visibleChildren); // The total amount we have to shrink double shrinkSize = -remaining; while (toShrink.Count > 0 && shrinkSize > 0) { SizeSplitter sizePart = new SizeSplitter(shrinkSize, toShrink.Count); shrinkSize = 0; for (int i = 0; i < toShrink.Count; i++) { var bp = toShrink[i]; bp.NextSize -= sizePart.NextSizePart(); WidgetSize size = sizes [bp]; if (bp.NextSize < size.MinSize) { // If the widget can't be shrinked anymore, we remove it from the shrink list // and increment the remaining shrink size. We'll loop again and this size will be // substracted from the cells which can still be reduced shrinkSize += (size.MinSize - bp.NextSize); bp.NextSize = size.MinSize; toShrink.RemoveAt(i); i--; } } } } else { var expandRemaining = new SizeSplitter(remaining, nexpands); foreach (var bp in visibleChildren) { if ((bp.BoxMode & BoxMode.Expand) != 0) { bp.NextSize += expandRemaining.NextSizePart(); } } } }
public WidgetSize UnionWith(WidgetSize s2) { return new WidgetSize (Math.Max (MinSize, s2.MinSize), Math.Max (NaturalSize, s2.NaturalSize)); }
WidgetSize IWidgetSurface.GetPreferredWidthForHeight(double height) { if (widthCached) return width; else { widthCached = true; return width = OnGetPreferredWidthForHeight (height); } }
public virtual WidgetSize GetPreferredWidthForHeight(double height) { try { gettingPreferredSize = true; var s = new WidgetSize (Widget.SizeRequest ().Width); if (minSizeSet && Frontend.MinWidth != -1) s.MinSize = Frontend.MinWidth; return s; } finally { gettingPreferredSize = false; } }
WidgetSize IWidgetSurface.GetPreferredWidth() { if (widthCached) return width; else { widthCached = true; return width = OnGetPreferredWidth (); } }
WidgetSize IWidgetSurface.GetPreferredHeight() { if (heightCached) return height; else { heightCached = true; return height = OnGetPreferredHeight (); } }
public WidgetSize UnionWith(WidgetSize s2) { return(new WidgetSize(Math.Max(MinSize, s2.MinSize), Math.Max(NaturalSize, s2.NaturalSize))); }