11 ButtonRowController::ContentView::ContentView(
ViewController * mainViewController,
ButtonRowDelegate * delegate, Position position, Style style, Size size) :
13 m_mainViewController(mainViewController),
22 int ButtonRowController::ContentView::numberOfButtons()
const {
23 return m_delegate->numberOfButtons(m_position);
26 Button * ButtonRowController::ContentView::buttonAtIndex(
int index)
const {
27 return m_delegate->buttonAtIndex(index, m_position);
30 int ButtonRowController::ContentView::numberOfSubviews()
const {
31 return numberOfButtons() + 1;
34 View * ButtonRowController::ContentView::subviewAtIndex(
int index) {
40 if (index == numberOfSubviews() - 1) {
41 return m_mainViewController->view();
43 return buttonAtIndex(index);
47 void ButtonRowController::ContentView::layoutSubviews() {
49 if (numberOfButtons() == 0) {
50 KDCoordinate margin = m_position == Position::Top ? 1 : 0;
51 KDRect mainViewFrame(0, margin, bounds().width(), bounds().height()-margin);
52 m_mainViewController->view()->setFrame(mainViewFrame);
56 if (m_style == Style::PlainWhite) {
57 rowHeight = k_plainStyleHeight;
59 rowHeight = m_size == Size::Small ? k_embossedStyleHeightSmall : k_embossedStyleHeightLarge;
61 KDCoordinate frameOrigin = m_position == Position::Top ? rowHeight+1 : 0;
62 KDRect mainViewFrame(0, frameOrigin, bounds().width(), bounds().height() - rowHeight - 1);
63 m_mainViewController->view()->setFrame(mainViewFrame);
66 int nbOfButtons = numberOfButtons();
70 if (m_style == Style::EmbossedGrey) {
72 for (
int i = 0; i < nbOfButtons; i++) {
73 Button * button = buttonAtIndex(i);
76 widthMargin =
std::round(((
float)(bounds().width() - totalButtonWidth))/((
float)(nbOfButtons+1)));
77 buttonHeightMargin = m_size == Size::Small ? k_embossedStyleHeightMarginSmall : k_embossedStyleHeightMarginLarge;
78 buttonHeight = rowHeight- 2*buttonHeightMargin;
80 KDCoordinate yOrigin = m_position == Position::Top ? buttonHeightMargin : bounds().height()-rowHeight+buttonHeightMargin;
81 int currentXOrigin = widthMargin;
82 for (
int i = 0; i < numberOfButtons(); i++) {
83 Button * button = buttonAtIndex(i);
85 KDRect buttonFrame(currentXOrigin, yOrigin, buttonWidth, buttonHeight);
87 currentXOrigin += buttonWidth + widthMargin;
91 void ButtonRowController::ContentView::drawRect(
KDContext * ctx,
KDRect rect)
const {
92 if (numberOfButtons() == 0) {
93 if (m_position == Position::Top) {
98 if (m_style == Style::PlainWhite) {
99 if (m_position == Position::Top) {
108 int buttonHeight = m_size == Size::Small ? k_embossedStyleHeightSmall : k_embossedStyleHeightLarge;
109 int buttonMargin = m_size == Size::Small ? k_embossedStyleHeightMarginSmall : k_embossedStyleHeightMarginLarge;
110 if (m_position == Position::Top) {
117 KDCoordinate y0 = m_position == Position::Top ? buttonMargin-1 : bounds().height()-buttonHeight+buttonMargin-1;
118 KDCoordinate y1 = m_position == Position::Top ? buttonHeight-buttonMargin-2 : bounds().height()-buttonMargin;
120 for (
int i = 0; i < numberOfButtons(); i++) {
121 Button * button = buttonAtIndex(i);
124 KDCoordinate widthMargin =
std::round(((
float)(bounds().width() - totalButtonWidth))/((
float)(numberOfButtons()+1)));
126 int currentXOrigin = widthMargin-1;
127 for (
int i = 0; i < numberOfButtons(); i++) {
128 Button * button = buttonAtIndex(i);
136 currentXOrigin += buttonWidth + widthMargin;
140 bool ButtonRowController::ContentView::setSelectedButton(
int selectedButton,
App * application) {
141 if (selectedButton < -1 || selectedButton >= numberOfButtons() || selectedButton == m_selectedButton) {
144 if (m_selectedButton >= 0) {
145 Button * button = buttonAtIndex(m_selectedButton);
148 m_selectedButton = selectedButton;
149 if (m_selectedButton >= 0) {
150 Button * button = buttonAtIndex(selectedButton);
160 m_contentView(mainViewController, delegate, position, style, size)
165 return m_contentView.mainViewController()->title();
173 return m_contentView.selectedButton();
177 App * application =
app();
178 return m_contentView.setSelectedButton(
selectedButton, application);
183 if (m_contentView.selectedButton() == 0) {
190 if (m_contentView.selectedButton() == - 1) {
205 m_contentView.layoutSubviews();
206 m_contentView.mainViewController()->viewWillAppear();
210 m_contentView.mainViewController()->viewDidDisappear();
void setFrame(KDRect frame)
constexpr KDCoordinate width() const
static constexpr KDColor GreyDark
constexpr KDColor KDColorWhite
static constexpr KDColor GreyMiddle
void fillRect(KDRect rect, KDColor color)
void setFirstResponder(Responder *responder)
static constexpr KDColor GreyWhite