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

Method createDirEntryWidget

Tactility/Source/app/files/View.cpp:322–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320}
321
322void View::createDirEntryWidget(lv_obj_t* list, dirent& dir_entry) {
323 check(list);
324 const char* symbol;
325 if (dir_entry.d_type == file::TT_DT_DIR || dir_entry.d_type == file::TT_DT_CHR) {
326 symbol = LV_SYMBOL_DIRECTORY;
327 } else if (isSupportedImageFile(dir_entry.d_name)) {
328 symbol = LV_SYMBOL_IMAGE;
329 } else if (dir_entry.d_type == file::TT_DT_LNK) {
330 symbol = LV_SYMBOL_LOOP;
331 } else {
332 symbol = LV_SYMBOL_FILE;
333 }
334
335 // Get file size for regular files
336 std::string label_text = dir_entry.d_name;
337 if (dir_entry.d_type == file::TT_DT_REG) {
338 std::string file_path = file::getChildPath(state->getCurrentPath(), dir_entry.d_name);
339 struct stat st;
340 if (stat(file_path.c_str(), &st) == 0) {
341 // Format file size in human-readable format
342 const char* size_suffix;
343 double size;
344 if (st.st_size < 1024) {
345 size = st.st_size;
346 size_suffix = " B";
347 } else if (st.st_size < 1024 * 1024) {
348 size = st.st_size / 1024.0;
349 size_suffix = " KB";
350 } else {
351 size = st.st_size / (1024.0 * 1024.0);
352 size_suffix = " MB";
353 }
354
355 char size_str[32];
356 if (st.st_size < 1024) {
357 snprintf(size_str, sizeof(size_str), " (%d%s)", (int)size, size_suffix);
358 } else {
359 snprintf(size_str, sizeof(size_str), " (%.1f%s)", size, size_suffix);
360 }
361 label_text += size_str;
362 }
363 }
364
365 lv_obj_t* button = lv_list_add_button(list, symbol, label_text.c_str());
366 lv_obj_add_event_cb(button, &onDirEntryPressedCallback, LV_EVENT_SHORT_CLICKED, this);
367 lv_obj_add_event_cb(button, &onDirEntryLongPressedCallback, LV_EVENT_LONG_PRESSED, this);
368}
369
370void View::onNavigateUpPressed() {
371 if (state->getCurrentPath() != "/") {

Callers

nothing calls this directly

Calls 5

isSupportedImageFileFunction · 0.85
getChildPathFunction · 0.85
statClass · 0.70
checkFunction · 0.50
getCurrentPathMethod · 0.45

Tested by

no test coverage detected