Hi! I tried positioning text in texture but my code now work. I think so SFML 2.6.2 not working correctly, because I think my code is correct. I use global coordinates for all objects and result is in screenshot. I think this red bar should be a hover of blue rect.
ScrollableText::ScrollableText(std::wstring text) : Dialog(DialogType::ScrollableText) {
border = sf::RectangleShape(sf::Vector2f(width, height));
border.setFillColor(panelColor_dark);
border.setPosition(cam->position.x-width/2.0f, cam->position.y-height/2.0f);
rect = sf::RectangleShape(sf::Vector2f(width-2*borderWidth, height-2*borderWidth));
rect.setFillColor(panelColor_normal);
rect.setPosition(cam->position.x - width/2.0f + borderWidth, cam->position.y - height/2.0f+borderWidth);
sf::Vector2f scrollbar_size = sf::Vector2f(16, height - 2.0f * borderWidth);
textarea = new TextArea(text, cam->position, width - 2.0f*borderWidth - 2.0f*margin - scrollbar_size.x);
textarea->setPosition(sf::Vector2f(- width/2.0f + borderWidth + margin, - height/2.0f + borderWidth + margin));
sf::Vector2f scrollbar_position = sf::Vector2f(width/2.0f-borderWidth-scrollbar_size.x, -height/2.0f + borderWidth);
float scroll_max = textarea->getSize().y + textarea->getLineHeight();
float scroll_len = height;
scrollbar = new Scrollbar(scrollbar_size, scrollbar_position, 0, scroll_max, 0, scroll_len);
// TO-DO - generowanie tekstury przewijalnej dla tekstu
text_texture.create(width-2.0f*(borderWidth+margin) - scrollbar_size.x, height-2.0f*(borderWidth+margin));
sf::View v = sf::View(sf::FloatRect(sf::Vector2f(cam->position.x-width/2.0f+borderWidth+margin, cam->position.y-height/2.0f+borderWidth+margin), sf::Vector2f(width-2*(borderWidth+margin), height-2*(borderWidth+margin))));
text_texture.setView(v);
text_texture.setSmooth(true);
text_texture.clear(sf::Color::Red);
textarea->setRectColor(sf::Color::Blue);
text_texture.draw(textarea->rect);
for (auto& text : textarea->texts)
text_texture.draw(text);
text_texture.display();
text_sprite = sf::Sprite(text_texture.getTexture());
sf::Vector2f textpos;
textpos.x = cam->position.x + position.x - width / 2.0f + borderWidth + margin - (textarea->texts[0].getPosition().x-textarea->rect.getPosition().x);
textpos.y = cam->position.y + position.y - height / 2.0f + borderWidth + margin - (textarea->texts[0].getPosition().y - textarea->rect.getPosition().y);
text_sprite.setPosition(textpos);
// TO-DO
}