Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions main/ui/appstore_image_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,38 @@ lv_obj_t *AppStoreImageRenderer::draw_packaged(lv_obj_t *root, const std::string
}

bool AppStoreImageRenderer::draw_app_icon(lv_obj_t *root, const std::string &app_dir,
const appstore::StoreApp &app)
const appstore::StoreApp &app, int x, int y,
int size)
{
#if LV_USE_LODEPNG && LV_USE_FS_POSIX
const std::string path = icon_file_path(app_dir, app);
if (path.empty()) return false;
constexpr int x = 39, y = 65, width = 60, height = 60;
if (path.empty() || size <= 0) return false;
lv_obj_t *clip = lv_obj_create(root);
lv_obj_remove_style_all(clip);
lv_obj_set_pos(clip, x, y);
lv_obj_set_size(clip, width, height);
lv_obj_set_size(clip, size, size);
lv_obj_clear_flag(clip, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_set_style_bg_opa(clip, LV_OPA_TRANSP, 0);
lv_obj_set_style_border_width(clip, 0, 0);
lv_obj_set_style_radius(clip, 10, 0);
lv_obj_set_style_radius(clip, std::max(4, size / 6), 0);
lv_obj_set_style_clip_corner(clip, true, 0);
lv_obj_set_style_pad_all(clip, 0, 0);
lv_obj_t *icon = lv_image_create(clip);
lv_image_set_src(icon, retain_source(lvgl_posix_src(path)));
lv_obj_update_layout(icon);
int image_width = lv_obj_get_width(icon);
int image_height = lv_obj_get_height(icon);
if (image_width <= 0) image_width = 256;
if (image_height <= 0) image_height = 256;
int scale = std::min(width * 256 / image_width, height * 256 / image_height);
if (image_width <= 0) image_width = size;
if (image_height <= 0) image_height = size;
int scale = std::min(size * 256 / image_width, size * 256 / image_height);
if (scale <= 0) scale = 1;
lv_image_set_scale(icon, static_cast<uint16_t>(scale));
lv_obj_set_pos(icon, (width - image_width) / 2, (height - image_height) / 2);
lv_image_set_inner_align(icon, LV_IMAGE_ALIGN_CENTER);
lv_obj_set_pos(icon, 0, 0);
lv_obj_set_size(icon, size, size);
return true;
#else
(void)root; (void)app_dir; (void)app;
(void)root; (void)app_dir; (void)app; (void)x; (void)y; (void)size;
return false;
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion main/ui/appstore_image_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AppStoreImageRenderer
// Returns the image so callers can align it by its real size; null on failure.
lv_obj_t *draw_packaged(lv_obj_t *root, const std::string &name, int x, int y);
bool draw_app_icon(lv_obj_t *root, const std::string &app_dir,
const appstore::StoreApp &app);
const appstore::StoreApp &app, int x, int y, int size);
bool draw_screenshot(lv_obj_t *root, const std::string &path);
// Returns the aspect-preserving row height, or zero when decoding fails.
int draw_thumbnail(lv_obj_t *root, const std::string &path, int x, int y);
Expand Down
127 changes: 68 additions & 59 deletions main/ui/appstore_pages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,25 +606,28 @@ void CatalogDisplayPage::render(const PageRenderContext &context,
box(root, 0, 20, 320, 150, 0x081010, 0x081010, 0);
draw_category();
draw_icon();
const lv_font_t *header_font = store_font("", 12);
const int header_y = catalog_header::kCenterY - glyph_middle(header_font, 'H');
label(root, "In category: " + std::to_string(model.show_empty ? 0 : model.selected_index + 1) +
"/" + std::to_string(model.app_count), 138, 26, 116, 18,
store_font("", 12), 0xFFFFFF, LV_LABEL_LONG_DOT);
label(root, "All: " + std::to_string(model.total_count), 256, 26, 64, 18,
store_font("", 12), 0xFFFFFF, LV_LABEL_LONG_DOT);
"/" + std::to_string(model.app_count), 138, header_y, 116, header_font->line_height,
header_font, 0xFFFFFF, LV_LABEL_LONG_DOT);
label(root, std::to_string(model.total_count), catalog_header::kCountX,
header_y, 318 - catalog_header::kCountX, header_font->line_height,
header_font, 0xFFFFFF, LV_LABEL_LONG_DOT);
if (model.show_empty) {
label(root, model.empty_message, 137, 76, 178, 40,
store_font(model.empty_message, 14), 0xFFFFFF, LV_LABEL_LONG_WRAP);
} else {
marquee_label(root, model.name, 137, 58, 178, 27, store_font(model.name, 20, true),
0xFFFFFF, title_marquee_, model.name);
label(root, model.version, 137, 86, 66, 20,
store_font(model.version, 14), 0xFFFFFF, LV_LABEL_LONG_DOT);
store_font(model.version, 14), kVersionColor, LV_LABEL_LONG_DOT);
marquee_label(root, model.author, 207, 86, 108, 20, store_font(model.author, 14),
0xFFFFFF, author_marquee_, model.name + model.author);
kMaintainerColor, author_marquee_, model.name + model.author);
label(root, model.size, 137, 105, 68, 20,
store_font(model.size, 14), 0xFFFFFF, LV_LABEL_LONG_DOT);
store_font(model.size, 14), kSizeColor, LV_LABEL_LONG_DOT);
label(root, model.updated, 207, 105, 110, 20,
store_font(model.updated, 14), 0xFFFFFF, LV_LABEL_LONG_DOT);
store_font(model.updated, 14), kDateColor, LV_LABEL_LONG_DOT);
if (model.update_available)
label(root, "UPDATE AVAILABLE", 137, 126, 178, 11,
&lv_font_montserrat_10, 0xF0B429);
Expand Down Expand Up @@ -849,74 +852,80 @@ void AppDetailPage::render_confirmation(const PageRenderContext &context,
context.prepare();
context.draw_system_bar();
lv_obj_t *root = screen();
box(root, 0, 20, 320, 150, 0x0D1117, 0x0D1117, 0);
box(root, 0, 20, 320, 150, kPageBackground, kPageBackground, 0);
const bool ownership_conflict =
!model.lines.empty() && model.lines[0] == "FILE OWNERSHIP CONFLICT";
const bool safety_warning = model.lines.size() >= 4 &&
model.lines[1].find("cannot verify") != std::string::npos;
const uint32_t accent = ownership_conflict || safety_warning ? 0xF85149 : 0x58A6FF;
const uint32_t header = ownership_conflict || safety_warning ? 0x8B2F34 : 0x1F6FEB;
box(root, 18, 30, 284, 116, 0x111923, accent, 2, 4);
box(root, 18, 30, 284, 23, header, header, 0);
center_strong_label(root, ownership_conflict ? "FORCE OVERWRITE?" :
(safety_warning ? "SAFETY WARNING" : "CONFIRM ACTION"),
38, 35, 244, 15,
&lv_font_montserrat_12, 0xFFFFFF);
int y = 60;
for (size_t index = 0; index < model.lines.size(); ++index) {
const std::string &line_text = model.lines[index];
const bool warning = ownership_conflict || safety_warning;
box(root, 18, 26, 284, 122, 0x1C1C1E, 0x2C2C2E, 1, 14);
const std::string heading = ownership_conflict ? "Force overwrite?" :
(safety_warning ? "Safety warning" : "Confirm action");
const lv_font_t *heading_font = store_font(heading, 15, true);
center_strong_label(root, heading, 28, 33, 264, heading_font->line_height,
heading_font, warning ? 0xFF9F0A : 0xFFFFFF);
int y = 56;
for (size_t index = 0; index < model.lines.size() && index < 4; ++index) {
const std::string &text = model.lines[index];
const bool action_line = index == 0 && !ownership_conflict;
center_strong_label(root, appstore::one_line(line_text, 44),
28, y, 264, action_line ? 15 : 12,
action_line ? &lv_font_montserrat_12 : &lv_font_montserrat_10,
index >= 1 && safety_warning ? 0xFFD2D2 : 0xE6EDF3,
LV_LABEL_LONG_DOT);
const lv_font_t *font = store_font(text, action_line ? 12 : 10);
marquee_label(root, text, 28, y, 264, font->line_height, font,
action_line ? 0xFFFFFF : (warning ? 0xFFD2D2 : kSecondaryText),
confirmation_marquees_[index], text, LV_TEXT_ALIGN_CENTER);
y += action_line ? 18 : 14;
if (y > 111) break;
}
const bool yes = model.focus == 0;
const bool no = model.focus == 1;
box(root, 62, 122, 84, 17, yes ? 0x2EA043 : 0x1A6A2A,
yes ? 0xCCCC33 : 0x2EA043, yes ? 2 : 1);
center_strong_label(root, "YES", 66, 125, 76, 12,
&lv_font_montserrat_10, 0xFFFFFF);
box(root, 174, 122, 84, 17, no ? 0x8B2F34 : 0x4B1F24,
no ? 0xCCCC33 : 0xF85149, no ? 2 : 1);
center_strong_label(root, "NO", 178, 125, 76, 12,
&lv_font_montserrat_10, 0xFFFFFF);
const char *const buttons[] = {"Yes", "No"};
for (int i = 0; i < 2; ++i) {
const bool focused = model.focus == i;
const int x = 32 + i * 132;
const uint32_t fill = focused ? (i == 0 && warning ? 0xD63B30 : kSystemBlue)
: kSystemGray;
box(root, x, 118, 124, 26, fill, fill, 0, 8);
const lv_font_t *font = store_font(buttons[i], 13);
center_strong_label(root, buttons[i], x, 131 - glyph_middle(font, 'H'),
124, font->line_height, font, 0xFFFFFF);
}
key_hint(root, "enter", "Confirm", 160, 159);
}

void AppDetailPage::render_progress(const PageRenderContext &context,
const PackageProgressViewModel &model)
const PackageProgressViewModel &model,
const std::function<void(lv_obj_t *, int, int, int)> &draw_logo)
{
using namespace startup;
context.prepare();
context.draw_system_bar();
lv_obj_t *root = screen();
box(root, 0, 20, 320, 150, 0x0D1117, 0x0D1117, 0);
box(root, 0, 20, 320, 22, 0x1F6FEB, 0x1F6FEB, 0);
label(root, "Package Operation", 8, 24, 190, 15, &lv_font_montserrat_12, 0xFFFFFF);
label(root, "Esc Exit", 262, 24, 52, 14, &lv_font_montserrat_10, 0xAECBFA);
center_strong_label(root, appstore::upper_ascii(model.action), 24, 50, 272, 18,
&lv_font_montserrat_14, 0xCCCC33, LV_LABEL_LONG_DOT);
const std::string title = appstore::one_line(model.title, 26);
center_strong_label(root, title, 24, 70, 272, 16,
context.font_for_text(title, &lv_font_montserrat_12),
0xE6EDF3, LV_LABEL_LONG_DOT);
box(root, 28, 92, 264, 12, 0x30363D, 0x30363D, 0, 2);
box(root, 0, 20, 320, 150, kPageBackground, kPageBackground, 0);
draw_logo(root, (320 - kLogoSize) / 2, kLogoY, kLogoSize);
const std::string action = model.action + "...";
const lv_font_t *action_font = store_font(action, 15, true);
center_strong_label(root, action, 10, kTitleCapsY - glyph_top(action_font, 'H'),
300, action_font->line_height, action_font, 0xFFFFFF);
const lv_font_t *title_font = store_font(model.title, 12);
marquee_label(root, model.title, 10, 99, 300, title_font->line_height, title_font,
0xFFFFFF, progress_title_marquee_, model.action + model.title,
LV_TEXT_ALIGN_CENTER);
constexpr int bar_y = 119;
lv_obj_t *track = box(root, kBarX, bar_y, kBarWidth, kBarHeight,
kSystemGray, kSystemGray, 0, kBarHeight / 2);
lv_obj_clear_flag(track, LV_OBJ_FLAG_SCROLLABLE);
if (model.progress >= 0) {
const int fill = std::max(4, std::min(264, model.progress * 264 / 100));
box(root, 28, 92, fill, 12, 0xCCCC33, 0xCCCC33, 0, 2);
box(track, 0, 0, progress_width(model.progress), kBarHeight,
kSystemBlue, kSystemBlue, 0, kBarHeight / 2);
} else {
const int offset = static_cast<int>((lv_tick_get() / 90) % 216);
box(root, 28 + offset, 92, 48, 12, 0xCCCC33, 0xCCCC33, 0, 2);
sweep_progress(track);
}
center_label(root, appstore::one_line(model.detail, 48), 18, 113, 284, 14,
&lv_font_montserrat_10, 0xB8B8B8, LV_LABEL_LONG_DOT);
center_strong_label(root, "Elapsed " + std::to_string(model.elapsed_seconds) + "s",
88, 132, 144, 13, &lv_font_montserrat_10, 0x58A6FF,
LV_LABEL_LONG_DOT);
center_label(root, "Keep Store open until this finishes.", 18, 153, 284, 12,
&lv_font_montserrat_10, 0xCCCC33, LV_LABEL_LONG_DOT);
const lv_font_t *detail_font = store_font(model.detail, 10);
marquee_label(root, model.detail, 10, 128, 300, detail_font->line_height, detail_font,
kSecondaryText, progress_detail_marquee_, model.detail,
LV_TEXT_ALIGN_CENTER);
const std::string footer = "Keep Store open \xC2\xB7 " +
std::to_string(model.elapsed_seconds) + "s";
const lv_font_t *footer_font = store_font(footer, 10);
center_label(root, footer, 10, kHintMiddle - glyph_middle(footer_font, 'H'),
300, footer_font->line_height, footer_font, kSecondaryText,
LV_LABEL_LONG_DOT);
}

