mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-22 15:20:39 +01:00
[poincare] GridLayoutNode keep track of its number of children
Before, the number of children was only computed with the number of rows and columns, but we might need to know the real number of added children during construction.
This commit is contained in:
@@ -17,12 +17,14 @@ class GridLayoutNode : public LayoutNode {
|
||||
public:
|
||||
GridLayoutNode() :
|
||||
LayoutNode(),
|
||||
m_numberOfChildren(0),
|
||||
m_numberOfRows(0),
|
||||
m_numberOfColumns(0)
|
||||
{}
|
||||
|
||||
void setNumberOfRows(int numberOfRows) { m_numberOfRows = numberOfRows; }
|
||||
void setNumberOfColumns(int numberOfColumns) { m_numberOfColumns = numberOfColumns; }
|
||||
KDSize gridSize() const { return KDSize(width(), height()); }
|
||||
|
||||
// LayoutNode
|
||||
void moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) override;
|
||||
@@ -38,8 +40,20 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(GridLayoutNode); }
|
||||
int numberOfChildren() const override { return m_numberOfRows * m_numberOfColumns; }
|
||||
int numberOfChildren() const override { return m_numberOfChildren; }
|
||||
void incrementNumberOfChildren(int increment = 1) override {
|
||||
assert(increment >= 0);
|
||||
m_numberOfChildren += increment;
|
||||
}
|
||||
void decrementNumberOfChildren(int decrement = 1) override {
|
||||
m_numberOfChildren -= decrement;
|
||||
if (m_numberOfChildren < 0) {
|
||||
m_numberOfChildren = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void eraseNumberOfChildren() override {
|
||||
m_numberOfChildren = 0;
|
||||
m_numberOfRows = 0;
|
||||
m_numberOfColumns = 0;
|
||||
}
|
||||
@@ -62,6 +76,7 @@ protected:
|
||||
int rowAtChildIndex(int index) const;
|
||||
int columnAtChildIndex(int index) const;
|
||||
int indexAtRowColumn(int rowIndex, int columnIndex) const;
|
||||
int m_numberOfChildren;
|
||||
int m_numberOfRows;
|
||||
int m_numberOfColumns;
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ int GridLayoutNode::indexAtRowColumn(int rowIndex, int columnIndex) const {
|
||||
}
|
||||
|
||||
void GridLayoutNode::computeSize() {
|
||||
m_frame.setSize(KDSize(width(), height()));
|
||||
m_frame.setSize(gridSize());
|
||||
m_sized = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user