summaryrefslogtreecommitdiff
path: root/apps/csharp/mvvm-example/src/mvvm_basic.cs
blob: 74199e677db9b8f8d51a40926f7ca5bf7633c181 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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.BindProperty("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();
    }
}