mono examples: Adapt to Efl.Csharp.Application

This class simplifies app development, so the examples have to showcase it.
Basically:
- Your app inherits form it
- You do not need to init() or shutdown()
- You override the methods you want (like OnInitialize).

Fixes T7655
Differential Revision: https://phab.enlightenment.org/D8477
This commit is contained in:
Xavi Artigas 2019-03-26 11:19:13 +00:00 committed by Marcel Hollerbach
parent 871add6fe5
commit b55e5150c9
17 changed files with 197 additions and 175 deletions

View File

@ -1,9 +1,10 @@
using System; using System;
public class LifeWindow public class LifeWindow : Efl.Csharp.Application
{ {
private LifeBoard lifeBoard; private LifeBoard lifeBoard;
private LifeRender lifeRender; private LifeRender lifeRender;
private Efl.Ui.Win win;
void ResizeEvt(object sender, EventArgs ev) void ResizeEvt(object sender, EventArgs ev)
{ {
@ -14,13 +15,12 @@ public class LifeWindow
{ {
// quit the mainloop // quit the mainloop
if (ev.arg == false) if (ev.arg == false)
Efl.Ui.Config.Exit(); Efl.App.AppMain.Quit(0);
} }
void TouchEvt(object sender, Efl.Input.IInterfacePointerDownEvt_Args ev) void TouchEvt(object sender, Efl.Input.IInterfacePointerDownEvt_Args ev)
{ {
int cellx, celly; int cellx, celly;
Efl.Ui.Win win = (Efl.Ui.Win)sender;
var position = ev.arg.GetPosition(); var position = ev.arg.GetPosition();
lifeRender.CellForCoords(win, position, out cellx, out celly); lifeRender.CellForCoords(win, position, out cellx, out celly);
@ -31,14 +31,13 @@ public class LifeWindow
void KeyDownEvt(object sender, Efl.Input.IInterfaceKeyDownEvt_Args ev) void KeyDownEvt(object sender, Efl.Input.IInterfaceKeyDownEvt_Args ev)
{ {
Efl.Ui.Win win = (Efl.Ui.Win)sender;
if (ev.arg.GetKey() == "space") if (ev.arg.GetKey() == "space")
lifeBoard.TogglePause(win); lifeBoard.TogglePause(win);
} }
public LifeWindow() protected override void OnInitialize(Eina.Array<System.String> args)
{ {
Efl.Ui.Win win = new Efl.Ui.Win(parent: null, winName: "Life", winType: Efl.Ui.WinType.Basic); win = new Efl.Ui.Win(parent: null, winName: "Life", winType: Efl.Ui.WinType.Basic);
win.SetText("EFL Life"); win.SetText("EFL Life");
win.SetAutohide(true); win.SetAutohide(true);
@ -61,19 +60,30 @@ public class LifeWindow
lifeBoard.Run(win); lifeBoard.Run(win);
} }
protected override void OnPause() {
if (win != null) {
lifeBoard.TogglePause(win);
}
}
protected override void OnResume() {
if (win != null) {
lifeBoard.TogglePause(win);
}
}
protected override void OnTerminate() {
Console.WriteLine("Goodbye.");
}
} }
public class Example public class Example
{ {
public static void Main() public static void Main()
{ {
Efl.All.Init(Efl.Components.Ui);
var lifeWin = new LifeWindow(); var lifeWin = new LifeWindow();
// start the mainloop lifeWin.Launch();
Efl.Ui.Config.Run();
Efl.All.Shutdown();
} }
} }

View File

@ -17,7 +17,7 @@
using System; using System;
public class TextEditor public class TextEditor : Efl.Csharp.Application
{ {
private Efl.Ui.Win win; // The main window private Efl.Ui.Win win; // The main window
private Efl.Ui.Text editorTextBox; // The main text entry private Efl.Ui.Text editorTextBox; // The main text entry
@ -35,7 +35,7 @@ public class TextEditor
private void GUIQuitCb(object sender, Efl.Gfx.IEntityVisibilityChangedEvt_Args ea) private void GUIQuitCb(object sender, Efl.Gfx.IEntityVisibilityChangedEvt_Args ea)
{ {
if (ea.arg == false) if (ea.arg == false)
Efl.Ui.Config.Exit(); Efl.App.AppMain.Quit(0);
} }
// Enables or disables buttons on the toolbar as required // Enables or disables buttons on the toolbar as required
@ -151,7 +151,7 @@ public class TextEditor
} }
// Builds the user interface for the text editor // Builds the user interface for the text editor
public TextEditor() protected override void OnInitialize(Eina.Array<System.String> args)
{ {
// Create a window and initialize it // Create a window and initialize it
win = new Efl.Ui.Win(parent: Efl.App.AppMain); win = new Efl.Ui.Win(parent: Efl.App.AppMain);
@ -180,13 +180,6 @@ public class TextEditor
// Initial refresh of the toolbar buttons // Initial refresh of the toolbar buttons
GUIToolbarRefresh(); GUIToolbarRefresh();
} }
// This method won't return until the application quits
public void Run()
{
// Start the EFL main loop
Efl.Ui.Config.Run();
}
} }
public class Example public class Example
@ -196,14 +189,8 @@ public class Example
#endif #endif
public static void Main() public static void Main()
{ {
// Initialize EFL and all UI components TextEditor editor = new TextEditor();
Efl.All.Init(Efl.Components.Ui); editor.Launch();
var textEditor = new TextEditor();
textEditor.Run();
// Shutdown EFL
Efl.All.Shutdown();
} }
} }

