Update text rendering.

This commit is contained in:
jmsgrogan 2023-01-18 17:31:16 +00:00
parent 8536908eab
commit 8130308f7f
27 changed files with 503 additions and 77 deletions

View file

@ -0,0 +1,64 @@
#include "FontTokens.h"
std::string FontTokens::getFont(Theme::Ref::Typeface::Font font)
{
switch (font)
{
case Theme::Ref::Typeface::Font::Brand:
return "Segoe UI";
case Theme::Ref::Typeface::Font::Plain:
return "Segoe UI";
default:
return "Segoe UI";
}
}
Theme::Ref::Typeface::Font FontTokens::getFont(Theme::Sys::Typescale typescale)
{
switch (typescale)
{
case Theme::Sys::Typescale::Label_Large:
return Theme::Ref::Typeface::Font::Brand;
default:
return Theme::Ref::Typeface::Font::Brand;
}
}
unsigned FontTokens::getLineHeight(Theme::Sys::Typescale typescale)
{
switch (typescale)
{
case Theme::Sys::Typescale::Label_Large:
return 67;
default:
return 67;
}
}
unsigned FontTokens::getSize(Theme::Sys::Typescale typescale)
{
switch (typescale)
{
case Theme::Sys::Typescale::Label_Large:
return static_cast<unsigned>(57/3);
default:
return 57;
}
}
unsigned FontTokens::getTracking(Theme::Sys::Typescale typescale)
{
return 0;
}
unsigned FontTokens::getWeight(Theme::Ref::Typeface::Font font)
{
return 0;
}
Theme::Ref::Typeface::Font FontTokens::getWeight(Theme::Sys::Typescale typescale)
{
return Theme::Ref::Typeface::Font::Brand;
}

View file

