Skip to content

Commit

Permalink
fix gray box & remove multiple line text support for NewButton (#2426)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxkmm authored Dec 15, 2024
1 parent ee10081 commit 42da744
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 36 deletions.
2 changes: 1 addition & 1 deletion firmware/application/ui_navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ static void add_apps(NavigationView& nav, BtnGridView& grid, app_location_t loc)
void add_external_items(NavigationView& nav, app_location_t location, BtnGridView& grid, uint8_t error_tile_pos) {
auto externalItems = ExternalItemsMenuLoader::load_external_items(location, nav);
if (externalItems.empty()) {
grid.insert_item({"ExtApp\nError",
grid.insert_item({"ExtAppErr",
Theme::getInstance()->error_dark->foreground,
nullptr,
[&nav]() {
Expand Down
2 changes: 1 addition & 1 deletion firmware/application/ui_navigation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class InformationView : public View {

Rectangle backdrop{
{0, 0 * 16, 240, 16},
{33, 33, 33}};
Theme::getInstance()->bg_darker->background};

Text version{
{2, 0, 11 * 8, 16},
Expand Down
40 changes: 6 additions & 34 deletions firmware/common/ui_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1327,11 +1327,10 @@ void NewButton::paint(Painter& painter) {
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;
y += bitmap_->size.height() - offset_y;

painter.draw_bitmap(
bmp_pos,
Expand All @@ -1341,38 +1340,11 @@ void NewButton::paint(Painter& painter) {
}

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;
}
} 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;
}
const auto label_r = style.font.size_of(text_);
painter.draw_string(
{r.left() + (r.width() - label_r.width()) / 2, y + (r.height() - label_r.height()) / 2},
style,
text_);
}
}

Expand Down

0 comments on commit 42da744

Please sign in to comment.