csharp: Add tentative MVVM example
This commit is contained in:
parent
3aecb39a18
commit
535b1e0dbe
|
@ -27,3 +27,10 @@ executable('efl_reference_ui_custom_widget',
|
|||
cs_args : efl_mono_libs,
|
||||
install : true
|
||||
)
|
||||
|
||||
executable('efl_reference_ui_mvvm_basic',
|
||||
files(['ui_mvvm_basic.cs']),
|
||||
dependencies : deps,
|
||||
cs_args : efl_mono_libs,
|
||||
install : true
|
||||
)
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
|
||||
class WeatherStation
|
||||
{
|
||||
public String Nick { get; set; }
|
||||
public float Temperature { get; set; }
|
||||
|
||||
public static Efl.UserModel<WeatherStation> CreateModel(Efl.Loop loop)
|
||||
{
|
||||
Efl.UserModel<WeatherStation> stations = new Efl.UserModel<WeatherStation>(loop);
|
||||
stations.Add (new WeatherStation{ Nick="FLN", Temperature=20 });
|
||||
stations.Add (new WeatherStation{ Nick="SAO", Temperature=25 });
|
||||
stations.Add (new WeatherStation{ Nick="RIO", Temperature=35 });
|
||||
stations.Add (new WeatherStation{ Nick="BSB", Temperature=30 });
|
||||
|
||||
return stations;
|
||||
}
|
||||
}
|
||||
|
||||
class WeatherServer
|
||||
{
|
||||
}
|
||||
|
||||
class Application : Efl.Csharp.Application
|
||||
{
|
||||
private Efl.Ui.Win win;
|
||||
|
||||
protected override void OnInitialize(string[] args)
|
||||
{
|
||||
win = new Efl.Ui.Win(parent: null, winName: "MVVM Example",
|
||||
winType: Efl.Ui.WinType.Basic);
|
||||
win.SetText("EFL Life");
|
||||
win.SetAutohide(true);
|
||||
|
||||
win.VisibilityChangedEvent += QuitEvt;
|
||||
|
||||
|
||||
var factory = new Efl.Ui.ItemFactory<Efl.Ui.ListDefaultItem>(win);
|
||||
/* factory.TextPart().Markup().Bind("Nick"); */
|
||||
factory.PropertyBind("text", "Nick");
|
||||
|
||||
var model = WeatherStation.CreateModel(Efl.App.AppMain);
|
||||
model.SetProperty("item.width", 1);
|
||||
model.SetProperty("item.height", 1);
|
||||
|
||||
Console.WriteLine($"Width: {model.GetProperty("item.width")}");
|
||||
|
||||
/* var list = new Efl.Ui.ListView(box); */
|
||||
|
||||
/* list.LayoutFactory = factory; */
|
||||
/* list.Model = model; */
|
||||
|
||||
var manager = new Efl.Ui.PositionManager.List(win);
|
||||
var list = new Efl.Ui.CollectionView(win);
|
||||
|
||||
Eina.Log.Error("Setting manager");
|
||||
list.PositionManager = manager;
|
||||
Eina.Log.Error("Setting model");
|
||||
list.Model = model;
|
||||
Eina.Log.Error("Setting factory");
|
||||
list.Factory = factory;
|
||||
|
||||
/* var box = new Efl.Ui.Box(win); */
|
||||
/* box.PackEnd(list); */
|
||||
win.SetContent(list);
|
||||
win.SetSize(new Eina.Size2D(640, 480));
|
||||
win.Visible = true;
|
||||
}
|
||||
|
||||
void QuitEvt(object sender, Efl.Gfx.EntityVisibilityChangedEventArgs ev)
|
||||
{
|
||||
if (ev.arg == false)
|
||||
{
|
||||
Efl.App.AppMain.Quit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
var app = new Application();
|
||||
app.Launch();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue