ui/wpf/UIcore/Controls.cs

Tue, 16 Feb 2016 17:39:33 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 16 Feb 2016 17:39:33 +0100
changeset 123
55adc92e7c09
parent 104
3efe0210e27e
child 135
b9dc9cdfa23a
permissions
-rw-r--r--

fixed build with older gtk3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace UI
{  
    public class Controls
    {

        public static Button Button(Container container, String label, RoutedEventHandler e)
        {
            return Application.GetInstance().Exec<Button>(() => Controls.CreateButton(container, label, e));
        }

        public static Label Label(Container container, String label, int alignment)
        {
            HorizontalAlignment a;
            switch(alignment)
            {
                case 0: a = HorizontalAlignment.Left; break;
                case 1: a = HorizontalAlignment.Right; break;
                case 2: a = HorizontalAlignment.Center; break;
                default: a = HorizontalAlignment.Left; break;
            }
            return Application.GetInstance().Exec<Label>(() => Controls.CreateLabel(container, label, a));
        }

        public static Label Space(Container container)
        {
            return Application.GetInstance().Exec<Label>(() => Controls.CreateLabel(container, null, HorizontalAlignment.Center));
        }

        public static Separator Separator(Container container)
        {
            return Application.GetInstance().Exec<Separator>(() => Controls.CreateSeparator(container));
        }

        public static Button CreateButton(Container container, String label, RoutedEventHandler e)
        {
            Button button = new Button();
            button.Content = label;
            container.Add(button, false);

            button.Click += e;

            return button;
        }

        public static Label CreateLabel(Container container, String str, HorizontalAlignment alignment)
        {
            Label label = new Label();
            label.HorizontalAlignment = alignment;
            label.Content = str;
            container.Add(label, false);

            return label;
        }

        public static Separator CreateSeparator(Container container)
        {
            Separator separator = new Separator();
            container.Add(separator, false);
            return separator;
        }
    }
}

mercurial