Update text rendering.
This commit is contained in:
parent
8536908eab
commit
8130308f7f
27 changed files with 503 additions and 77 deletions
|
@ -6,6 +6,8 @@
|
|||
#include "ThemeManager.h"
|
||||
#include "PaintEvent.h"
|
||||
|
||||
#include "FontTokens.h"
|
||||
|
||||
#include "MouseEvent.h"
|
||||
#include "FileLogger.h"
|
||||
|
||||
|
@ -16,6 +18,10 @@ Button::Button(ButtonData::Component component)
|
|||
{
|
||||
mStyle.mComponent = component;
|
||||
mName = "Button";
|
||||
|
||||
setHeight(mStyle.getContainerHeight());
|
||||
setMaxHeight(mStyle.getContainerHeight());
|
||||
setRadius(mStyle.getContainerCornerRadius());
|
||||
}
|
||||
|
||||
Button::~Button()
|
||||
|
@ -66,7 +72,39 @@ void Button::setEnabled(bool isEnabled)
|
|||
void Button::updateState()
|
||||
{
|
||||
setBackground(mStyle.getContainerColor());
|
||||
setBackgroundTone(mStyle.getContainerSurfaceTintColor());
|
||||
setElevation(mStyle.getContainerElevation());
|
||||
|
||||
setLabelTextColor(mStyle.getLabelTextColor());
|
||||
setLabelTextOpacity(mStyle.getLabelOpacity());
|
||||
setLabelTextTypescale(mStyle.getLabelTypescale());
|
||||
}
|
||||
|
||||
void Button::setLabelTextColor(Theme::Sys::Color color)
|
||||
{
|
||||
if (mLabelTextColor != color)
|
||||
{
|
||||
mLabelTextColor = color;
|
||||
mMaterialDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Button::setLabelTextOpacity(float opacity)
|
||||
{
|
||||
if (mLabelOpacity != opacity)
|
||||
{
|
||||
mLabelOpacity = opacity;
|
||||
mMaterialDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Button::setLabelTextTypescale(Theme::Sys::Typescale typescale)
|
||||
{
|
||||
if (mLabelTextTypescale != typescale)
|
||||
{
|
||||
mLabelTextTypescale = typescale;
|
||||
mMaterialDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Button::onMyMouseEvent(const MouseEvent* event)
|
||||
|
@ -131,29 +169,31 @@ void Button::doPaint(const PaintEvent* event)
|
|||
|
||||
void Button::updateLabel(const PaintEvent* event)
|
||||
{
|
||||
unsigned fontOffset = unsigned(mLabel.size()) * 4;
|
||||
auto middle = DiscretePoint(mLocation.getX() + mSize.mWidth/2 - fontOffset, mLocation.getY() + mSize.mHeight/2 + 4);
|
||||
|
||||
if (!mTextNode)
|
||||
{
|
||||
mTextNode = TextNode::Create(mLabel, middle);
|
||||
mTextNode = TextNode::Create(mLabel, mLocation);
|
||||
mTextNode->setName(mName + "_TextNode");
|
||||
mTextNode->setContent(mLabel);
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
mRootNode->addChild(mTextNode.get());
|
||||
}
|
||||
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mTextNode->setLocation(middle);
|
||||
mTextNode->setLocation(mLocation);
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
}
|
||||
|
||||
if (mMaterialDirty)
|
||||
{
|
||||
mTextNode->setFillColor(event->getThemesManager()->getColor(mBackground));
|
||||
auto fill_color = event->getThemesManager()->getColor(mLabelTextColor);
|
||||
fill_color.setAlpha(mLabelOpacity);
|
||||
mTextNode->setFillColor(fill_color);
|
||||
|
||||
auto size = FontTokens::getSize(mLabelTextTypescale);
|
||||
auto family = FontTokens::getFont(FontTokens::getFont(mLabelTextTypescale));
|
||||
auto font_data = FontItem(family, static_cast<float>(size));
|
||||
mTextNode->setFont(font_data);
|
||||
}
|
||||
|
||||
if (mContentDirty)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue