[kandinsky] Replace KDText::stringSize(" ") by KDText::charSize()

Change-Id: Ie962d7784b54ff41431d21f64d9af0887a86f9b7
This commit is contained in:
Émilie Feral
2017-08-09 10:34:46 +02:00
parent cdee87527e
commit 5c4740913b
17 changed files with 32 additions and 27 deletions

View File

@@ -1,7 +1,7 @@
#include "exam_pop_up_controller.h"
#include "apps_container.h"
#include "i18n.h"
#include "global_preferences.h"
#include "apps_container.h"
#include <assert.h>
ExamPopUpController::ExamPopUpController() :
@@ -128,7 +128,7 @@ View * ExamPopUpController::ContentView::subviewAtIndex(int index) {
void ExamPopUpController::ContentView::layoutSubviews() {
KDCoordinate height = bounds().height();
KDCoordinate width = bounds().width();
KDCoordinate textHeight = KDText::stringSize(" ", KDText::FontSize::Small).height();
KDCoordinate textHeight = KDText::charSize(KDText::FontSize::Small).height();
m_warningTextView.setFrame(KDRect(0, k_topMargin, width, textHeight));
m_messageTextView1.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+textHeight, width, textHeight));
m_messageTextView2.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+2*textHeight, width, textHeight));

View File

@@ -35,7 +35,7 @@ KDCoordinate ListController::rowHeight(int j) {
return k_emptyRowHeight;
}
KDCoordinate functionSize = function->layout()->size().height();
return functionSize + k_emptyRowHeight - KDText::stringSize(" ").height();
return functionSize + k_emptyRowHeight - KDText::charSize().height();
}
void ListController::editExpression(Function * function, Ion::Events::Event event) {

View File

@@ -94,7 +94,7 @@ void BatteryTestController::ContentView::setColor(KDColor color) {
void BatteryTestController::ContentView::layoutSubviews() {
m_batteryStateView.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height/2));
KDSize textSize = KDText::stringSize(" ", KDText::FontSize::Small);
KDSize textSize = KDText::charSize(KDText::FontSize::Small);
m_batteryLevelView.setFrame(KDRect(0, Ion::Display::Height-2*textSize.height(), Ion::Display::Width, textSize.height()));
m_batteryChargingView.setFrame(KDRect(0, Ion::Display::Height-textSize.height(), Ion::Display::Width, textSize.height()));
}

View File

@@ -100,7 +100,7 @@ View * PopUpController::ContentView::subviewAtIndex(int index) {
void PopUpController::ContentView::layoutSubviews() {
KDCoordinate height = bounds().height();
KDCoordinate width = bounds().width();
KDCoordinate textHeight = KDText::stringSize(" ", KDText::FontSize::Small).height();
KDCoordinate textHeight = KDText::charSize(KDText::FontSize::Small).height();
m_warningTextView.setFrame(KDRect(0, k_topMargin, width, textHeight));
m_messageTextView1.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+textHeight, width, textHeight));
m_messageTextView2.setFrame(KDRect(0, k_topMargin+k_paragraphHeight+2*textHeight, width, textHeight));

View File

@@ -70,7 +70,7 @@ void UpdateController::ContentView::layoutSubviews() {
KDCoordinate height = bounds().height();
KDCoordinate width = bounds().width();
KDCoordinate titleHeight = m_titleTextView.minimalSizeForOptimalDisplay().height();
KDCoordinate textHeight = KDText::stringSize(" ", KDText::FontSize::Small).height();
KDCoordinate textHeight = KDText::charSize(KDText::FontSize::Small).height();
m_titleTextView.setFrame(KDRect(0, k_titleMargin, width, titleHeight));
m_messageTextView1.setFrame(KDRect(0, k_paragraphHeight, width, textHeight));
m_messageTextView2.setFrame(KDRect(0, k_paragraphHeight+textHeight, width, textHeight));

View File

@@ -72,9 +72,9 @@ void CalculationController::ContentView::willDisplayEditableCellAtIndex(int inde
void CalculationController::ContentView::layoutSubviews() {
markRectAsDirty(bounds());
KDCoordinate titleHeight = KDText::stringSize("", KDText::FontSize::Small).height()+k_titleHeightMargin;
KDCoordinate titleHeight = KDText::charSize(KDText::FontSize::Small).height()+k_titleHeightMargin;
m_titleView.setFrame(KDRect(0, 0, bounds().width(), titleHeight));
KDSize charSize = KDText::stringSize(" ");
KDSize charSize = KDText::charSize();
KDCoordinate xCoordinate = 0;
m_lawCurveView.setFrame(KDRect(0, titleHeight+ImageTableView::k_oneCellHeight, bounds().width(), bounds().height() - ImageTableView::k_oneCellHeight-titleHeight));
KDSize tableSize = m_imageTableView.minimalSizeForOptimalDisplay();
@@ -102,9 +102,9 @@ void CalculationController::ContentView::layoutSubviews() {
}
void CalculationController::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate titleHeight = KDText::stringSize("", KDText::FontSize::Small).height()+k_titleHeightMargin;
KDCoordinate titleHeight = KDText::charSize(KDText::FontSize::Small).height()+k_titleHeightMargin;
ctx->fillRect(KDRect(0,titleHeight, bounds().width(), ImageTableView::k_oneCellWidth), KDColorWhite);
KDSize charSize = KDText::stringSize(" ");
KDSize charSize = KDText::charSize();
int numberOfCharacters;
KDCoordinate xCoordinate = ImageTableView::k_oneCellWidth + k_textWidthMargin;
KDCoordinate textFieldWidth = k_largeTextFieldWidth;

View File

@@ -39,7 +39,7 @@ View * LawController::ContentView::subviewAtIndex(int index) {
}
void LawController::ContentView::layoutSubviews() {
KDCoordinate titleHeight = KDText::stringSize("", KDText::FontSize::Small).height()+k_titleMargin;
KDCoordinate titleHeight = KDText::charSize(KDText::FontSize::Small).height()+k_titleMargin;
m_titleView.setFrame(KDRect(0, 0, bounds().width(), titleHeight));
m_selectableTableView->setFrame(KDRect(0, titleHeight, bounds().width(), bounds().height()-titleHeight));
}

View File

@@ -51,11 +51,11 @@ View * ParametersController::ContentView::subviewAtIndex(int index) {
}
void ParametersController::ContentView::layoutSubviews() {
KDCoordinate titleHeight = KDText::stringSize("", KDText::FontSize::Small).height()+k_titleMargin;
KDCoordinate titleHeight = KDText::charSize(KDText::FontSize::Small).height()+k_titleMargin;
m_titleView.setFrame(KDRect(0, 0, bounds().width(), titleHeight));
KDCoordinate tableHeight = m_selectableTableView->size().height() + Metric::CommonTopMargin + Metric::CommonBottomMargin;
m_selectableTableView->setFrame(KDRect(0, titleHeight, bounds().width(), tableHeight));
KDCoordinate textHeight = KDText::stringSize("", KDText::FontSize::Small).height();
KDCoordinate textHeight = KDText::charSize(KDText::FontSize::Small).height();
KDCoordinate defOrigin = (titleHeight+tableHeight)/2+(bounds().height()-textHeight)/2;
m_secondParameterDefinition.setFrame(KDRectZero);
if (m_numberOfParameters == 2) {

View File

@@ -67,7 +67,7 @@ KDCoordinate ListController::rowHeight(int j) {
return defaultHeight;
}
KDCoordinate sequenceSize = layout->size().height();
return sequenceSize + defaultHeight - KDText::stringSize(" ").height();
return sequenceSize + defaultHeight - KDText::charSize().height();
}
void ListController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {

View File

@@ -22,7 +22,7 @@ void BannerView::setMessageAtIndex(I18n::Message text, int index) {
}
KDSize BannerView::minimalSizeForOptimalDisplay() const {
return KDSize(0, KDText::stringSize(" ", KDText::FontSize::Small).height()*numberOfLines());
return KDSize(0, KDText::charSize(KDText::FontSize::Small).height()*numberOfLines());
}
int BannerView::numberOfSubviews() const {

View File

@@ -120,7 +120,7 @@ TextArea::ContentView::ContentView(char * textBuffer, size_t textBufferSize, KDT
}
KDSize TextArea::ContentView::minimalSizeForOptimalDisplay() const {
KDSize charSize = KDText::stringSize(" ", m_fontSize);
KDSize charSize = KDText::charSize(m_fontSize);
Text::Position span = m_text.span();
return KDSize(
charSize.width() * span.column(),
@@ -132,7 +132,7 @@ KDSize TextArea::ContentView::minimalSizeForOptimalDisplay() const {
void TextArea::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(rect, m_backgroundColor);
KDSize charSize = KDText::stringSize(" ", m_fontSize);
KDSize charSize = KDText::charSize(m_fontSize);
// We want to draw even partially visible characters. So we need to round
// down for the top left corner and up for the bottom right one.
@@ -197,7 +197,7 @@ KDRect TextArea::TextArea::ContentView::cursorRect() {
}
KDRect TextArea::TextArea::ContentView::characterFrameAtIndex(size_t index) {
KDSize charSize = KDText::stringSize(" ", m_fontSize);
KDSize charSize = KDText::charSize(m_fontSize);
Text::Position p = m_text.positionAtIndex(index);
return KDRect(
p.column() * charSize.width(),

View File

@@ -160,12 +160,12 @@ KDSize TextField::ContentView::minimalSizeForOptimalDisplay() const {
}
KDCoordinate TextField::ContentView::textHeight() const {
KDSize textSize = KDText::stringSize(" ", m_fontSize);
KDSize textSize = KDText::charSize(m_fontSize);
return textSize.height();
}
KDCoordinate TextField::ContentView::charWidth() {
KDSize textSize = KDText::stringSize(" ", m_fontSize);
KDSize textSize = KDText::charSize(m_fontSize);
return textSize.width();
}

View File

@@ -10,6 +10,7 @@ public:
Large
};
static KDSize stringSize(const char * text, FontSize size = FontSize::Large);
static KDSize charSize(FontSize size = FontSize::Large);
};
#endif

View File

@@ -7,8 +7,12 @@ KDSize KDText::stringSize(const char * text, FontSize size) {
if (text == nullptr) {
return KDSizeZero;
}
if (size == FontSize::Large) {
return KDSize(BITMAP_LargeFont_CHARACTER_WIDTH*strlen(text), BITMAP_LargeFont_CHARACTER_HEIGHT);
}
return KDSize(BITMAP_SmallFont_CHARACTER_WIDTH*strlen(text), BITMAP_SmallFont_CHARACTER_HEIGHT);
KDSize cSize = charSize(size);
return KDSize(cSize.width()*strlen(text), cSize.height());
}
KDSize KDText::charSize(FontSize size) {
if (size == FontSize::Large) {
return KDSize(BITMAP_LargeFont_CHARACTER_WIDTH, BITMAP_LargeFont_CHARACTER_HEIGHT);
}
return KDSize(BITMAP_SmallFont_CHARACTER_WIDTH, BITMAP_SmallFont_CHARACTER_HEIGHT);}

View File

@@ -10,7 +10,7 @@ ExpressionLayout(), m_numerator_layout(numerator_layout), m_denominator_layout(d
m_denominator_layout->setParent(this);
m_baseline = m_numerator_layout->size().height()
+ k_fractionLineMargin
+ KDText::stringSize(" ").height()/2;
+ KDText::charSize().height()/2;
}
FractionLayout::~FractionLayout() {

View File

@@ -16,7 +16,7 @@ GridLayout::GridLayout(ExpressionLayout ** entryLayouts, int numberOfRows, int n
m_entryLayouts[i] = entryLayouts[i];
m_entryLayouts[i]->setParent(this);
}
m_baseline = height()/2 + KDText::stringSize(" ").height()/2;
m_baseline = height()/2 + KDText::charSize().height()/2;
}
GridLayout::~GridLayout() {

View File

@@ -12,7 +12,7 @@ StringLayout::StringLayout(const char * string, size_t length, KDText::FontSize
memcpy(m_string, string, length);
m_string[length] = 0;
// Height of the font.
m_baseline = KDText::stringSize(" ", m_fontSize).height();
m_baseline = KDText::charSize(m_fontSize).height();
}
StringLayout::~StringLayout() {