[apps/shared] Improve validate button rendering in float parameter

controllers

Change-Id: I58ccc4da68c83509fe734038781b971d2a8f74c6
This commit is contained in:
Émilie Feral
2017-03-13 10:15:19 +01:00
parent e7abdbe2e3
commit 9aa516fe5d
6 changed files with 54 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
app_objs += $(addprefix apps/shared/,\
banner_view.o\
button_with_separator.o\
cursor_view.o\
curve_view.o\
curve_view_cursor.o\

View File

@@ -0,0 +1,27 @@
#include "button_with_separator.h"
ButtonWithSeparator::ButtonWithSeparator(Responder * parentResponder, const char * textBody, Invocation invocation) :
Button(parentResponder, textBody, invocation, KDText::FontSize::Large, KDColorBlack)
{
}
void ButtonWithSeparator::drawRect(KDContext * ctx, KDRect rect) const {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
ctx->fillRect(KDRect(0, 0, width, k_margin), Palette::WallScreen);
// Draw rectangle around cell
ctx->fillRect(KDRect(0, k_margin, width, k_lineThickness), Palette::GreyBright);
ctx->fillRect(KDRect(0, k_margin+k_lineThickness, k_lineThickness, height-k_margin), Palette::GreyBright);
ctx->fillRect(KDRect(width-k_lineThickness, k_lineThickness+k_margin, k_lineThickness, height-k_margin), Palette::GreyBright);
ctx->fillRect(KDRect(0, height-3*k_lineThickness, width, k_lineThickness), Palette::GreyWhite);
ctx->fillRect(KDRect(0, height-2*k_lineThickness, width, k_lineThickness), Palette::GreyBright);
ctx->fillRect(KDRect(k_lineThickness, height-k_lineThickness, width-2*k_lineThickness, k_lineThickness), Palette::GreyMiddle);
}
void ButtonWithSeparator::layoutSubviews() {
KDCoordinate width = bounds().width();
KDCoordinate height = bounds().height();
m_pointerTextView.setFrame(KDRect(k_lineThickness, k_margin + k_lineThickness, width-2*k_lineThickness, height - 4*k_lineThickness-k_margin));
}

View File

@@ -0,0 +1,16 @@
#ifndef SHARED_BUTTON_WITH_SEPARATOR_H
#define SHARED_BUTTON_WITH_SEPARATOR_H
#include <escher.h>
class ButtonWithSeparator : public Button {
public:
ButtonWithSeparator(Responder * parentResponder, const char * textBody, Invocation invocation);
void drawRect(KDContext * ctx, KDRect rect) const override;
private:
constexpr static KDCoordinate k_margin = 5;
constexpr static KDCoordinate k_lineThickness = 1;
void layoutSubviews() override;
};
#endif

View File

@@ -12,10 +12,10 @@ FloatParameterController::FloatParameterController(Responder * parentResponder,
ViewController(parentResponder),
m_selectableTableView(SelectableTableView(this, this, Metric::CommonTopMargin, Metric::CommonRightMargin,
Metric::CommonBottomMargin, Metric::CommonLeftMargin, this)),
m_okButton(Button(&m_selectableTableView, okButtonText, Invocation([](void * context, void * sender) {
m_okButton(ButtonWithSeparator(&m_selectableTableView, okButtonText, Invocation([](void * context, void * sender) {
FloatParameterController * parameterController = (FloatParameterController *) context;
parameterController->buttonAction();
}, this), KDText::FontSize::Large))
}, this)))
{
}
@@ -72,6 +72,9 @@ KDCoordinate FloatParameterController::rowHeight(int j) {
}
KDCoordinate FloatParameterController::cumulatedHeightFromIndex(int j) {
if (j == numberOfRows()) {
return j*Metric::ParameterCellHeight+k_buttonMargin;
}
return Metric::ParameterCellHeight*j;
}

View File

@@ -3,6 +3,7 @@
#include <escher.h>
#include "text_field_delegate.h"
#include "button_with_separator.h"
namespace Shared {
@@ -32,7 +33,7 @@ protected:
StackViewController * stackController();
SelectableTableView m_selectableTableView;
private:
constexpr static int k_buttonMargin = 5;
constexpr static int k_buttonMargin = 6;
virtual void buttonAction();
virtual int reusableParameterCellCount(int type) = 0;
virtual HighlightCell * reusableParameterCell(int index, int type) = 0;
@@ -40,7 +41,7 @@ private:
virtual float previousParameterAtIndex(int index) = 0;
virtual float parameterAtIndex(int index) = 0;
virtual void setParameterAtIndex(int parameterIndex, float f) = 0;
Button m_okButton;
ButtonWithSeparator m_okButton;
};
}

View File

@@ -12,13 +12,14 @@ public:
bool handleEvent(Ion::Events::Event event) override;
void setHighlighted(bool highlight) override;
KDSize minimalSizeForOptimalDisplay() const override;
protected:
PointerTextView m_pointerTextView;
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;
PointerTextView m_pointerTextView;
Invocation m_invocation;
};