mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
[poincare] Create a class subscript layout
Change-Id: I3496f1942ed661f751612472f72e1d11fffa1ccc
This commit is contained in:
@@ -46,6 +46,7 @@ objs += $(addprefix poincare/src/layout/,\
|
||||
nth_root_layout.o\
|
||||
parenthesis_layout.o\
|
||||
string_layout.o\
|
||||
subscript_layout.o\
|
||||
)
|
||||
|
||||
tests += $(addprefix poincare/test/,\
|
||||
|
||||
49
poincare/src/layout/subscript_layout.cpp
Normal file
49
poincare/src/layout/subscript_layout.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "subscript_layout.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
SubscriptLayout::SubscriptLayout(ExpressionLayout * baseLayout, ExpressionLayout * subscriptLayout) :
|
||||
ExpressionLayout(),
|
||||
m_baseLayout(baseLayout),
|
||||
m_subscriptLayout(subscriptLayout)
|
||||
{
|
||||
m_baseLayout->setParent(this);
|
||||
m_subscriptLayout->setParent(this);
|
||||
m_baseline = m_baseLayout->baseline();
|
||||
}
|
||||
|
||||
SubscriptLayout::~SubscriptLayout() {
|
||||
delete m_baseLayout;
|
||||
delete m_subscriptLayout;
|
||||
}
|
||||
|
||||
void SubscriptLayout::render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) {
|
||||
// There is nothing to draw for a power, only the position of the children matters
|
||||
}
|
||||
|
||||
KDSize SubscriptLayout::computeSize() {
|
||||
KDSize baseSize = m_baseLayout->size();
|
||||
KDSize subscriptSize = m_subscriptLayout->size();
|
||||
return KDSize(baseSize.width() + subscriptSize.width(), m_baseLayout->baseline() + subscriptSize.height() - k_subscriptHeight);
|
||||
}
|
||||
|
||||
ExpressionLayout * SubscriptLayout::child(uint16_t index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return m_baseLayout;
|
||||
case 1:
|
||||
return m_subscriptLayout;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
KDPoint SubscriptLayout::positionOfChild(ExpressionLayout * child) {
|
||||
KDCoordinate x = 0;
|
||||
KDCoordinate y = 0;
|
||||
if (child == m_subscriptLayout) {
|
||||
x = m_baseLayout->size().width();
|
||||
y = m_baseLayout->baseline() - k_subscriptHeight;
|
||||
}
|
||||
return KDPoint(x,y);
|
||||
}
|
||||
22
poincare/src/layout/subscript_layout.h
Normal file
22
poincare/src/layout/subscript_layout.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef POINCARE_SUBSCRIPT_LAYOUT_H
|
||||
#define POINCARE_SUBSCRIPT_LAYOUT_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/expression_layout.h>
|
||||
|
||||
class SubscriptLayout : public ExpressionLayout {
|
||||
public:
|
||||
SubscriptLayout(ExpressionLayout * baseLayout, ExpressionLayout * subscriptLayout);
|
||||
~SubscriptLayout();
|
||||
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:
|
||||
constexpr static KDCoordinate k_subscriptHeight = 5;
|
||||
ExpressionLayout * m_baseLayout;
|
||||
ExpressionLayout * m_subscriptLayout;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user