summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_view_model.eo
blob: 83a3e781b093c65d429981a4cc5e0c09e5eef96b (plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
function @beta EflUiViewModelPropertyGet {
   [[Function called when a property is get.]]
   params {
      @in view_model: const(Efl.Ui.View_Model); [[The ViewModel object the @.property.get is issued on.]]
      @in property: stringshare; [[The property name the @.property.get is issued on.]]
   }
   return: any_value_ptr; [[The property value.]]
};

function @beta EflUiViewModelPropertySet {
   [[Function called when a property is set.]]
   params {
      @in view_model: Efl.Ui.View_Model; [[The ViewModel object the @.property.set is issued on.]]
      @in property: stringshare; [[The property name the @.property.set is issued on.]]
      @in value: any_value_ptr @owned; [[The new value to set.]]
   }
   return: future<any_value_ptr>; [[The value that was finally set.]]
};

class @beta Efl.Ui.View_Model extends Efl.Composite_Model
{
   [[Efl model providing helpers for custom properties used when linking a model to a view and you need to
     generate/adapt values for display.

     There is two ways to use this class, you can either inherit from it and have a custom constructor for example.
     Or you can just instantiate it and manually define your property on it via callbacks.
   ]]
   methods {
      property_string_add {
         [[Adds a synthetic string property, generated from a $definition string and other properties in the model.

           The $definition string, similar to how $printf works, contains ${} placeholders that are replaced by the
           actual value of the property inside the placeholder tags when the synthetic property is retrieved.
           For example, a numeric property $length might be strange to use as a label, since it will only display a
           number. However, a synthetic string can be generated with the definition "Length ${length}." which renders
           more nicely and does not require any more code by the user of the property.

           $not_ready and $on_error strings can be given to be used when the data is not ready or there is some error,
           respectively. These strings do accept placeholder tags.

           See @.property_string_del
         ]]
         params {
            name: string; [[The name for the new synthetic property.]]
            definition: string; [[The definition string for the new synthetic property.]]
            not_ready: string; [[The text to be used if any of the properties used in $definition is not ready yet.
                                 If set to $null, no check against EAGAIN will be done.]]
            on_error: string; [[The text to be used if any of the properties used in $definition is in error. It takes
                                precedence over $not_ready. If set to $null, no error checks are performed.]]
         }
         return: Eina.Error;
      }
      property_string_del {
         [[Delete a synthetic property previously defined by @.property_string_add.

           See @.property_string_add
         ]]
         params {
            name: string; [[The name of the synthetic property to delete.]]
         }
         return: Eina.Error;
      }
      property_logic_add {
         [[Add callbacks that will be triggered when someone ask for the specified property name when getting or
           setting a property.

           A get or set should at least be provided for this call to succeed.

           See @.property_logic_del
         ]]
         params {
            property: string; [[The property to bind on to.]]
            get: EflUiViewModelPropertyGet; [[Define the get callback called when the @Efl.Model.property.get is called
                                            with the above property name.]]
            set: EflUiViewModelPropertySet; [[Define the set callback called when the @Efl.Model.property.set is called
                                            with the above property name.]]
            binded: iterator<string>; [[Iterator of property name to bind with this defined property see
                                        @.property_bind.]]
         }
         return: Eina.Error;
      }
      property_logic_del {
         [[Delete previously added callbacks that were triggered when someone asked for the specified property name
           when getting or setting a property.

           A get or set should at least be provided for this call to succeed.

           See @.property_logic_add
         ]]
         params {
            property: string; [[The property to bind on to.]]
         }
         return: Eina.Error;
      }
      property_bind {
         [[Automatically update the field for the event @[Efl.Model.properties,changed] to include property
           that are impacted with change in a property from the composited model.

           The source doesn't have to be provided at this point by the composited model.
         ]]
         params {
            @in source: string; [[Property name in the composited model.]]
            @in destination: string; [[Property name in the @Efl.Ui.View_Model]]
         }
      }
      property_unbind {
         [[Stop automatically updating the field for the event @[Efl.Model.properties,changed] to
           include property that are impacted with change in a property from the
           composited model.
         ]]
         params {
            @in source: string; [[Property name in the composited model.]]
            @in destination: string; [[Property name in the @Efl.Ui.View_Model]]
         }
      }
      @property children_bind {
         [[Define if we will intercept all children object reference and
           bind them through the ViewModel with the same property logic as this
           one. Be careful of recursivity.

           This can only be applied at construction time.]]
         get {
            [[Get the state of the automatic binding of children object.]]
         }
         set {
            [[Set the state of the automatic binding of children object.]]
         }
         values {
            enable: bool; [[Do you automatically bind children. Default to true.]]
         }
      }
   }
   implements {
      Efl.Object.constructor;
      Efl.Object.finalize;
      Efl.Object.destructor;
      Efl.Model.children_slice_get;
      Efl.Model.properties { get; }
      Efl.Model.property { set; get; }
   }
   constructors {
      Efl.Ui.View_Model.children_bind @optional;
   }
}