summaryrefslogtreecommitdiff
path: root/reference/csharp/ui/src/ui_custom_widget.cs
blob: c486be6a03f111903c88da5929ed2fb7449b7378 (plain)
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
/*
 * Efl.UI custom widget examples.
 *
 * Inherit from an EFL C# class and customize it
 */

using System;

// This is our own button with customized text functions
public class MyButton : Efl.Ui.Button
{
    // This id shows how our data is preserved when overriden methods
    // are called from native code
    private int button_id;

    // Constructor sets an initial text
    public MyButton(Efl.Object parent, int id = 0) :
        base(parent)
    {
        button_id = id;
        base.SetText("Base text for button id " + id);
    }

    // This calls the parent's SetText() method with a modified string
    public override void SetText(System.String text)
    {
        base.SetText("Overriden text for button id " + button_id + ": " + text);
    }
}

public class Example : Efl.Csharp.Application
{
    protected override void OnInitialize(Eina.Array<System.String> args)
    {
        // Create a window and initialize it
        Efl.Ui.Win win = new Efl.Ui.Win(null, winType: Efl.Ui.WinType.Basic);
        win.SetText("Custom widget demo");
        win.SetAutohide(true);
        win.VisibilityChangedEvt += (object sender, Efl.Gfx.IEntityVisibilityChangedEvt_Args e) => {
          // Exit the EFL main loop when the window is closed
          if (e.arg == false)
              Efl.Ui.Config.Exit();
        };
        // Give the window an initial size
        win.SetSize(new Eina.Size2D(350,250));

        // Instantiate our custom button widget
        MyButton btn = new MyButton(win, 99);
        btn.ClickedEvt += (object sender, Efl.Ui.IClickableClickedEvt_Args e) => {
          // When the button is clicked, change its text
          MyButton b = (MyButton)sender;
          b.SetText("Hello!");
        };

        win.SetContent(btn);
    }
    public static void Main()
    {
        var example = new Example();
        example.Launch();
    }
}