[escher] Improve rendering of input view controller

Change-Id: I3d92fdc5bba7ec21dfb4d2c15e5827f29b2e57a8
This commit is contained in:
Émilie Feral
2017-03-16 10:47:12 +01:00
parent 0716307b36
commit 9d7284e2e2
2 changed files with 62 additions and 11 deletions

View File

@@ -1,26 +1,62 @@
#include <escher/input_view_controller.h>
#include <escher/app.h>
#include <escher/palette.h>
#include <assert.h>
InputViewController::TextFieldController::TextFieldController(Responder * parentResponder, TextFieldDelegate * textFieldDelegate) :
ViewController(parentResponder),
m_textField(parentResponder, m_textBody, m_textBody, 255, textFieldDelegate)
InputViewController::TextFieldController::ContentView::ContentView(Responder * parentResponder, TextFieldDelegate * textFieldDelegate) :
Responder(parentResponder),
View(),
m_textField(this, m_textBody, m_textBody, 255, textFieldDelegate)
{
m_textBody[0] = 0;
}
View * InputViewController::TextFieldController::view() {
return &m_textField;
}
void InputViewController::TextFieldController::didBecomeFirstResponder() {
void InputViewController::TextFieldController::ContentView::didBecomeFirstResponder() {
app()->setFirstResponder(&m_textField);
}
TextField * InputViewController::TextFieldController::textField() {
TextField * InputViewController::TextFieldController::ContentView::textField() {
return &m_textField;
}
void InputViewController::TextFieldController::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(KDRect(0, 0, bounds().width(), k_separatorThickness), Palette::GreyMiddle);
}
KDSize InputViewController::TextFieldController::ContentView::minimalSizeForOptimalDisplay() const {
return KDSize(0, k_inputHeight);
}
int InputViewController::TextFieldController::ContentView::numberOfSubviews() const {
return 1;
}
View * InputViewController::TextFieldController::ContentView::subviewAtIndex(int index) {
return &m_textField;
}
void InputViewController::TextFieldController::ContentView::layoutSubviews() {
m_textField.setFrame(KDRect(0, k_separatorThickness, bounds().width(), bounds().height()));
}
InputViewController::TextFieldController::TextFieldController(Responder * parentResponder, TextFieldDelegate * textFieldDelegate) :
ViewController(parentResponder),
m_view(this, textFieldDelegate)
{
}
View * InputViewController::TextFieldController::view() {
return &m_view;
}
void InputViewController::TextFieldController::didBecomeFirstResponder() {
app()->setFirstResponder(&m_view);
}
TextField * InputViewController::TextFieldController::textField() {
return m_view.textField();
}
InputViewController::InputViewController(Responder * parentResponder, ViewController * child, TextFieldDelegate * textFieldDelegate) :
ModalViewController(parentResponder, child),
m_textFieldController(TextFieldController(this, this)),