diff --git a/reference/csharp/ui/src/meson.build b/reference/csharp/ui/src/meson.build index bfe5e9a9..cf376ec9 100644 --- a/reference/csharp/ui/src/meson.build +++ b/reference/csharp/ui/src/meson.build @@ -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 +) diff --git a/reference/csharp/ui/src/ui_mvvm_basic.cs b/reference/csharp/ui/src/ui_mvvm_basic.cs new file mode 100644 index 00000000..4d22d94a --- /dev/null +++ b/reference/csharp/ui/src/ui_mvvm_basic.cs @@ -0,0 +1,83 @@ +using System; + +class WeatherStation +{ + public String Nick { get; set; } + public float Temperature { get; set; } + + public static Efl.UserModel CreateModel(Efl.Loop loop) + { + Efl.UserModel stations = new Efl.UserModel(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(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(); + } +}