3 #include "render_flex.h"
5 int litehtml::render_item_flex::_render_content(int x
, int y
, bool second_pass
, const containing_block_context
&self_size
, formatting_context
* fmt_ctx
)
10 void litehtml::render_item_flex::draw_children(uint_ptr hdc
, int x
, int y
, const position
* clip
, draw_flag flag
, int zindex
)
15 std::shared_ptr
<litehtml::render_item
> litehtml::render_item_flex::init()
17 auto doc
= src_el()->get_document();
18 decltype(m_children
) new_children
;
19 decltype(m_children
) inlines
;
21 auto convert_inlines
= [&]()
25 // Find last not space
26 auto not_space
= std::find_if(inlines
.rbegin(), inlines
.rend(), [&](const std::shared_ptr
<render_item
>& el
)
28 return !el
->src_el()->is_space();
30 if(not_space
!= inlines
.rend())
32 // Erase all spaces at the end
33 inlines
.erase((not_space
.base()), inlines
.end());
36 auto anon_el
= std::make_shared
<html_tag
>(src_el());
37 auto anon_ri
= std::make_shared
<render_item_block
>(anon_el
);
38 for(const auto& inl
: inlines
)
40 anon_ri
->add_child(inl
);
42 anon_ri
->parent(shared_from_this());
44 new_children
.push_back(anon_ri
->init());
49 for (const auto& el
: m_children
)
51 if(el
->src_el()->css().get_display() == display_inline_text
)
55 inlines
.push_back(el
);
58 if (!el
->src_el()->is_white_space())
60 inlines
.push_back(el
);
66 if(el
->src_el()->is_block_box())
68 // Add block boxes as is
69 el
->parent(shared_from_this());
70 new_children
.push_back(el
->init());
73 // Wrap inlines with anonymous block box
74 auto anon_el
= std::make_shared
<html_tag
>(el
->src_el());
75 auto anon_ri
= std::make_shared
<render_item_block
>(anon_el
);
76 anon_ri
->add_child(el
->init());
77 anon_ri
->parent(shared_from_this());
78 new_children
.push_back(anon_ri
->init());
83 children() = new_children
;
84 for(const auto& el
: children())
86 m_flex_items
.emplace_back(new flex_item(el
));
89 return shared_from_this();