mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 01:49:44 +00:00
Add textbox selection and layout API for custom rendering
This commit is contained in:
parent
bb6bd27b94
commit
61b3f8f973
7 changed files with 393 additions and 5 deletions
|
|
@ -204,11 +204,18 @@ uint Label::getLinesNumber() const {
|
|||
return cache.lines.size();
|
||||
}
|
||||
|
||||
void Label::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
auto batch = pctx.getBatch2D();
|
||||
glm::vec2 Label::getTextOrigin() const {
|
||||
return textOrigin;
|
||||
}
|
||||
|
||||
void Label::setRenderText(bool value) {
|
||||
renderText = value;
|
||||
}
|
||||
|
||||
bool Label::prepareLayout(const Assets& assets) {
|
||||
auto font = assets.getShared<Font>(fontName);
|
||||
if (font == nullptr) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
cache.prepare(
|
||||
font,
|
||||
|
|
@ -222,7 +229,6 @@ void Label::draw(const DrawContext& pctx, const Assets& assets) {
|
|||
if (cache.resetFlag) {
|
||||
cache.update(text, multiline, textWrap);
|
||||
}
|
||||
batch->setColor(calcColor());
|
||||
|
||||
uint lineHeight = font->getLineHeight();
|
||||
if (cache.lines.size() > 1) {
|
||||
|
|
@ -248,6 +254,18 @@ void Label::draw(const DrawContext& pctx, const Assets& assets) {
|
|||
textYOffset = pos.y-calcPos().y;
|
||||
totalLineHeight = lineHeight;
|
||||
|
||||
textOrigin = pos;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Label::draw(const DrawContext& pctx, const Assets& assets) {
|
||||
if (!prepareLayout(assets) || !renderText) {
|
||||
return;
|
||||
}
|
||||
auto batch = pctx.getBatch2D();
|
||||
auto font = assets.getShared<Font>(fontName);
|
||||
batch->setColor(calcColor());
|
||||
glm::vec2 pos = textOrigin;
|
||||
const auto& viewport = pctx.getViewport();
|
||||
glm::vec4 bounds {0, 0, viewport.x, viewport.y};
|
||||
if (parent) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue