mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/calculation] ExpressionWithEqualSignView inherits from
ExpressionView instead of composing This is useful for future change on ScrollableExactApproximateExpressionView
This commit is contained in:
@@ -3,24 +3,30 @@
|
||||
namespace Calculation {
|
||||
|
||||
KDSize ExpressionWithEqualSignView::minimalSizeForOptimalDisplay() const {
|
||||
KDSize expressionSize = m_expressionView.minimalSizeForOptimalDisplay();
|
||||
KDSize expressionSize = ExpressionView::minimalSizeForOptimalDisplay();
|
||||
KDSize equalSize = m_equalSign.minimalSizeForOptimalDisplay();
|
||||
return KDSize(expressionSize.width() + equalSize.width() + Metric::CommonLargeMargin, expressionSize.height());
|
||||
}
|
||||
|
||||
View * ExpressionWithEqualSignView::subviewAtIndex(int index) {
|
||||
if (index == 0) {
|
||||
return &m_expressionView;
|
||||
void ExpressionWithEqualSignView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
if (m_layout.isUninitialized()) {
|
||||
return;
|
||||
}
|
||||
assert(index == 1);
|
||||
// Do not color the whole background to avoid coloring behind the equal symbol
|
||||
KDSize expressionSize = ExpressionView::minimalSizeForOptimalDisplay();
|
||||
ctx->fillRect(KDRect(0, 0, expressionSize), m_backgroundColor);
|
||||
m_layout.draw(ctx, drawingOrigin(), m_textColor, m_backgroundColor, m_selectionStart, m_selectionEnd, Palette::Select);
|
||||
}
|
||||
|
||||
View * ExpressionWithEqualSignView::subviewAtIndex(int index) {
|
||||
assert(index == 0);
|
||||
return &m_equalSign;
|
||||
}
|
||||
|
||||
void ExpressionWithEqualSignView::layoutSubviews(bool force) {
|
||||
KDSize expressionSize = m_expressionView.minimalSizeForOptimalDisplay();
|
||||
KDSize expressionSize = ExpressionView::minimalSizeForOptimalDisplay();
|
||||
KDSize equalSize = m_equalSign.minimalSizeForOptimalDisplay();
|
||||
KDCoordinate expressionBaseline = m_expressionView.layout().baseline();
|
||||
m_expressionView.setFrame(KDRect(0, 0, expressionSize), force);
|
||||
KDCoordinate expressionBaseline = layout().baseline();
|
||||
m_equalSign.setFrame(KDRect(expressionSize.width() + Metric::CommonLargeMargin, expressionBaseline - equalSize.height()/2, equalSize), force);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,22 +7,17 @@
|
||||
|
||||
namespace Calculation {
|
||||
|
||||
class ExpressionWithEqualSignView : public View {
|
||||
class ExpressionWithEqualSignView : public ExpressionView {
|
||||
public:
|
||||
ExpressionWithEqualSignView() :
|
||||
m_expressionView(),
|
||||
m_equalSign(KDFont::LargeFont, I18n::Message::Equal, 0.5f, 0.5f, KDColorBlack)
|
||||
{}
|
||||
ExpressionView * expressionView() { return &m_expressionView; }
|
||||
KDSize minimalSizeForOptimalDisplay() const override;
|
||||
void setBackgroundColor(KDColor color) { m_expressionView.setBackgroundColor(color); }
|
||||
Poincare::Layout layout() const { return m_expressionView.layout(); }
|
||||
bool setLayout(Poincare::Layout layout) { return m_expressionView.setLayout(layout); }
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews(bool force = false) override;
|
||||
int numberOfSubviews() const override { return 2; }
|
||||
ExpressionView m_expressionView;
|
||||
int numberOfSubviews() const override { return 1; }
|
||||
MessageTextView m_equalSign;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,19 +26,20 @@ public:
|
||||
KDSize minimalSizeForOptimalDisplay() const override;
|
||||
KDPoint drawingOrigin() const;
|
||||
KDPoint absoluteDrawingOrigin() const;
|
||||
private:
|
||||
protected:
|
||||
/* Warning: we do not need to delete the previous expression layout when
|
||||
* deleting object or setting a new expression layout. Indeed, the expression
|
||||
* layout is always possessed by a controller which only gives a pointer to
|
||||
* the expression view (without cloning it). The named controller is then
|
||||
* responsible for freeing the expression layout when required. */
|
||||
mutable Poincare::Layout m_layout; // TODO find better way to have minimalSizeForOptimalDisplay const
|
||||
Poincare::Layout * m_selectionStart;
|
||||
Poincare::Layout * m_selectionEnd;
|
||||
float m_horizontalAlignment;
|
||||
float m_verticalAlignment;
|
||||
KDColor m_textColor;
|
||||
KDColor m_backgroundColor;
|
||||
Poincare::Layout * m_selectionStart;
|
||||
Poincare::Layout * m_selectionEnd;
|
||||
private:
|
||||
float m_horizontalAlignment;
|
||||
float m_verticalAlignment;
|
||||
KDCoordinate m_horizontalMargin;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@ static inline KDCoordinate maxCoordinate(KDCoordinate x, KDCoordinate y) { retur
|
||||
ExpressionView::ExpressionView(float horizontalAlignment, float verticalAlignment,
|
||||
KDColor textColor, KDColor backgroundColor, Poincare::Layout * selectionStart, Poincare::Layout * selectionEnd ) :
|
||||
m_layout(),
|
||||
m_textColor(textColor),
|
||||
m_backgroundColor(backgroundColor),
|
||||
m_selectionStart(selectionStart),
|
||||
m_selectionEnd(selectionEnd),
|
||||
m_horizontalAlignment(horizontalAlignment),
|
||||
m_verticalAlignment(verticalAlignment),
|
||||
m_textColor(textColor),
|
||||
m_backgroundColor(backgroundColor),
|
||||
m_horizontalMargin(0)
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user