Fixed alignment on UI Label
This commit is contained in:
@ -16,8 +16,9 @@
|
||||
<UIRichTextLabel
|
||||
alignment="0, 0, 0, 0"
|
||||
alignX="UI_COMPONENT_ALIGN_STRETCH"
|
||||
alignY="UI_COMPONENT_ALIGN_STRETCH"
|
||||
alignY="UI_COMPONENT_ALIGN_MIDDLE"
|
||||
ref="uiLabel"
|
||||
lineHeight="2"
|
||||
>
|
||||
</UIRichTextLabel>
|
||||
</child>
|
||||
|
@ -166,11 +166,11 @@
|
||||
</text>
|
||||
|
||||
<text>
|
||||
<string lang="en">"I wouldn't expect any less from our daughter,” Mother says. She smiles at me: it creases her mouth in an unnatural way. "Doesn't Ethereality look like Angelwood's Queen already?”</string>
|
||||
<string lang="en">"I wouldn't expect any less from our daughter," Mother says. She smiles at me: it creases her mouth in an unnatural way. "Doesn't Ethereality look like Angelwood's Queen already?"</string>
|
||||
</text>
|
||||
|
||||
<text>
|
||||
<string lang="en">My father nods his agreement. "Yes,” he tells me, "An Estridge in her finest.”</string>
|
||||
<string lang="en">My father nods his agreement. "Yes," he tells me, "An Estridge in her finest."</string>
|
||||
</text>
|
||||
|
||||
<text>
|
||||
@ -198,7 +198,7 @@
|
||||
</text>
|
||||
|
||||
<text>
|
||||
<string lang="en">"Thank you,” I say. "I'm really happy you think that.”</string>
|
||||
<string lang="en">"Thank you," I say. "I'm really happy you think that."</string>
|
||||
</text>
|
||||
|
||||
<text>
|
||||
|
@ -9,7 +9,8 @@
|
||||
using namespace Dawn;
|
||||
|
||||
UILabel::UILabel(SceneItem *item) :
|
||||
UIComponentRenderable(item)
|
||||
UIComponentRenderable(item),
|
||||
lineHeight(1.0f)
|
||||
{
|
||||
|
||||
}
|
||||
@ -22,6 +23,10 @@ void UILabel::onStart() {
|
||||
useEvent([&]{
|
||||
this->rebufferQuads(this->texts);
|
||||
}, eventAlignmentUpdated);
|
||||
|
||||
useEffect([&]{
|
||||
this->rebufferQuads(this->texts);
|
||||
}, lineHeight);
|
||||
}
|
||||
|
||||
std::vector<struct ShaderPassItem> UILabel::getUIRenderPasses() {
|
||||
@ -94,10 +99,15 @@ float_t UILabel::getContentHeight() {
|
||||
h += it->height;
|
||||
++it;
|
||||
}
|
||||
return 1;
|
||||
return h;
|
||||
}
|
||||
|
||||
void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
|
||||
if(this->ignoreAlignmentUpdate) {
|
||||
this->ignoreAlignmentUpdate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
assertTrue(newTexts.size() <= FONT_SHADER_PARTS_MAX);
|
||||
|
||||
int32_t nextTexture = 0;
|
||||
@ -116,7 +126,7 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
|
||||
// Determine font dimensions.
|
||||
auto itText = newTexts.begin();
|
||||
while(itText != newTexts.end()) {
|
||||
position.y = mathMax<float_t>(position.y, itText->style.size);
|
||||
position.y = mathMax<float_t>(position.y, itText->style.size * this->lineHeight);
|
||||
++itText;
|
||||
}
|
||||
|
||||
@ -189,7 +199,7 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
|
||||
// Move to next line
|
||||
if(i != len) {
|
||||
position.x = 0;
|
||||
position.y += realText.style.size;
|
||||
position.y += realText.style.size * this->lineHeight;
|
||||
lines.push_back(currentLine);
|
||||
}
|
||||
|
||||
@ -203,11 +213,11 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
|
||||
currentLine = UILabelLine();
|
||||
currentLine.quadStart = quadCountTotal;
|
||||
currentLine.position = position;
|
||||
currentLine.height = realText.style.size;
|
||||
currentLine.height = realText.style.size * this->lineHeight;
|
||||
// Here I subtract line height from the line position because we start
|
||||
// by moving the text down by the initial line height, so we need to
|
||||
// compensate for that.
|
||||
currentLine.position.y -= realText.style.size;
|
||||
currentLine.position.y -= realText.style.size * this->lineHeight;
|
||||
}
|
||||
};
|
||||
|
||||
@ -342,6 +352,9 @@ void UILabel::rebufferQuads(const std::vector<struct UILabelText> newTexts) {
|
||||
textsBuffered = realNewTexts;
|
||||
texts = newTexts;
|
||||
|
||||
this->ignoreAlignmentUpdate = true;
|
||||
this->alignmentNeedsUpdating = true;
|
||||
|
||||
// Event
|
||||
this->eventTextChanged.invoke();
|
||||
}
|
@ -36,11 +36,18 @@ namespace Dawn {
|
||||
int32_t quadCount = 0;
|
||||
};
|
||||
|
||||
enum UILabelVerticalAlign {
|
||||
UI_LABEL_VERTICAL_ALIGN_TOP,
|
||||
UI_LABEL_VERTICAL_ALIGN_MIDDLE,
|
||||
UI_LABEL_VERTICAL_ALIGN_BOTTOM
|
||||
};
|
||||
|
||||
class UILabel : public UIComponentRenderable {
|
||||
private:
|
||||
Mesh mesh;
|
||||
FontShaderBuffer shaderBuffer;
|
||||
std::map<TrueTypeFaceTexture*, int32_t> textureMap;
|
||||
bool_t ignoreAlignmentUpdate = false;
|
||||
|
||||
public:
|
||||
int32_t quadStart = 0;
|
||||
@ -55,6 +62,9 @@ namespace Dawn {
|
||||
|
||||
StateEvent<> eventTextChanged;
|
||||
|
||||
// @optional
|
||||
StateProperty<float_t> lineHeight;
|
||||
|
||||
UILabel(SceneItem *item);
|
||||
|
||||
void onStart() override;
|
||||
|
Reference in New Issue
Block a user