SFTK/include/containers/label.hpp

50 lines
1.4 KiB
C++

#ifndef LABEL_HPP
#define LABEL_HPP
#include <string>
#include <vector>
#include <font.hpp>
#include <containers/container.hpp>
namespace sftk
{
class Label : public Container
{
public:
static Label &create(pContainer parent = nullptr);
static Label &create(sf::Vector2f pos, pContainer parent = nullptr);
static Label &create(std::wstring text, pContainer parent = nullptr);
static Label &create(Font font, pContainer parent = nullptr);
static Label &create(std::wstring text, Font font, pContainer parent = nullptr);
void setText(std::wstring text);
void setFont(Font font);
void setColor(sf::Color color);
void setSize(sf::Vector2f size) = delete;
const std::wstring &getText() const;
const Font &getFont() const;
sf::Color getColor() const;
protected:
Label(pContainer parent = nullptr);
Label(sf::Vector2f pos, pContainer parent = nullptr);
void draw(sf::RenderWindow &sfwindow) const;
private:
std::wstring text;
Font font;
sf::Color color;
// After setText() called, this vector will be filled.
std::vector<uint> wrongGlyphs;
// This vector records every characters' x offset.
std::vector<std::vector<float>> linesGlyphPrefixSum;
std::vector<float> linesWidths;
};
};
#endif