mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-20 09:17:23 +01:00
[apps/variable_box] Prepare for Code::VariableBox factorization
This commit is contained in:
@@ -3,29 +3,28 @@
|
||||
#include <apps/i18n.h>
|
||||
#include <assert.h>
|
||||
|
||||
using namespace Poincare;
|
||||
using namespace Ion;
|
||||
|
||||
VariableBoxEmptyController::VariableBoxEmptyView::VariableBoxEmptyView() :
|
||||
m_layoutExample(0.5f, 0.5f, KDColorBlack, Palette::WallScreen)
|
||||
{
|
||||
for (int i = 0; i < k_numberOfMessages; i++) {
|
||||
m_messages[i].setFont(k_font);
|
||||
m_messages[i].setAlignment(0.5f, 0.5f);
|
||||
m_messages[i].setBackgroundColor(Palette::WallScreen);
|
||||
}
|
||||
m_messages[0].setAlignment(0.5f,1.0f);
|
||||
m_messages[k_numberOfMessages-1].setAlignment(0.5f,0.0f);
|
||||
}
|
||||
|
||||
void VariableBoxEmptyController::VariableBoxEmptyView::setMessages(I18n::Message * message) {
|
||||
for (int i = 0; i < k_numberOfMessages; i++) {
|
||||
m_messages[i].setMessage(message[i]);
|
||||
// VariableBoxEmptyController::VariableBoxEmptyView
|
||||
void VariableBoxEmptyController::VariableBoxEmptyView::initMessageViews() {
|
||||
const int numberOfMessageViews = numberOfMessageTextViews();
|
||||
for (int i = 0; i < numberOfMessageViews; i++) {
|
||||
MessageTextView * message = messageTextViewAtIndex(i);
|
||||
message->setFont(k_font);
|
||||
message->setBackgroundColor(Palette::WallScreen);
|
||||
float verticalAlignment = 0.5f;
|
||||
if (i == 0) {
|
||||
verticalAlignment = 1.0f;
|
||||
} else if (i == numberOfMessageViews - 1) {
|
||||
verticalAlignment = 0.0f;
|
||||
}
|
||||
message->setAlignment(0.5f, verticalAlignment);
|
||||
}
|
||||
}
|
||||
|
||||
void VariableBoxEmptyController::VariableBoxEmptyView::setLayout(Poincare::Layout layout) {
|
||||
m_layoutExample.setLayout(layout);
|
||||
void VariableBoxEmptyController::VariableBoxEmptyView::setMessages(I18n::Message * message) {
|
||||
const int numberOfMessageViews = numberOfMessageTextViews();
|
||||
for (int i = 0; i < numberOfMessageViews; i++) {
|
||||
messageTextViewAtIndex(i)->setMessage(message[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void VariableBoxEmptyController::VariableBoxEmptyView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
@@ -33,76 +32,48 @@ void VariableBoxEmptyController::VariableBoxEmptyView::drawRect(KDContext * ctx,
|
||||
}
|
||||
|
||||
int VariableBoxEmptyController::VariableBoxEmptyView::numberOfSubviews() const {
|
||||
return k_numberOfMessages+1;
|
||||
return numberOfMessageTextViews() + hasExpressionView();
|
||||
}
|
||||
|
||||
View * VariableBoxEmptyController::VariableBoxEmptyView::subviewAtIndex(int index) {
|
||||
if (index == k_layoutRowIndex) {
|
||||
return &m_layoutExample;
|
||||
if (hasExpressionView()) {
|
||||
if (index == k_expressionViewRowIndex) {
|
||||
return expressionView();
|
||||
}
|
||||
return messageTextViewAtIndex(index + (index < k_expressionViewRowIndex ? 0 : -1));
|
||||
}
|
||||
if (index < k_layoutRowIndex) {
|
||||
return &m_messages[index];
|
||||
}
|
||||
return &m_messages[index-1];
|
||||
return messageTextViewAtIndex(index);
|
||||
}
|
||||
|
||||
void VariableBoxEmptyController::VariableBoxEmptyView::layoutSubviews(bool force) {
|
||||
KDCoordinate width = bounds().width() - 2*k_separatorThickness;
|
||||
KDCoordinate height = bounds().height() - 2*k_separatorThickness;
|
||||
const int numberOfMessageViews = numberOfMessageTextViews();
|
||||
const bool hasExpression = hasExpressionView();
|
||||
KDCoordinate width = bounds().width() - 2 * k_separatorThickness;
|
||||
KDCoordinate height = bounds().height() - 2 * k_separatorThickness;
|
||||
KDCoordinate textHeight = k_font->glyphSize().height();
|
||||
KDCoordinate layoutHeight = m_layoutExample.minimalSizeForOptimalDisplay().height();
|
||||
KDCoordinate margin = (height - k_numberOfMessages*textHeight-layoutHeight)/2;
|
||||
m_layoutExample.setFrame(KDRect(k_separatorThickness, k_separatorThickness+margin+k_layoutRowIndex*textHeight, width, layoutHeight), force);
|
||||
KDCoordinate layoutHeight = hasExpression ? expressionView()->minimalSizeForOptimalDisplay().height() : 0;
|
||||
KDCoordinate margin = (height - numberOfMessageViews * textHeight - layoutHeight) / 2;
|
||||
if (hasExpression) {
|
||||
expressionView()->setFrame(KDRect(
|
||||
k_separatorThickness,
|
||||
k_separatorThickness + margin + k_expressionViewRowIndex * textHeight,
|
||||
width,
|
||||
layoutHeight),
|
||||
force);
|
||||
}
|
||||
KDCoordinate currentHeight = k_separatorThickness;
|
||||
for (uint8_t i = 0; i < k_numberOfMessages; i++) {
|
||||
if (i == k_layoutRowIndex) {
|
||||
for (uint8_t i = 0; i < numberOfMessageViews; i++) {
|
||||
if (hasExpression && i == k_expressionViewRowIndex) {
|
||||
currentHeight += layoutHeight;
|
||||
}
|
||||
KDCoordinate h = i == 0 || i == k_numberOfMessages - 1 ? textHeight+margin : textHeight;
|
||||
m_messages[i].setFrame(KDRect(k_separatorThickness, currentHeight, width, h), force);
|
||||
KDCoordinate h = (i == 0 || i == numberOfMessageViews - 1) ? textHeight + margin : textHeight;
|
||||
messageTextViewAtIndex(i)->setFrame(KDRect(k_separatorThickness, currentHeight, width, h), force);
|
||||
currentHeight += h;
|
||||
}
|
||||
}
|
||||
|
||||
VariableBoxEmptyController::VariableBoxEmptyController() :
|
||||
ViewController(nullptr),
|
||||
m_view()
|
||||
{
|
||||
}
|
||||
// VariableBoxEmptyController
|
||||
|
||||
View * VariableBoxEmptyController::view() {
|
||||
return &m_view;
|
||||
}
|
||||
|
||||
void VariableBoxEmptyController::viewDidDisappear() {
|
||||
m_view.setLayout(Layout());
|
||||
}
|
||||
|
||||
void VariableBoxEmptyController::setType(Type type) {
|
||||
I18n::Message messages[VariableBoxEmptyView::k_numberOfMessages] = {I18n::Message::Default, I18n::Message::Default, I18n::Message::Default, I18n::Message::EnableCharacters};
|
||||
Layout layout;
|
||||
switch (type) {
|
||||
case Type::Expressions:
|
||||
{
|
||||
messages[0] = I18n::Message::EmptyExpressionBox0;
|
||||
messages[1] = I18n::Message::EmptyExpressionBox1;
|
||||
messages[2] = I18n::Message::EmptyExpressionBox2;
|
||||
const char * storeExpression = "3→A";
|
||||
layout = LayoutHelper::String(storeExpression, strlen(storeExpression), VariableBoxEmptyView::k_font);
|
||||
break;
|
||||
}
|
||||
case Type::Functions:
|
||||
{
|
||||
messages[0] = I18n::Message::EmptyFunctionBox0;
|
||||
messages[1] = I18n::Message::EmptyFunctionBox1;
|
||||
messages[2] = I18n::Message::EmptyFunctionBox2;
|
||||
const char * storeFunction = "3+x→f(x)";
|
||||
layout = LayoutHelper::String(storeFunction, strlen(storeFunction), VariableBoxEmptyView::k_font);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
m_view.setMessages(messages);
|
||||
m_view.setLayout(layout);
|
||||
void VariableBoxEmptyController::setMessages(I18n::Message * messages) {
|
||||
static_cast<VariableBoxEmptyView *>(view())->setMessages(messages);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user