public override void AddAuto(UIComponent comp) { Add(comp); AutoComponents.Add(comp); }
protected override void SelfRemove(UIComponent comp) { AutoComponents.Remove(comp); }
public virtual void AddAuto(UIComponent child) { // some uicomponents expose an auto ordering system // TODO: move that system from uipanel / uiautolist to uicomponent itself?? Add(child); }
protected virtual void SelfRemove(UIComponent comp) { // override if needed }
protected override void SelfInit() { BackgroundColor = Style.BackgroundColor; BackgroundColor2 = Style.SecondaryBackgroundColor; BorderColor = Style.BackgroundAccent; BorderWidth = Style.BorderWidth; OuterBorderColor = Style.BackgroundAccent; OuterBorderWidth = Style.BorderWidth; if (OldAutoComponents != AutoComponents) { DoneAuto = false; AutoOriginalPositions = new Dictionary <int, Vector2>(); } // handle auto components int totalheight = (int)InnerY; int totalwidth = (int)InnerX; int ax = 0; // GetInnerX(); int ay = 0; // GetInnerY(); for (int c = 0; c < AutoComponents.Count; c++) { UIComponent comp = AutoComponents[c]; // if auto has already happened, we need to revert the components to their original // positions before spacing them again. if (!DoneAuto || !AutoOriginalPositions.ContainsKey(c)) { AutoOriginalPositions.Add(c, new Vector2(comp.x, comp.y)); } else { comp.x = AutoOriginalPositions[c].X; comp.y = AutoOriginalPositions[c].Y; } comp.x += ax + MarginX; comp.y += ay + MarginY; int wid = FixedWidthPerIndex > 0 ? FixedWidthPerIndex : comp.GetWidth(); int hei = FixedHeightPerIndex > 0 ? FixedHeightPerIndex : comp.GetHeight(); if (AutoOrientation == eUIOrientation.HORIZONTAL) { if (c > 0) // skip adding extra margin to the first element { ax += wid + MarginX; totalwidth += wid + MarginX * 2; } else { ax += wid; totalwidth += wid + MarginX; } if ((int)InnerY + hei + MarginY * 2 > totalheight) { totalheight = (int)InnerY + hei + MarginY * 2; } } else if (AutoOrientation == eUIOrientation.VERTICAL) { if (c > 0) // skip adding extra margin to the first element { ay += hei + MarginY; totalheight += hei + MarginY * 2; } else { ay += hei; totalheight += hei + MarginY; } if ((int)InnerX + wid + MarginX * 2 > totalwidth) { totalwidth = (int)InnerX + wid + MarginX * 2; } } } DoneAuto = true; OldAutoComponents = AutoComponents; Width = totalwidth; Height = totalheight; if (MaxHeight != 0 && Height > MaxHeight) { Height = MaxHeight; } if (MaxWidth != 0 && Width > MaxWidth) { Width = MaxWidth; } if (LeftAlign) { x = MaxWidth - Width; } if (BottomAlign) { y = MaxHeight - Height; } // exceptions occur if list is empty & these are 0, so clamp them at 1 if (Width == 0) { Width = 1; } if (Height == 0) { Height = 1; } }
public override void Render(float elapsedms, GraphicsDevice g, SpriteBatch sb, InputManager input, float dx, float dy) { // note: this component overwrites the base render logic Rectangle oldrect = RenderTargetScope.Open(sb, (int)Math.Floor(dx + x), (int)Math.Floor(dy + y), Width, Height); { dx += x; dy += y; SelfRender(elapsedms, g, sb, input, dx, dy); if (ComponentsVisible) { int count = 0; int totalw = 0; int totalh = 0; for (int i = StartingIndex; i < Components.Count && (MaxIndex == -1 || i <= MaxIndex) && (MaxCount == -1 || count < MaxCount); i++) { UIComponent u = Components[i]; if (u.Visible) { int uw = 0; int uh = 0; if (AutoOrientation == eUIOrientation.HORIZONTAL) { u.y = MarginY; uh = Height - MarginY * 2; if (FixedWidthPerIndex > 0) { u.x = MarginX + count * (MarginX * 2 + FixedWidthPerIndex); uw = FixedWidthPerIndex; } else { u.x = MarginX + totalw; totalw += u.GetWidth() + MarginX * 2; uw = u.GetWidth(); } } else { u.x = MarginX; uw = Width - MarginX * 2; if (FixedHeightPerIndex > 0) { u.y = MarginY + count * (MarginY * 2 + FixedHeightPerIndex); uh = FixedHeightPerIndex; } else { u.y = MarginY + totalh; totalh += u.GetHeight() + MarginY * 2; uh = u.GetHeight(); } } if (AlternateBackgrounds && count % 2 == 0) { Draw.DrawRectangleHandle(sb, (int)(dx + u.x - MarginX), (int)(dy + u.y - MarginY), uw + MarginX * 2, uh + MarginY * 2, BackgroundColor2); } Rectangle inneroldrect = RenderTargetScope.Open(sb, (int)Math.Floor(dx + u.x), (int)Math.Floor(dy + u.y), uw, uh); { u.Render(elapsedms, g, sb, input, dx + InnerX, dy + InnerY); } RenderTargetScope.Close(sb, inneroldrect); // draw border if (HasBorder) { Draw.DrawRectangleHandleOutline(sb, (int)(dx + u.x - MarginX), (int)(dy + u.y - MarginY), uw + MarginX * 2, uh + MarginY * 2, BorderColor, BorderWidth); } } count++; } } if (HasOuterBorder) { Draw.DrawRectangleHandleOutline(sb, (int)dx, (int)dy, Width, Height, OuterBorderColor, OuterBorderWidth); } } RenderTargetScope.Close(sb, oldrect); }