app_context.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef _APP_CONTEXT_H_
  2. #define _APP_CONTEXT_H_
  3. #include <gui/view_dispatcher.h>
  4. #include <gui/scene_manager.h>
  5. #include "utils/linked_list.h"
  6. typedef enum {
  7. MENU,
  8. SUBMENU,
  9. VIEW,
  10. VARIABLE_ITEM_LIST,
  11. POPUP,
  12. } ViewType;
  13. struct View_t {
  14. ViewType type;
  15. int viewId;
  16. void* viewData;
  17. };
  18. typedef enum {
  19. APP_CONTEXT_OK = 0,
  20. APP_CONTEXT_CANT_ALLOCATE = -1,
  21. APP_CONTEXT_CANT_FREE_VIEWS = -2,
  22. APP_CONTEXT_NOT_ENOUGH_VIEWS = -3,
  23. APP_CONTEXT_UNKNOWN_ERROR = -4,
  24. } AppContextStatus;
  25. struct AppContext_t {
  26. SceneManager* scene_manager;
  27. ViewDispatcher* view_dispatcher;
  28. struct View_t** activeViews;
  29. int activeViewsCount;
  30. void* additionalData;
  31. };
  32. /// @brief Creates an app context with the desired scene handlers.
  33. /// @param context The app context to populate. Will be passed through to the supplied scene handlers.
  34. /// @param viewsCount The number of views that to be added to this scene.
  35. /// @param sceneManagerHandlers The scene handlers to use for each scene in your app.
  36. /// @return Returns APP_CONTEXT_OK on success, APP_CONTEXT_CANT_ALLOCATE if there is an error.
  37. AppContextStatus initializeAppContext(
  38. struct AppContext_t** context,
  39. int viewsCount,
  40. const SceneManagerHandlers* sceneManagerHandlers);
  41. /// @brief Adds a view to the given app context.
  42. /// @param context The app context to add the view to.
  43. /// @param view The view to add to the app context.
  44. /// @return Returns APP_CONTEXT_OK on success, APP_CONTEXT_NOT_ENOUGH_VIEWS if the ID of
  45. // the view exceeds the number of available views in the app context.
  46. AppContextStatus addViewToAppContext(struct AppContext_t** context, struct View_t* view);
  47. /// @brief Frees the app context entirely, cleaning it up from usage.
  48. /// @param context The app context to clean up.
  49. /// @return Returns APP_CONTEXT_OK on success. Should not error.
  50. AppContextStatus freeAppContext(struct AppContext_t** context);
  51. #endif