From c28f7bc6c72009ff163de0a553cda73150fca71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 13 Oct 2016 09:53:06 +0200 Subject: [PATCH] [escher] Implement minimlSizeForOptimalDisplay in text view and button Change-Id: I86cbc1cc9314623a1deb69f2dd36ac8c45338d92 --- escher/include/escher/button.h | 4 +++- escher/include/escher/header_view_controller.h | 1 - escher/include/escher/text_view.h | 2 +- escher/src/button.cpp | 5 +++-- escher/src/header_view_controller.cpp | 12 ++++++------ escher/src/text_view.cpp | 4 ++-- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/escher/include/escher/button.h b/escher/include/escher/button.h index 3564f32e3..7c3e31ed0 100644 --- a/escher/include/escher/button.h +++ b/escher/include/escher/button.h @@ -14,8 +14,10 @@ public: void setText(const char * textBody); void setInvocation(Invocation invocation); void setBackgroundColor(KDColor backgroundColor); - KDSize textSize(); + KDSize minimalSizeForOptimalDisplay() override; private: + constexpr static KDCoordinate k_verticalMargin = 5; + constexpr static KDCoordinate k_horizontalMargin = 10; int numberOfSubviews() const override; View * subviewAtIndex(int index) override; void layoutSubviews() override; diff --git a/escher/include/escher/header_view_controller.h b/escher/include/escher/header_view_controller.h index 669849908..f9057c85a 100644 --- a/escher/include/escher/header_view_controller.h +++ b/escher/include/escher/header_view_controller.h @@ -33,7 +33,6 @@ private: int selectedButton(); private: constexpr static KDCoordinate k_headerHeight = 20; - constexpr static KDCoordinate k_buttonTextMargin = 10; constexpr static KDColor k_separatorHeaderColor = KDColor(0xDEE0E2); constexpr static KDColor k_selectedBackgroundColor = KDColor(0x426DA7);; Button m_buttonOne; diff --git a/escher/include/escher/text_view.h b/escher/include/escher/text_view.h index 57c6e2488..b3df3ea44 100644 --- a/escher/include/escher/text_view.h +++ b/escher/include/escher/text_view.h @@ -18,7 +18,7 @@ public: void setBackgroundColor(KDColor backgroundColor); void setTextColor(KDColor textColor); void setAlignment(float horizontalAlignment, float verticalAlignment); - KDSize textSize(); + KDSize minimalSizeForOptimalDisplay() override; protected: #if ESCHER_VIEW_LOGGING const char * className() const override; diff --git a/escher/src/button.cpp b/escher/src/button.cpp index 123560892..3f3e45278 100644 --- a/escher/src/button.cpp +++ b/escher/src/button.cpp @@ -53,6 +53,7 @@ void Button::setBackgroundColor(KDColor backgroundColor) { markRectAsDirty(bounds()); } -KDSize Button::textSize() { - return m_textView.textSize(); +KDSize Button::minimalSizeForOptimalDisplay() { + KDSize textSize = m_textView.minimalSizeForOptimalDisplay(); + return KDSize(textSize.width() + k_horizontalMargin, textSize.height() + k_verticalMargin); } diff --git a/escher/src/header_view_controller.cpp b/escher/src/header_view_controller.cpp index 863589ed0..a74d0968a 100644 --- a/escher/src/header_view_controller.cpp +++ b/escher/src/header_view_controller.cpp @@ -45,12 +45,12 @@ void HeaderViewController::ContentView::layoutSubviews() { m_mainView->setFrame(mainViewFrame); } else { KDRect mainViewFrame(0, k_headerHeight + 1, bounds().width(), bounds().height() - k_headerHeight - 1); - KDCoordinate buttonOneWidth = m_buttonOne.textSize().width(); - KDCoordinate buttonTwoWidth = m_buttonTwo.textSize().width(); - KDCoordinate buttonThreeWidth = m_buttonThree.textSize().width(); - KDRect buttonOneFrame(0, 0, buttonOneWidth + k_buttonTextMargin, k_headerHeight); - KDRect buttonTwoFrame(buttonOneWidth + k_buttonTextMargin, 0, buttonTwoWidth + k_buttonTextMargin, k_headerHeight); - KDRect buttonThreeFrame(buttonOneWidth + buttonTwoWidth + 2*k_buttonTextMargin, 0, buttonThreeWidth + k_buttonTextMargin, k_headerHeight); + KDCoordinate buttonOneWidth = m_buttonOne.minimalSizeForOptimalDisplay().width(); + KDCoordinate buttonTwoWidth = m_buttonTwo.minimalSizeForOptimalDisplay().width(); + KDCoordinate buttonThreeWidth = m_buttonThree.minimalSizeForOptimalDisplay().width(); + KDRect buttonOneFrame(0, 0, buttonOneWidth, k_headerHeight); + KDRect buttonTwoFrame(buttonOneWidth, 0, buttonTwoWidth, k_headerHeight); + KDRect buttonThreeFrame(buttonOneWidth + buttonTwoWidth, 0, buttonThreeWidth, k_headerHeight); switch(m_numberOfButtons) { case 3: m_buttonThree.setFrame(buttonThreeFrame); diff --git a/escher/src/text_view.cpp b/escher/src/text_view.cpp index 4b3d68b37..836f5cb67 100644 --- a/escher/src/text_view.cpp +++ b/escher/src/text_view.cpp @@ -36,8 +36,8 @@ void TextView::setAlignment(float horizontalAlignment, float verticalAlignment) markRectAsDirty(bounds()); } -KDSize TextView::textSize() { - if (m_text == nullptr) { +KDSize TextView::minimalSizeForOptimalDisplay() { + if (m_text == nullptr) { return KDSizeZero; } else { return KDText::stringSize(m_text);