A game framework written with osu! in mind.
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2// See the LICENCE file in the repository root for full licence text.
3
4using System;
5using osu.Framework.Allocation;
6using osu.Framework.Graphics;
7using osu.Framework.Graphics.Containers;
8using osu.Framework.Graphics.Shapes;
9using osu.Framework.Graphics.Sprites;
10using osuTK;
11using osuTK.Graphics;
12
13namespace osu.Framework.Testing.Drawables
14{
15 internal class TestButton : TestButtonBase
16 {
17 private SpriteIcon icon;
18 private Container leftBoxContainer;
19 private const float left_box_width = LEFT_TEXT_PADDING / 2;
20
21 public TestButton(string header)
22 : base(header)
23 {
24 }
25
26 public TestButton(Type type)
27 : base(type)
28 {
29 }
30
31 [BackgroundDependencyLoader]
32 private void load()
33 {
34 AddRange(new Drawable[]
35 {
36 new Box
37 {
38 Colour = FrameworkColour.Green,
39 RelativeSizeAxes = Axes.Both
40 },
41 leftBoxContainer = new Container
42 {
43 RelativeSizeAxes = Axes.Both,
44 Width = 0,
45 Padding = new MarginPadding { Right = -left_box_width },
46 Child = new Box
47 {
48 Colour = FrameworkColour.YellowGreen,
49 RelativeSizeAxes = Axes.Both,
50 },
51 },
52 icon = new SpriteIcon
53 {
54 Size = new Vector2(10),
55 Icon = FontAwesome.Solid.ChevronDown,
56 Colour = Color4.White,
57 Margin = new MarginPadding { Right = left_box_width + 5 },
58 Anchor = Anchor.CentreRight,
59 Origin = Anchor.CentreRight,
60 }
61 });
62 }
63
64 public override bool Current
65 {
66 set
67 {
68 base.Current = value;
69
70 icon.FadeColour(value ? Color4.Black : Color4.White, 100);
71
72 if (value)
73 {
74 leftBoxContainer.ResizeWidthTo(1, TRANSITION_DURATION);
75 leftBoxContainer.TransformTo(nameof(Padding), new MarginPadding { Right = left_box_width }, TRANSITION_DURATION);
76 Content.TransformTo(nameof(Padding), new MarginPadding { Right = 0f }, TRANSITION_DURATION);
77 }
78 else
79 {
80 leftBoxContainer.ResizeWidthTo(0, TRANSITION_DURATION);
81 leftBoxContainer.TransformTo(nameof(Padding), new MarginPadding { Right = -left_box_width }, TRANSITION_DURATION);
82 Content.TransformTo(nameof(Padding), new MarginPadding { Right = LEFT_TEXT_PADDING }, TRANSITION_DURATION);
83 }
84 }
85 }
86
87 public override bool Collapsed
88 {
89 set
90 {
91 icon.Icon = value ? FontAwesome.Solid.ChevronDown : FontAwesome.Solid.ChevronUp;
92 base.Collapsed = value;
93 }
94 }
95
96 public override void Show()
97 {
98 }
99
100 public override void Hide()
101 {
102 }
103 }
104}