public SetVisualSize ( float width, float height ) : void | ||
width | float | |
height | float | |
return | void |
public void Arrange() { int j = flexItems.Count; float curX = 0; float curY = 0; float availableW = AvaliableParentWidth; for (int i = 0; i < j; ++i) { FlexItem flexItem = flexItems[i]; CssBox box = flexItem.Box; box.SetLocation(curX, curY); curX += flexItem.PlanWidth; } //----------------------------------------------- if (curX < availableW) { //find box that can expand List <FlexItem> widthResizableItems = new List <FlexItem>(); for (int i = 0; i < j; ++i) { FlexItem flexItem = flexItems[i]; if (!flexItem.ReachMaxHeight) { widthResizableItems.Add(flexItem); } } //remain some space //so expand it if ((j = widthResizableItems.Count) > 0) { //how to expand it //1. check grow feature int totalExpandCount = 0; for (int i = j - 1; i >= 0; --i) { totalExpandCount += widthResizableItems[i].FlexGrow; } if (totalExpandCount > 0) { float remainingW = availableW - curX; float onePart = remainingW / totalExpandCount; //add to plan width for (int i = j - 1; i >= 0; --i) { widthResizableItems[i].PlanWidth += (onePart * widthResizableItems[i].FlexGrow); } //then rearrange the line again curX = 0;//reset for (int i = 0; i < j; ++i) { FlexItem flexItem = flexItems[i]; CssBox box = flexItem.Box; box.SetLocation(curX, curY); box.SetVisualSize(flexItem.PlanWidth, flexItem.PlanHeight); curX += flexItem.PlanWidth; } } } } else if (curX > availableW) { //use more than available width //find if it can shrink? } this.LineWidthAfterArrange = curX; //----------------------------------------------- //check for height float maxHeight = 0; for (int i = flexItems.Count - 1; i >= 0; --i) { FlexItem flexItem = flexItems[i]; CssBox box = flexItem.Box; if (maxHeight < box.VisualHeight) { maxHeight = box.VisualHeight; } } if (maxHeight < this.AvaliableParentHeight) { //expand item or shrink if (this.flexCssBox.Height.IsEmptyOrAuto) { //autoheight //then set new height for parent this.LineHeightAfterArrange = maxHeight; } else { //try expand flex item for (int i = flexItems.Count - 1; i >= 0; --i) { FlexItem flexItem = flexItems[i]; if (!flexItem.ReachMaxHeight) { flexItem.Box.SetVisualHeight(this.AvaliableParentHeight); } } this.LineHeightAfterArrange = this.AvaliableParentHeight; } } }
public void PerformLayout(LayoutVisitor lay) { if (this._rootBox == null) { return; } //----------------------- //reset _actualWidth = _actualHeight = 0; // if width is not restricted we set it to large value to get the actual later _rootBox.SetLocation(0, 0); _rootBox.SetVisualSize(this._maxWidth > 0 ? this._maxWidth : MAX_WIDTH, 0); CssBox.ValidateComputeValues(_rootBox); //----------------------- //LayoutVisitor layoutArgs = new LayoutVisitor(this.GraphicsPlatform, this); lay.PushContaingBlock(_rootBox); //----------------------- _rootBox.PerformLayout(lay); if (this._maxWidth <= 0.1) { // in case the width is not restricted we need to double layout, first will find the width so second can layout by it (center alignment) _rootBox.SetVisualWidth((int)Math.Ceiling(this._actualWidth)); _actualWidth = _actualHeight = 0; _rootBox.PerformLayout(lay); } lay.PopContainingBlock(); //----------------------- //TODO: review here again FloatingContextStack floatStack = lay.GetFloatingContextStack(); List <FloatingContext> totalContexts = floatStack.GetTotalContexts(); int j = totalContexts.Count; for (int i = 0; i < j; ++i) { FloatingContext floatingContext = totalContexts[i]; int floatBoxCount = floatingContext.FloatBoxCount; if (floatBoxCount == 0) { continue; } CssBox floatingOwner = floatingContext.Owner; float rfx, rfy; floatingOwner.GetGlobalLocation(out rfx, out rfy); CssBox prevParent = null; //TODO: review here again float extraAdjustX = 0; //temp fixed for (int n = 0; n < floatBoxCount; ++n) { float bfx, bfy; CssBox box = floatingContext.GetBox(n); box.GetGlobalLocation(out bfx, out bfy); //diff float nx = bfx - rfx; float ny = bfy - rfy; if (prevParent != null && prevParent != box.ParentBox) { if (n > 0) { CssBox prevFloatChild = floatingContext.GetBox(n - 1); //TODO: review here again //temp fix extraAdjustX = prevFloatChild.ActualMarginRight + box.ActualMarginLeft; ny += box.ActualMarginTop; } } box.SetLocation(nx + extraAdjustX, ny); prevParent = box.ParentBox; floatingOwner.AppendToAbsoluteLayer(box); } } OnLayoutFinished(); //----------------------- unchecked { layoutVersion++; } //----------------------- }
public void SetInnerBox(CssBox innerBox) { if (this.innerBox != null) { return; } this.innerBox = innerBox; this.scrollView = new CssScrollWrapper(innerBox); //scroll barwidth = 10; bool needHScrollBar = false; bool needVScrollBar = false; int originalBoxW = (int)innerBox.VisualWidth; int originalBoxH = (int)innerBox.VisualHeight; int newW = originalBoxW; int newH = originalBoxH; const int scBarWidth = 10; if (innerBox.InnerContentHeight > innerBox.ExpectedHeight) { needVScrollBar = true; newW -= scBarWidth; } if (innerBox.InnerContentWidth > innerBox.ExpectedWidth) { needHScrollBar = true; newH -= scBarWidth; } innerBox.SetVisualSize(newW, newH); innerBox.SetExpectedSize(newW, newH); this.AppendToAbsoluteLayer(innerBox); //check if need vertical scroll and/or horizontal scroll //vertical scrollbar if (needVScrollBar) { this.vscbar = new ScrollBar(scBarWidth, needHScrollBar ? newH : originalBoxH); vscbar.ScrollBarType = ScrollBarType.Vertical; vscbar.MinValue = 0; vscbar.MaxValue = innerBox.VisualHeight; vscbar.SmallChange = 20; //add relation between viewpanel and scroll bar vscRelation = new ScrollingRelation(vscbar.SliderBox, scrollView); //---------------------- var scBarWrapCssBox = LayoutFarm.Composers.CustomCssBoxGenerator.CreateWrapper( this.vscbar, this.vscbar.GetPrimaryRenderElement((RootGraphic)this.GetInternalRootGfx()), CssBox.UnsafeGetBoxSpec(this), false); scBarWrapCssBox.SetLocation(newW, 0); this.AppendToAbsoluteLayer(scBarWrapCssBox); } if (needHScrollBar) { this.hscbar = new ScrollBar(needVScrollBar ? newW : originalBoxW, scBarWidth); hscbar.ScrollBarType = ScrollBarType.Horizontal; hscbar.MinValue = 0; hscbar.MaxValue = innerBox.VisualHeight; hscbar.SmallChange = 20; //add relation between viewpanel and scroll bar hscRelation = new ScrollingRelation(hscbar.SliderBox, scrollView); //---------------------- var renderE = this.hscbar.GetPrimaryRenderElement((RootGraphic)this.GetInternalRootGfx()); var scBarWrapCssBox = LayoutFarm.Composers.CustomCssBoxGenerator.CreateWrapper( this.hscbar, this.hscbar.GetPrimaryRenderElement((RootGraphic)this.GetInternalRootGfx()), CssBox.UnsafeGetBoxSpec(this), false); scBarWrapCssBox.SetLocation(0, newH); this.AppendToAbsoluteLayer(scBarWrapCssBox); } }
public void SetInnerBox(CssBox innerBox) { if (this.innerBox != null) { return; } this.innerBox = innerBox; this.scrollView = new CssScrollWrapper(innerBox); //scroll barwidth = 10; bool needHScrollBar = false; bool needVScrollBar = false; int originalBoxW = (int)innerBox.VisualWidth; int originalBoxH = (int)innerBox.VisualHeight; int newW = originalBoxW; int newH = originalBoxH; const int scBarWidth = 10; if (innerBox.InnerContentHeight > innerBox.ExpectedHeight) { needVScrollBar = true; newW -= scBarWidth; } if (innerBox.InnerContentWidth > innerBox.ExpectedWidth) { needHScrollBar = true; newH -= scBarWidth; } innerBox.SetVisualSize(newW, newH); innerBox.SetExpectedSize(newW, newH); this.AppendToAbsoluteLayer(innerBox); //check if need vertical scroll and/or horizontal scroll //vertical scrollbar if (needVScrollBar) { this.vscbar = new ScrollBar(scBarWidth, needHScrollBar ? newH : originalBoxH); vscbar.ScrollBarType = ScrollBarType.Vertical; vscbar.MinValue = 0; vscbar.MaxValue = innerBox.VisualHeight; vscbar.SmallChange = 20; //add relation between viewpanel and scroll bar vscRelation = new ScrollingRelation(vscbar, scrollView); //---------------------- var scBarWrapCssBox = LayoutFarm.Composers.CustomCssBoxGenerator.CreateWrapper( this.vscbar, this.vscbar.GetPrimaryRenderElement((RootGraphic)this.RootGfx), CssBox.UnsafeGetBoxSpec(this), false); scBarWrapCssBox.SetLocation(newW, 0); this.AppendToAbsoluteLayer(scBarWrapCssBox); } if (needHScrollBar) { this.hscbar = new ScrollBar(needVScrollBar ? newW : originalBoxW, scBarWidth); hscbar.ScrollBarType = ScrollBarType.Horizontal; hscbar.MinValue = 0; hscbar.MaxValue = innerBox.VisualHeight; hscbar.SmallChange = 20; //add relation between viewpanel and scroll bar hscRelation = new ScrollingRelation(hscbar, scrollView); //---------------------- var renderE = this.hscbar.GetPrimaryRenderElement((RootGraphic)this.RootGfx); var scBarWrapCssBox = LayoutFarm.Composers.CustomCssBoxGenerator.CreateWrapper( this.hscbar, this.hscbar.GetPrimaryRenderElement((RootGraphic)this.RootGfx), CssBox.UnsafeGetBoxSpec(this), false); scBarWrapCssBox.SetLocation(0, newH); this.AppendToAbsoluteLayer(scBarWrapCssBox); } }