summaryrefslogtreecommitdiff
path: root/unsorted/elementary/efl_ui_slider_mono.cs
blob: 6a5c6af16eb371669d6ca09d195686434f26981c (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;

public class Example
{
    public static efl.ui.Button CreateButton(efl.Object parent,
                                             string text,
                                             int w, int h,
                                             EventHandler callback) {
        efl.ui.Button button = new efl.ui.ButtonConcrete(parent);
        button.SetText(text);
        button.SetSize(new eina.Size2D(w, h));

        button.ClickedEvt += callback;

        return button;
    }

    public static void Formatter(eina.Strbuf buf, eina.Value val){
        double ratio;
        if (val.Get(out ratio)) {
            buf.Append($"{(int)(ratio*100)}%");
        } else {
            buf.Append("Error");
        }
    }


#if WIN32 // Passed to the C# compiler with -define:WIN32
    // Mono on Windows by default uses multi-thread apartments for COM stuff while
    // OLE - used by ecore win32 DnD requires single threading for COM.
    [STAThreadAttribute()]
#endif
    public static void Main() {
        int W = 120;
        int H = 30;

        efl.All.Init(efl.Components.Ui);

        efl.ui.Win win = new efl.ui.WinConcrete(null);
        win.SetText("Hello, C#!!");
        win.SetAutohide(true);

        efl.ui.Box_Flow box = new efl.ui.Box_FlowConcrete(win);

        efl.ui.Button button = CreateButton(box, "Click to exit", 120, 30,
                (object sender, EventArgs e) => {
                    efl.ui.Config.Exit();
                });

        box.Pack(button);

        efl.ui.Progressbar bar = new efl.ui.ProgressbarConcrete(box);
        bar.SetSize(new eina.Size2D(W, H));
        bar.SetFormatCb(Formatter);

        efl.ui.Slider slider = new efl.ui.SliderConcrete(box);
        slider.SetSize(new eina.Size2D(W, H));

        slider.ChangedEvt += (object sender, EventArgs e) => {
            bar.SetRangeValue(slider.GetRangeValue());
        };

        box.Pack(bar);
        box.Pack(slider);

        button.SetVisible(true);
        box.SetVisible(true);

        win.SetSize(new eina.Size2D(W, 3 * H));
        win.SetVisible(true);

        efl.ui.Config.Run();

        efl.All.Shutdown();
    }

}