Numworks Epsilon  1.4.1
Graphing Calculator Operating System
buffer_text_view.cpp
Go to the documentation of this file.
2 #include <string.h>
3 #include <assert.h>
4 
5 BufferTextView::BufferTextView(KDText::FontSize size, float horizontalAlignment, float verticalAlignment,
6  KDColor textColor, KDColor backgroundColor) :
7  TextView(size, horizontalAlignment, verticalAlignment, textColor, backgroundColor),
8  m_buffer()
9 {
10 }
11 
12 const char * BufferTextView::text() const {
13  return m_buffer;
14 }
15 
16 void BufferTextView::setText(const char * text) {
17  assert(strlen(text) < sizeof(m_buffer));
18  strlcpy(m_buffer, text, sizeof(m_buffer));
20 }
21 
22 void BufferTextView::appendText(const char * text) {
23  size_t previousTextLength = strlen(m_buffer);
24  size_t argTextLength = strlen(text);
25  if (previousTextLength + argTextLength + 1 < k_maxNumberOfChar) {
26  strlcpy(&m_buffer[previousTextLength], text, argTextLength + 1);
27  }
28 }
BufferTextView(KDText::FontSize size=KDText::FontSize::Large, float horizontalAlignment=0.5f, float verticalAlignment=0.5f, KDColor textColor=KDColorBlack, KDColor backgroundColor=KDColorWhite)
#define assert(e)
Definition: assert.h:9
void setText(const char *text) override
void appendText(const char *text)
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
size_t strlcpy(char *dst, const char *src, size_t len)
Definition: strlcpy.c:3
size_t strlen(const char *s)
Definition: strlen.c:3
const char * text() const override
Definition: color.h:6
FontSize
Definition: text.h:10
KDRect bounds() const
Definition: view.cpp:157