efl-mono: Add custom widget example
This commit is contained in:
parent
d325da2119
commit
b2c7e2c2dd
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue