mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 01:29:58 +01:00
[poincare] In string layout, add a instance variable to decide the font
size Change-Id: I2ef41531209e21db1e5d22dcf8c846e2a0e8fba7
This commit is contained in:
@@ -2,13 +2,15 @@
|
||||
#include <stdlib.h>
|
||||
#include "string_layout.h"
|
||||
|
||||
StringLayout::StringLayout(const char * string, size_t length) :
|
||||
ExpressionLayout() {
|
||||
StringLayout::StringLayout(const char * string, size_t length, KDText::FontSize fontSize) :
|
||||
ExpressionLayout(),
|
||||
m_fontSize(fontSize)
|
||||
{
|
||||
m_string = (char *)malloc(sizeof(char)*(length+1));
|
||||
memcpy(m_string, string, length);
|
||||
m_string[length] = 0;
|
||||
// Height of the font.
|
||||
m_baseline = KDText::stringSize(" ", KDText::FontSize::Large).height();
|
||||
m_baseline = KDText::stringSize(" ", m_fontSize).height();
|
||||
}
|
||||
|
||||
StringLayout::~StringLayout() {
|
||||
@@ -20,7 +22,7 @@ ExpressionLayout * StringLayout::child(uint16_t index) {
|
||||
}
|
||||
|
||||
void StringLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
|
||||
ctx->drawString(m_string, KDText::FontSize::Large, p, expressionColor, backgroundColor);
|
||||
ctx->drawString(m_string, m_fontSize, p, expressionColor, backgroundColor);
|
||||
}
|
||||
|
||||
KDPoint StringLayout::positionOfChild(ExpressionLayout * child) {
|
||||
@@ -29,5 +31,5 @@ KDPoint StringLayout::positionOfChild(ExpressionLayout * child) {
|
||||
}
|
||||
|
||||
KDSize StringLayout::computeSize() {
|
||||
return KDText::stringSize(m_string, KDText::FontSize::Large);
|
||||
return KDText::stringSize(m_string, m_fontSize);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class StringLayout : public ExpressionLayout {
|
||||
// Here the inverse is a uint8_t instead of a bool, because the size of a bool is
|
||||
// not standardized, thus since we call a foreign C function with this value we want to be
|
||||
// sure about compatibility.
|
||||
StringLayout(const char * string, size_t length);
|
||||
StringLayout(const char * string, size_t length, KDText::FontSize fontSize = KDText::FontSize::Large);
|
||||
~StringLayout();
|
||||
protected:
|
||||
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
|
||||
@@ -18,6 +18,7 @@ class StringLayout : public ExpressionLayout {
|
||||
KDPoint positionOfChild(ExpressionLayout * child) override;
|
||||
private:
|
||||
char * m_string;
|
||||
KDText::FontSize m_fontSize;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user