mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-20 01:08:15 +01:00
[escher] merge label view and text view in text view
Change-Id: Ia2422af03ebb79ba7450a1c8d220933cdd7a4586
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#define ESCHER_TEXT_VIEW_H
|
||||
|
||||
#include <escher/childless_view.h>
|
||||
#include <kandinsky/color.h>
|
||||
|
||||
class TextView : public ChildlessView {
|
||||
public:
|
||||
@@ -10,10 +11,12 @@ public:
|
||||
// alignment = 0.5 -> align center
|
||||
// alignment = 1.0 -> align right or bottom
|
||||
TextView(const char * text,
|
||||
float horizontalAlignment,
|
||||
float verticalAlignment);
|
||||
float horizontalAlignment, float verticalAlignment,
|
||||
KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
void setText(const char * text);
|
||||
void setBackgroundColor(KDColor backgroundColor);
|
||||
void setTextColor(KDColor textColor);
|
||||
protected:
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * className() const override;
|
||||
@@ -22,6 +25,8 @@ private:
|
||||
const char * m_text;
|
||||
float m_horizontalAlignment;
|
||||
float m_verticalAlignment;
|
||||
KDColor m_textColor;
|
||||
KDColor m_backgroundColor;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
#include <escher/text_view.h>
|
||||
|
||||
TextView::TextView() : TextView(nullptr, 0.0f, 0.0f)
|
||||
TextView::TextView() : TextView(nullptr, 0.0f, 0.0f, KDColorBlack, KDColorWhite)
|
||||
{
|
||||
}
|
||||
|
||||
TextView::TextView(const char * text, float horizontalAlignment, float verticalAlignment) :
|
||||
TextView::TextView(const char * text, float horizontalAlignment, float verticalAlignment,
|
||||
KDColor textColor, KDColor backgroundColor) :
|
||||
ChildlessView(),
|
||||
m_text(text),
|
||||
m_horizontalAlignment(horizontalAlignment),
|
||||
m_verticalAlignment(verticalAlignment)
|
||||
m_verticalAlignment(verticalAlignment),
|
||||
m_textColor(textColor),
|
||||
m_backgroundColor(backgroundColor)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -16,13 +19,23 @@ void TextView::setText(const char * text) {
|
||||
m_text = text;
|
||||
}
|
||||
|
||||
void TextView::setBackgroundColor(KDColor backgroundColor) {
|
||||
m_backgroundColor = backgroundColor;
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
void TextView::setTextColor(KDColor textColor) {
|
||||
m_textColor = textColor;
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
void TextView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
KDSize textSize = KDText::stringSize(m_text);
|
||||
KDPoint origin = {
|
||||
(KDCoordinate)(m_horizontalAlignment*(m_frame.width() - textSize.width())),
|
||||
(KDCoordinate)(m_verticalAlignment*(m_frame.height() - textSize.height()))
|
||||
};
|
||||
ctx->drawString(m_text, origin, 0);
|
||||
ctx->drawString(m_text, origin, m_textColor, m_backgroundColor);
|
||||
}
|
||||
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
|
||||
Reference in New Issue
Block a user