Expose more information about text layout.

This commit is contained in:
Twan van Laarhoven
2020-05-10 14:12:53 +02:00
parent 1c35183839
commit e8eacac5e7
6 changed files with 145 additions and 23 deletions
+33 -6
View File
@@ -97,11 +97,38 @@ void TextStyle::checkContentDependencies(Context& ctx, const Dependency& dep) co
alignment.initDependencies(ctx, dep);
}
template <typename T> void reflect_content(T& handler, const TextStyle& ts) {}
template <> void reflect_content(GetMember& handler, const TextStyle& ts) {
REFLECT_N("content_width", ts.content_width);
REFLECT_N("content_height", ts.content_height);
REFLECT_N("content_lines", ts.content_lines);
template <typename T> void reflect_layout(T& handler, const TextStyle& ts) {}
template <> void reflect_layout(GetMember& handler, const TextStyle& ts) {
REFLECT(ts.layout);
if (ts.layout) {
REFLECT_N("content_width", ts.layout->width);
REFLECT_N("content_height", ts.layout->height);
REFLECT_N("content_lines", ts.layout->lines.size());
} else {
REFLECT_N("content_width", 0.);
REFLECT_N("content_height", 0.);
REFLECT_N("content_lines", 0);
}
}
template <> void GetMember::handle(LineLayout const& obj) { obj.reflect(*this); }
template <> void GetDefaultMember::handle(LineLayout const& obj) {}
void LineLayout::reflect(GetMember& handler) const {
REFLECT(width);
REFLECT(top);
REFLECT(height);
REFLECT_N("bottom", bottom());
REFLECT_N("middle", top + height/2);
if (type > Type::LINE) REFLECT(lines);
if (type > Type::PARAGRAPH) REFLECT(paragraphs);
if (type > Type::BLOCK) REFLECT(blocks);
}
template <> void GetMember::handle(TextLayout const& obj) { obj.reflect(*this); }
template <> void GetDefaultMember::handle(TextLayout const& obj) {}
void TextLayout::reflect(GetMember& handler) const {
REFLECT_BASE(LineLayout);
REFLECT(separators);
}
IMPLEMENT_REFLECTION(TextStyle) {
@@ -127,7 +154,7 @@ IMPLEMENT_REFLECTION(TextStyle) {
REFLECT(line_height_line_max);
REFLECT(paragraph_height);
REFLECT(direction);
reflect_content(handler, *this);
reflect_layout(handler, *this);
}
// ----------------------------------------------------------------------------- : TextValue
+23
View File
@@ -25,6 +25,8 @@ DECLARE_POINTER_TYPE(TextField);
DECLARE_POINTER_TYPE(TextStyle);
DECLARE_POINTER_TYPE(TextValue);
DECLARE_POINTER_TYPE(TextBackground);
DECLARE_POINTER_TYPE(TextLayout);
DECLARE_POINTER_TYPE(LineLayout);
/// A field for values containing tagged text
class TextField : public Field {
@@ -44,6 +46,26 @@ class TextField : public Field {
// ----------------------------------------------------------------------------- : TextStyle
// information coming from text rendering
class LineLayout : public IntrusivePtrVirtualBase {
public:
double width, top, height;
enum class Type { LINE, PARAGRAPH, BLOCK, ALL } type;
vector<LineLayoutP> lines, paragraphs, blocks;
LineLayout() {}
LineLayout(double width, double top, double height, Type type) : width(width), top(top), height(height), type(type) {}
inline double bottom() const { return top+height; }
void reflect(GetMember& gm) const;
};
class TextLayout : public LineLayout {
public:
vector<double> separators;
TextLayout() : LineLayout(0,0,0,Type::ALL) {}
void reflect(GetMember& gm) const;
};
/// The Style for a TextField
class TextStyle : public Style {
public:
@@ -69,6 +91,7 @@ class TextStyle : public Style {
paragraph_height; ///< Fixed height of paragraphs
Direction direction; ///< In what direction is text layed out?
// information from text rendering
TextLayoutP layout;
double content_width, content_height; ///< Size of the rendered text
int content_lines; ///< Number of rendered lines