View File

@ -7,7 +7,7 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
// Polling callback // Polling callback
private static void PollCb(object sender, EventArgs e) private static void PollCb(object sender, EventArgs e)
@ -15,14 +15,8 @@ public class Example
Console.WriteLine(" Poll from {0}", ((Efl.Object)sender).GetName()); Console.WriteLine(" Poll from {0}", ((Efl.Object)sender).GetName());
} }
#if WIN32 protected override void OnInitialize(Eina.Array<System.String> args)
[STAThreadAttribute()]
#endif
public static void Main()
{ {
// Initialize EFL and all UI components
Efl.All.Init();
// Retrieve the application's main loop // Retrieve the application's main loop
var mainloop = Efl.App.AppMain; var mainloop = Efl.App.AppMain;
mainloop.SetName("Mainloop"); mainloop.SetName("Mainloop");
@ -57,14 +51,20 @@ public class Example
}; };
Console.WriteLine("Waiting for Timer to call back..."); Console.WriteLine("Waiting for Timer to call back...");
}
// Start the EFL main loop (and the experiment) protected override void OnTerminate()
mainloop.Begin(); {
// Shutdown EFL
Efl.All.Shutdown();
Console.WriteLine("Application is over"); Console.WriteLine("Application is over");
} }
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
}
} }

View File

@ -9,16 +9,10 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
#if WIN32 protected override void OnInitialize(Eina.Array<System.String> args)
[STAThreadAttribute()]
#endif
public static void Main()
{ {
// Initialize EFL and all UI components
Efl.All.Init();
// Retrieve the application's main loop // Retrieve the application's main loop
var mainloop = Efl.App.AppMain; var mainloop = Efl.App.AppMain;
@ -34,16 +28,19 @@ public class Example
}; };
// Use a timer to exit the application // Use a timer to exit the application
var timer = new Efl.LoopTimer(mainloop, 0.01); var timer = new Efl.LoopTimer(mainloop, 0.02);
timer.TimerTickEvt += (object sender, EventArgs e) => { timer.TimerTickEvt += (object sender, EventArgs e) => {
Console.WriteLine("TIMER: timer callback called, exiting."); Console.WriteLine("TIMER: timer callback called, exiting.");
mainloop.Quit(new Eina.Value(0)); mainloop.Quit(0);
}; };
}
// Start the EFL main loop (and the experiment) #if WIN32
mainloop.Begin(); [STAThreadAttribute()]
#endif
// Shutdown EFL public static void Main()
Efl.All.Shutdown(); {
var example = new Example();
example.Launch();
} }
} }

View File

