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

58 lines
1.7 KiB
C++

#include <TactilityCore.h>
#include "TextViewer.h"
#include "lvgl.h"
#include "lvgl/LabelUtils.h"
#include "lvgl/Style.h"
#include "lvgl/Toolbar.h"
#include "service/loader/Loader.h"
#define TAG "text_viewer"
#define TEXT_VIEWER_FILE_ARGUMENT "file"
namespace tt::app::textviewer {
static void onShow(AppContext& app, lv_obj_t* parent) {
lv_obj_set_flex_flow(parent, LV_FLEX_FLOW_COLUMN);
lvgl::toolbar_create(parent, app);
lv_obj_t* wrapper = lv_obj_create(parent);
lv_obj_set_width(wrapper, LV_PCT(100));
lv_obj_set_flex_grow(wrapper, 1);
lv_obj_set_flex_flow(wrapper, LV_FLEX_FLOW_COLUMN);
lvgl::obj_set_style_no_padding(wrapper);
lvgl::obj_set_style_bg_invisible(wrapper);
lv_obj_t* label = lv_label_create(wrapper);
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
auto parameters = app.getParameters();
tt_check(parameters != nullptr, "Parameters missing");
bool success = false;
std::string file_argument;
if (parameters->optString(TEXT_VIEWER_FILE_ARGUMENT, file_argument)) {
TT_LOG_I(TAG, "Opening %s", file_argument.c_str());
if (lvgl::label_set_text_file(label, file_argument.c_str())) {
success = true;
}
}
if (!success) {
lv_label_set_text_fmt(label, "Failed to load %s", file_argument.c_str());
}
}
extern const AppManifest manifest = {
.id = "TextViewer",
.name = "Text Viewer",
.type = TypeHidden,
.onShow = onShow
};
void start(const std::string& file) {
auto parameters = std::make_shared<Bundle>();
parameters->putString(TEXT_VIEWER_FILE_ARGUMENT, file);
service::loader::startApp(manifest.id, parameters);
}
} // namespace