[apps] Probability: fix bug in layout (the textfield was moving when

adding characters)
This commit is contained in:
Émilie Feral
2018-01-03 14:03:30 +01:00
committed by EmilieNumworks
parent fd06d428e5
commit 26bbfa85ec
4 changed files with 7 additions and 6 deletions

View File

@@ -30,14 +30,14 @@ void CalculationCell::setHighlighted(bool highlight) {
KDSize CalculationCell::minimalSizeForOptimalDisplay() const {
KDSize textSize = m_text.minimalSizeForOptimalDisplay();
return KDSize(2*k_margin+textSize.width()+calculationCellWidth()+ResponderImageCell::k_outline, KDText::charSize().height());
return KDSize(2*k_margin+textSize.width()+calculationCellWidth()+2*ResponderImageCell::k_outline, KDText::charSize().height());
}
void CalculationCell::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), KDColorWhite);
if (m_isResponder) {
KDSize textSize = m_text.minimalSizeForOptimalDisplay();
ctx->strokeRect(KDRect(2*k_margin+textSize.width()-ResponderImageCell::k_outline, ResponderImageCell::k_margin, calculationCellWidth()+2*ResponderImageCell::k_outline, ImageCell::k_height+2*ResponderImageCell::k_outline), Palette::GreyMiddle);
ctx->strokeRect(KDRect(2*k_margin+textSize.width(), 0, calculationCellWidth()+2*ResponderImageCell::k_outline, ImageCell::k_height+2*ResponderImageCell::k_outline), Palette::GreyMiddle);
}
}
@@ -64,7 +64,7 @@ View * CalculationCell::subviewAtIndex(int index) {
void CalculationCell::layoutSubviews() {
KDSize textSize = m_text.minimalSizeForOptimalDisplay();
m_text.setFrame(KDRect(k_margin, 0, textSize.width(), bounds().height()));
m_calculation.setFrame(KDRect(2*k_margin+textSize.width(), ResponderImageCell::k_totalMargin, calculationCellWidth(), ImageCell::k_height));
m_calculation.setFrame(KDRect(2*k_margin+textSize.width()+ResponderImageCell::k_outline, ResponderImageCell::k_outline, calculationCellWidth(), ImageCell::k_height));
}
KDCoordinate CalculationCell::calculationCellWidth() const {

View File

@@ -17,8 +17,8 @@ public:
MessageTextView * messageTextView();
private:
constexpr static KDCoordinate k_margin = 5;
constexpr static KDCoordinate k_minTextFieldWidth = 4*KDText::charSize().width();
constexpr static KDCoordinate k_maxTextFieldWidth = 10*KDText::charSize().width();
constexpr static KDCoordinate k_minTextFieldWidth = 4*KDText::charSize().width()+TextCursorView::k_width;
constexpr static KDCoordinate k_maxTextFieldWidth = 14*KDText::charSize().width()+TextCursorView::k_width;
int numberOfSubviews() const override;
View * subviewAtIndex(int index) override;
void layoutSubviews() override;

View File

@@ -8,6 +8,7 @@ public:
using View::View;
void drawRect(KDContext * ctx, KDRect rect) const override;
KDSize minimalSizeForOptimalDisplay() const override;
constexpr static KDCoordinate k_width = 1;
};
#endif

View File

@@ -6,6 +6,6 @@ void TextCursorView::drawRect(KDContext * ctx, KDRect rect) const {
}
KDSize TextCursorView::minimalSizeForOptimalDisplay() const {
return KDSize(1, 0);
return KDSize(k_width, 0);
}