MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / AlertDialogApp

Class AlertDialogApp

Tactility/Source/app/alertdialog/AlertDialog.cpp:67–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65
66
67class AlertDialogApp : public App {
68
69 static void onButtonClickedCallback(lv_event_t* e) {
70 auto app = std::static_pointer_cast<AlertDialogApp>(getCurrentApp());
71 assert(app != nullptr);
72 app->onButtonClicked(e);
73 }
74
75 void onButtonClicked(lv_event_t* e) {
76 auto index = reinterpret_cast<std::size_t>(lv_event_get_user_data(e));
77 LOGGER.info("Selected item at index {}", index);
78
79 auto bundle = std::make_unique<Bundle>();
80 bundle->putInt32(RESULT_BUNDLE_KEY_INDEX, (int32_t)index);
81 setResult(Result::Ok, std::move(bundle));
82
83 stop(manifest.appId);
84 }
85
86 static void createButton(lv_obj_t* parent, const std::string& text, size_t index) {
87 lv_obj_t* button = lv_button_create(parent);
88 lv_obj_t* button_label = lv_label_create(button);
89 lv_obj_align(button_label, LV_ALIGN_CENTER, 0, 0);
90 lv_label_set_text(button_label, text.c_str());
91 lv_obj_add_event_cb(button, onButtonClickedCallback, LV_EVENT_SHORT_CLICKED, (void*)index);
92 }
93
94public:
95
96 void onShow(AppContext& app, lv_obj_t* parent) override {
97 auto parameters = app.getParameters();
98 check(parameters != nullptr, "Parameters missing");
99
100 std::string title = getTitleParameter(app.getParameters());
101 lv_obj_t* toolbar = lvgl::toolbar_create(parent, title);
102 lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
103
104 lv_obj_t* message_label = lv_label_create(parent);
105 lv_obj_align(message_label, LV_ALIGN_CENTER, 0, 0);
106 lv_obj_set_width(message_label, LV_PCT(80));
107 lv_obj_set_style_text_align(message_label, LV_TEXT_ALIGN_CENTER, 0);
108
109 std::string message;
110 if (parameters->optString(PARAMETER_BUNDLE_KEY_MESSAGE, message)) {
111 lv_label_set_text(message_label, message.c_str());
112 lv_label_set_long_mode(message_label, LV_LABEL_LONG_WRAP);
113 }
114
115 lv_obj_t* button_wrapper = lv_obj_create(parent);
116 lv_obj_set_flex_flow(button_wrapper, LV_FLEX_FLOW_ROW);
117 lv_obj_set_size(button_wrapper, LV_PCT(100), LV_SIZE_CONTENT);
118 lv_obj_set_style_pad_all(button_wrapper, 0, 0);
119 lv_obj_set_flex_align(button_wrapper, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
120 lv_obj_set_style_border_width(button_wrapper, 0, 0);
121 lv_obj_align(button_wrapper, LV_ALIGN_BOTTOM_MID, 0, -4);
122
123 std::string items_concatenated;
124 if (parameters->optString(PARAMETER_BUNDLE_KEY_BUTTON_LABELS, items_concatenated)) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected