mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 05:40:38 +01:00
Add exponent layout.
Change-Id: Iffce8dcdd4ecf10a8ed4170494b59fa6c524b9cb
This commit is contained in:
committed by
Félix Raimundo
parent
2db5b3e092
commit
d42bbaf25a
@@ -1,6 +1,6 @@
|
||||
SFLAGS += -Ipoincare/include
|
||||
objs += $(addprefix poincare/src/, addition.o context.o expression.o float.o integer.o fraction.o expression_lexer.o expression_parser.o power.o product.o symbol.o)
|
||||
objs += $(addprefix poincare/src/layout/, expression_layout.o fraction_layout.o horizontal_layout.o string_layout.o)
|
||||
objs += $(addprefix poincare/src/layout/, expression_layout.o fraction_layout.o horizontal_layout.o exponent_layout.o string_layout.o)
|
||||
tests += $(addprefix poincare/test/, integer.cpp)
|
||||
|
||||
# Even though flex and bison will generate both implementation and headers at
|
||||
|
||||
55
poincare/src/layout/exponent_layout.cpp
Normal file
55
poincare/src/layout/exponent_layout.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "exponent_layout.h"
|
||||
|
||||
// TODO(fraimundo): Find a better name.
|
||||
#define EXPONENT_HEIGHT 5
|
||||
|
||||
ExponentLayout::ExponentLayout(ExpressionLayout * parent, Expression * base, Expression * exponent) :
|
||||
ExpressionLayout(parent) {
|
||||
m_base_layout = base->createLayout(this);
|
||||
m_exponent_layout = exponent->createLayout(this);
|
||||
}
|
||||
|
||||
ExponentLayout::~ExponentLayout() {
|
||||
delete m_exponent_layout;
|
||||
delete m_base_layout;
|
||||
}
|
||||
|
||||
// There is nothing to draw for a power, only the position of the children matters
|
||||
void ExponentLayout::render(KDPoint point) { }
|
||||
|
||||
KDSize ExponentLayout::computeSize() {
|
||||
KDSize s;
|
||||
KDSize exponent_size, base_size;
|
||||
exponent_size = m_exponent_layout->size();
|
||||
base_size = m_base_layout->size();
|
||||
s.height = base_size.height + exponent_size.height - EXPONENT_HEIGHT;
|
||||
s.width = base_size.width + exponent_size.width;
|
||||
return s;
|
||||
}
|
||||
|
||||
ExpressionLayout * ExponentLayout::child(uint16_t index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return m_base_layout;
|
||||
case 1:
|
||||
return m_exponent_layout;
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
KDPoint ExponentLayout::positionOfChild(ExpressionLayout * child) {
|
||||
KDPoint p;
|
||||
if (child == m_base_layout) {
|
||||
p.x = 0;
|
||||
p.y = m_exponent_layout->size().height - EXPONENT_HEIGHT;
|
||||
} else if (child == m_exponent_layout) {
|
||||
p.x = m_base_layout->size().width;
|
||||
p.y = 0;
|
||||
} else {
|
||||
assert(false); // Should not happen
|
||||
}
|
||||
return p;
|
||||
}
|
||||
21
poincare/src/layout/exponent_layout.h
Normal file
21
poincare/src/layout/exponent_layout.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef POINCARE_EXPONENT_LAYOUT_H
|
||||
#define POINCARE_EXPONENT_LAYOUT_H
|
||||
|
||||
#include <poincare/expression.h>
|
||||
#include <poincare/expression_layout.h>
|
||||
|
||||
class ExponentLayout : public ExpressionLayout {
|
||||
public:
|
||||
ExponentLayout(ExpressionLayout * parent, Expression * base, Expression * exponent);
|
||||
~ExponentLayout();
|
||||
protected:
|
||||
void render(KDPoint point) override;
|
||||
KDSize computeSize() override;
|
||||
ExpressionLayout * child(uint16_t index) override;
|
||||
KDPoint positionOfChild(ExpressionLayout * child) override;
|
||||
private:
|
||||
ExpressionLayout * m_base_layout;
|
||||
ExpressionLayout * m_exponent_layout;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <poincare/power.h>
|
||||
#include "layout/horizontal_layout.h"
|
||||
#include "layout/exponent_layout.h"
|
||||
|
||||
Power::Power(Expression * base, Expression * exponent) :
|
||||
m_base(base),
|
||||
@@ -17,5 +17,5 @@ float Power::approximate(Context& context) {
|
||||
}
|
||||
|
||||
ExpressionLayout * Power::createLayout(ExpressionLayout * parent) {
|
||||
return new HorizontalLayout(parent, m_base, '^', m_exponent);
|
||||
return new ExponentLayout(parent, m_base, m_exponent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user