mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-22 23:30:37 +01:00
51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
#include <escher/expression_view.h>
|
|
|
|
ExpressionView::ExpressionView(float horizontalAlignment, float verticalAlignment,
|
|
KDColor textColor, KDColor backgroundColor) :
|
|
m_expressionLayout(nullptr),
|
|
m_horizontalAlignment(horizontalAlignment),
|
|
m_verticalAlignment(verticalAlignment),
|
|
m_textColor(textColor),
|
|
m_backgroundColor(backgroundColor)
|
|
{
|
|
}
|
|
|
|
void ExpressionView::setExpression(ExpressionLayout * expressionLayout) {
|
|
m_expressionLayout = expressionLayout;
|
|
markRectAsDirty(bounds());
|
|
}
|
|
|
|
void ExpressionView::setBackgroundColor(KDColor backgroundColor) {
|
|
m_backgroundColor = backgroundColor;
|
|
markRectAsDirty(bounds());
|
|
}
|
|
|
|
void ExpressionView::setTextColor(KDColor textColor) {
|
|
m_textColor = textColor;
|
|
markRectAsDirty(bounds());
|
|
}
|
|
|
|
void ExpressionView::setAlignment(float horizontalAlignment, float verticalAlignment) {
|
|
m_horizontalAlignment = horizontalAlignment;
|
|
m_verticalAlignment = verticalAlignment;
|
|
markRectAsDirty(bounds());
|
|
}
|
|
|
|
KDSize ExpressionView::minimalSizeForOptimalDisplay() {
|
|
if (m_expressionLayout == nullptr) {
|
|
return KDSizeZero;
|
|
}
|
|
return m_expressionLayout->size();
|
|
}
|
|
|
|
void ExpressionView::drawRect(KDContext * ctx, KDRect rect) const {
|
|
ctx->fillRect(rect, m_backgroundColor);
|
|
if (m_expressionLayout != nullptr) {
|
|
//Position the origin of expression
|
|
KDSize expressionSize = m_expressionLayout->size();
|
|
KDPoint origin(m_horizontalAlignment*(m_frame.width() - expressionSize.width()),
|
|
0.5f*(m_frame.height() - expressionSize.height()));
|
|
m_expressionLayout->draw(ctx, origin, m_textColor, m_backgroundColor);
|
|
}
|
|
}
|