~aleteoryx/muditaos

ref: 264b84f5b25ba4f791b58b021302ac9241618dfd muditaos/module-gui/gui/widgets/ImageBoxWithText.cpp -rw-r--r-- 1.7 KiB
264b84f5 — Przemyslaw Brudny Merge remote-tracking branch 'origin/stable' 4 years 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ImageBoxWithText.hpp"

using namespace gui;

ImageBoxWithText::ImageBoxWithText(Item *parent,
                                   const Position &x,
                                   const Position &y,
                                   const Length &w,
                                   const Length &h,
                                   Image *image,
                                   const UTF8 &description)
    : ImageBox(parent, x, y, w, h, image)
{
    setText(description);
    setMinimumSize(imageBoxWithText::wh, imageBoxWithText::wh);
    image->setEdges(RectangleEdge::All);

    focusChangedCallback = [&](Item &item) {
        if (focus) {
            setEdges(RectangleEdge::Bottom | RectangleEdge::Top);
        }
        else {
            setEdges(RectangleEdge::None);
        }
        return true;
    };
}

ImageBoxWithText::ImageBoxWithText(Item *parent, Image *image, const UTF8 &description)
    : ImageBoxWithText(parent, 0, 0, 0, 0, image, description)
{}

void ImageBoxWithText::setText(const UTF8 &description)
{
    text = new TextFixedSize(this);
    text->drawUnderline(false);
    text->setMargins(Margins(0, imageBoxWithText::text_margin, 0, imageBoxWithText::text_margin));
    text->setFont(imageBoxWithText::font);
    text->setText(description);
    text->setMinimumWidthToFitText(description);
    text->setMinimumHeightToFitText();
}

void ImageBoxWithText::setMinimumSizeToFitImage()
{
    auto minW = std::max(image->getWidth(), text->widgetMinimumArea.w);
    auto minH = image->getHeight() + imageBoxWithText::text_margin + text->widgetMinimumArea.h;
    setMinimumSize(minW, minH);
}