/// <summary> /// Overload added to prevent implicit casting to ConstraintCategory when edgeDistance is set to 0. /// http://geekswithblogs.net/BlackRabbitCoder/archive/2012/01/26/c.net-little-pitfalls-implicit-zero-to-enum-conversion.aspx /// </summary> public static void AddConstraint(this UIControl control, Edge controlEdge, UIControl anchor, Edge anchorEdge, int edgeDistance) { control.AddConstraint(controlEdge, anchor, anchorEdge, edgeDistance, ConstraintCategory.All); }
/// <summary> /// Adds a UI constraint to this control. /// </summary> /// <param name="control">Control instance.</param> /// <param name="controlEdge">Control edge to constraint.</param> /// <param name="anchor">Anchoring control on which the control edge is constrained. If 'null', the control is anchored relative to the viewport.</param> /// <param name="anchorEdge">Anchor edge on which the control edge is constrained relative to.</param> /// <param name="category">The category this constaint belongs to.</param> public static void AddConstraint(this UIControl control, Edge controlEdge, UIControl anchor, Edge anchorEdge, ConstraintCategory category) { control.AddConstraint(controlEdge, anchor, anchorEdge, 0f, category); }
public UIScrollBar(ScrollBarOrientation orientation = ScrollBarOrientation.Vertical) { Orientation = orientation; string arrowResource = string.Empty; Vector2 sliderSize = Vector2.Zero; switch (orientation) { case ScrollBarOrientation.Vertical: sliderSize = new Vector2(0, 20); arrowResource = "graphics/arrow_down"; break; case ScrollBarOrientation.Horizontal: sliderSize = new Vector2(20, 0); arrowResource = "graphics/arrow_left"; break; } AutoSize = false; scrollStep = 0.02f; Color = new Color(240, 240, 240); Alpha = 1f; DrawBounds = true; sliderBackground = new UIPanel(); sliderBackground.Color = new Color(240, 240, 240); sliderBackground.Alpha = 1f; sliderBackground.InputMoved += sliderBackground_MouseMoved; sliderBackground.InputPressed += sliderBackground_MousePressed; slider = new UIPanel(); slider.Color = new Color(205, 205, 205); slider.Alpha = 1f; slider.AutoSize = false; slider.AbsorbPointer = false; slider.Size = sliderSize; //slider.InputDown += sliderBackground_MousePressed; arrowA = new UIButton(); var arrowAImg = new UIImage(arrowResource); arrowAImg.Color = new Color(96, 96, 96); arrowAImg.AddConstraint(Edge.Dock, arrowA, Edge.Dock); arrowA.Tag = "bla"; arrowA.AddDecoration(arrowAImg); arrowA.PointedColor = new Color(190, 190, 190); arrowA.PressedColor = new Color(120, 120, 120); arrowA.HighlightZoom = false; arrowA.InputDown += arrowA_MouseHeld; arrowB = new UIButton(); var arrowBImg = new UIImage(arrowResource); arrowBImg.Color = new Color(96, 96, 96); arrowBImg.AddConstraint(Edge.Dock, arrowB, Edge.Dock); arrowB.AddDecoration(arrowBImg); arrowB.PointedColor = new Color(190, 190, 190); arrowB.PressedColor = new Color(120, 120, 120); arrowB.HighlightZoom = false; arrowB.InputDown += arrowB_MouseHeld; switch (orientation) { case ScrollBarOrientation.Vertical: arrowAImg.SpriteEffect = SpriteEffects.FlipVertically; arrowA.AddConstraint(Edge.Horizontal | Edge.Top, this, Edge.Horizontal | Edge.Top); arrowB.AddConstraint(Edge.Horizontal, this, Edge.Horizontal); arrowB.AddConstraint(Edge.Bottom, this, Edge.Bottom); sliderBackground.AddConstraint(Edge.Horizontal, this, Edge.Horizontal); sliderBackground.AddConstraint(Edge.Top, arrowA, Edge.Bottom); sliderBackground.AddConstraint(Edge.Bottom, arrowB, Edge.Top); slider.AddConstraint(Edge.Top, sliderBackground, Edge.Top, ConstraintCategory.Initialization); slider.AddConstraint(Edge.Horizontal, sliderBackground, Edge.Horizontal); break; case ScrollBarOrientation.Horizontal: arrowBImg.SpriteEffect = SpriteEffects.FlipHorizontally; arrowA.AddConstraint(Edge.Vertical | Edge.Left, this, Edge.Vertical | Edge.Left); arrowB.AddConstraint(Edge.Vertical, this, Edge.Vertical); arrowB.AddConstraint(Edge.Right, this, Edge.Right); sliderBackground.AddConstraint(Edge.Vertical, this, Edge.Vertical); sliderBackground.AddConstraint(Edge.Left, arrowA, Edge.Right); sliderBackground.AddConstraint(Edge.Right, arrowB, Edge.Left); slider.AddConstraint(Edge.Left, sliderBackground, Edge.Left, ConstraintCategory.Initialization); slider.AddConstraint(Edge.Vertical, sliderBackground, Edge.Vertical); break; } AbsorbPointer = false; //base.AbsorbPointer = true; //slider.AbsorbPointer = true; //arrowDown.AbsorbPointer = true; //arrowUp.AbsorbPointer = true; sliderBackground.AbsorbPointer = true; AddChild(arrowA); AddChild(arrowB); AddChild(sliderBackground); AddChild(slider); }