summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--reference/csharp/ui/src/meson.build7
-rw-r--r--reference/csharp/ui/src/ui_custom_widget.cs62
2 files changed, 69 insertions, 0 deletions
diff --git a/reference/csharp/ui/src/meson.build b/reference/csharp/ui/src/meson.build
index 12a5ef3..bfe5e9a 100644
--- a/reference/csharp/ui/src/meson.build
+++ b/reference/csharp/ui/src/meson.build
@@ -20,3 +20,10 @@ executable('efl_reference_ui_focus',
20 cs_args : efl_mono_libs, 20 cs_args : efl_mono_libs,
21 install : true 21 install : true
22) 22)
23
24executable('efl_reference_ui_custom_widget',
25 files(['ui_custom_widget.cs']),
26 dependencies : deps,
27 cs_args : efl_mono_libs,
28 install : true
29)
diff --git a/reference/csharp/ui/src/ui_custom_widget.cs b/reference/csharp/ui/src/ui_custom_widget.cs
new file mode 100644
index 0000000..c486be6
--- /dev/null
+++ b/reference/csharp/ui/src/ui_custom_widget.cs
@@ -0,0 +1,62 @@
1/*
2 * Efl.UI custom widget examples.
3 *
4 * Inherit from an EFL C# class and customize it
5 */
6
7using System;
8
9// This is our own button with customized text functions
10public class MyButton : Efl.Ui.Button
11{
12 // This id shows how our data is preserved when overriden methods
13 // are called from native code
14 private int button_id;
15
16 // Constructor sets an initial text
17 public MyButton(Efl.Object parent, int id = 0) :
18 base(parent)
19 {
20 button_id = id;
21 base.SetText("Base text for button id " + id);
22 }
23
24 // This calls the parent's SetText() method with a modified string
25 public override void SetText(System.String text)
26 {
27 base.SetText("Overriden text for button id " + button_id + ": " + text);
28 }
29}
30
31public class Example : Efl.Csharp.Application
32{
33 protected override void OnInitialize(Eina.Array<System.String> args)
34 {
35 // Create a window and initialize it
36 Efl.Ui.Win win = new Efl.Ui.Win(null, winType: Efl.Ui.WinType.Basic);
37 win.SetText("Custom widget demo");
38 win.SetAutohide(true);
39 win.VisibilityChangedEvt += (object sender, Efl.Gfx.IEntityVisibilityChangedEvt_Args e) => {
40 // Exit the EFL main loop when the window is closed
41 if (e.arg == false)
42 Efl.Ui.Config.Exit();
43 };
44 // Give the window an initial size
45 win.SetSize(new Eina.Size2D(350,250));
46
47 // Instantiate our custom button widget
48 MyButton btn = new MyButton(win, 99);
49 btn.ClickedEvt += (object sender, Efl.Ui.IClickableClickedEvt_Args e) => {
50 // When the button is clicked, change its text
51 MyButton b = (MyButton)sender;
52 b.SetText("Hello!");
53 };
54
55 win.SetContent(btn);
56 }
57 public static void Main()
58 {
59 var example = new Example();
60 example.Launch();
61 }
62}