Numworks Epsilon  1.4.1
Graphing Calculator Operating System
string_layout.cpp
Go to the documentation of this file.
1 #include <assert.h>
2 #include <stdlib.h>
3 #include "string_layout.h"
4 
5 namespace Poincare {
6 
7 StringLayout::StringLayout(const char * string, size_t length, KDText::FontSize fontSize) :
9  m_fontSize(fontSize)
10 {
11  m_string = new char[length+1];
12  memcpy(m_string, string, length);
13  m_string[length] = 0;
14  // Half height of the font.
15  m_baseline = (KDText::charSize(m_fontSize).height()+1)/2;
16 }
17 
19  delete[] m_string;
20 }
21 
23  return m_string;
24 }
25 
27  return nullptr;
28 }
29 
30 void StringLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
31  ctx->drawString(m_string, p, m_fontSize, expressionColor, backgroundColor);
32 }
33 
35  assert(false); // We should never be here
36  return KDPointZero;
37 }
38 
40  return KDText::stringSize(m_string, m_fontSize);
41 }
42 
43 }
#define assert(e)
Definition: assert.h:9
KDPoint drawString(const char *text, KDPoint p, KDText::FontSize size=KDText::FontSize::Large, KDColor textColor=KDColorBlack, KDColor backgroundColor=KDColorWhite, int maxLength=-1)
Definition: context_text.cpp:9
static KDSize stringSize(const char *text, FontSize size=FontSize::Large)
Definition: text.cpp:6
constexpr KDPoint KDPointZero
Definition: point.h:25
unsigned short uint16_t
Definition: stdint.h:5
Definition: point.h:6
Definition: size.h:6
ExpressionLayout * child(uint16_t index) override
KDSize computeSize() override
Definition: color.h:6
static constexpr KDSize charSize(FontSize size=FontSize::Large)
Definition: text.h:16
FontSize
Definition: text.h:10
StringLayout(const char *string, size_t length, KDText::FontSize fontSize=KDText::FontSize::Large)
void * memcpy(void *dst, const void *src, size_t n)
Definition: memcpy.c:3
void render(KDContext *ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override
KDPoint positionOfChild(ExpressionLayout *child) override
constexpr KDCoordinate height() const
Definition: size.h:11