Browse Source

new input element, start text selection handler

pull/2/head
Odilitime 5 years ago
parent
commit
f439a3c09b
  1. 32
      src/graphics/components/ComponentBuilder.cpp

32
src/graphics/components/ComponentBuilder.cpp

@ -14,6 +14,7 @@ const std::unordered_map<std::string, std::shared_ptr<Element>> ComponentBuilder @@ -14,6 +14,7 @@ const std::unordered_map<std::string, std::shared_ptr<Element>> ComponentBuilder
{"div", std::make_shared<DIVElement>()},
{"br", std::make_shared<DIVElement>()},
{"strong", std::make_shared<STRONGElement>()},
{"input", std::make_shared<INPUTElement>()},
{"b", std::make_shared<STRONGElement>()}
};
@ -26,8 +27,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -26,8 +27,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
if (tagNode) {
tag = tagNode->tag;
}
}
else if (node->nodeType == NodeType::TEXT) {
} else if (node->nodeType == NodeType::TEXT) {
TagNode *tagNode = dynamic_cast<TagNode*>(node->parent.get());
if (tagNode) {
tag = tagNode->tag;
@ -35,7 +35,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -35,7 +35,7 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
}
bool isInline = false;
std::unordered_map<std::string, std::shared_ptr<Element>>::const_iterator elementPair = elementMap.find(tag);
if (elementPair != elementMap.end()) {
std::shared_ptr<Element> element = elementPair->second;
@ -53,14 +53,28 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -53,14 +53,28 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
}
if (!component) {
//std::cout << "tag [" << tag << "] didn't yeild any component" << std::endl;
component = std::make_unique<Component>();
}
/*
TextComponent *textComponent = dynamic_cast<TextComponent*>(component.get());
if (textComponent) {
std::cout << "compositing [" << textComponent->text << "]" << std::endl;
//std::cout << "compositing [" << textComponent->text << "]" << std::endl;
component->onMousedown = [component](int x, int y) {
std::cout << "TextSelection starting at " << x << "," << y << std::endl;
// 0 to -640 (windowHeight)
// so if y=640 , f(y)=-640
int ny = -y;
std::cout << "TextSelection adjusted " << x << "," << ny << std::endl;
std::cout << "Component at " << (int)component->x << "," << (int)component->y << std::endl;
};
component->onMouseup = [component](int x, int y) {
std::cout << "TextSelection ending at " << x << "," << y << std::endl;
};
}
InputComponent *inputComponent = dynamic_cast<InputComponent*>(component.get());
if (inputComponent) {
// any input set up we need to do?
}
*/
//std::cout << "composting component, initial: " << (int)component->width << "x" << (int)component->height << std::endl;
// set our available dimensions
@ -80,6 +94,12 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n @@ -80,6 +94,12 @@ std::shared_ptr<Component> ComponentBuilder::build(const std::shared_ptr<Node> n
// figure out our position, size, texture
component->layout();
/*
InputComponent *inputComponent = dynamic_cast<InputComponent*>(component.get());
if (inputComponent) {
std::cout << "ComponentBuilder::build - Just laid out input component" << std::endl;
}
*/
//std::cout << "post layout placed: " << (int)component->x << "x" << (int)component->y << " w/h: " << (int)component->width << "x" << (int)component->height << std::endl;
return component;

Loading…
Cancel
Save