63 lines
1.8 KiB
C#
63 lines
1.8 KiB
C#
/*
|
|
* 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(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.VisibilityChangedEvent += (object sender, Efl.Gfx.IEntityVisibilityChangedEventArgs 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.ClickedEvent += (object sender, Efl.Input.IClickableClickedEventArgs 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();
|
|
}
|
|
}
|