Numworks Epsilon  1.4.1
Graphing Calculator Operating System
text_view.cpp
Go to the documentation of this file.
1 #include <escher/text_view.h>
2 
3 TextView::TextView(KDText::FontSize size, float horizontalAlignment, float verticalAlignment,
4  KDColor textColor, KDColor backgroundColor) :
5  View(),
6  m_fontSize(size),
7  m_horizontalAlignment(horizontalAlignment),
8  m_verticalAlignment(verticalAlignment),
9  m_textColor(textColor),
10  m_backgroundColor(backgroundColor)
11 {
12 }
13 
14 void TextView::setBackgroundColor(KDColor backgroundColor) {
15  m_backgroundColor = backgroundColor;
17 }
18 
20  m_textColor = textColor;
22 }
23 
24 void TextView::setAlignment(float horizontalAlignment, float verticalAlignment) {
25  m_horizontalAlignment = horizontalAlignment;
26  m_verticalAlignment = verticalAlignment;
28 }
29 
31  m_fontSize = fontSize;
33 }
34 
37 }
38 
39 void TextView::drawRect(KDContext * ctx, KDRect rect) const {
40  if (text() == nullptr) {
41  return;
42  }
44  KDPoint origin(m_horizontalAlignment*(m_frame.width() - textSize.width()),
45  m_verticalAlignment*(m_frame.height() - textSize.height()));
46  ctx->fillRect(bounds(), m_backgroundColor);
47  ctx->drawString(text(), origin, m_fontSize, m_textColor, m_backgroundColor);
48 }
49 
50 #if ESCHER_VIEW_LOGGING
51 const char * TextView::className() const {
52  return "TextView";
53 }
54 #endif
KDText::FontSize m_fontSize
Definition: text_view.h:26
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
constexpr KDCoordinate width() const
Definition: size.h:10
static KDSize stringSize(const char *text, FontSize size=FontSize::Large)
Definition: text.cpp:6
void markRectAsDirty(KDRect rect)
Definition: view.cpp:39
TextView(KDText::FontSize size=KDText::FontSize::Large, float horizontalAlignment=0.0f, float verticalAlignment=0.0f, KDColor textColor=KDColorBlack, KDColor backgroundColor=KDColorWhite)
Definition: text_view.cpp:3
Definition: point.h:6
Definition: size.h:6
KDRect m_frame
Definition: view.h:66
void drawRect(KDContext *ctx, KDRect rect) const override
Definition: text_view.cpp:39
virtual const char * text() const =0
Definition: rect.h:26
void fillRect(KDRect rect, KDColor color)
Definition: context_rect.cpp:8
Definition: color.h:6
Definition: view.h:23
void setAlignment(float horizontalAlignment, float verticalAlignment)
Definition: text_view.cpp:24
KDCoordinate width() const
Definition: rect.h:39
void setTextColor(KDColor textColor)
Definition: text_view.cpp:19
void setFontSize(KDText::FontSize fontSize)
Definition: text_view.cpp:30
void setBackgroundColor(KDColor backgroundColor)
Definition: text_view.cpp:14
FontSize
Definition: text.h:10
KDCoordinate height() const
Definition: rect.h:40
KDRect bounds() const
Definition: view.cpp:157
KDSize minimalSizeForOptimalDisplay() const override
Definition: text_view.cpp:35
constexpr KDCoordinate height() const
Definition: size.h:11