This example shows how to create a simple prefs widget with Elementary, where the items values are "reset" on each timer tick.
We do that programmatically, to demonstrate that by touching a given prefs widgets prefs data values, the changes reflect instantly on the UI.
We'll create items on the .EPC file and after handle it on the .C file.
First we'll create prefs items on .EPC file that we'll use later on the .C file. Note that the code is similar to .EDC (edje) files.
Here we define a page item. Pages are group of items grouped together, on a given prefs widget.
In this part, we create a
INT type item, that by default will become a spinner widget in the UI, and default, min and max parameters are optional as well as in
INT type widget implementations may exist, as is exemplifyed on the item that follows.
Now we create a LABEL type item and by default will become a read-only label in UI.
Now we create a TEXT type item and by default will become a single-line text entry in UI. Note that we use a Regular Expression to deny only entries with numbers.
In this part we create a DATE type item, by default will become a datetime in UI, and default, min and max parameters are optional.
Here we create a SEPARATOR type item, it has no value bound, serves only to divide and organize prefs items.
In this part, we create a SAVE type item that will get all the values bounded to items and save it on CFG file. Next time you execute the application, all the values that you saved before will be loaded.
Here we create a RESET type item that will return all the values bounded to items as default declared on .EPC file.
Pages and items have default implementation widgets, but, with the tag 'widget', you can use different widgets for prefs items. To a list of default widgets supported by each type, by default, refer to the Elementary Prefs Collection reference sheet. One can also register, at run time, custom item widget handlers too.
Now we're handling the .C file and first we'll create a prefs widget.
Here we add some specific callbacks, for example "item,changed" that will be called when any item that we created on EPC file changes.
Here we set the prefs to save its values back (on the user data file) automatically on every UI element changes.
In this part we create the prefs data handle and set the .EPB file (.EPC compiled). This .EPB file contains all the default values from the items that we created, this file will be loaded when the program starts or when clicked on a RESET type item. There is another file created when the values from prefs items are saved, the .CFG file, that contains all the non-standard saved values from the prefs items, this file will be loaded when program starts as well.
Here we just create a notify widget to appear when the values are reset.
Now we add a timer to reset the items values on each 5.0 seconds and show the notify.