Cross-platform C SDK logo

Cross-platform C SDK

GUI Data binding

❮ Back
Next ❯

One of the usual uses of the dbind tables will be the synchronization of the data model with the user interface. Normally this task requires capturing the events of the controls to update the data and vice versa, refresh the contents of the controls each time the data changes. This task is tedious and requires a lot of additional code. To avoid this, when we create the view, we will link the different controls with the structure fields by cell_dbind (Listing 1). This paradigm is known as data binding or MVVM (Model-View-ViewModel) (Listing 1) and will keep both parts synchronized automatically.

Listing 1: Binding GUI controls with data fields.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Cell *cell0 = i_code_cell(layout);
Cell *cell1 = i_desc_cell(layout);
Cell *cell2 = i_type_cell(layout);
Cell *cell3 = i_img_cell(layout);
Cell *cell4 = i_price_cell(layout);
cell_dbind(cell0, Product, String*, code);
cell_dbind(cell1, Product, String*, description);
cell_dbind(cell2, Product, type_t, type);
cell_dbind(cell3, Product, Image*, image64);
cell_dbind(cell4, Product, real32_t, price);
layout_dbind(layout, Product);
❮ Back
Next ❯