@ -8,16 +8,10 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
#if WIN32 protected override void OnInitialize(Eina.Array<System.String> args)
[STAThreadAttribute()]
#endif
public static void Main()
{ {
// Initialize EFL and all UI components
Efl.All.Init();
// Retrieve the application's main loop // Retrieve the application's main loop
var mainloop = Efl.App.AppMain; var mainloop = Efl.App.AppMain;
@ -36,13 +30,16 @@ public class Example
var timer = new Efl.LoopTimer(mainloop, 30); var timer = new Efl.LoopTimer(mainloop, 30);
timer.TimerTickEvt += (object sender, EventArgs e) => { timer.TimerTickEvt += (object sender, EventArgs e) => {
Console.WriteLine("\nTIMER: timer callback called, exiting."); Console.WriteLine("\nTIMER: timer callback called, exiting.");
mainloop.Quit(new Eina.Value(0)); mainloop.Quit(0);
}; };
}
// Start the EFL main loop (and the experiment) #if WIN32
mainloop.Begin(); [STAThreadAttribute()]
#endif
// Shutdown EFL public static void Main()
Efl.All.Shutdown(); {
var example = new Example();
example.Launch();
} }
} }

View File

@ -8,7 +8,7 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
static Eina.Array<string> CreateArray() static Eina.Array<string> CreateArray()
{ {
@ -38,10 +38,8 @@ public class Example
return true; return true;
} }
public static void Main() protected override void OnInitialize(Eina.Array<System.String> args)
{ {
Efl.All.Init();
var array = CreateArray(); var array = CreateArray();
// Show the contents of our array // Show the contents of our array
@ -69,7 +67,16 @@ public class Example
array.Dispose(); array.Dispose();
Efl.All.Shutdown(); Efl.App.AppMain.Quit(0);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
} }
} }

View File

@ -12,7 +12,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
public class Example public class Example : Efl.Csharp.Application
{ {
static Eina.Hash<Int32, string> CreateHash() static Eina.Hash<Int32, string> CreateHash()
{ {
@ -117,13 +117,20 @@ public class Example
phone_book.Dispose(); phone_book.Dispose();
} }
public static void Main() protected override void OnInitialize(Eina.Array<System.String> args)
{ {
Efl.All.Init();
HashDemo(); HashDemo();
PhonebookDemo(); PhonebookDemo();
Efl.All.Shutdown(); Efl.App.AppMain.Quit(0);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
} }
} }

View File

@ -10,7 +10,7 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
static void PrintIterator(Eina.Iterator<string> it) static void PrintIterator(Eina.Iterator<string> it)
{ {
@ -55,10 +55,8 @@ public class Example
return list; return list;
} }
public static void Main() protected override void OnInitialize(Eina.Array<System.String> args)
{ {
Efl.All.Init();
// Create an Eina.Array and iterate through its contents // Create an Eina.Array and iterate through its contents
var array = CreateArray(); var array = CreateArray();
var it = array.GetIterator(); var it = array.GetIterator();
@ -73,6 +71,15 @@ public class Example
it.Dispose(); it.Dispose();
list.Dispose(); list.Dispose();
Efl.All.Shutdown(); Efl.App.AppMain.Quit(0);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
} }
} }

View File

@ -10,7 +10,7 @@
using System; using System;
using System.Linq; using System.Linq;
public class Example public class Example : Efl.Csharp.Application
{ {
static Eina.List<string> CreateList() static Eina.List<string> CreateList()
{ {
@ -23,10 +23,8 @@ public class Example
return list; return list;
} }
public static void Main() protected override void OnInitialize(Eina.Array<System.String> args)
{ {
Efl.All.Init();
var list = CreateList(); var list = CreateList();
// Print our list with a simple foreach // Print our list with a simple foreach
@ -66,6 +64,12 @@ public class Example
list.Dispose(); list.Dispose();
Efl.All.Shutdown(); Efl.App.AppMain.Quit(0);
}
public static void Main()
{
var example = new Example();
example.Launch();
} }
} }

View File

@ -8,7 +8,7 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
static double Divide(int num, int denom) static double Divide(int num, int denom)
{ {
@ -48,15 +48,22 @@ public class Example
Divides(); Divides();
} }
public static void Main() protected override void OnInitialize(Eina.Array<System.String> args)
{ {
Efl.All.Init();
LogLevels(); LogLevels();
// TODO: missing // TODO: missing
//LogCustom(); //LogCustom();
Efl.All.Shutdown(); Efl.App.AppMain.Quit(0);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
} }
} }

View File

