~aleteoryx/muditaos

ref: b00548440b4d37ee2806f0760a949b23b7e14aa8 muditaos/module-gui/gui/widgets/text/TextFixedSize.cpp -rw-r--r-- 2.0 KiB
b0054844 — Lefucjusz [BH-2020] Fix double-free in DecoderMP3 1 year, 5 months 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-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "TextFixedSize.hpp"

namespace gui
{
    TextFixedSize::TextFixedSize() : TextFixedSize(nullptr, 0, 0, 0, 0)
    {}

    TextFixedSize::TextFixedSize(Item *parent, Position x, Position y, Length w, Length h) : Text(parent, x, y, w, h)
    {
        setEditMode(EditMode::Edit);
        drawUnderline(true);
    }

    void TextFixedSize::setLines(const unsigned int val)
    {
        if (linesCount != val) {
            linesCount = val;
            drawLines();
        }
    }

    void TextFixedSize::setLinesSpacing(unsigned int val)
    {
        lines->setLineSpacing(val);
        drawLines();
    }

    void TextFixedSize::setUnderlinePadding(Position val)
    {
        if (lines->getUnderLineProperties().underLinePadding != val) {
            lines->getUnderLineProperties().underLinePadding = val;
            drawLines();
        }
    }

    void TextFixedSize::setUnderlineThickness(unsigned int val)
    {
        if (lines->getUnderLineProperties().thickness != val) {
            lines->getUnderLineProperties().thickness = val;
            drawLines();
        }
    }

    void TextFixedSize::drawLines()
    {
        lines->erase();

        const auto [startDrawBlockNumber, startDrawBlockPosition] = lines->drawStartConditions;
        BlockCursor drawCursor(
            cursor->getDocument(), startDrawBlockPosition, startDrawBlockNumber, getTextFormat().getFont());

        lines->draw(drawCursor,
                    getSizeMinusPadding(Axis::X, Area::Normal) - getCursorDrawSpace(),
                    getSizeMinusPadding(Axis::Y, Area::Normal),
                    padding.top,
                    padding.left,
                    linesCount,
                    textType);

        lines->linesHAlign(getSizeMinusPadding(Axis::X, Area::Normal));
        lines->linesVAlign(getSizeMinusPadding(Axis::Y, Area::Normal));
    }
} // namespace gui