Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User function and plugins support for LGFX_Base and LGFX_Sprite #517

Closed
wants to merge 2 commits into from

Conversation

tobozo
Copy link
Collaborator

@tobozo tobozo commented Jan 30, 2024

This change adds the possibility to call LGFX object with a user function, it can make life easier when creating plugins that work on top of LovyanGFX.

Example:

void my_circle_function( LovyanGFX* dst, int32_t x, int32_t y, uint32_t radius,  uint32_t color1 , uint32_t color2 )
{
   dst->fillCircle( x, y, radius, color1 );
   dst->fillCircle( x, y, radius/2, color2 );
}

// optional macro to use tft.funCircle(...) without calling 'userFunc'
#define funCircle(...)  userFunc( my_circle_function, __VA_ARGS__);

void setup()
{
  tft.init();

  tft.userFunc( my_circle_function, 100, 100, 50, 0xff0000u, 0x00ffffu );
  // or if using the optional macro:
  tft.funCircle( 100, 100, 50, 0xff0000u, 0x00ffffu );
}

@tobozo
Copy link
Collaborator Author

tobozo commented Feb 2, 2024

Mixing C macros with cpp templates was a bad idea so I got rid of the macro and moved the template to a single location instead:

  /// @brief LovyanGFX class.
  /// that depend on the include order of the environment, such as file system, are inherited from LGFX_FILESYSTEM_Support.
  class LovyanGFX : public
  #ifdef LGFX_FILESYSTEM_SUPPORT_HPP_
      LGFX_FILESYSTEM_Support<
  #endif
       LGFXBase
  #ifdef LGFX_FILESYSTEM_SUPPORT_HPP_
      >
  #endif
  {
    public:
      template<typename Fun, typename ...Args>
      auto userFunc(Fun& fn, Args&&... arg) -> void{ fn(this, std::forward<Args>(arg)...); }
  };

I'll close this PR and work on a plugin example.

@tobozo tobozo closed this Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant