Added WidgetText. Fixed some things. Updated README
This commit is contained in:
71
Widgets/WidgetText.h
Normal file
71
Widgets/WidgetText.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef WIDGET_TEXT_H_
|
||||
#define WIDGET_TEXT_H_
|
||||
|
||||
#include "Widget.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "../sdl_helpers.h"
|
||||
#include "../json.hpp"
|
||||
|
||||
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;
|
||||
|
||||
public:
|
||||
WidgetText(int width, int height, std::string text,
|
||||
TextFit fit, bool should_wrap,
|
||||
HorizontalAlign halign, VerticalAlign valign,
|
||||
SDL_Color text_color,
|
||||
int size, std::string font = "");
|
||||
|
||||
WidgetText(int width, int height, std::string text,
|
||||
TextFit fit, bool should_wrap,
|
||||
int size, std::string font = "");
|
||||
|
||||
WidgetText(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 Widget* builder(const nlohmann::json& j);
|
||||
};
|
||||
|
||||
#endif // WIDGET_TEXT_H_
|
||||
Reference in New Issue
Block a user