examples/reference/csharp/ui/src/focus_main.cs

86 lines
2.7 KiB
C#
Raw Normal View History

using System;
public class Example
{
public static void FocusChangedCb(object sender, EventArgs e)
{
Console.WriteLine($"Focus for object {((efl.IText)sender).GetText()} changed to {((efl.ui.IWidget)sender).GetFocus()}");
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
// Initialize EFL and all UI components
efl.All.Init(efl.Components.Ui);
// Create a window and initialize it
var win = new efl.ui.Win(null, (efl.ui.IWin ewin) => {
ewin.SetWinType(efl.ui.Win_Type.Basic);
ewin.SetText("Focus example");
ewin.SetAutohide(true);
ewin.HideEvt += (object sender, EventArgs e) => {
// Exit the EFL main loop
efl.ui.Config.Exit();
};
});
// Create the main box container
var vbox = new efl.ui.Box(win, (efl.ui.IBox ebox) => {
ebox.SetHintMin(new eina.Size2D(360, 240));
win.SetContent(ebox);
});
// Create some check boxes
efl.ui.ICheck first_checkbox = null;
for (int i = 0; i< 5; i++) {
var checkbox = new efl.ui.Check(vbox, (efl.ui.ICheck echeck) => {
echeck.SetText("Check " + i);
echeck.SetHintAlign(0.5, 0.5);
echeck.FocusChangedEvt += FocusChangedCb;
vbox.DoPack(echeck);
});
if (i == 0) first_checkbox = checkbox;
};
// Create an horizontal box to contain the two buttons
var hbox = new efl.ui.Box(vbox, (efl.ui.IBox ebox) => {
ebox.SetDirection(efl.ui.Dir.Horizontal);
vbox.DoPack(ebox);
});
// Create a "Focus Mover" button
new efl.ui.Button(hbox, (efl.ui.IButton ebutton) => {
ebutton.SetText("Focus mover");
ebutton.FocusChangedEvt += FocusChangedCb;
ebutton.ClickedEvt += (object sender, EventArgs e) => {
Console.WriteLine("Clicked Focus Mover");
// Manually transfer focus to the first check box
efl.ui.focus.Util.Focus(first_checkbox);
};
hbox.DoPack(ebutton);
});
// Create a Quit button
new efl.ui.Button(hbox, (efl.ui.IButton ebutton) => {
ebutton.SetText("Quit");
ebutton.FocusChangedEvt += FocusChangedCb;
ebutton.ClickedEvt += (object sender, EventArgs e) => {
Console.WriteLine("Clicked Quit");
efl.ui.Config.Exit();
};
hbox.DoPack(ebutton);
// Set focus on this widget and show the focus highlight
ebutton.SetFocusHighlightEnabled(true);
});
// Start the EFL main loop
efl.ui.Config.Run();
// Shutdown EFL
efl.All.Shutdown();
}
}