@ -9,7 +9,7 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
static void ValueInt() static void ValueInt()
{ {
@ -47,10 +47,8 @@ public class Example
Console.WriteLine("str_val was \"{0}\", converted to int is {1}", str_val, int_val); Console.WriteLine("str_val was \"{0}\", converted to int is {1}", str_val, int_val);
} }
public static void Main() protected override void OnInitialize(Eina.Array<System.String> args)
{ {
Efl.All.Init();
ValueInt(); ValueInt();
Console.WriteLine(""); Console.WriteLine("");
@ -60,6 +58,15 @@ public class Example
ValueConvert(); ValueConvert();
Console.WriteLine(""); Console.WriteLine("");
Efl.All.Shutdown(); Efl.App.AppMain.Quit(0);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
} }
} }

View File

@ -1,20 +1,14 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
public static void FocusChangedCb(object sender, EventArgs e) public static void FocusChangedCb(object sender, EventArgs e)
{ {
Console.WriteLine($"Focus for object {((Efl.IText)sender).GetText()} changed to {((Efl.Ui.Widget)sender).GetFocus()}"); Console.WriteLine($"Focus for object {((Efl.IText)sender).GetText()} changed to {((Efl.Ui.Widget)sender).GetFocus()}");
} }
#if WIN32 protected override void OnInitialize(Eina.Array<System.String> args)
[STAThreadAttribute()]
#endif
public static void Main()
{ {
// Initialize EFL and all UI components
Efl.All.Init(Efl.Components.Ui);
// Create a window and initialize it // Create a window and initialize it
var win = new Efl.Ui.Win(null); var win = new Efl.Ui.Win(null);
win.SetWinType(Efl.Ui.WinType.Basic); win.SetWinType(Efl.Ui.WinType.Basic);
@ -71,12 +65,15 @@ public class Example
// Show the focus highlight // Show the focus highlight
win.SetFocusHighlightEnabled(true); win.SetFocusHighlightEnabled(true);
}
// Start the EFL main loop #if WIN32
Efl.Ui.Config.Run(); [STAThreadAttribute()]
#endif
// Shutdown EFL public static void Main()
Efl.All.Shutdown(); {
var example = new Example();
example.Launch();
} }
} }

View File

@ -7,7 +7,7 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
// Create a box container full of buttons // Create a box container full of buttons
static Efl.Ui.Box CreateBox(Efl.Ui.Win win) static Efl.Ui.Box CreateBox(Efl.Ui.Win win)
@ -57,14 +57,8 @@ public class Example
return table; return table;
} }
#if WIN32 protected override void OnInitialize(Eina.Array<System.String> args)
[STAThreadAttribute()]
#endif
public static void Main()
{ {
// Initialize EFL and all UI components
Efl.All.Init(Efl.Components.Ui);
// Create a window and initialize it // Create a window and initialize it
Efl.Ui.Win win = new Efl.Ui.Win(null); Efl.Ui.Win win = new Efl.Ui.Win(null);
win.SetWinType(Efl.Ui.WinType.Basic); win.SetWinType(Efl.Ui.WinType.Basic);
@ -110,12 +104,15 @@ public class Example
Efl.Ui.Config.Exit(); Efl.Ui.Config.Exit();
}; };
Efl.IContentConcrete.static_cast(hsplit.GetPart("second")).SetContent(quit_btn); Efl.IContentConcrete.static_cast(hsplit.GetPart("second")).SetContent(quit_btn);
}
// Start the EFL main loop #if WIN32
Efl.Ui.Config.Run(); [STAThreadAttribute()]
#endif
// Shutdown EFL public static void Main()
Efl.All.Shutdown(); {
var example = new Example();
example.Launch();
} }
} }

View File

@ -8,16 +8,10 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
#if WIN32 protected override void OnInitialize(Eina.Array<System.String> args)
[STAThreadAttribute()]
#endif
public static void Main()
{ {
// Initialize EFL and all UI components
Efl.All.Init(Efl.Components.Ui);
// Create a window and initialize it // Create a window and initialize it
Efl.Ui.Win win = new Efl.Ui.Win(null); Efl.Ui.Win win = new Efl.Ui.Win(null);
win.SetWinType(Efl.Ui.WinType.Basic); win.SetWinType(Efl.Ui.WinType.Basic);
@ -49,12 +43,15 @@ public class Example
button.SetText("Big button"); button.SetText("Big button");
button.SetHintSizeMin(new Eina.Size2D(100,100)); button.SetHintSizeMin(new Eina.Size2D(100,100));
box.DoPack(button); box.DoPack(button);
}
// Start the EFL main loop #if WIN32
Efl.Ui.Config.Run(); [STAThreadAttribute()]
#endif
// Shutdown EFL public static void Main()
Efl.All.Shutdown(); {
var example = new Example();
example.Launch();
} }
} }

