Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. using Duality;
  6. using Duality.Resources;
  7. using SnowyPeak.Duality.Plugins.YAUI;
  8. using SnowyPeak.Duality.Plugins.YAUI.Controls;
  9. using SnowyPeak.Duality.Plugins.YAUI.Controls.Configuration;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12.  
  13. namespace UITest
  14. {
  15.     public class ShowcaseUI : UI
  16.     {
  17.         protected override ControlsContainer CreateUI()
  18.         {
  19.             DockPanel root = new DockPanel();
  20.  
  21.             // Grid: 4 rows, 2 columns
  22.             GridPanel grid = new GridPanel()
  23.             {
  24.                 Docking = Dock.Left,
  25.                 Rows = new float[] { .25f, .25f, .25f, .25f },
  26.                 Columns = new float[] { .5f, .5f },
  27.                 Margin = new Border(5),
  28.                 Size = new Size(200)
  29.             };
  30.  
  31.             // some grouped radiobuttons
  32.             for (int r = 0; r < grid.Rows.Length - 1; r++)
  33.             {
  34.                 for (int c = 0; c < grid.Columns.Length; c++)
  35.                 {
  36.                     RadioButton rb = new RadioButton()
  37.                     {
  38.                         RadioGroup = "RadioGroup",
  39.                         Text = String.Format("Radio/n@Cell {0},{1}", r, c),
  40.                         Cell = new CellInfo()
  41.                         {
  42.                             Row = r,
  43.                             Column = c
  44.                         }
  45.                     };
  46.  
  47.                     // don't forget to clone the configuration when you want to set specific values
  48.                     // it's shared with all controls otherwise!
  49.                     rb.TextConfiguration = rb.TextConfiguration.Clone();
  50.                     rb.TextConfiguration.Alignment = Alignment.Center;
  51.                     rb.GlyphConfiguration = rb.GlyphConfiguration.Clone();
  52.                     rb.GlyphConfiguration.Alignment = Alignment.Top;
  53.  
  54.                     grid.Add(rb);
  55.                 }
  56.             }
  57.  
  58.             // A column-spanning listbox
  59.             ListBox listBox = new ListBox()
  60.             {
  61.                 MultiSelection = true,
  62.                 Cell = new CellInfo()
  63.                 {
  64.                     Row = grid.Rows.Length - 1,
  65.                     ColSpan = 2
  66.                 }
  67.             };
  68.             listBox.SetItems(new string[] { "One", "Two", "3", "Four", "5!", "Six", "Seven", "Even 8" });
  69.  
  70.             grid.Add(listBox);
  71.  
  72.             // Vertical stack
  73.             StackPanel stackV = new StackPanel()
  74.             {
  75.                 Docking = Dock.Right,
  76.                 Direction = Direction.UpToDown,
  77.                 Margin = new Border(5),
  78.                 Size = new Size(200)
  79.             };
  80.  
  81.             // Buttons to change skin.
  82.             // Notice: once you change skin, you lose all the preferences you set in this one
  83.             // Supported but not that useful IMHO
  84.             stackV.Add(new Button()
  85.             {
  86.                 Text = "Apply Light Skin",
  87.                 Size = new Size(30),
  88.                 MouseButtonEventHandler = (sender, e) =>
  89.                 {
  90.                     root.ApplySkin(Skin.YAUI_ROUNDED);
  91.                 }
  92.             });
  93.             stackV.Add(new Separator() { Size = new Size(5) });
  94.             stackV.Add(new Button()
  95.             {
  96.                 Text = "Apply Dark Skin",
  97.                 Size = new Size(30),
  98.                 MouseButtonEventHandler = (sender, e) =>
  99.                 {
  100.                     root.ApplySkin(Skin.YAUI_DARK);
  101.                 }
  102.             });
  103.             stackV.Add(new Separator() { Size = new Size(5) });
  104.             stackV.Add(new Button()
  105.             {
  106.                 Text = "Apply Fathoms Skin",
  107.                 Size = new Size(30),
  108.                 MouseButtonEventHandler = (sender, e) =>
  109.                 {
  110.                     root.ApplySkin(Skin.YAUI_FATHOMS);
  111.                 }
  112.             });
  113.  
  114.             // Some textboxes now.. disabled, enabled and password
  115.             stackV.Add(new Separator() { Size = new Size(15) });
  116.             TextBox textBoxDisabled = new TextBox()
  117.             {
  118.                 Text = "This is disabled.. :(",
  119.                 Size = new Size(30),
  120.                 Status = Control.ControlStatus.Disabled,
  121.             };
  122.             textBoxDisabled.TextConfiguration = textBoxDisabled.TextConfiguration.Clone();
  123.             textBoxDisabled.TextConfiguration.Alignment = Alignment.Right;
  124.             stackV.Add(textBoxDisabled);
  125.             stackV.Add(new Separator() { Size = new Size(5) });
  126.             TextBox textBox = new TextBox()
  127.             {
  128.                 Text = "This is not :)",
  129.                 Size = new Size(30)
  130.             };
  131.             stackV.Add(textBox);
  132.             stackV.Add(new Separator() { Size = new Size(5) });
  133.             stackV.Add(new TextBox()
  134.             {
  135.                 Text = "Password!",
  136.                 IsPassword = true,
  137.                 MaxLength = 15,
  138.                 Size = new Size(30),
  139.             });
  140.  
  141.             // Make some space
  142.             stackV.Add(new Separator() { Size = new Size(15) });
  143.  
  144.             // Auto-increasing progress bar
  145.             ProgressBar pBar = new ProgressBar()
  146.             {
  147.                 Size = new Size(30),
  148.                 UpdateHandler = (sender, ms) =>
  149.                 {
  150.                     ProgressBar p = sender as ProgressBar;
  151.                     p.Value += (ms / 1000 / 10);
  152.                     if (p.Value == 1) p.Value = 0;
  153.  
  154.                     p.Text = String.Format("Restart in {0:0}...", (1 - p.Value) * 10);
  155.                 }
  156.             };
  157.             pBar.TextConfiguration = pBar.TextConfiguration.Clone();
  158.             pBar.TextConfiguration.Alignment = Alignment.Center;
  159.             stackV.Add(pBar);
  160.             stackV.Add(new Separator() { Size = new Size(15) });
  161.  
  162.             // A textblock
  163.             stackV.Add(new TextBlock()
  164.             {
  165.                 Size = new Size(80),
  166.                 Text = "Text/nNewLine/nAnd Another"
  167.             });
  168.  
  169.             // Horizontal stack...
  170.             StackPanel stackH = new StackPanel()
  171.             {
  172.                 Docking = Dock.Bottom,
  173.                 Direction = Direction.LeftToRight,
  174.                 Margin = new Border(5),
  175.                 Size = new Size(80)
  176.             };
  177.  
  178.             // ... with 3 togglebuttons
  179.             for (int i = 0; i < 3; i++)
  180.             {
  181.                 ToggleButton b = new ToggleButton()
  182.                 {
  183.                     Text = "Toggle/nButton",
  184.                     Size = new Size(120)
  185.                 };
  186.  
  187.                 b.TextConfiguration = b.TextConfiguration.Clone();
  188.                 b.TextConfiguration.Alignment = Alignment.Right;
  189.  
  190.                 stackH.Add(b);
  191.                 stackH.Add(new Separator() { Size = new Size(5) });
  192.             }
  193.  
  194.             // This togglebutton controls the following progressbar
  195.             ToggleButton stopAndGo = new ToggleButton()
  196.             {
  197.                 Text = "Stop&Go",
  198.                 Size = new Size(80)
  199.             };
  200.             stackH.Add(stopAndGo);
  201.  
  202.             // and this progressbar won't increase unless the previous togglebutton is Toggled
  203.             ProgressBar vBar = new ProgressBar()
  204.             {
  205.                 Size = new Size(40),
  206.                 UpdateHandler = (sender, ms) =>
  207.                 {
  208.                     if (stopAndGo.Toggled)
  209.                     {
  210.                         ProgressBar p = sender as ProgressBar;
  211.                         p.Value += (ms / 1000 / 8); // takes 8 seconds to fill
  212.                         if (p.Value == 1) p.Value = 0;
  213.                     }
  214.                 }
  215.             };
  216.             vBar.ProgressConfiguration = vBar.ProgressConfiguration.Clone();
  217.             vBar.ProgressConfiguration.Direction = Direction.DownToUp;
  218.  
  219.             stackH.Add(vBar);
  220.  
  221.             // Central panel: canvas w/ scrollbars!
  222.             DockPanel central = new DockPanel();
  223.             CanvasPanel canvas = new CanvasPanel();
  224.  
  225.             HorizontalScrollBar hScrollBar = new HorizontalScrollBar()
  226.             {
  227.                 ValueChangedEventHandler = (sender, e) => {
  228.                     canvas.Offset.X = -(sender.Value * 2);
  229.                 }
  230.             };
  231.  
  232.             VerticalScrollBar vScrollBar = new VerticalScrollBar()
  233.             {
  234.                 Docking = Dock.Right,
  235.                 ValueChangedEventHandler = (sender, e) => {
  236.                     canvas.Offset.Y = -(sender.Value * 2);
  237.                 }
  238.             };
  239.  
  240.             // Stupid function checkbutton.. makes things move
  241.             CheckButton funButton = new CheckButton()
  242.             {
  243.                 Size = new Size(150, 50),
  244.                 Position = new Vector2(100, 200),
  245.                 Text = "Checked = fun!",
  246.                 UpdateHandler = (sender, ms) => {
  247.                     if ((sender as CheckButton).Checked)
  248.                     {
  249.                         bool growing = Convert.ToBoolean(sender.Tag);
  250.  
  251.                         stackV.Size.X += (ms * .1f * (growing ? 1 : -1));
  252.                         if (stackV.Size.X > 300) sender.Tag = false;
  253.                         if (stackV.Size.X < 150) sender.Tag = true;
  254.                     }
  255.                 }
  256.             };
  257.  
  258.             canvas.Add(funButton);
  259.  
  260.             // Pack it all up together
  261.             DockPanel cBottom = new DockPanel() { Docking = Dock.Bottom, Size = new Size(20) };
  262.             cBottom.Add(new Separator() { Docking = Dock.Right, Size = new Size(20) });
  263.             cBottom.Add(hScrollBar);
  264.  
  265.             central
  266.                 .Add(cBottom)
  267.                 .Add(vScrollBar)
  268.                 .Add(canvas);
  269.  
  270.             return root.Add(stackH)
  271.                 .Add(grid)
  272.                 .Add(stackV)
  273.                 .Add(central);
  274.         }
  275.     }
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement