# Changes 0.2.4-1
- Add GIT_BRANCH (for development and stable) - Write Documentation of - pd-core (exept of vec.hpp) - pd-app - pd-drivers - pd-lib3ds - pd-image - pd-image - pd-ui7
This commit is contained in:
		| @@ -27,8 +27,21 @@ SOFTWARE. | ||||
|  | ||||
| namespace PD { | ||||
| namespace UI7 { | ||||
| /** | ||||
|  * Button Object | ||||
|  * @note Button Press is delayed by 1 frame | ||||
|  * (but the visual reaction is done in the same frame) | ||||
|  * This only means that InPressed is responding the info in | ||||
|  * the next frame | ||||
|  */ | ||||
| class Button : public Container { | ||||
|  public: | ||||
|   /** | ||||
|    * Button Object constructor | ||||
|    * @param label Label of the Button | ||||
|    * @param pos Base Position | ||||
|    * @param lr Reference to the Renderer | ||||
|    */ | ||||
|   Button(const std::string& label, vec2 pos, LI::Renderer::Ref lr) { | ||||
|     this->screen = lr->CurrentScreen(); | ||||
|     this->label = label; | ||||
| @@ -37,17 +50,27 @@ class Button : public Container { | ||||
|     color = UI7Color_Button; | ||||
|     this->SetSize(tdim + vec2(8, 4)); | ||||
|   } | ||||
|   ~Button() {} | ||||
|   ~Button() = default; | ||||
|  | ||||
|   /** Return true if butten is pressed*/ | ||||
|   bool IsPressed() { return pressed; } | ||||
|   /** | ||||
|    * Override for the Input Handler | ||||
|    * @note This function is usally called by Menu::Update | ||||
|    * @param inp Reference to the Input Handler | ||||
|    */ | ||||
|   void HandleInput(Hid::Ref inp) override; | ||||
|   /** | ||||
|    * Override for the Rendering Handler | ||||
|    * @note This function is usally called by Menu::Update | ||||
|    * */ | ||||
|   void Draw() override; | ||||
|  | ||||
|  private: | ||||
|   vec2 tdim; | ||||
|   UI7Color color; | ||||
|   std::string label; | ||||
|   bool pressed = false; | ||||
|   vec2 tdim;             ///< Text size | ||||
|   UI7Color color;        ///< current button color | ||||
|   std::string label;     ///< Label of the Button | ||||
|   bool pressed = false;  ///< ispressed value | ||||
| }; | ||||
| }  // namespace UI7 | ||||
| }  // namespace PD | ||||
| @@ -27,8 +27,21 @@ SOFTWARE. | ||||
|  | ||||
| namespace PD { | ||||
| namespace UI7 { | ||||
| /** | ||||
|  * Checkbox Object | ||||
|  * @note The Updated input is available after | ||||
|  * Context::Update while the visual update is done | ||||
|  * during the Update | ||||
|  */ | ||||
| class Checkbox : public Container { | ||||
|  public: | ||||
|   /** | ||||
|    * Constructor for Checkbox Object | ||||
|    * @param label Label of the Checkbox | ||||
|    * @param pos Base Position | ||||
|    * @param usr_ref Reference to the bool value to update | ||||
|    * @param lr Reference to the renderer (for text size calculation) | ||||
|    */ | ||||
|   Checkbox(const std::string& label, vec2 pos, bool& usr_ref, | ||||
|            LI::Renderer::Ref lr) | ||||
|       : usr_ref(usr_ref) { | ||||
| @@ -39,17 +52,25 @@ class Checkbox : public Container { | ||||
|     color = UI7Color_FrameBackground; | ||||
|     this->SetSize(cbs + vec2(tdim.x() + 5, 0)); | ||||
|   } | ||||
|   ~Checkbox() {} | ||||
|  | ||||
|   ~Checkbox() = default; | ||||
|   /** | ||||
|    * Override for the Input Handler | ||||
|    * @note This function is usally called by Menu::Update | ||||
|    * @param inp Reference to the Input Handler | ||||
|    */ | ||||
|   void HandleInput(Hid::Ref inp) override; | ||||
|   /** | ||||
|    * Override for the Rendering Handler | ||||
|    * @note This function is usally called by Menu::Update | ||||
|    * */ | ||||
|   void Draw() override; | ||||
|  | ||||
|  private: | ||||
|   vec2 tdim; | ||||
|   vec2 cbs = vec2(18); | ||||
|   UI7Color color; | ||||
|   std::string label; | ||||
|   bool& usr_ref; | ||||
|   vec2 tdim;            ///< Text Size | ||||
|   vec2 cbs = vec2(18);  ///< Checkbox size | ||||
|   UI7Color color;       ///< Checkbox background Color | ||||
|   std::string label;    ///< Checkbox Label | ||||
|   bool& usr_ref;        ///< User bool reference | ||||
| }; | ||||
| }  // namespace UI7 | ||||
| }  // namespace PD | ||||
| @@ -25,59 +25,128 @@ SOFTWARE. | ||||
|  | ||||
| #include <pd/core/common.hpp> | ||||
| #include <pd/core/strings.hpp> | ||||
| #include <pd/drivers/hid.hpp> | ||||
| #include <pd/core/vec.hpp> | ||||
| #include <pd/drivers/hid.hpp> | ||||
| #include <pd/ui7/drawlist.hpp> | ||||
|  | ||||
| namespace PD { | ||||
| namespace UI7 { | ||||
| /** | ||||
|  * Container base class all Objects are based on | ||||
|  * @note this class can be used to create custom Objects as well | ||||
|  */ | ||||
| class Container : public SmartCtor<Container> { | ||||
|  public: | ||||
|   Container() {} | ||||
|   Container() = default; | ||||
|   /** | ||||
|    * Constructor with pos and Size | ||||
|    * @param pos Container Position | ||||
|    * @param size Container Size | ||||
|    */ | ||||
|   Container(const vec2& pos, const vec2& size) : pos(pos), size(size) {} | ||||
|   Container(const vec4& box) : pos(box.xy()), size(box.zw()) {} | ||||
|   ~Container() {} | ||||
|   /** | ||||
|    * Constructor by a vec4 box | ||||
|    * @param box Box containing top left and bottom right coords | ||||
|    */ | ||||
|   Container(const vec4& box) : pos(box.xy()), size(box.zw() - box.xy()) {} | ||||
|   ~Container() = default; | ||||
|  | ||||
|   /** | ||||
|    * Init Function Required by every Object that uses | ||||
|    * Render or Input functions | ||||
|    * @param r Renderer Reference | ||||
|    * @param l DrawList Reference | ||||
|    * @param lt Theme Reference | ||||
|    */ | ||||
|   void Init(LI::Renderer::Ref r, UI7::DrawList::Ref l, UI7::Theme::Ref lt) { | ||||
|     list = l; | ||||
|     theme = lt; | ||||
|     ren = r; | ||||
|   } | ||||
|  | ||||
|   /** Setter for Position */ | ||||
|   void SetPos(const vec2& pos) { this->pos = pos; } | ||||
|   /** Setter for Size */ | ||||
|   void SetSize(const vec2& size) { this->size = size; } | ||||
|  | ||||
|   /** Getter for Position */ | ||||
|   vec2 GetPos() { return pos; } | ||||
|   /** Getter for Size */ | ||||
|   vec2 GetSize() { return size; } | ||||
|   /** | ||||
|    * Get the Containers Final Position | ||||
|    * for Rendering and Input (if it has a parent Object) | ||||
|    */ | ||||
|   vec2 FinalPos() { | ||||
|     vec2 res = pos; | ||||
|     if (parent) { | ||||
|       /// Probably should use parant->FinalPos here | ||||
|       res += parent->GetPos(); | ||||
|     } | ||||
|     return res; | ||||
|   } | ||||
|  | ||||
|   /** Setter for Parent Container */ | ||||
|   void SetParent(Container::Ref v) { parent = v; } | ||||
|   /** Getter for Parent Container */ | ||||
|   Container::Ref GetParent() { return parent; } | ||||
|  | ||||
|   /** Check if Rendering can be skipped */ | ||||
|   bool Skippable() const { return skippable; } | ||||
|   /** Check if the Object got a timeout (ID OBJ Relevant) */ | ||||
|   bool Removable() const { return rem; } | ||||
|  | ||||
|   /** | ||||
|    * Handles Scrolling by scrolling pos as well as | ||||
|    * Time for Remove for ID Objects | ||||
|    * @param scrolling Scrolling Position | ||||
|    * @param viewport Viewport to check if the Object is skippable | ||||
|    */ | ||||
|   void HandleScrolling(vec2 scrolling, vec4 viewport); | ||||
|   /** Template function for Input Handling */ | ||||
|   virtual void HandleInput(Hid::Ref inp) {} | ||||
|   /** Tamplate function for Object rendering */ | ||||
|   virtual void Draw() {} | ||||
|  | ||||
|   /** | ||||
|    * Function to unlock Input after Rendering is done in | ||||
|    * Menu::Update | ||||
|    * @note This is used if the Object got Input Handled directly after creation | ||||
|    * to not check for Inputs twice | ||||
|    */ | ||||
|   void UnlockInput() { inp_done = false; } | ||||
|  | ||||
|   /** Get the Objects ID (if it is an ID object)*/ | ||||
|   u32 GetID() const { return id; } | ||||
|   /** | ||||
|    * Set ID for ID Objects | ||||
|    * @param id Object ID (hashed prefix+objname+prefixed_counter) | ||||
|    */ | ||||
|   void SetID(u32 id) { this->id = id; } | ||||
|  | ||||
|  protected: | ||||
|   /// used to skip Input/Render preocessing ot not | ||||
|   /** used to skip Input/Render preocessing ot not*/ | ||||
|   bool skippable = false; | ||||
|   /** value to check if an ID Object goes out of lifetime*/ | ||||
|   bool rem = false; | ||||
|   /** Time of the last use (set by HandleScrolling)*/ | ||||
|   u64 last_use = 0; | ||||
|   /** Input done or not for current frame*/ | ||||
|   bool inp_done = false; | ||||
|   /** Reference to the Screen to draw the Object on*/ | ||||
|   Screen::Ref screen; | ||||
|   /** Container Position*/ | ||||
|   vec2 pos; | ||||
|   /** Container Size*/ | ||||
|   vec2 size; | ||||
|   /** Reference to the Drawlist to Draw to*/ | ||||
|   UI7::DrawList::Ref list; | ||||
|   /** Reference to the theme to use*/ | ||||
|   UI7::Theme::Ref theme; | ||||
|   /** Reference to the Renderer*/ | ||||
|   LI::Renderer::Ref ren; | ||||
|   /** Reference to the parent container*/ | ||||
|   Container::Ref parent; | ||||
|   /** Object ID (0 if unused)*/ | ||||
|   u32 id = 0; | ||||
| }; | ||||
| }  // namespace UI7 | ||||
|   | ||||
| @@ -27,8 +27,18 @@ SOFTWARE. | ||||
|  | ||||
| namespace PD { | ||||
| namespace UI7 { | ||||
| /** | ||||
|  * Image Object | ||||
|  */ | ||||
| class Image : public Container { | ||||
|  public: | ||||
|   /** | ||||
|    * Constructor for the Image Object | ||||
|    * @param img Image Texture Reference | ||||
|    * @param pos Base Position | ||||
|    * @param lr Renderer Reference [to determinate screen] | ||||
|    * @param size Custom Size of the Image | ||||
|    */ | ||||
|   Image(Texture::Ref img, vec2 pos, LI::Renderer::Ref lr, vec2 size = 0.f) { | ||||
|     this->screen = lr->CurrentScreen(); | ||||
|     this->img = img; | ||||
| @@ -39,12 +49,16 @@ class Image : public Container { | ||||
|       this->SetSize(img->GetSize()); | ||||
|     } | ||||
|   } | ||||
|   ~Image() {} | ||||
|   ~Image() = default; | ||||
|  | ||||
|   /** | ||||
|    * Override for the Rendering Handler | ||||
|    * @note This function is usally called by Menu::Update | ||||
|    * */ | ||||
|   void Draw() override; | ||||
|  | ||||
|  private: | ||||
|   Texture::Ref img; | ||||
|   Texture::Ref img;  ///< Texture reference to the Image | ||||
| }; | ||||
| }  // namespace UI7 | ||||
| }  // namespace PD | ||||
| @@ -27,8 +27,17 @@ SOFTWARE. | ||||
|  | ||||
| namespace PD { | ||||
| namespace UI7 { | ||||
| /** | ||||
|  * Label [Text] Object | ||||
|  */ | ||||
| class Label : public Container { | ||||
|  public: | ||||
|   /** | ||||
|    * Constructor for Label Object | ||||
|    * @param label Label [Text] to Draw | ||||
|    * @param pos Base Position | ||||
|    * @param lr Renderer Reference | ||||
|    */ | ||||
|   Label(const std::string& label, vec2 pos, LI::Renderer::Ref lr) { | ||||
|     this->screen = lr->CurrentScreen(); | ||||
|     this->label = label; | ||||
| @@ -37,14 +46,18 @@ class Label : public Container { | ||||
|     color = UI7Color_Text; | ||||
|     this->SetSize(tdim); | ||||
|   } | ||||
|   ~Label() {} | ||||
|   ~Label() = default; | ||||
|  | ||||
|   /** | ||||
|    * Override for the Rendering Handler | ||||
|    * @note This function is usally called by Menu::Update | ||||
|    * */ | ||||
|   void Draw() override; | ||||
|  | ||||
|  private: | ||||
|   vec2 tdim; | ||||
|   UI7Color color; | ||||
|   std::string label; | ||||
|   vec2 tdim;          ///< Text Size | ||||
|   UI7Color color;     ///< Color | ||||
|   std::string label;  ///< Text to Render | ||||
| }; | ||||
| }  // namespace UI7 | ||||
| }  // namespace PD | ||||
		Reference in New Issue
	
	Block a user