I'm trying to make TextField widget, here's header:
class TextField: public sf::Drawable, public sf::Transformable
{
public:
TextField(sf::Font& font, unsigned int charSize, const std::string& content, const sf::Vector2f& size);
void setFocused(bool state);
std::string getText() const;
void setBackgroundColor(sf::Color);
void processInput(sf::Event event);
void draw(sf::RenderTarget& target, sf::RenderStates states) const;
void clear();
sf::Vector2f getSize() const;
private:
sf::RectangleShape background;
sf::Text text;
std::string string;
sf::Color focusedColor;
sf::Color unfocusedColor;
};
As you can see it's just wrapper with rectangle inside and text on top of it and bunch of helper functions.
I've figured out how to draw passing it to the window, by inheriting from drawable and overloading draw method.
But i can't figure out how to make setPosition method for this class. Documentation suggests just inheriting from Transformable and using inherited setPosition method and all will be fine.
However it's doesn't work - position remains 0,0 whatever is passed to setPosition.
Transformable::setPosition isn't virtual so only option is make my own setPosition, right?
But what's the point in inheriting Transformable then? It doesn't work because i'm doing something wrong?