Ken Van Hoeylandt 3ea02d912f
Merge develop into main (#167)
- WiFi Connect app is now hidden by default, but accessible at the bottom of the WiFi Manage app when WiFi is turned on.
- WiFi service now turns on WiFi when calling connect() and WiFi is not on.
- Removed `blocking` option for `service::loader::startApp()`. This feature was unused and complex.
- Various apps: Moved private headers into Private/ folder.
- Various apps: created start() function for easy starting.
- Added documentation to all TactilityC APIs
- Refactored various `enum` into `class enum`
- Refactor M5Stack `initBoot()` (but VBus is still 0V for some reason)
2025-01-17 19:37:42 +01:00

68 lines
2.3 KiB
C++

#include <TactilityCore.h>
#include "lvgl.h"
#include "lvgl/Style.h"
#include "lvgl/Toolbar.h"
#include "StringUtils.h"
#include "service/loader/Loader.h"
namespace tt::app::imageviewer {
extern const AppManifest manifest;
#define TAG "image_viewer"
#define IMAGE_VIEWER_FILE_ARGUMENT "file"
static void onShow(AppContext& app, lv_obj_t* parent) {
auto wrapper = lv_obj_create(parent);
lv_obj_set_size(wrapper, LV_PCT(100), LV_PCT(100));
lv_obj_set_style_border_width(wrapper, 0, 0);
lvgl::obj_set_style_no_padding(wrapper);
auto toolbar = lvgl::toolbar_create(wrapper, app);
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
auto* image_wrapper = lv_obj_create(wrapper);
lv_obj_align_to(image_wrapper, toolbar, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
lv_obj_set_width(image_wrapper, LV_PCT(100));
auto parent_height = lv_obj_get_height(wrapper);
lv_obj_set_height(image_wrapper, parent_height - TOOLBAR_HEIGHT);
lv_obj_set_flex_flow(image_wrapper, LV_FLEX_FLOW_COLUMN);
lv_obj_set_flex_align(image_wrapper, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lvgl::obj_set_style_no_padding(image_wrapper);
lvgl::obj_set_style_bg_invisible(image_wrapper);
auto* image = lv_image_create(image_wrapper);
lv_obj_align(image, LV_ALIGN_CENTER, 0, 0);
auto* file_label = lv_label_create(wrapper);
lv_obj_align_to(file_label, wrapper, LV_ALIGN_BOTTOM_LEFT, 0, 0);
std::shared_ptr<const Bundle> bundle = app.getParameters();
tt_check(bundle != nullptr, "Parameters not set");
std::string file_argument;
if (bundle->optString(IMAGE_VIEWER_FILE_ARGUMENT, file_argument)) {
std::string prefixed_path = "A:" + file_argument;
TT_LOG_I(TAG, "Opening %s", prefixed_path.c_str());
lv_img_set_src(image, prefixed_path.c_str());
auto path = string::getLastPathSegment(file_argument);
lv_label_set_text(file_label, path.c_str());
} else {
lv_label_set_text(file_label, "File not found");
}
}
extern const AppManifest manifest = {
.id = "ImageViewer",
.name = "Image Viewer",
.type = TypeHidden,
.onShow = onShow
};
void start(const std::string& file) {
auto parameters = std::make_shared<Bundle>();
parameters->putString(IMAGE_VIEWER_FILE_ARGUMENT, file);
service::loader::startApp(manifest.id, parameters);
}
} // namespace