acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

fragment.md (2445B)

      1 ```eval_rst
      2 .. include:: /header.rst
      3 :github_url: |github_link_base|/others/fragment.md
      4 ```
      5 
      6 # Fragment
      7 
      8 Fragment is a concept copied from [Android](https://developer.android.com/guide/fragments).
      9 
     10 It represents a reusable portion of your app's UI. A fragment defines and manages its own layout, has its own lifecycle,
     11 and can handle its own events. Like Android's Fragment that must be hosted by an activity or another fragment, Fragment
     12 in LVGL needs to be hosted by an object, or another fragment. The fragment’s view hierarchy becomes part of, or attaches
     13 to, the host’s view hierarchy.
     14 
     15 Such concept also has some similarities
     16 to [UiViewController on iOS](https://developer.apple.com/documentation/uikit/uiviewcontroller).
     17 
     18 Fragment Manager is a manager holding references to fragments attached to it, and has an internal stack to achieve
     19 navigation. You can use fragment manager to build navigation stack, or multi pane application easily.
     20 
     21 ## Usage
     22 
     23 Enable `LV_USE_FRAGMENT` in `lv_conf.h`.
     24 
     25 ### Create Fragment Class
     26 
     27 ```c
     28 struct sample_fragment_t {
     29     /* IMPORTANT: don't miss this part */
     30     lv_fragment_t base;
     31     /* States, object references and data fields for this fragment */
     32     const char *title;
     33 };
     34 
     35 const lv_fragment_class_t sample_cls = {
     36         /* Initialize something needed */
     37         .constructor_cb = sample_fragment_ctor,
     38         /* Create view objects */
     39         .create_obj_cb = sample_fragment_create_obj,
     40         /* IMPORTANT: size of your fragment struct */
     41         .instance_size = sizeof(struct sample_fragment_t)
     42 };
     43 ```
     44 
     45 ### Use `lv_fragment_manager`
     46 
     47 ```c
     48 /* Create fragment instance, and objects will be added to container */
     49 lv_fragment_manager_t *manager = lv_fragment_manager_create(container, NULL);
     50 /* Replace current fragment with instance of sample_cls, and init_argument is user defined pointer */
     51 lv_fragment_manager_replace(manager, &sample_cls, init_argument);
     52 ```
     53 
     54 ### Fragment Based Navigation
     55 
     56 ```c
     57 /* Add one instance into manager stack. View object of current fragment will be destroyed,
     58  * but instances created in class constructor will be kept.
     59  */
     60 lv_fragment_manager_push(manager, &sample_cls, NULL);
     61 
     62 /* Remove the top most fragment from the stack, and bring back previous one. */
     63 lv_fragment_manager_pop(manager);
     64 ```
     65 
     66 ## Example
     67 
     68 ```eval_rst
     69 
     70 .. include:: ../../examples/others/fragment/index.rst
     71 
     72 ```
     73 
     74 ## API
     75 
     76 ```eval_rst
     77 
     78 .. doxygenfile:: lv_fragment.h
     79   :project: lvgl
     80 
     81 ```