~aleteoryx/muditaos

muditaos/module-gui/test/mock/buildTextDocument.cpp -rw-r--r-- 2.3 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "buildTextDocument.hpp"
#include "InitializedFontManager.hpp"
#include "multi-line-string.hpp"

#include <widgets/text/parsers/TextParse.hpp>

namespace mockup
{

    std::tuple<gui::TextDocument, gui::RawFont *> buildEmptyTestDocument()
    {
        using namespace gui;
        auto &fontmanager = mockup::fontManager();
        auto testfont     = fontmanager.getFont();
        auto document     = TextDocument({});
        return std::tuple{document, testfont};
    }

    std::tuple<gui::TextDocument, gui::RawFont *> buildTestDocument(gui::TextBlock::End lineEnd)
    {
        using namespace gui;

        const auto no_lines = 3;

        auto &fontmanager = mockup::fontManager();
        auto testfont     = fontmanager.getFont();
        std::string text  = mockup::multiLineString(no_lines);
        auto blocks       = textToTextBlocks(text, testfont, lineEnd);
        auto document     = TextDocument(blocks);
        return std::tuple{document, testfont};
    }

    auto buildOnelineTestDocument(std::string text) -> std::tuple<gui::TextDocument, gui::RawFont *>
    {
        using namespace gui;

        auto &fontmanager = fontManager();
        auto testfont     = fontmanager.getFont();
        auto blocks       = textToTextBlocks(text, testfont, gui::TextBlock::End::None);
        auto document     = TextDocument(blocks);
        return std::tuple{document, testfont};
    }

    auto buildMultilineTestDocument(std::list<std::string> source) -> std::tuple<gui::TextDocument, gui::RawFont *>
    {
        using namespace gui;
        auto &fontmanager = mockup::fontManager();
        auto testfont     = fontmanager.getFont();
        std::list<TextBlock> blocks;
        for (auto el : source) {
            blocks.emplace_back(TextBlock(el, testfont, TextBlock::End::Newline));
        }
        auto document = TextDocument(blocks);
        return std::tuple{document, testfont};
    }

    auto buildJustNewlineTestDocument() -> gui::TextDocument
    {
        using namespace gui;
        auto &fontmanager = mockup::fontManager();
        auto testfont     = fontmanager.getFont();
        return TextDocument({TextBlock("", testfont, TextBlock::End::Newline)});
    }
} // namespace mockup