mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-18 00:48:09 +08:00
Add html_like example. Improve take_any_args.
This commit is contained in:
@@ -1,18 +1,30 @@
|
||||
#include <type_traits>
|
||||
|
||||
template <class T>
|
||||
void Merge(Elements& container, T t) {}
|
||||
|
||||
template <>
|
||||
inline void Merge(Elements& container, Element element) {
|
||||
container.push_back(std::move(element));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void Merge(Elements& container, Elements elements) {
|
||||
for(auto& element : elements)
|
||||
container.push_back(std::move(element));
|
||||
}
|
||||
|
||||
// Turn a set of arguments into a vector.
|
||||
template <class... Args>
|
||||
Elements unpack(Args... args) {
|
||||
using T = std::common_type_t<Args...>;
|
||||
std::vector<T> vec;
|
||||
(vec.push_back(std::forward<Args>(args)), ...);
|
||||
std::vector<Element> vec;
|
||||
(Merge(vec, std::move(args)), ...);
|
||||
return vec;
|
||||
}
|
||||
|
||||
// Make |container| able to take any number of argments.
|
||||
#define TAKE_ANY_ARGS(container) \
|
||||
template <class... Args> \
|
||||
Element container(Args... children) { \
|
||||
return container(unpack(std::forward<Args>(children)...)); \
|
||||
} \
|
||||
|
||||
template <class... Args> \
|
||||
Element container(Args... children) { \
|
||||
return container(unpack(std::forward<Args>(children)...)); \
|
||||
}
|
||||
|
@@ -8,9 +8,7 @@ Elements paragraph(std::wstring the_text) {
|
||||
std::wstringstream ss(the_text);
|
||||
std::wstring word;
|
||||
while (std::getline(ss, word, L' ')) {
|
||||
if (word.size()) {
|
||||
output.push_back(text(word + L' '));
|
||||
}
|
||||
output.push_back(text(word + L' '));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
@@ -39,8 +39,26 @@ class Size : public Node {
|
||||
|
||||
void SetBox(Box box) override {
|
||||
Node::SetBox(box);
|
||||
if (constraint_ == LESS_THAN)
|
||||
box.x_max = std::min(box.x_min + value_ + 1, box.x_max);
|
||||
|
||||
if (direction_ == WIDTH) {
|
||||
switch(constraint_) {
|
||||
case LESS_THAN:
|
||||
case EQUAL:
|
||||
box.x_max = std::min(box.x_min + value_ + 1, box.x_max);
|
||||
break;
|
||||
case GREATER_THAN:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch(constraint_) {
|
||||
case LESS_THAN:
|
||||
case EQUAL:
|
||||
box.y_max = std::min(box.y_min + value_ + 1, box.y_max);
|
||||
break;
|
||||
case GREATER_THAN:
|
||||
break;
|
||||
}
|
||||
}
|
||||
children[0]->SetBox(box);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user