View File

@ -1,6 +1,6 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
static Efl.GenericModel root, child2; static Efl.GenericModel root, child2;
@ -32,16 +32,23 @@ public class Example
child2.Dispose(); child2.Dispose();
} }
public static void Main() protected override void OnInitialize(Eina.Array<System.String> args)
{ {
Efl.All.Init(Efl.Components.Ui);
// Create all objects // Create all objects
ObjCreate(); ObjCreate();
// Destroy all objects // Destroy all objects
ObjDestroy(); ObjDestroy();
Efl.All.Shutdown(); Efl.App.AppMain.Quit(0);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
} }
} }

View File

@ -1,23 +1,17 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
// Callback to quit the application // Callback to quit the application
public static void QuitCb(object sender, Efl.Gfx.IEntityVisibilityChangedEvt_Args e) public static void QuitCb(object sender, Efl.Gfx.IEntityVisibilityChangedEvt_Args e)
{ {
// Exit the EFL main loop // Exit the EFL main loop
if (e.arg == false) if (e.arg == false)
Efl.Ui.Config.Exit(); Efl.App.AppMain.Quit(0);
} }
#if WIN32 protected override void OnInitialize(Eina.Array<System.String> args)
[STAThreadAttribute()]
#endif
public static void Main()
{ {
// Initialize EFL and all UI components
Efl.All.Init(Efl.Components.Ui);
// Create a window and initialize it // Create a window and initialize it
Efl.Ui.Win win = new Efl.Ui.Win(Efl.App.AppMain); Efl.Ui.Win win = new Efl.Ui.Win(Efl.App.AppMain);
// Set the window's title // Set the window's title
@ -52,15 +46,18 @@ public class Example
button.SetText("Quit"); button.SetText("Quit");
button.SetHintWeight(1.0, 0.1); button.SetHintWeight(1.0, 0.1);
// Set the method to be called when the button is pressed // Set the method to be called when the button is pressed
button.ClickedEvt += (object sender, EventArgs e) => { Efl.Ui.Config.Exit(); }; button.ClickedEvt += (object sender, EventArgs e) => { Efl.App.AppMain.Quit(0); };
// Add the button to the box container // Add the button to the box container
box.DoPack(button); box.DoPack(button);
}
// Start the EFL main loop #if WIN32
Efl.Ui.Config.Run(); [STAThreadAttribute()]
#endif
// Shutdown EFL public static void Main()
Efl.All.Shutdown(); {
var example = new Example();
example.Launch();
} }
} }

View File

@ -1,15 +1,9 @@
using System; using System;
public class Example public class Example : Efl.Csharp.Application
{ {
#if WIN32 protected override void OnInitialize(Eina.Array<System.String> args)
[STAThreadAttribute()]
#endif
public static void Main()
{ {
// Initialize EFL and all UI components
Efl.All.Init(Efl.Components.Ui);
// Create a window and initialize it // Create a window and initialize it
Efl.Ui.Win win = new Efl.Ui.Win(Efl.App.AppMain); Efl.Ui.Win win = new Efl.Ui.Win(Efl.App.AppMain);
// Set the window's title // Set the window's title
@ -20,11 +14,14 @@ public class Example
// Window size must be explicitly set, otherwise it will be invisible // Window size must be explicitly set, otherwise it will be invisible
// due to its lack of content. // due to its lack of content.
win.SetSize(new Eina.Size2D(360, 240)); win.SetSize(new Eina.Size2D(360, 240));
}
// Start the EFL main loop #if WIN32
Efl.Ui.Config.Run(); [STAThreadAttribute()]
#endif
// Shutdown EFL public static void Main()
Efl.All.Shutdown(); {
var example = new Example();
example.Launch();
} }
} }