#ifndef WIDGET_TEXT_H_ #define WIDGET_TEXT_H_ #include "Widget.h" #include #include "../sdl_helpers.h" // Renders text within a specified box class WidgetText : public Widget { protected: // Text to display std::string m_text; // Desired font file // Leave empty for default std::string m_font_file; // Desired font size int m_size; // Whether to fit text inside rectangle // FIT_SHRINK will try with the desired font size and shrink if needed // FIT_AUTO will with the desired font size and shrink or enlarge if needed // Default - FIT_NONE TextFit m_fit; // Whether to wrap to multiple lines // Default - false bool m_should_wrap; // Default - center HorizontalAlign m_halign; // Default - center VerticalAlign m_valign; // Default - black SDL_Color m_text_color; // Whether to H-align via visible pixels or rendering surface // Default - true bool m_halign_via_visible; // Whether to V-align via visible pixels or rendering surface // Default - true bool m_valign_via_visible; public: WidgetText(int x, int y, int width, int height, std::string text, TextFit fit, bool should_wrap, HorizontalAlign halign, VerticalAlign valign, bool halign_via_visible, bool valign_via_visible, SDL_Color text_color, int size, std::string font = ""); WidgetText(int x, int y, int width, int height, std::string text, TextFit fit, bool should_wrap, int size, std::string font = ""); WidgetText(int x, int y, int width, int height, std::string text, int size, std::string font = ""); void set_text(const std::string& text); void set_font(const std::string& font_file); void set_font_size(int size); void set_fit(TextFit fit); void set_halign(HorizontalAlign halign); void set_valign(VerticalAlign valign); void set_color(SDL_Color text_color); virtual void draw() override; static std::unique_ptr builder(const nlohmann::json& j); }; #endif // WIDGET_TEXT_H_