Compare commits

...

1 Commits

Author SHA1 Message Date
Lauro Moura 535b1e0dbe csharp: Add tentative MVVM example 2019-09-13 11:37:27 -03:00
2 changed files with 90 additions and 0 deletions

View File

@ -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
)

View File

@ -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();
}
}