#if !defined (__GUI_DRIVER_H__)
  #define __GUI_DRIVER_H__
  #include <avr/pgmspace.h>
  #include "GUIuser.h"                                                  //Need SCR_NUMBER and will also include \ref GUIcommon.h

  /*****************************************************************************************************************************
   * File:     GUIdriver.h
   * Purpose:  Contains GUI functions that are common use, less probable to change over different Displays or Applications.
   * Author:   Erno Gilissen Belgium
   * Created:  October 31, 2025
   * Description:
   * - Defines several global data; ex. computes the \ref SCR_DATA offsets required to address these structs in Flash.
   * - Contains the function prototypes of more generic GUI functions (like the handles for the slider bars or sliding buttons).
   *
   * Dependencies:
   * - "GUIuser.h" as it needs information how the screens are built up.
   * - "GUIcommon.h" (indirect via "GUIuser.h") since it requires the GUI datatypes.
   */

  #define CHECKBOX_THICK       (3)
  #define CHECKBOX0         (0x01)                                        //If Checkbox is not used, you can delete this safely.
  #define CHECKBOX1         (0x02)
  #define CHECKBOX2         (0x04)
  #define CHECKBOX3         (0x08)
  #define CHECKBOX4         (0x10)
  #define CHECKBOX5         (0x20)
  #define CHECKBOX6         (0x40)
  #define CHECKBOX7         (0x80)

  /*****************************************************************************************************************************
   * \ingroup API
   * Structure addressing only works for RAM, not for FLASH structs. So we have to work in a different way to access the structure elements:
   * 1. The struct pointer is typecasted to an 8bit pointer.
   * 2. The compiler computes the offsets for the parameters (that happens at the left).
   * 3. Read the correct parameter size relative to the 8bit pointer. For this reason, a number of macros are added in the  Display.cpp file.
   *    For instance FLRw? will conduct a  FLashRead word size (I still use the MC68K naming, since those are the first large CPU/MCU cores I
   *    worked with for a very long time. So this naming is still part of my mind (as ROM)).
   */
  #define OF_OBJ   (offsetof (SCR_DATA, obj))                            //Object.
  #define OF_TX0   (offsetof (SCR_DATA, tX0))                            //Touch X0 (left).
  #define OF_TX1   (offsetof (SCR_DATA, tX1))                            //Touch X1 (right).
  #define OF_TY0   (offsetof (SCR_DATA, tY0))                            //Touch Y0 (top).
  #define OF_TY1   (offsetof (SCR_DATA, tY1))                            //Touch Y1 (bottom).
  #define OF_OX0   (offsetof (SCR_DATA, oX0))                            //Object X0.
  #define OF_OW    (offsetof (SCR_DATA, oW))                             //Object Width.
  #define OF_OY0   (offsetof (SCR_DATA, oY0))                            //Object Y0.
  #define OF_OH    (offsetof (SCR_DATA, oH))                             //Object Height.
  #define OF_OE    (offsetof (SCR_DATA, oE))                             //Object Extra Info.
  #define OF_OC    (offsetof (SCR_DATA, oC))                             //Object Color (RGB565)
  #define OF_LX0   (offsetof (SCR_DATA, lX0))                            //Label X0.
  #define OF_LY0   (offsetof (SCR_DATA, lY0))                            //Label Y0.
  #define OF_TXT   (offsetof (SCR_DATA, txt))                            //Label Text Pointer (this must be pointer, as the size is fixed).
  #define OF_FS    (offsetof (SCR_DATA, fS))                             //Font Size.
  #define OF_LC    (offsetof (SCR_DATA, lC))                             //Label Color.
  #define OF_OCL   (offsetof (SCR_DATA, onClick))                        //CallBack function when the GUI object is touched.
  #define OF_LOP   (offsetof (SCR_DATA, oLoPct))                         //Lo Percentage Value (passed to CallBack if the object uses Lo Percentage).
  #define OF_HIP   (offsetof (SCR_DATA, oHiPct))                         //Hi Percentage Value.






  /*****************************************************************************************************************************
  * \ingroup API.
  * Generic Driver Prototypes. Note functions that modify a sliderbar use default TOUCHPOS_CALC. As a result, external functions
  * calling this function to modify the position don't need this append this parameter in the call. Only library functions
  * use TOUCHPOS_REF (this is somewhat faster in the drawing as the actual touch position is used, not calculated from a percentage).
  */
  uint16_t      background_color_get ();
  void          button_sl_h_pct (const SCR_DATA* oPtr, const int8_t pct, const TOUCH_REFERENCE enXtouch = TOUCHPOS_CALC);
  void          button_sl_v_pct (const SCR_DATA* oPtr, const int8_t pct, const TOUCH_REFERENCE enYtouch = TOUCHPOS_CALC);
  void          checkbox_update (const SCR_DATA* sd, const uint8_t state);
  int8_t        screen_draw (SCR_NUMBER scrWanted, SCR_UPDATE drawMode = SCR_DRAW);
  SCR_NUMBER    screen_no_get ();
  void          screen_obj_draw (const SCR_DATA* sd, uint8_t  count);
//#if !defined(__AVR_ATmega328P__) && !defined(__AVR_ATmega328PB__)
    void        slider_h_fill_pct (const SCR_DATA* oPtr, const int8_t pct, const TOUCH_REFERENCE tr = TOUCHPOS_CALC);
    void        slider_v_fill_pct (const SCR_DATA* oPtr, const int8_t pct, const TOUCH_REFERENCE tr = TOUCHPOS_CALC);
//#endif
  void          tft_mcufriend_init (int8_t initLevel);
  uint8_t       touch_index_get ();                                     //Return the Index of the Screen Array Element being 'touched'.
  void          touch_scan ();


#endif