Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix gray box & remove multiple line text support for NewButton #2426

Merged

Conversation

zxkmm
Copy link
Contributor

@zxkmm zxkmm commented Dec 15, 2024

  • fix bad gray box in the left-bottom corner and right-bottom corner
  • this feat was implemented in sdcard format detect and warn user #2420
  • Currently it's not worth to consume performance for this feature, until in the future, developers want that feature
  • whoever want this feature can manually add this back:
void NewButton::paint(Painter& painter) {
    if (!bitmap_ && text_.empty())
        return;

    const auto r = screen_rect();
    const Style style = paint_style();

    painter.draw_rectangle({r.location(), {r.width(), 1}}, Theme::getInstance()->bg_light->background);
    painter.draw_rectangle({r.left(), r.top() + r.height() - 1, r.width(), 1}, Theme::getInstance()->bg_dark->background);
    painter.draw_rectangle({r.left() + r.width() - 1, r.top(), 1, r.height()}, Theme::getInstance()->bg_dark->background);

    painter.fill_rectangle(
        {r.left(), r.top() + 1, r.width() - 1, r.height() - 2},
        style.background);

    int y = r.top();

    if (bitmap_) {
        int offset_y = vertical_center_ ? (r.height() / 2) - (bitmap_->size.height() / 2) : 6;
        Point bmp_pos = {r.left() + (r.width() / 2) - (bitmap_->size.width() / 2), r.top() + offset_y};
        y += bitmap_->size.height() + offset_y;

        painter.draw_bitmap(
            bmp_pos,
            *bitmap_,
            color_,
            style.background);
    }

    if (!text_.empty()) {
        // multi line worker
        std::vector<std::string> lines;
        size_t start = 0;
        size_t end = 0;

        while ((end = text_.find('\n', start)) != std::string::npos) {
            lines.push_back(text_.substr(start, end - start));
            start = end + 1;
        }
        lines.push_back(text_.substr(start));

        const int line_height = style.font.line_height();
        const int total_text_height = lines.size() * line_height;

        // satisfy the situation that bitmap is nullptr
        if (bitmap_) {
            if (vertical_center_) {
                y = r.top() + (r.height() - total_text_height) / 2;
            }
            y += 3;
        } else {
            y = r.top() + (r.height() - total_text_height) / 2;
        }

        // draw worker
        for (const auto& line : lines) {
            const auto label_r = style.font.size_of(line);
            painter.draw_string(
                {r.left() + (r.width() - label_r.width()) / 2, y},
                style,
                line);
            y += line_height;
        }
    }
}
  • since this feat were gone, I tuned the display string in grid (which is the only place that using this feat) to allow the width (in the receive or transmit menu, the grid is smaller)

@zxkmm zxkmm marked this pull request as ready for review December 15, 2024 14:09
@zxkmm zxkmm changed the title remove multiple line text support for NewButton fix gray box & remove multiple line text support for NewButton Dec 15, 2024
Copy link
Member

@gullradriel gullradriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

@gullradriel gullradriel merged commit 42da744 into portapack-mayhem:next Dec 15, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants