srctree

Robin Linden parent e201c8ac 8ba8aeee
layout: Be more explicit about the assignments to layout_text

inlinesplit
layout/layout.cpp added: 13, removed: 9, total 4
@@ -37,7 +37,7 @@ bool last_node_was_anonymous(LayoutBox const &box) {
// https://www.w3.org/TR/CSS2/visuren.html#box-gen
std::optional<LayoutBox> create_tree(style::StyledNode const &node) {
if (auto const *text = std::get_if<dom::Text>(&node.node)) {
return LayoutBox{.node = &node, .type = LayoutType::Inline, .layout_text = text->text};
return LayoutBox{.node = &node, .type = LayoutType::Inline, .layout_text = std::string_view{text->text}};
}
 
assert(std::holds_alternative<dom::Element>(node.node));
 
layout/layout_test.cpp added: 13, removed: 9, total 4
@@ -202,8 +202,8 @@ int main() {
.children = {
{&style_root.children[0], LayoutType::Block, {{0, 0, 0, 10}}, {
{nullptr, LayoutType::AnonymousBlock, {{0, 0, 60, 10}}, {
{&style_root.children[0].children[0], LayoutType::Inline, {{0, 0, 25, 10}}, {}, "hello"},
{&style_root.children[0].children[1], LayoutType::Inline, {{25, 0, 35, 10}}, {}, "goodbye"},
{&style_root.children[0].children[0], LayoutType::Inline, {{0, 0, 25, 10}}, {}, "hello"sv},
{&style_root.children[0].children[1], LayoutType::Inline, {{25, 0, 35, 10}}, {}, "goodbye"sv},
}},
}},
}
 
render/render_test.cpp added: 13, removed: 9, total 4
@@ -12,10 +12,14 @@
#include "layout/layout.h"
#include "style/styled_node.h"
 
#include <string_view>
 
using etest::expect_eq;
 
using CanvasCommands = std::vector<gfx::CanvasCommand>;
 
using namespace std::literals;
 
constexpr auto kInvalidColor = gfx::Color{0xFF, 0, 0};
 
int main() {
@@ -33,7 +37,7 @@ int main() {
.node = &styled,
.type = layout::LayoutType::Inline,
.dimensions = {},
.children = {{&styled.children[0], layout::LayoutType::Inline, {}, {}, "hello"}},
.children = {{&styled.children[0], layout::LayoutType::Inline, {}, {}, "hello"sv}},
};
 
gfx::CanvasCommandSaver saver;
@@ -59,7 +63,7 @@ int main() {
auto layout = layout::LayoutBox{
.node = &styled,
.type = layout::LayoutType::Inline,
.children = {{&styled.children[0], layout::LayoutType::Inline, {}, {}, "hello"}},
.children = {{&styled.children[0], layout::LayoutType::Inline, {}, {}, "hello"sv}},
};
 
gfx::CanvasCommandSaver saver;
@@ -329,7 +333,7 @@ int main() {
{css::PropertyId::FontFamily, "arial"},
{css::PropertyId::FontSize, "16px"},
}};
auto layout = layout::LayoutBox{.node = &styled, .layout_text = "hello"};
auto layout = layout::LayoutBox{.node = &styled, .layout_text = "hello"sv};
 
gfx::CanvasCommandSaver saver;
render::render_layout(saver, layout);