Files
Upsilon/escher/include/escher/input_view_controller.h
Émilie Feral 9d7284e2e2 [escher] Improve rendering of input view controller
Change-Id: I3d92fdc5bba7ec21dfb4d2c15e5827f29b2e57a8
2017-03-16 15:12:12 +01:00

52 lines
2.1 KiB
C++

#ifndef ESCHER_INPUT_VIEW_CONTROLLER_H
#define ESCHER_INPUT_VIEW_CONTROLLER_H
#include <escher/modal_view_controller.h>
#include <escher/invocation.h>
#include <escher/text_field.h>
#include <escher/text_field_delegate.h>
class InputViewController : public ModalViewController, TextFieldDelegate {
public:
InputViewController(Responder * parentResponder, ViewController * child, TextFieldDelegate * textFieldDelegate);
void edit(Responder * caller, Ion::Events::Event event, void * context, const char * initialText, Invocation::Action successAction, Invocation::Action failureAction);
const char * textBody();
void setTextFieldDelegate(TextFieldDelegate * textFieldDelegate);
bool textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) override;
bool textFieldDidFinishEditing(TextField * textField, const char * text) override;
bool textFieldDidAbortEditing(TextField * textField, const char * text) override;
Toolbox * toolboxForTextField(TextField * textFied) override;
private:
class TextFieldController : public ViewController {
public:
TextFieldController(Responder * parentResponder, TextFieldDelegate * textFieldDelegate);
void didBecomeFirstResponder() override;
View * view() override;
TextField * textField();
private:
class ContentView : public Responder, public View {
public:
ContentView(Responder * parentResponder, TextFieldDelegate * textFieldDelegate);
void didBecomeFirstResponder() override;
TextField * textField();
void drawRect(KDContext * ctx, KDRect rect) const override;
KDSize minimalSizeForOptimalDisplay() const override;
private:
View * subviewAtIndex(int index) override;
int numberOfSubviews() const override;
void layoutSubviews() override;
constexpr static int k_inputHeight = 37;
constexpr static int k_separatorThickness = 1;
TextField m_textField;
char m_textBody[255];
};
ContentView m_view;
};
TextFieldController m_textFieldController;
Invocation m_successAction;
Invocation m_failureAction;
TextFieldDelegate * m_textFieldDelegate;
};
#endif