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;
public class LifeWindow
public class LifeWindow : Efl.Csharp.Application
{
private LifeBoard lifeBoard;
private LifeRender lifeRender;
private Efl.Ui.Win win;
void ResizeEvt(object sender, EventArgs ev)
{
@ -14,13 +15,12 @@ public class LifeWindow
{
// quit the mainloop
if (ev.arg == false)
Efl.Ui.Config.Exit();
Efl.App.AppMain.Quit(0);
}
void TouchEvt(object sender, Efl.Input.IInterfacePointerDownEvt_Args ev)
{
int cellx, celly;
Efl.Ui.Win win = (Efl.Ui.Win)sender;
var position = ev.arg.GetPosition();
lifeRender.CellForCoords(win, position, out cellx, out celly);
@ -31,14 +31,13 @@ public class LifeWindow
void KeyDownEvt(object sender, Efl.Input.IInterfaceKeyDownEvt_Args ev)
{
Efl.Ui.Win win = (Efl.Ui.Win)sender;
if (ev.arg.GetKey() == "space")
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.SetAutohide(true);
@ -61,19 +60,30 @@ public class LifeWindow
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 static void Main()
{
Efl.All.Init(Efl.Components.Ui);
var lifeWin = new LifeWindow();
// start the mainloop
Efl.Ui.Config.Run();
Efl.All.Shutdown();
lifeWin.Launch();
}
}

View File

@ -17,7 +17,7 @@
using System;
public class TextEditor
public class TextEditor : Efl.Csharp.Application
{
private Efl.Ui.Win win; // The main window
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)
{
if (ea.arg == false)
Efl.Ui.Config.Exit();
Efl.App.AppMain.Quit(0);
}
// Enables or disables buttons on the toolbar as required
@ -151,7 +151,7 @@ public class TextEditor
}
// 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
win = new Efl.Ui.Win(parent: Efl.App.AppMain);
@ -180,13 +180,6 @@ public class TextEditor
// Initial refresh of the toolbar buttons
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
@ -196,14 +189,8 @@ public class Example
#endif
public static void Main()
{
// Initialize EFL and all UI components
Efl.All.Init(Efl.Components.Ui);
var textEditor = new TextEditor();
textEditor.Run();
// Shutdown EFL
Efl.All.Shutdown();
TextEditor editor = new TextEditor();
editor.Launch();
}
}

View File

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

View File

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

View File

@ -8,7 +8,7 @@
using System;
public class Example
public class Example : Efl.Csharp.Application
{
static Eina.Array<string> CreateArray()
{
@ -38,10 +38,8 @@ public class Example
return true;
}
public static void Main()
protected override void OnInitialize(Eina.Array<System.String> args)
{
Efl.All.Init();
var array = CreateArray();
// Show the contents of our array
@ -69,7 +67,16 @@ public class Example
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.Collections.Generic;
public class Example
public class Example : Efl.Csharp.Application
{
static Eina.Hash<Int32, string> CreateHash()
{
@ -117,13 +117,20 @@ public class Example
phone_book.Dispose();
}
public static void Main()
protected override void OnInitialize(Eina.Array<System.String> args)
{
Efl.All.Init();
HashDemo();
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;
public class Example
public class Example : Efl.Csharp.Application
{
static void PrintIterator(Eina.Iterator<string> it)
{
@ -55,10 +55,8 @@ public class Example
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
var array = CreateArray();
var it = array.GetIterator();
@ -73,6 +71,15 @@ public class Example
it.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.Linq;
public class Example
public class Example : Efl.Csharp.Application
{
static Eina.List<string> CreateList()
{
@ -23,10 +23,8 @@ public class Example
return list;
}
public static void Main()
protected override void OnInitialize(Eina.Array<System.String> args)
{
Efl.All.Init();
var list = CreateList();
// Print our list with a simple foreach
@ -66,6 +64,12 @@ public class Example
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;
public class Example
public class Example : Efl.Csharp.Application
{
static double Divide(int num, int denom)
{
@ -48,15 +48,22 @@ public class Example
Divides();
}
public static void Main()
protected override void OnInitialize(Eina.Array<System.String> args)
{
Efl.All.Init();
LogLevels();
// TODO: missing
//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;
public class Example
public class Example : Efl.Csharp.Application
{
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);
}
public static void Main()
protected override void OnInitialize(Eina.Array<System.String> args)
{
Efl.All.Init();
ValueInt();
Console.WriteLine("");
@ -60,6 +58,15 @@ public class Example
ValueConvert();
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;
public class Example
public class Example : Efl.Csharp.Application
{
public static void FocusChangedCb(object sender, EventArgs e)
{
Console.WriteLine($"Focus for object {((Efl.IText)sender).GetText()} changed to {((Efl.Ui.Widget)sender).GetFocus()}");
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
protected override void OnInitialize(Eina.Array<System.String> args)
{
// 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);
win.SetWinType(Efl.Ui.WinType.Basic);
@ -71,12 +65,15 @@ public class Example
// Show the focus highlight
win.SetFocusHighlightEnabled(true);
}
// Start the EFL main loop
Efl.Ui.Config.Run();
// Shutdown EFL
Efl.All.Shutdown();
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
}
}

View File

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

View File

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

View File

@ -1,6 +1,6 @@
using System;
public class Example
public class Example : Efl.Csharp.Application
{
static Efl.GenericModel root, child2;
@ -32,16 +32,23 @@ public class Example
child2.Dispose();
}
public static void Main()
protected override void OnInitialize(Eina.Array<System.String> args)
{
Efl.All.Init(Efl.Components.Ui);
// Create all objects
ObjCreate();
// Destroy all objects
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;
public class Example
public class Example : Efl.Csharp.Application
{
// Callback to quit the application
public static void QuitCb(object sender, Efl.Gfx.IEntityVisibilityChangedEvt_Args e)
{
// Exit the EFL main loop
if (e.arg == false)
Efl.Ui.Config.Exit();
Efl.App.AppMain.Quit(0);
}
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
protected override void OnInitialize(Eina.Array<System.String> args)
{
// Initialize EFL and all UI components
Efl.All.Init(Efl.Components.Ui);
// Create a window and initialize it
Efl.Ui.Win win = new Efl.Ui.Win(Efl.App.AppMain);
// Set the window's title
@ -52,15 +46,18 @@ public class Example
button.SetText("Quit");
button.SetHintWeight(1.0, 0.1);
// 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
box.DoPack(button);
}
// Start the EFL main loop
Efl.Ui.Config.Run();
// Shutdown EFL
Efl.All.Shutdown();
#if WIN32
[STAThreadAttribute()]
#endif
public static void Main()
{
var example = new Example();
example.Launch();
}
}

View File

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