mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-27 17:50:04 +01:00
[escher] Clean TextView
This commit is contained in:
@@ -4,13 +4,20 @@
|
||||
#include <escher/view.h>
|
||||
#include <kandinsky/color.h>
|
||||
|
||||
/* alignment = 0 -> align left or top
|
||||
* alignment = 0.5 -> align center
|
||||
* alignment = 1.0 -> align right or bottom */
|
||||
|
||||
class TextView : public View {
|
||||
public:
|
||||
// alignment = 0 -> align left or top
|
||||
// alignment = 0.5 -> align center
|
||||
// alignment = 1.0 -> align right or bottom
|
||||
TextView(const KDFont * font = KDFont::LargeFont, float horizontalAlignment = 0.0f, float verticalAlignment = 0.0f,
|
||||
KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite);
|
||||
TextView(const KDFont * font = KDFont::LargeFont, float horizontalAlignment = 0.0f, float verticalAlignment = 0.0f, KDColor textColor = KDColorBlack, KDColor backgroundColor = KDColorWhite) :
|
||||
View(),
|
||||
m_font(font),
|
||||
m_horizontalAlignment(horizontalAlignment),
|
||||
m_verticalAlignment(verticalAlignment),
|
||||
m_textColor(textColor),
|
||||
m_backgroundColor(backgroundColor)
|
||||
{}
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
void setBackgroundColor(KDColor backgroundColor);
|
||||
void setTextColor(KDColor textColor);
|
||||
@@ -22,7 +29,7 @@ public:
|
||||
void setFont(const KDFont * font);
|
||||
protected:
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * className() const override;
|
||||
const char * className() const override { return "TextView"; }
|
||||
#endif
|
||||
const KDFont * m_font;
|
||||
float m_horizontalAlignment;
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
#include <escher/text_view.h>
|
||||
|
||||
TextView::TextView(const KDFont * font, float horizontalAlignment, float verticalAlignment,
|
||||
KDColor textColor, KDColor backgroundColor) :
|
||||
View(),
|
||||
m_font(font),
|
||||
m_horizontalAlignment(horizontalAlignment),
|
||||
m_verticalAlignment(verticalAlignment),
|
||||
m_textColor(textColor),
|
||||
m_backgroundColor(backgroundColor)
|
||||
{
|
||||
}
|
||||
|
||||
void TextView::setBackgroundColor(KDColor backgroundColor) {
|
||||
m_backgroundColor = backgroundColor;
|
||||
markRectAsDirty(bounds());
|
||||
@@ -44,14 +33,9 @@ void TextView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
return;
|
||||
}
|
||||
KDSize textSize = m_font->stringSize(text());
|
||||
KDPoint origin(m_horizontalAlignment*(m_frame.width() - textSize.width()),
|
||||
m_verticalAlignment*(m_frame.height() - textSize.height()));
|
||||
KDPoint origin(
|
||||
m_horizontalAlignment * (m_frame.width() - textSize.width()),
|
||||
m_verticalAlignment * (m_frame.height() - textSize.height()));
|
||||
ctx->fillRect(bounds(), m_backgroundColor);
|
||||
ctx->drawString(text(), origin, m_font, m_textColor, m_backgroundColor);
|
||||
}
|
||||
|
||||
#if ESCHER_VIEW_LOGGING
|
||||
const char * TextView::className() const {
|
||||
return "TextView";
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user