~aleteoryx/muditaos

cd89787351b8f50e89d14962692eb1470f6e6547 — Przemyslaw Brudny 5 years ago b2075be
[EGD-3410] TextLine inheritance to Rect added.
M module-apps/application-phonebook/data/PhonebookStyle.hpp => module-apps/application-phonebook/data/PhonebookStyle.hpp +3 -3
@@ 129,10 129,10 @@ namespace phonebookStyle
    namespace inputLineWithLabelItem
    {
        constexpr uint32_t w             = style::window::default_body_width;
        constexpr uint32_t h             = 200;
        constexpr uint32_t h             = 75;
        constexpr uint32_t title_label_h = 20;
        constexpr uint32_t input_text_h  = 100;
        constexpr uint32_t span_size     = 15;
        constexpr uint32_t input_text_h  = 33;
        constexpr uint32_t span_size     = 100;
    } // namespace inputLineWithLabelItem

    namespace multiLineTextWithLabelItem

M module-apps/application-phonebook/models/NewContactModel.cpp => module-apps/application-phonebook/models/NewContactModel.cpp +47 -47
@@ 41,53 41,53 @@ void NewContactModel::createData()
        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));

    internalData.push_back(new gui::InputLineWithLabelItem(
        phonebookInternals::ListItemName::SecondName,
        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));

    internalData.push_back(new gui::InputLineWithLabelItem(
        phonebookInternals::ListItemName::Number,
        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));

    internalData.push_back(new gui::InputLineWithLabelItem(
        phonebookInternals::ListItemName::OtherNumber,
        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));

    internalData.push_back(new gui::InputLineWithLabelItem(
        phonebookInternals::ListItemName::Email,
        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));

    internalData.push_back(new gui::InputBoxWithLabelAndIconItem(phonebookInternals::ListItemName::SpeedDialKey));

    internalData.push_back(new gui::InputBoxWithLabelAndIconItem(
        phonebookInternals::ListItemName::AddToFavourites,
        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text, false); },
        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); }));

    internalData.push_back(new gui::InputBoxWithLabelAndIconItem(
        phonebookInternals::ListItemName::AddToICE,
        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text, false); },
        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); }));

    internalData.push_back(new gui::InputLineWithLabelItem(
        phonebookInternals::ListItemName::Address,
        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text, false); },
        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));

    internalData.push_back(new gui::InputLineWithLabelItem(
        phonebookInternals::ListItemName::Note,
        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text, false); },
        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));
    //    internalData.push_back(new gui::InputLineWithLabelItem(
    //        phonebookInternals::ListItemName::SecondName,
    //        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
    //        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
    //        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));
    //
    //    internalData.push_back(new gui::InputLineWithLabelItem(
    //        phonebookInternals::ListItemName::Number,
    //        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
    //        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
    //        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));
    //
    //    internalData.push_back(new gui::InputLineWithLabelItem(
    //        phonebookInternals::ListItemName::OtherNumber,
    //        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
    //        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
    //        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));
    //
    //    internalData.push_back(new gui::InputLineWithLabelItem(
    //        phonebookInternals::ListItemName::Email,
    //        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
    //        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
    //        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));
    //
    //    internalData.push_back(new gui::InputBoxWithLabelAndIconItem(phonebookInternals::ListItemName::SpeedDialKey));
    //
    //    internalData.push_back(new gui::InputBoxWithLabelAndIconItem(
    //        phonebookInternals::ListItemName::AddToFavourites,
    //        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text, false); },
    //        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); }));
    //
    //    internalData.push_back(new gui::InputBoxWithLabelAndIconItem(
    //        phonebookInternals::ListItemName::AddToICE,
    //        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text, false); },
    //        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); }));
    //
    //    internalData.push_back(new gui::InputLineWithLabelItem(
    //        phonebookInternals::ListItemName::Address,
    //        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text, false); },
    //        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
    //        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));
    //
    //    internalData.push_back(new gui::InputLineWithLabelItem(
    //        phonebookInternals::ListItemName::Note,
    //        [app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text, false); },
    //        [app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
    //        [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));

    for (auto item : internalData) {
        item->deleteByList = false;

M module-apps/application-phonebook/widgets/InputLineWithLabelItem.cpp => module-apps/application-phonebook/widgets/InputLineWithLabelItem.cpp +5 -8
@@ 14,8 14,7 @@ namespace gui
                                                   std::function<void()> selectSpecialCharacter)
        : listItemName(listItemName)
    {
        setMinimumSize(phonebookStyle::inputLineWithLabelItem::w, phonebookStyle::inputLineWithLabelItem::h);
        setMaximumSize(phonebookStyle::inputLineWithLabelItem::w, phonebookStyle::inputLineWithLabelItem::h);
        setMinimumSize(phonebookStyle::inputLineWithLabelItem::w, phonebookStyle::inputLineWithLabelItem::h * 4);
        setMargins(gui::Margins(0, style::margins::very_big, 0, 0));

        vBox = new VBox(this, 0, 0, 0, phonebookStyle::inputLineWithLabelItem::title_label_h);


@@ 27,11 26,12 @@ namespace gui
        titleLabel->setFont(style::window::font::small);
        titleLabel->activeItem = false;

        new gui::Span(vBox, Axis::Y, phonebookStyle::inputLineWithLabelItem::span_size); // spread title & inputText
        inputText = new TextFixedSize(vBox, 0, 0, 0, 0);
        inputText->setMaximumSize(phonebookStyle::inputLineWithLabelItem::w, 600);
        inputText->setMargins(Margins(0, phonebookStyle::inputLineWithLabelItem::span_size, 0, 0));

        inputText = new Text(vBox, 0, 0, 0, phonebookStyle::inputLineWithLabelItem::input_text_h);
        inputText->setEdges(RectangleEdgeFlags::GUI_RECT_EDGE_NO_EDGES);
        inputText->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Bottom));
        inputText->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Top));
        inputText->setFont(style::window::font::medium);
        inputText->setInputMode(new InputMode(
            {InputMode::ABC, InputMode::abc, InputMode::digit},


@@ 58,9 58,6 @@ namespace gui
        vBox->setPosition(0, 0);
        vBox->setSize(newDim.w, newDim.h);

        // this shouldn't be needed - without it there will be nothing shown in place of digit labels
        titleLabel->setSize(newDim.w, phonebookStyle::inputLineWithLabelItem::title_label_h);
        inputText->setSize(newDim.w, phonebookStyle::inputLineWithLabelItem::input_text_h);
        return true;
    }


M module-gui/gui/widgets/Item.hpp => module-gui/gui/widgets/Item.hpp +1 -1
@@ 287,7 287,7 @@ namespace gui
        {
            return (widgetArea.y);
        }
        [[nodiscard]] uint32_t getWidth() const
        [[nodiscard]] virtual uint32_t getWidth() const
        {
            return (widgetArea.w);
        }

M module-gui/gui/widgets/Text.cpp => module-gui/gui/widgets/Text.cpp +1 -1
@@ 296,7 296,7 @@ namespace gui

        auto line_x_position = padding.left;
        do {
            auto text_line = gui::TextLine(document.get(), cursor, w);
            auto text_line = gui::TextLine(this, document.get(), cursor, w);
            cursor += text_line.length();

            if (text_line.length() == 0) {

M module-gui/gui/widgets/TextFixedSize.cpp => module-gui/gui/widgets/TextFixedSize.cpp +45 -14
@@ 7,9 7,6 @@ namespace gui
    {
        this->linesCount = linesCount;
        setEditMode(EditMode::EDIT);
        //
        //        inputText->setMinimumSize(phonebookStyle::inputLineWithLabelItem::w,phonebookStyle::inputLineWithLabelItem::input_text_h);
        //        inputText->setMaximumSize(phonebookStyle::inputLineWithLabelItem::w,phonebookStyle::inputLineWithLabelItem::input_text_h);
    }

    void TextFixedSize::setLines(const unsigned int val)


@@ 32,24 29,33 @@ namespace gui
            return size;
        };

        uint32_t w = sizeMinusPadding(Axis::X, Area::Max);
        //        uint32_t h           = sizeMinusPadding(Axis::Y, Area::Max);
        uint32_t w           = sizeMinusPadding(Axis::X, Area::Normal);
        uint32_t h           = sizeMinusPadding(Axis::Y, Area::Normal);
        auto line_y_position = padding.top;
        auto cursor          = 0;

        unsigned int currentLine = 0;
        unsigned int lineHeight  = 0;

        auto line_x_position = padding.left;
        do {
            auto text_line = gui::TextLine(document.get(), cursor, w);
            auto text_line = gui::TextLine(this, document.get(), cursor, w);
            cursor += text_line.length();

            if (text_line.length() == 0) {
            if (text_line.length() == 0 && currentLine == 0) {
                break;
            }

            if (text_line.height() > 0 && lineHeight != text_line.height()) {
                lineHeight = text_line.height();
            }

            LOG_INFO("Wtf? %d", line_y_position + lineHeight);
            LOG_INFO("wtf 2 %d", h);

            if (line_y_position + lineHeight > h) { // no more space for next line
                break;
            }
            //            if (line_y_position + text_line.height() > h) { // no more space for next line
            //                break;
            //            }

            // for each different text which fits in line, addWidget last - to not trigger callbacks to parent
            // on resizes while not needed, after detach there can be no `break` othervise there will be leak - hence


@@ 58,13 64,38 @@ namespace gui
            auto &line = lines.last();
            line.setPosition(line_x_position, line_y_position);
            line.setParent(this);
            line.alignH(getAlignment(Axis::X), w);
            //            line.alignH(getAlignment(Axis::X), w);

            line_y_position += lineHeight;

            LOG_INFO("Jaka wyskosc lini %d", text_line.height());
            LOG_INFO("Ile mamy lini %d", currentLine);

            LOG_INFO("debug text drawing: \n start cursor: %d line length: %d end cursor %d : document length "
                     "%d \n x: %d, y: %d \n%s",
                     cursor - lines.last().length(),
                     lines.last().length(),
                     cursor,
                     document->getText().length(),
                     line_x_position,
                     line_y_position,
                     [&]() -> std::string {
                         std::string text = document->getText();
                         return std::string(text.begin() + cursor - lines.last().length(), text.begin() + cursor);
                     }()
                                  .c_str());

            line_y_position += line.height();
            currentLine++;

        } while (currentLine != linesCount);
        } while (true);

        lines.linesVAlign(sizeMinusPadding(Axis::Y, Area::Normal));
        //        lines.linesVAlign(sizeMinusPadding(Axis::Y, Area::Normal));
    }

    bool TextFixedSize::onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim)
    {
        Text::onDimensionChanged(oldDim, newDim);
        drawLines();
        return true;
    }
} // namespace gui

M module-gui/gui/widgets/TextFixedSize.hpp => module-gui/gui/widgets/TextFixedSize.hpp +2 -1
@@ 8,9 8,10 @@ namespace gui
    class TextFixedSize : public Text
    {
      protected:
        unsigned int linesCount = 1;
        unsigned int linesCount = 3;

        void drawLines() override;
        bool onDimensionChanged(const BoundingBox &oldDim, const BoundingBox &newDim) override;

      public:
        TextFixedSize(Item *parent, Position x, Position y, Length w, Length h, unsigned int linesCount = 1);

M module-gui/gui/widgets/TextLine.cpp => module-gui/gui/widgets/TextLine.cpp +19 -2
@@ 5,6 5,7 @@
#include "TextDocument.hpp"
#include <cstdio>
#include <RawFont.hpp>
#include "log/log.hpp"

namespace gui
{


@@ 23,17 24,22 @@ namespace gui

    /// Note - line breaking could be done here with different TextLines to return
    /// or via different block types (i.e. numeric block tyle could be not "breakable"
    TextLine::TextLine(TextDocument *document, unsigned int start_position, unsigned int max_width)
    TextLine::TextLine(Item *parent, TextDocument *document, unsigned int start_position, unsigned int max_width)
    {
        if (document == nullptr) {
            return;
        }

        this->parent = parent;

        auto cursor     = document->getBlockCursor(start_position);
        auto old_cursor = cursor;
        do {

            if (!cursor) { // cursor is faulty
                return;
            }

            // it would be better if cursor would know what to do when it jumps over blocks
            if (old_cursor.getBlockNr() != cursor.getBlockNr() &&
                (*document)(old_cursor).getEnd() == TextBlock::End::Newline) {


@@ 46,6 52,7 @@ namespace gui
            if (text_format->getFont() == nullptr) {
                return;
            }

            auto can_show = text_format->getFont()->getCharCountInSpace(text_part.text, max_width - width_used);

            // we can show nothing - this is the end of this line


@@ 58,6 65,7 @@ namespace gui
            number_letters_shown += can_show;
            width_used += item->getTextNeedSpace();
            height_used = std::max(height_used, item->getTextHeight());

            elements_to_show_in_line.emplace_back(item);

            // not whole text shown, try again for next line if you want


@@ 109,7 117,7 @@ namespace gui
        }
    };

    void TextLine::setPosition(int32_t x, int32_t y)
    void TextLine::setPosition(const short &x, const short &y)
    {
        auto line_x_position = x;
        for (auto &el : elements_to_show_in_line) {


@@ 125,6 133,15 @@ namespace gui
        if (parent == nullptr) {
            return;
        }

        setArea({int16_t(0), int16_t(0), uint16_t(100), uint16_t(100)});
        setEdges(RectangleEdgeFlags::GUI_RECT_ALL_EDGES);
        setFillColor(ColorFullBlack);
        setFilled(true);
        updateDrawArea();

        LOG_INFO("Rozmiar i pozycja tego gówna %d, %d, %d, %d", widgetArea.x, widgetArea.y, widgetArea.w, widgetArea.h);

        for (auto &el : elements_to_show_in_line) {
            parent->addWidget(el);
        }

M module-gui/gui/widgets/TextLine.hpp => module-gui/gui/widgets/TextLine.hpp +6 -6
@@ 9,7 9,7 @@ namespace gui
{

    /// interface element for TextDocument->getLine() <-- Text
    class TextLine
    class TextLine : public Rect
    {
        unsigned int number_letters_shown = 0;
        Length width_used                 = 0;


@@ 19,7 19,7 @@ namespace gui
      public:
        /// creates TextLine with data from text from start position in `TextDocument` filling max_width
        /// @note might be better to have TextBlockIterator which could hop through TextBlock inside TextDocument
        TextLine(TextDocument *, unsigned int start_position, unsigned int max_width);
        TextLine(Item *parent, TextDocument *, unsigned int start_position, unsigned int max_width);
        ~TextLine();
        TextLine(TextLine &) = delete;
        TextLine(TextLine &&);


@@ 63,11 63,11 @@ namespace gui
            return elements_to_show_in_line.front()->area().pos(Axis::X);
        }

        void setPosition(int32_t x, int32_t y);
        void setPosition(const short &x, const short &y) override;
        void setParent(Item *parent);
        Length getWidth() const;
        Length getWidthTo(unsigned int pos) const;
        void erase();
        [[nodiscard]] Length getWidth() const override;
        [[nodiscard]] Length getWidthTo(unsigned int pos) const;
        void erase() override;
        /// align TextLine due to alignment axis in parent_width
        ///
        /// moves Text parts in Text. To not call n times callbacks on resize, call prior to setting parent