mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 16:57:31 +01:00
[poincare] create a condensed sum layout
Change-Id: Ie79da6d99069b487122f3cc4fa61a9264d8f7881
This commit is contained in:
committed by
Romain Goyet
parent
654bd358f8
commit
e2eae2b2d0
@@ -1,6 +1,7 @@
|
||||
#include "term_sum_controller.h"
|
||||
#include "../../shared/text_field_delegate.h"
|
||||
#include "../../../poincare/src/layout/baseline_relative_layout.h"
|
||||
#include "../../../poincare/src/layout/condensed_sum_layout.h"
|
||||
#include "../../../poincare/src/layout/string_layout.h"
|
||||
#include "../../../poincare/src/layout/horizontal_layout.h"
|
||||
|
||||
@@ -203,7 +204,7 @@ void TermSumController::ContentView::LegendView::setSumSubscript(float start) {
|
||||
const char sigma[2] = {Ion::Charset::CapitalSigma, 0};
|
||||
char buffer[Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
|
||||
Complex::convertFloatToText(start, buffer, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
|
||||
m_sumLayout = new BaselineRelativeLayout(new StringLayout(sigma, 1), new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript);
|
||||
m_sumLayout = new CondensedSumLayout(new StringLayout(sigma, 1), new StringLayout(buffer, strlen(buffer), KDText::FontSize::Small), nullptr);
|
||||
m_sum.setExpression(m_sumLayout);
|
||||
m_sum.setAlignment(0.0f, 0.5f);
|
||||
layoutSubviews();
|
||||
@@ -219,8 +220,7 @@ void TermSumController::ContentView::LegendView::setSumSuperscript(float start,
|
||||
Complex::convertFloatToText(start, bufferStart, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
|
||||
char bufferEnd[Complex::bufferSizeForFloatsWithPrecision(1)];
|
||||
Complex::convertFloatToText(end, bufferEnd, Complex::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Expression::FloatDisplayMode::Decimal);
|
||||
ExpressionLayout * sigmaLayout = new BaselineRelativeLayout(new StringLayout(sigma, 1), new StringLayout(bufferStart, strlen(bufferStart), KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript);
|
||||
m_sumLayout = new BaselineRelativeLayout(sigmaLayout, new StringLayout(bufferEnd, strlen(bufferEnd), KDText::FontSize::Small), BaselineRelativeLayout::Type::Superscript);
|
||||
m_sumLayout = new CondensedSumLayout(new StringLayout(sigma, 1), new StringLayout(bufferStart, strlen(bufferStart), KDText::FontSize::Small), new StringLayout(bufferEnd, strlen(bufferEnd), KDText::FontSize::Small));
|
||||
m_sum.setExpression(m_sumLayout);
|
||||
layoutSubviews();
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ objs += $(addprefix poincare/src/,\
|
||||
objs += $(addprefix poincare/src/layout/,\
|
||||
absolute_value_layout.o\
|
||||
baseline_relative_layout.o\
|
||||
condensed_sum_layout.o\
|
||||
expression_layout.o\
|
||||
fraction_layout.o\
|
||||
horizontal_layout.o\
|
||||
|
||||
73
poincare/src/layout/condensed_sum_layout.cpp
Normal file
73
poincare/src/layout/condensed_sum_layout.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "condensed_sum_layout.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
CondensedSumLayout::CondensedSumLayout(ExpressionLayout * baseLayout, ExpressionLayout * subscriptLayout, ExpressionLayout * superscriptLayout) :
|
||||
ExpressionLayout(),
|
||||
m_baseLayout(baseLayout),
|
||||
m_subscriptLayout(subscriptLayout),
|
||||
m_superscriptLayout(superscriptLayout)
|
||||
{
|
||||
m_baseLayout->setParent(this);
|
||||
m_subscriptLayout->setParent(this);
|
||||
if (m_superscriptLayout) {
|
||||
m_superscriptLayout->setParent(this);
|
||||
}
|
||||
KDSize superscriptSize = m_superscriptLayout == nullptr ? KDSizeZero : m_superscriptLayout->size();
|
||||
m_baseline = m_baseLayout->baseline() + max(0, superscriptSize.height() - m_baseLayout->size().height()/2);
|
||||
}
|
||||
|
||||
CondensedSumLayout::~CondensedSumLayout() {
|
||||
delete m_baseLayout;
|
||||
delete m_subscriptLayout;
|
||||
if (m_superscriptLayout) {
|
||||
delete m_superscriptLayout;
|
||||
}
|
||||
}
|
||||
|
||||
void CondensedSumLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
|
||||
// Nothing to draw
|
||||
}
|
||||
|
||||
KDSize CondensedSumLayout::computeSize() {
|
||||
KDSize baseSize = m_baseLayout->size();
|
||||
KDSize subscriptSize = m_subscriptLayout->size();
|
||||
KDSize superscriptSize = m_superscriptLayout == nullptr ? KDSizeZero : m_superscriptLayout->size();
|
||||
return KDSize(baseSize.width() + max(subscriptSize.width(), superscriptSize.width()), max(baseSize.height()/2, subscriptSize.height()) + max(baseSize.height()/2, superscriptSize.height()));
|
||||
}
|
||||
|
||||
ExpressionLayout * CondensedSumLayout::child(uint16_t index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return m_baseLayout;
|
||||
case 1:
|
||||
return m_subscriptLayout;
|
||||
case 2:
|
||||
return m_superscriptLayout;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
KDPoint CondensedSumLayout::positionOfChild(ExpressionLayout * child) {
|
||||
KDCoordinate x = 0;
|
||||
KDCoordinate y = 0;
|
||||
KDSize baseSize = m_baseLayout->size();
|
||||
KDSize superscriptSize = m_superscriptLayout == nullptr ? KDSizeZero : m_superscriptLayout->size();
|
||||
if (child == m_baseLayout) {
|
||||
y = max(0, superscriptSize.height() - baseSize.height()/2);
|
||||
}
|
||||
if (child == m_subscriptLayout) {
|
||||
x = baseSize.width();
|
||||
y = max(baseSize.height()/2, superscriptSize.height());
|
||||
}
|
||||
if (child == m_superscriptLayout) {
|
||||
x = baseSize.width();
|
||||
}
|
||||
return KDPoint(x,y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
27
poincare/src/layout/condensed_sum_layout.h
Normal file
27
poincare/src/layout/condensed_sum_layout.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef POINCARE_CONDENSED_SUM_LAYOUT_H
|
||||
#define POINCARE_CONDENSED_SUM_LAYOUT_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/expression_layout.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
class CondensedSumLayout : public ExpressionLayout {
|
||||
public:
|
||||
CondensedSumLayout(ExpressionLayout * baseLayout, ExpressionLayout * subscriptLayout, ExpressionLayout * superscriptLayout = nullptr);
|
||||
~CondensedSumLayout();
|
||||
protected:
|
||||
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
|
||||
KDSize computeSize() override;
|
||||
ExpressionLayout * child(uint16_t index) override;
|
||||
KDPoint positionOfChild(ExpressionLayout * child) override;
|
||||
private:
|
||||
ExpressionLayout * m_baseLayout;
|
||||
ExpressionLayout * m_subscriptLayout;
|
||||
ExpressionLayout * m_superscriptLayout;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user