Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Duality;
- using Duality.Resources;
- using SnowyPeak.Duality.Plugins.YAUI;
- using SnowyPeak.Duality.Plugins.YAUI.Controls;
- using SnowyPeak.Duality.Plugins.YAUI.Controls.Configuration;
- using System.Text;
- using System.Threading.Tasks;
- namespace UITest
- {
- public class ShowcaseUI : UI
- {
- protected override ControlsContainer CreateUI()
- {
- DockPanel root = new DockPanel();
- // Grid: 4 rows, 2 columns
- GridPanel grid = new GridPanel()
- {
- Docking = Dock.Left,
- Rows = new float[] { .25f, .25f, .25f, .25f },
- Columns = new float[] { .5f, .5f },
- Margin = new Border(5),
- Size = new Size(200)
- };
- // some grouped radiobuttons
- for (int r = 0; r < grid.Rows.Length - 1; r++)
- {
- for (int c = 0; c < grid.Columns.Length; c++)
- {
- RadioButton rb = new RadioButton()
- {
- RadioGroup = "RadioGroup",
- Text = String.Format("Radio/n@Cell {0},{1}", r, c),
- Cell = new CellInfo()
- {
- Row = r,
- Column = c
- }
- };
- // don't forget to clone the configuration when you want to set specific values
- // it's shared with all controls otherwise!
- rb.TextConfiguration = rb.TextConfiguration.Clone();
- rb.TextConfiguration.Alignment = Alignment.Center;
- rb.GlyphConfiguration = rb.GlyphConfiguration.Clone();
- rb.GlyphConfiguration.Alignment = Alignment.Top;
- grid.Add(rb);
- }
- }
- // A column-spanning listbox
- ListBox listBox = new ListBox()
- {
- MultiSelection = true,
- Cell = new CellInfo()
- {
- Row = grid.Rows.Length - 1,
- ColSpan = 2
- }
- };
- listBox.SetItems(new string[] { "One", "Two", "3", "Four", "5!", "Six", "Seven", "Even 8" });
- grid.Add(listBox);
- // Vertical stack
- StackPanel stackV = new StackPanel()
- {
- Docking = Dock.Right,
- Direction = Direction.UpToDown,
- Margin = new Border(5),
- Size = new Size(200)
- };
- // Buttons to change skin.
- // Notice: once you change skin, you lose all the preferences you set in this one
- // Supported but not that useful IMHO
- stackV.Add(new Button()
- {
- Text = "Apply Light Skin",
- Size = new Size(30),
- MouseButtonEventHandler = (sender, e) =>
- {
- root.ApplySkin(Skin.YAUI_ROUNDED);
- }
- });
- stackV.Add(new Separator() { Size = new Size(5) });
- stackV.Add(new Button()
- {
- Text = "Apply Dark Skin",
- Size = new Size(30),
- MouseButtonEventHandler = (sender, e) =>
- {
- root.ApplySkin(Skin.YAUI_DARK);
- }
- });
- stackV.Add(new Separator() { Size = new Size(5) });
- stackV.Add(new Button()
- {
- Text = "Apply Fathoms Skin",
- Size = new Size(30),
- MouseButtonEventHandler = (sender, e) =>
- {
- root.ApplySkin(Skin.YAUI_FATHOMS);
- }
- });
- // Some textboxes now.. disabled, enabled and password
- stackV.Add(new Separator() { Size = new Size(15) });
- TextBox textBoxDisabled = new TextBox()
- {
- Text = "This is disabled.. :(",
- Size = new Size(30),
- Status = Control.ControlStatus.Disabled,
- };
- textBoxDisabled.TextConfiguration = textBoxDisabled.TextConfiguration.Clone();
- textBoxDisabled.TextConfiguration.Alignment = Alignment.Right;
- stackV.Add(textBoxDisabled);
- stackV.Add(new Separator() { Size = new Size(5) });
- TextBox textBox = new TextBox()
- {
- Text = "This is not :)",
- Size = new Size(30)
- };
- stackV.Add(textBox);
- stackV.Add(new Separator() { Size = new Size(5) });
- stackV.Add(new TextBox()
- {
- Text = "Password!",
- IsPassword = true,
- MaxLength = 15,
- Size = new Size(30),
- });
- // Make some space
- stackV.Add(new Separator() { Size = new Size(15) });
- // Auto-increasing progress bar
- ProgressBar pBar = new ProgressBar()
- {
- Size = new Size(30),
- UpdateHandler = (sender, ms) =>
- {
- ProgressBar p = sender as ProgressBar;
- p.Value += (ms / 1000 / 10);
- if (p.Value == 1) p.Value = 0;
- p.Text = String.Format("Restart in {0:0}...", (1 - p.Value) * 10);
- }
- };
- pBar.TextConfiguration = pBar.TextConfiguration.Clone();
- pBar.TextConfiguration.Alignment = Alignment.Center;
- stackV.Add(pBar);
- stackV.Add(new Separator() { Size = new Size(15) });
- // A textblock
- stackV.Add(new TextBlock()
- {
- Size = new Size(80),
- Text = "Text/nNewLine/nAnd Another"
- });
- // Horizontal stack...
- StackPanel stackH = new StackPanel()
- {
- Docking = Dock.Bottom,
- Direction = Direction.LeftToRight,
- Margin = new Border(5),
- Size = new Size(80)
- };
- // ... with 3 togglebuttons
- for (int i = 0; i < 3; i++)
- {
- ToggleButton b = new ToggleButton()
- {
- Text = "Toggle/nButton",
- Size = new Size(120)
- };
- b.TextConfiguration = b.TextConfiguration.Clone();
- b.TextConfiguration.Alignment = Alignment.Right;
- stackH.Add(b);
- stackH.Add(new Separator() { Size = new Size(5) });
- }
- // This togglebutton controls the following progressbar
- ToggleButton stopAndGo = new ToggleButton()
- {
- Text = "Stop&Go",
- Size = new Size(80)
- };
- stackH.Add(stopAndGo);
- // and this progressbar won't increase unless the previous togglebutton is Toggled
- ProgressBar vBar = new ProgressBar()
- {
- Size = new Size(40),
- UpdateHandler = (sender, ms) =>
- {
- if (stopAndGo.Toggled)
- {
- ProgressBar p = sender as ProgressBar;
- p.Value += (ms / 1000 / 8); // takes 8 seconds to fill
- if (p.Value == 1) p.Value = 0;
- }
- }
- };
- vBar.ProgressConfiguration = vBar.ProgressConfiguration.Clone();
- vBar.ProgressConfiguration.Direction = Direction.DownToUp;
- stackH.Add(vBar);
- // Central panel: canvas w/ scrollbars!
- DockPanel central = new DockPanel();
- CanvasPanel canvas = new CanvasPanel();
- HorizontalScrollBar hScrollBar = new HorizontalScrollBar()
- {
- ValueChangedEventHandler = (sender, e) => {
- canvas.Offset.X = -(sender.Value * 2);
- }
- };
- VerticalScrollBar vScrollBar = new VerticalScrollBar()
- {
- Docking = Dock.Right,
- ValueChangedEventHandler = (sender, e) => {
- canvas.Offset.Y = -(sender.Value * 2);
- }
- };
- // Stupid function checkbutton.. makes things move
- CheckButton funButton = new CheckButton()
- {
- Size = new Size(150, 50),
- Position = new Vector2(100, 200),
- Text = "Checked = fun!",
- UpdateHandler = (sender, ms) => {
- if ((sender as CheckButton).Checked)
- {
- bool growing = Convert.ToBoolean(sender.Tag);
- stackV.Size.X += (ms * .1f * (growing ? 1 : -1));
- if (stackV.Size.X > 300) sender.Tag = false;
- if (stackV.Size.X < 150) sender.Tag = true;
- }
- }
- };
- canvas.Add(funButton);
- // Pack it all up together
- DockPanel cBottom = new DockPanel() { Docking = Dock.Bottom, Size = new Size(20) };
- cBottom.Add(new Separator() { Docking = Dock.Right, Size = new Size(20) });
- cBottom.Add(hScrollBar);
- central
- .Add(cBottom)
- .Add(vScrollBar)
- .Add(canvas);
- return root.Add(stackH)
- .Add(grid)
- .Add(stackV)
- .Add(central);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement