mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/stats] Display or not the formula input view
This commit is contained in:
@@ -9,6 +9,7 @@ BufferTextViewWithTextField::BufferTextViewWithTextField(Responder * parentRespo
|
||||
m_textField(this, m_textFieldBuffer, m_textFieldBuffer, k_textFieldBufferSize, delegate, false, size, 0.0f, 0.5f),
|
||||
m_textFieldBuffer{}
|
||||
{
|
||||
m_bufferTextView.setText("TODO");
|
||||
}
|
||||
|
||||
KDSize BufferTextViewWithTextField::minimalSizeForOptimalDisplay() const {
|
||||
@@ -21,6 +22,8 @@ void BufferTextViewWithTextField::setBufferText(const char * text) {
|
||||
|
||||
void BufferTextViewWithTextField::didBecomeFirstResponder() {
|
||||
app()->setFirstResponder(&m_textField);
|
||||
m_textField.setEditing(true, true);
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
|
||||
View * BufferTextViewWithTextField::subviewAtIndex(int index) {
|
||||
@@ -31,7 +34,7 @@ View * BufferTextViewWithTextField::subviewAtIndex(int index) {
|
||||
|
||||
void BufferTextViewWithTextField::layoutSubviews() {
|
||||
m_bufferTextView.setFrame(KDRect(0, 0, k_height, k_bufferTextWidth));
|
||||
m_textField.setFrame(KDRect(k_bufferTextWidth, 0, k_height, bounds().width() - k_bufferTextWidth));
|
||||
m_textField.setFrame(KDRect(k_bufferTextWidth, 0, bounds().width() - k_bufferTextWidth, k_height));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public:
|
||||
constexpr static KDCoordinate k_height = 50; //TODO
|
||||
BufferTextViewWithTextField(Responder * parentResponder, TextFieldDelegate * delegate = nullptr, KDText::FontSize size = KDText::FontSize::Large);
|
||||
KDSize minimalSizeForOptimalDisplay() const override;
|
||||
TextField * textField() { return &m_textField; }
|
||||
void setBufferText(const char * text);
|
||||
void setTextFieldText(const char * text);
|
||||
|
||||
@@ -16,7 +17,7 @@ public:
|
||||
void didBecomeFirstResponder() override;
|
||||
private:
|
||||
constexpr static int k_textFieldBufferSize = TextField::maxBufferSize();
|
||||
constexpr static KDCoordinate k_bufferTextWidth = 70; //TODO
|
||||
constexpr static KDCoordinate k_bufferTextWidth = 50; //TODO
|
||||
int numberOfSubviews() const override { return 2; }
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
|
||||
@@ -13,15 +13,23 @@ StoreController::ContentView::ContentView(FloatPairStore * store, Responder * pa
|
||||
Responder(parentResponder),
|
||||
m_dataView(store, this, dataSource, selectionDataSource),
|
||||
m_formulaInputView(this, textFieldDelegate),
|
||||
m_displayInputFormulaView(false)
|
||||
m_displayFormulaInputView(false)
|
||||
{
|
||||
m_dataView.setBackgroundColor(Palette::WallScreenDark);
|
||||
m_dataView.setVerticalCellOverlap(0);
|
||||
m_dataView.setMargins(k_margin, k_scrollBarMargin, k_scrollBarMargin, k_margin);
|
||||
}
|
||||
|
||||
void StoreController::ContentView::displayFormulaInput(bool display) {
|
||||
if (m_displayFormulaInputView != display) {
|
||||
m_displayFormulaInputView = display;
|
||||
layoutSubviews();
|
||||
markRectAsDirty(bounds());
|
||||
}
|
||||
}
|
||||
|
||||
void StoreController::ContentView::didBecomeFirstResponder() {
|
||||
app()->setFirstResponder(&m_dataView);
|
||||
app()->setFirstResponder(m_displayFormulaInputView ? static_cast<Responder *>(&m_formulaInputView) : static_cast<Responder *>(&m_dataView));
|
||||
}
|
||||
|
||||
View * StoreController::ContentView::subviewAtIndex(int index) {
|
||||
@@ -31,10 +39,13 @@ View * StoreController::ContentView::subviewAtIndex(int index) {
|
||||
}
|
||||
|
||||
void StoreController::ContentView::layoutSubviews() {
|
||||
KDRect dataViewFrame(0, 0, bounds().width(), bounds().height() - (m_displayInputFormulaView ? BufferTextViewWithTextField::k_height : 0));
|
||||
KDRect dataViewFrame(0, 0, bounds().width(), bounds().height() - (m_displayFormulaInputView ? BufferTextViewWithTextField::k_height : 0));
|
||||
m_dataView.setFrame(dataViewFrame);
|
||||
KDRect formulaFrame(0, bounds().height() - BufferTextViewWithTextField::k_height, bounds().width(), m_displayInputFormulaView ? BufferTextViewWithTextField::k_height : 0);
|
||||
m_formulaInputView.setFrame(formulaFrame);
|
||||
m_formulaInputView.setFrame(formulaFrame());
|
||||
}
|
||||
|
||||
KDRect StoreController::ContentView::formulaFrame() const {
|
||||
return KDRect(0, bounds().height() - BufferTextViewWithTextField::k_height, bounds().width(), m_displayFormulaInputView ? BufferTextViewWithTextField::k_height : 0);
|
||||
}
|
||||
|
||||
StoreController::StoreController(Responder * parentResponder, FloatPairStore * store, ButtonRowController * header) :
|
||||
@@ -47,10 +58,16 @@ StoreController::StoreController(Responder * parentResponder, FloatPairStore * s
|
||||
}
|
||||
|
||||
void StoreController::displayFormulaInput() {
|
||||
|
||||
contentView()->displayFormulaInput(true);
|
||||
}
|
||||
|
||||
bool StoreController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
|
||||
if (textField == contentView()->formulaInputView()->textField()) {
|
||||
// Handle formula input
|
||||
contentView()->displayFormulaInput(false);
|
||||
app()->setFirstResponder(contentView());
|
||||
return true;
|
||||
}
|
||||
AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
|
||||
Context * globalContext = appsContainer->globalContext();
|
||||
double floatBody = Expression::approximateToScalar<double>(text, *globalContext);
|
||||
|
||||
@@ -50,17 +50,20 @@ protected:
|
||||
public:
|
||||
ContentView(FloatPairStore * store, Responder * parentResponder, TableViewDataSource * dataSource, SelectableTableViewDataSource * selectionDataSource, TextFieldDelegate * textFieldDelegate);
|
||||
StoreSelectableTableView * dataView() { return &m_dataView; }
|
||||
BufferTextViewWithTextField * formulaInputView() { return &m_formulaInputView; }
|
||||
void displayFormulaInput(bool display);
|
||||
// Responder
|
||||
void didBecomeFirstResponder() override;
|
||||
private:
|
||||
static constexpr KDCoordinate k_margin = 8;
|
||||
static constexpr KDCoordinate k_scrollBarMargin = Metric::CommonRightMargin;
|
||||
int numberOfSubviews() const override { return 1 + m_displayInputFormulaView; }
|
||||
int numberOfSubviews() const override { return 1 + m_displayFormulaInputView; }
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
KDRect formulaFrame() const;
|
||||
StoreSelectableTableView m_dataView;
|
||||
BufferTextViewWithTextField m_formulaInputView;
|
||||
bool m_displayInputFormulaView;
|
||||
bool m_displayFormulaInputView;
|
||||
};
|
||||
|
||||
Responder * tabController() const override;
|
||||
|
||||
Reference in New Issue
Block a user