@ -51,6 +51,7 @@ namespace Theme
class FontTokens
{
public:
static std::string getFont(Theme::Ref::Typeface::Font font);
static Theme::Ref::Typeface::Font getFont(Theme::Sys::Typescale typescale);

View file

@ -77,6 +77,25 @@ void BoxGeometry::setBounds(unsigned width, unsigned height)
}
}
void BoxGeometry::setWidth(unsigned width)
{
setBounds(width, mSize.mHeight);
}
void BoxGeometry::setHeight(unsigned height)
{
setBounds(mSize.mWidth, height);
}
void BoxGeometry::setMaxHeight(unsigned maxHieght)
{
if (mSize.mMaxHeight != maxHieght)
{
mTransformDirty = true;
mSize.mMaxHeight = maxHieght;
}
}
void BoxGeometry::setLocation(const DiscretePoint& loc)
{
if (mLocation != loc)

View file

@ -59,6 +59,12 @@ public:
const DiscretePoint& getLocation() const;
void setWidth(unsigned width);
void setHeight(unsigned height);
void setMaxHeight(unsigned maxHieght);
void setBounds(unsigned width, unsigned height);
void setSize(const BoundedSize& size);

View file

@ -16,7 +16,6 @@
#include <algorithm>
#include <iterator>
#include <iostream>
Widget::Widget()
: BoxGeometry(),
@ -73,6 +72,24 @@ void Widget::setBackground(Theme::Sys::Color token)
}
}
void Widget::setBackgroundTone(Theme::Sys::Color token)
{
if (mBackgroundTone != token)
{
mBackgroundTone = token;
mMaterialDirty = true;
}
}
void Widget::setElevation(Theme::Sys::Elevation elevation)
{
if (mElevation != elevation)
{
mElevation = elevation;
mMaterialDirty = true;
}
}
void Widget::setBackgroundOpacity(float opacity)
{
if (mBackgroundOpacity != opacity)
@ -173,6 +190,9 @@ void Widget::onPaintEvent(const PaintEvent* event)
}
doPaint(event);
mGeometryDirty = false;
mMaterialDirty = false;
mTransformDirty = false;
if (mVisibilityDirty)
{
@ -293,32 +313,30 @@ void Widget::onMyMouseEvent(const MouseEvent* event)
void Widget::createOrUpdateGeometry()
{
const auto deltaX = mSize.mWidth - mMargin.mLeft - mMargin.mRight;
const auto deltaY = mSize.mHeight - mMargin.mTop - mMargin.mBottom;
if (!mBackgroundNode)
{
unsigned locX = mLocation.getX() + mMargin.mLeft;
unsigned locY = mLocation.getY() + mMargin.mTop;
unsigned deltaX = mSize.mWidth - mMargin.mLeft - mMargin.mRight;
unsigned deltaY = mSize.mHeight - mMargin.mTop - mMargin.mBottom;
const auto locX = mLocation.getX() + mMargin.mLeft;
const auto locY = mLocation.getY() + mMargin.mTop;
mBackgroundNode = std::make_unique<RectangleNode>(DiscretePoint(locX, locY), deltaX, deltaY);
mBackgroundNode->setRadius(mRadius);
mBackgroundNode->setName(mName + "_BackgroundNode");
mRootNode->addChild(mBackgroundNode.get());
}
else
{
mBackgroundNode->setWidth(deltaX);
mBackgroundNode->setHeight(deltaY);
mBackgroundNode->setRadius(mRadius);
}
}
void Widget::updateTransform()
{
unsigned locX = mLocation.getX() + mMargin.mLeft;
unsigned locY = mLocation.getY() + mMargin.mTop;
unsigned deltaX = mSize.mWidth - mMargin.mLeft - mMargin.mRight;
unsigned deltaY = mSize.mHeight - mMargin.mTop - mMargin.mBottom;
mBackgroundNode->setWidth(deltaX);
mBackgroundNode->setHeight(deltaY);
const auto locX = mLocation.getX() + mMargin.mLeft;
const auto locY = mLocation.getY() + mMargin.mTop;
mBackgroundNode->setLocation(DiscretePoint(locX, locY));
}
@ -326,9 +344,16 @@ void Widget::updateMaterial(const PaintEvent* event)
{
if (mBackground != Theme::Sys::Color::None)
{
auto background_color = event->getThemesManager()->getColor(mBackground);
background_color.setAlpha(mBackgroundOpacity);
mBackgroundNode->setFillColor(background_color);
//if (mBackgroundTone == Theme::Sys::Color::None || mElevation == Theme::Sys::Elevation::Level_0)
//{
auto background_color = event->getThemesManager()->getColor(mBackground);
background_color.setAlpha(mBackgroundOpacity);
mBackgroundNode->setFillColor(background_color);
//}
//else
//{
//event->getThemesManager()->getColor(mBackground);
//}
}
else
{
@ -348,22 +373,14 @@ void Widget::updateMaterial(const PaintEvent* event)
void Widget::updateBackground(const PaintEvent* event)
{
unsigned locX = mLocation.getX() + mMargin.mLeft;
unsigned locY = mLocation.getY() + mMargin.mTop;
unsigned deltaX = mSize.mWidth - mMargin.mLeft - mMargin.mRight;
unsigned deltaY = mSize.mHeight - mMargin.mTop - mMargin.mBottom;
if (!mBackgroundNode)
if (mGeometryDirty)
{
mBackgroundNode = std::make_unique<RectangleNode>(DiscretePoint(locX, locY), deltaX, deltaY);
mBackgroundNode->setName(mName + "_BackgroundNode");
mRootNode->addChild(mBackgroundNode.get());
createOrUpdateGeometry();
}
if (mTransformDirty)
{
updateTransform();
mTransformDirty = false;
}
if (mMaterialDirty)

View file

@ -1,11 +1,13 @@
#pragma once
#include "FontItem.h"
#include "ITheme.h"
#include "WidgetState.h"
#include "BoxGeometry.h"
#include "TransformNode.h"
#include "ITheme.h"
#include "ElevationTokens.h"
#include <memory>
#include <vector>
#include <string>
@ -55,6 +57,10 @@ public:
void setBackground(Theme::Sys::Color token);
void setBackgroundTone(Theme::Sys::Color token);
void setElevation(Theme::Sys::Elevation elevation);
void setOutlineThickness(double thickness);
void setOutline(Theme::Sys::Color token);
@ -102,7 +108,9 @@ protected:
Theme::Sys::Color mBorder;
double mBorderThickness{0};
Theme::Sys::Color mBackgroundTone;
Theme::Sys::Color mBackground;
Theme::Sys::Elevation mElevation{ Theme::Sys::Elevation::Level_0 };
float mBackgroundOpacity{ 1.0 };
bool mVisible{true};