-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
UIPanel.cs
64 lines (52 loc) · 1.85 KB
/
UIPanel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using Molten.Graphics;
namespace Molten.UI;
public class UIPanel : UIElement
{
/// <summary>
/// The border color
/// </summary>
[UIThemeMember]
public Color BorderColor = new Color(52, 189, 235, 255);
/// <summary>
/// The border line thickness
/// </summary>
[UIThemeMember]
public UIPadding BorderThickness { get; } = new UIPadding(2);
/// <summary>
/// The fill/inner color of the current <see cref="UIPanel"/>.
/// </summary>
[UIThemeMember]
public Color FillColor = new Color(0, 109, 155, 200);
/// <summary>
/// The corner radius values of the current <see cref="UIPanel"/>. Setting them all to 0 will produce a regular rectangle.
/// </summary>
[UIThemeMember]
public CornerInfo CornerRadius = new CornerInfo(8f);
protected override void OnInitialize(Engine engine, UISettings settings)
{
base.OnInitialize(engine, settings);
BorderThickness.OnChanged += BorderThickness_OnChanged;
InputRules = UIInputRuleFlags.Children;
}
private void BorderThickness_OnChanged(UIPadding value)
{
UpdateBounds();
}
protected override void OnAdjustRenderBounds(ref Rectangle renderbounds)
{
renderbounds.Inflate(-BorderThickness.Left, -BorderThickness.Top, -BorderThickness.Right, -BorderThickness.Bottom);
}
protected override void OnRender(SpriteBatcher sb)
{
float radiusLimit = Math.Min(GlobalBounds.Width, GlobalBounds.Height) / 2;
RoundedRectStyle style = new RoundedRectStyle()
{
FillColor = FillColor,
BorderColor = BorderColor,
BorderThickness = BorderThickness.Top,
CornerRadius = CornerRadius.Restrict(radiusLimit)
};
sb.DrawRoundedRect((RectangleF)GlobalBounds, 0, Vector2F.Zero, ref style);
base.OnRender(sb);
}
}