void AppDetailPage::render_error(const PageRenderContext &context,
Expand Down
13 changes: 12 additions & 1 deletion main/ui/appstore_pages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ namespace appstore_ui {

void render_exit_hint(lv_obj_t *root);

namespace catalog_header {
constexpr int kCenterY = 34;
constexpr int kCountIconX = 258;
constexpr int kCountIconSize = 24;
constexpr int kCountX = kCountIconX + kCountIconSize + 4;
} // namespace catalog_header

// Middle of a glyph's ink, measured from the top of the font's line box.
int glyph_middle(const lv_font_t *font, uint32_t letter);

Expand Down Expand Up @@ -92,7 +99,8 @@ class AppDetailPage : public AppStoreUiPage
void render_confirmation(const PageRenderContext &context,
const ConfirmationViewModel &model);
void render_progress(const PageRenderContext &context,
const PackageProgressViewModel &model);
const PackageProgressViewModel &model,
const std::function<void(lv_obj_t *, int, int, int)> &draw_logo);
void render_error(const PageRenderContext &context,
const ErrorDialogViewModel &model);
void render_screenshot_overlay(const PageRenderContext &context,
Expand All @@ -103,6 +111,9 @@ class AppDetailPage : public AppStoreUiPage

HorizontalMarquee title_marquee_;
HorizontalMarquee author_marquee_;
HorizontalMarquee confirmation_marquees_[4];
HorizontalMarquee progress_title_marquee_;
HorizontalMarquee progress_detail_marquee_;
// The drawn page, cleared when the page content is deleted.
lv_obj_t *document_ = nullptr;
lv_obj_t *top_fade_ = nullptr;
Expand Down
58 changes: 50 additions & 8 deletions main/ui/appstore_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,31 @@ void AppStorePresenter::prepare(AppStoreUiPage &page)

void AppStorePresenter::draw_category_selector(lv_obj_t *root)
{
if (!images_.draw_packaged(root, "store_arrow_left.png", 14, 27))
strong_label(root, "<", 14, 24, 14, 18, store_font("", 20), 0xFF6A3D);
const auto draw_chevron = [&](const char *asset, const char *fallback, int x) {
if (lv_obj_t *arrow = images_.draw_packaged(root, asset, x, 0)) {
lv_obj_set_y(arrow, catalog_header::kCenterY - lv_obj_get_height(arrow) / 2);
} else {
const lv_font_t *font = store_font(fallback, 20);
strong_label(root, fallback, x,
catalog_header::kCenterY - glyph_middle(font, fallback[0]),
14, font->line_height, font, 0xFF6A3D);
}
};
draw_chevron("store_arrow_left.png", "<", 14);
const std::string category = appstore::upper_ascii(session_.catalog.current_category_name());
marquee_label(root, category, 28, 24, 86, 20, store_font(category, 14, true), 0xFFFFFF,
const lv_font_t *font = store_font(category, 14, true);
marquee_label(root, category, 28, catalog_header::kCenterY - glyph_middle(font, 'H'),
86, font->line_height, font, 0xFFFFFF,
category_marquee_, category, LV_TEXT_ALIGN_CENTER);
if (!images_.draw_packaged(root, "store_arrow_right.png", 116, 27))
strong_label(root, ">", 116, 24, 14, 18, store_font("", 20), 0xFF6A3D);
draw_chevron("store_arrow_right.png", ">", 116);
if (!draw_store_icon(root, images_, catalog_header::kCountIconX,
catalog_header::kCenterY - catalog_header::kCountIconSize / 2,
catalog_header::kCountIconSize)) {
const lv_font_t *icon_font = &lv_font_montserrat_14;
label(root, LV_SYMBOL_LIST, catalog_header::kCountIconX,
catalog_header::kCenterY - icon_font->line_height / 2,
catalog_header::kCountIconSize, icon_font->line_height, icon_font, 0xFFFFFF);
}
}

void AppStorePresenter::draw_home_icon_panel(lv_obj_t *root,
Expand All @@ -148,7 +166,8 @@ void AppStorePresenter::draw_home_icon_panel(lv_obj_t *root,
if (!app) {
center_strong_label(root, "-", kHomeIconX + 22, kHomeIconY + 24, 24, 22,
&lv_font_montserrat_20, 0x9A9A9A);
} else if (!images_.draw_app_icon(root, session_.app_dir, *app)) {
} else if (!images_.draw_app_icon(root, session_.app_dir, *app,
kHomeIconX, kHomeIconY, kHomeIconSize)) {
center_strong_label(root, app_initial(*app), kHomeIconX, kHomeIconY + 21,
kHomeIconSize, 28, &lv_font_montserrat_20,
app->installed ? 0x52D05D : 0xFFFFFF);
Expand Down Expand Up @@ -215,9 +234,32 @@ void AppStorePresenter::render(Screen screen, bool registry_operation_running)
case Screen::Confirm:
detail_page_.render_confirmation(context(detail_page_), view_models_.confirmation());
break;
case Screen::Progress:
detail_page_.render_progress(context(detail_page_), view_models_.progress(lv_tick_get()));
case Screen::Progress: {
const PackageProgressViewModel model = view_models_.progress(lv_tick_get());
const appstore::StoreApp *app = nullptr;
for (const auto &candidate : session_.catalog.apps()) {
if (candidate.id == model.app_id) {
app = &candidate;
break;
}
}
detail_page_.render_progress(
context(detail_page_), model,
[this, app](lv_obj_t *root, int x, int y, int size) {
if (app && images_.draw_app_icon(root, session_.app_dir, *app, x, y, size))
return;
if (!app) {
draw_store_icon(root, images_, x, y, size);
return;
}
const lv_font_t *font = size >= 40 ? &lv_font_montserrat_20
: &lv_font_montserrat_14;
center_strong_label(root, app_initial(*app), x,
y + (size - font->line_height) / 2, size,
font->line_height, font, 0xFFFFFF);
});
break;
}
case Screen::ErrorDialog:
detail_page_.render_error(context(detail_page_), view_models_.error());
break;
Expand Down
1 change: 1 addition & 0 deletions main/ui/appstore_view_model_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ PackageProgressViewModel AppStoreViewModelFactory::progress(uint32_t now) const
{
PackageProgressViewModel model;
model.action = job_action_label(package_job_.action);
model.app_id = package_job_.app_id;
model.title = package_job_.title.empty() ? "Selected app" : package_job_.title;
model.detail = package_job_.pending_start ? "Preparing package worker" :
(package_job_.detail.empty() ? "Waiting for package output" : package_job_.detail);
Expand Down
1 change: 1 addition & 0 deletions main/ui/appstore_view_models.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct ConfirmationViewModel {

struct PackageProgressViewModel {
std::string action;
std::string app_id;
std::string title;
std::string detail;
int progress = -1;
Expand Down