mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-28 18:20:14 +01:00
LayoutCursor
This commit is contained in:
@@ -5,8 +5,6 @@
|
||||
#include "layout_node.h"
|
||||
#include "layout_cursor.h"
|
||||
|
||||
//#define TREE_LOGGING 1
|
||||
|
||||
class CharLayoutNode : public LayoutNode {
|
||||
public:
|
||||
CharLayoutNode() : LayoutNode() {}
|
||||
@@ -38,12 +36,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
#if TREE_LOGGING
|
||||
const char * description() const override {
|
||||
static char Description[] = {'C', 'h', 'a', 'r', ' ', m_char, 0};
|
||||
return Description;
|
||||
}
|
||||
#endif
|
||||
|
||||
void setChar(char c) { m_char = c; }
|
||||
private:
|
||||
char m_char;
|
||||
|
||||
5
cursor.h
5
cursor.h
@@ -1,14 +1,15 @@
|
||||
#ifndef CURSOR_H
|
||||
#define CURSOR_H
|
||||
|
||||
#include "char_layout_node.h"
|
||||
#include "tree_node.h"
|
||||
#include "tree_reference.h"
|
||||
|
||||
class Cursor {
|
||||
template <typename T>
|
||||
friend class TreeReference;
|
||||
private:
|
||||
public:
|
||||
bool isDefined() const { return m_treeReference.isDefined(); }
|
||||
protected:
|
||||
Cursor(TreeNode * node) : m_treeReference(node) {}
|
||||
TreeReference<TreeNode> m_treeReference;
|
||||
};
|
||||
|
||||
@@ -13,26 +13,26 @@ bool LayoutCursor::isEquivalentTo(LayoutCursor cursor) {
|
||||
/* Position */
|
||||
|
||||
int LayoutCursor::middleLeftPoint() {
|
||||
int layoutOrigin = m_layoutPointer.absoluteOrigin();
|
||||
int layoutOrigin = layoutReference().absoluteOrigin();
|
||||
return layoutOrigin;
|
||||
}
|
||||
|
||||
/* Move */
|
||||
|
||||
void LayoutCursor::moveLeft(bool * shouldRecomputeLayout) {
|
||||
m_layoutPointer.moveCursorLeft(this, shouldRecomputeLayout);
|
||||
layoutReference().node()->moveCursorLeft(this, shouldRecomputeLayout);
|
||||
}
|
||||
|
||||
void LayoutCursor::moveRight(bool * shouldRecomputeLayout) {
|
||||
m_layoutPointer.moveCursorRight(this, shouldRecomputeLayout);
|
||||
layoutReference().node()->moveCursorRight(this, shouldRecomputeLayout);
|
||||
}
|
||||
|
||||
void LayoutCursor::moveAbove(bool * shouldRecomputeLayout) {
|
||||
m_layoutPointer.moveCursorUp(this, shouldRecomputeLayout);
|
||||
layoutReference().node()->moveCursorUp(this, shouldRecomputeLayout);
|
||||
}
|
||||
|
||||
void LayoutCursor::moveUnder(bool * shouldRecomputeLayout) {
|
||||
m_layoutPointer.moveCursorDown(this, shouldRecomputeLayout);
|
||||
layoutReference().node()->moveCursorDown(this, shouldRecomputeLayout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,28 +1,23 @@
|
||||
#ifndef LAYOUT_CURSOR_H
|
||||
#define LAYOUT_CURSOR_H
|
||||
|
||||
#include "tree_pool.h"
|
||||
#include "layout_cursor_reference.h"
|
||||
#include "cursor.h"
|
||||
#include "layout_reference.h"
|
||||
#include "layout_node.h"
|
||||
#include <stdio.h>
|
||||
|
||||
class LayoutCursor {
|
||||
class LayoutCursor : public Cursor {
|
||||
template <typename T>
|
||||
friend class LayoutReference;
|
||||
public:
|
||||
enum class Position {
|
||||
Left,
|
||||
Right
|
||||
};
|
||||
LayoutCursor(Layout * layoutPointer, Position position = Position::Right) :
|
||||
m_layoutPointer(layoutPointer),
|
||||
m_position(position)
|
||||
{
|
||||
}
|
||||
|
||||
bool isDefined() const { return m_layoutPointer.isDefined(); }
|
||||
|
||||
/* Debug */
|
||||
void log() {
|
||||
printf("Pointed Layout id %d, cursor position ", m_layoutPointer.identifier());
|
||||
printf("Pointed Layout id %d, cursor position ", m_treeReference.identifier());
|
||||
if (m_position == Position::Left) {
|
||||
printf("Left");
|
||||
} else {
|
||||
@@ -32,6 +27,9 @@ public:
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
LayoutReference<LayoutNode> layoutReference() {
|
||||
return LayoutReference<LayoutNode>(m_treeReference.node());
|
||||
}
|
||||
//int pointedLayoutIdentifier() const { return m_layoutIdentifier; }
|
||||
//void setPointedLayoutIdentifier(int layoutID) { m_layoutIdentifier = layoutID; }
|
||||
Position position() const { return m_position; }
|
||||
@@ -51,7 +49,11 @@ public:
|
||||
void moveAbove(bool * shouldRecomputeLayout);
|
||||
void moveUnder(bool * shouldRecomputeLayout);
|
||||
private:
|
||||
LayoutPointer m_layoutPointer;
|
||||
LayoutCursor(TreeNode * node, Position position = Position::Right) :
|
||||
Cursor(node),
|
||||
m_position(position)
|
||||
{
|
||||
}
|
||||
Position m_position;
|
||||
};
|
||||
|
||||
|
||||
10
layout_reference.cpp
Normal file
10
layout_reference.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "layout_reference.h"
|
||||
#include "layout_cursor.h"
|
||||
#include "char_layout_node.h"
|
||||
|
||||
template <typename T>
|
||||
LayoutCursor LayoutReference<T>::cursor() const {
|
||||
return LayoutCursor(this->node());
|
||||
}
|
||||
|
||||
template LayoutCursor LayoutReference<CharLayoutNode>::cursor() const;
|
||||
@@ -2,9 +2,10 @@
|
||||
#define LAYOUT_REFERENCE_H
|
||||
|
||||
#include "tree_reference.h"
|
||||
//#include "layout_cursor.h"
|
||||
#include "layout_node.h"
|
||||
|
||||
class LayoutCursor;
|
||||
|
||||
template <typename T>
|
||||
class LayoutReference : public TreeReference<T> {
|
||||
friend class LayoutCursor;
|
||||
@@ -22,9 +23,9 @@ public:
|
||||
return (reinterpret_cast<LayoutReference<LayoutNode> *>(this));
|
||||
}
|
||||
|
||||
// LayoutReference<T> cursorReference() const;
|
||||
LayoutCursor cursor() const;
|
||||
|
||||
void addChild(LayoutReference<LayoutNode> l) {
|
||||
virtual void addChild(LayoutReference<LayoutNode> l) {
|
||||
TreeReference<T>::addChild(l);
|
||||
}
|
||||
|
||||
|
||||
11
tree_reference.cpp
Normal file
11
tree_reference.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "tree_reference.h"
|
||||
#include "char_layout_node.h"
|
||||
#include "cursor.h"
|
||||
|
||||
template <typename T>
|
||||
Cursor TreeReference<T>::treeCursor() {
|
||||
return Cursor(node());
|
||||
}
|
||||
|
||||
template Cursor TreeReference<TreeNode>::treeCursor();
|
||||
template Cursor TreeReference<CharLayoutNode>::treeCursor();
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
|
||||
int identifier() const { return m_identifier; }
|
||||
|
||||
Cursor cursor();
|
||||
Cursor treeCursor();
|
||||
|
||||
// Hierarchy
|
||||
int numberOfChildren() const {
|
||||
|
||||
Reference in New Issue
Block a user