aboutsummaryrefslogtreecommitdiffstats
path: root/reference
diff options
context:
space:
mode:
authorXavi Artigas <xavierartigas@yahoo.es>2019-06-14 12:27:40 +0200
committerXavi Artigas <xavierartigas@yahoo.es>2019-06-14 12:27:40 +0200
commitb2c7e2c2dde65d72309d3e075dfa598dae8be37e (patch)
treebf1e096e662b4c724ef3d4474cf28e54dd7b0baa /reference
parentefl-mono: Efl.Ui.Dir -> Efl.Ui.LayoutOrientation (diff)
downloadexamples-b2c7e2c2dde65d72309d3e075dfa598dae8be37e.tar.gz
efl-mono: Add custom widget example
Diffstat (limited to 'reference')
-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 12a5ef33..bfe5e9a9 100644
--- a/reference/csharp/ui/src/meson.build
+++ b/reference/csharp/ui/src/meson.build
@@ -20,3 +20,10 @@ executable('efl_reference_ui_focus',
cs_args : efl_mono_libs,
install : true
)
+
+executable('efl_reference_ui_custom_widget',
+ files(['ui_custom_widget.cs']),
+ dependencies : deps,
+ cs_args : efl_mono_libs,
+ install : true
+)
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 00000000..c486be6a
--- /dev/null
+++ b/reference/csharp/ui/src/ui_custom_widget.cs
@@ -0,0 +1,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();
+ }
+}