Skip to content
Snippets Groups Projects
Commit 459c3e6a authored by Odilitime's avatar Odilitime
Browse files

printComponentTree(), UIlayout engine for non-boundTopage components

parent 29161daa
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,9 @@
#include <algorithm>
#include <cmath>
#include "TextComponent.h"
#include "InputComponent.h"
#include "ComponentBuilder.h"
Component::~Component() {
}
......@@ -104,6 +107,7 @@ void Component::layout() {
std::cout << "Component::layout[" << textComponent->text << "]" << std::endl;
}
*/
//std::cout << "Component::layout - name: " << name << " boundToPage: " << boundToPage << std::endl;
// if we're a child, get our parents position
if (parent && boundToPage) {
......@@ -159,6 +163,19 @@ void Component::layout() {
// first component for this parent
}
}
if (!boundToPage) {
// select new x,y & w/h bassed on UImetric
//std::cout << "!boundToPage " << name << " from: " << (int)x << "," << (int)y << " " << (int)width << "," << (int)height << std::endl;
//std::cout << "uic.x.lenghtPct: " << uiControl.x.lengthPct << " width: " << windowWidth << " uic.x.offset: " << uiControl.x.offset << std::endl;
this->x = (uiControl.x.lengthPct / 100.0) * this->windowWidth + uiControl.x.offset;
//std::cout << "uic.y.lenghtPct: " << uiControl.y.lengthPct << " height: " << windowHeight << " uic.y.offset: " << uiControl.y.offset << std::endl;
this->y = (uiControl.y.lengthPct / 100.0) * this->windowHeight + uiControl.y.offset;
this->width = (uiControl.w.lengthPct / 100.0) * this->windowWidth + uiControl.w.offset;
this->height = (uiControl.h.lengthPct / 100.0) * this->windowHeight + uiControl.h.offset;
//std::cout << "!boundToPage " << name << " to: " << (int)x << "," << (int)y << " " << (int)width << "," << (int)height << std::endl;
}
//std::cout << "Component::layout - adjusted by prev: " << (int)x << "x" << (int)y << std::endl;
//std::cout << "Component::layout - moving component to " << (int)x << "x" << (int)y << std::endl;
......@@ -176,6 +193,7 @@ void Component::layout() {
// recurse down over my children and update their position
// if parent x or y changes or windowWindow changes, all children need to be adjust
// what about recurse up, if this element changes? well wrap recurses up the parent sizes
//std::cout << "Component::layout - I have " << children.size() << " children affected by my moved" << std::endl;
for (std::shared_ptr<Component> child : children) {
// maybe it should be like this:
......@@ -184,6 +202,7 @@ void Component::layout() {
// where do we update layout?
// So no, because this is a relayout, we don't know sf w/h has changes
// most component resize()s already update the w/h
//std::cout << "component::layout - " << name << " Doing relayout of a " << typeOfComponent(child) << "-" << child->name << std::endl;
// update new sizes
child->windowWidth = windowWidth;
......@@ -395,3 +414,24 @@ void Component::distanceToViewport(float &rawX, float &rawY) const {
rawX *= 2;
rawY *= 2;
}
void Component::printComponentTree(const std::shared_ptr<Component> &component, int depth) {
for (int i = 0; i < depth; i++) {
std::cout << '\t';
}
InputComponent *inputComponent = dynamic_cast<InputComponent*>(component.get());
if (inputComponent) {
std::cout << std::fixed << "X: " << static_cast<int>(inputComponent->x) << " Y: " << static_cast<int>(inputComponent->y) << " WIDTH: " << static_cast<int>(inputComponent->width) << " HEIGHT: " << static_cast<int>(inputComponent->height) << " INLINE: " << inputComponent->isInline << " INPUT: " << inputComponent->value << std::endl;
} else {
TextComponent *textComponent = dynamic_cast<TextComponent*>(component.get());
if (textComponent) {
std::cout << std::fixed << "X: " << static_cast<int>(textComponent->x) << " Y: " << static_cast<int>(textComponent->y) << " WIDTH: " << static_cast<int>(textComponent->width) << " HEIGHT: " << static_cast<int>(textComponent->height) << " INLINE: " << textComponent->isInline << " TEXT: " << textComponent->text << std::endl;
}
else {
std::cout << std::fixed << "X: " << static_cast<int>(component->x) << " Y: " << static_cast<int>(component->y) << " WIDTH: " << static_cast<int>(component->width) << " HEIGHT: " << static_cast<int>(component->height) << " INLINE: " << component->isInline << " NAME: " << component->name << std::endl;
}
}
for (std::shared_ptr<Component> child : component->children) {
Component::printComponentTree(child, depth + 1);
}
}
......@@ -19,6 +19,18 @@ struct rgba {
unsigned int a;
};
struct UImetric {
double lengthPct = 0;
int offset = 0;
};
struct UIlayout {
UImetric x = { false, 0 };
UImetric y = { false, 0 };
UImetric w = { false, 0 };
UImetric h = { false, 0 };
};
// should have 2 classes after this
// non-rendererable component (wtf are these?)
// and renderable component
......@@ -55,6 +67,9 @@ public:
void pointToViewport(float &rawX, float &rawY) const ;
void distanceToViewport(float &rawX, float &rawY) const ;
static void printComponentTree(const std::shared_ptr<Component> &component, int depth);
void unload(); // unload signal hook, pass down to children
// HELP I'M LOOKING FOR YOUR OPINION
// a ptr to window would be less memory
......@@ -115,6 +130,8 @@ public:
bool growLeft = false;
bool growTop = false; // if top/bott grow from center
bool growBottom = false;
//
UIlayout uiControl;
// color
rgba color;
bool isVisibile = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment