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
49 changes: 23 additions & 26 deletions src/apps/fmanager/fmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,8 @@ void FileManagerApp::run() {
}

void FileManagerApp::queueDraw() {
drawStatusBar();
// TODO: ToolBar part unified, so we can probably avoid overriding queueDraw at all
drawToolBar();
App::queueDraw();
}
void FileManagerApp::spaceUsageUpdate() {
Expand All @@ -1344,43 +1345,39 @@ void FileManagerApp::spaceUsageUpdate() {
}
}
}
void FileManagerApp::drawStatusBar() {
spaceUsageUpdate();
canvas->fillRect(
0, canvas->height() - STATUS_BAR_HEIGHT, canvas->width(), STATUS_BAR_HEIGHT, STATUS_BAR_FILL_COLOR
);
// Uncomment those to get an idea where is x, and where is y
// Draw xy
//canvas->drawLine(0, 0, 50, 0, lilka::colors::Red);
//canvas->drawLine(0, 0, 0, 50, lilka::colors::Blue);
// canvas->printf("Height %d, width %d", canvas->height(), canvas->width());
void FileManagerApp::drawToolBar() {
sToolBar = "";

canvas->setCursor(STATUS_BAR_SAFE_DISTANCE, canvas->height() - 20 / 2); // FONT_Y / 2
canvas->setFont(FONT_8x13);
uint16_t toolBarColor = lilka::colors::White;
uint16_t toolBarBgColor = lilka::colors::Black;

canvas->setTextBound(
STATUS_BAR_SAFE_DISTANCE, canvas->height() - STATUS_BAR_HEIGHT, STATUS_BAR_WIDTH, STATUS_BAR_HEIGHT
);
// Show errno if set
if (errno != 0) {
errnoTime = millis();
errnoStr = String(errno) + ":" + strerror(errno);
errno = 0;
}

if ((millis() - errnoTime) <= FM_ERRNO_TIME) {
canvas->setTextColor(lilka::colors::Red);
canvas->printf("%s", errnoStr.c_str());
return;
toolBarColor = lilka::colors::Red;
sToolBar = errnoStr.c_str();
}

// Other significant data to show
if (mode == FM_MODE_SELECT) {
canvas->setTextColor(lilka::colors::White);
canvas->printf(K_S_FMANAGER_SELECTED_FILES_FMT, selectedDirEntries.size());
} else if (mode == FM_MODE_VIEW) {
canvas->setTextColor(lilka::colors::White);
if (sToolBar == "" && mode == FM_MODE_SELECT) {
sToolBar = StringFormat(K_S_FMANAGER_SELECTED_FILES_FMT, selectedDirEntries.size());
}

if (sToolBar == "" && mode == FM_MODE_VIEW) {
auto fileListMenuIndex = fileListMenu.getCursor();
auto dirLength = currentDirEntries.size();
if (fileListMenuIndex != dirLength)
canvas->printf("(%s) [ %d / %d ] ", spaceUsageStr.c_str(), fileListMenuIndex + 1, dirLength);
if (fileListMenuIndex != dirLength) {
spaceUsageUpdate();
sToolBar = StringFormat("(%s) [ %d / %d ] ", spaceUsageStr.c_str(), fileListMenuIndex + 1, dirLength);
}
}

// Configure tool bar
setToolBarColor(toolBarColor, toolBarBgColor);
setToolBar(sToolBar);
}
18 changes: 7 additions & 11 deletions src/apps/fmanager/fmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,9 @@
#define FM_MKDIR_MODE 0777
#define FM_DEFAULT_NEW_FOLDER_NAME "New Folder"

// STATUS BAR SETTINGS: /////////////////////////////////////////////////////
#define STATUS_BAR_HEIGHT 30
#define STATUS_BAR_SAFE_DISTANCE 38
#define STATUS_BAR_WIDTH canvas->width() - STATUS_BAR_SAFE_DISTANCE * 2
#define STATUS_BAR_TEXT_COLOR lilka::colors::White
#define STATUS_BAR_FILL_COLOR lilka::colors::Black
#define FM_ERRNO_TIME 5000 // time to show last error
#define FM_FREE_SPACE_UPDATE 5000
// TOOL BAR SETTINGS: ///////////////////////////////////////////////////////
#define FM_ERRNO_TIME 5000 // time to show last error
#define FM_FREE_SPACE_UPDATE 5000
//////////////////////////////////////////////////////////////////////////////

#define ENTRY_NOT_FOUND_INDEX UINT16_MAX
Expand Down Expand Up @@ -111,7 +106,7 @@

// very bad test
// /sd/1 => /sd/1122/1
// no need with status bar
// no need with tool bar
#define MAKE_SANDWICH(X) \
if (0) ksystem.apps.startToast(X)

Expand Down Expand Up @@ -258,7 +253,7 @@ class FileManagerApp : public App {
int lastSpaceUsageTime = 0;

// Manual draw
void drawStatusBar();
void drawToolBar();
void spaceUsageUpdate(); // updates freeSpaceStr for current filesystem(by dir)

// Menu:
Expand Down Expand Up @@ -326,8 +321,9 @@ class FileManagerApp : public App {
std::vector<FMEntry, SPIRamAllocator<FMEntry>> currentDirEntries;
std::vector<FMEntry, SPIRamAllocator<FMEntry>> selectedDirEntries;

// Status bar stuff
// Tool bar stuff
int errnoTime = 0;
String errnoStr = "";
String spaceUsageStr = "";
String sToolBar = "";
};
16 changes: 5 additions & 11 deletions src/apps/partmanager/partmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,19 +571,13 @@ void PartManagerApp::run() {
// Drawing StatusBar //? Toolbar, right?
/////////////////////////////////////////////////////////////////////////////
void PartManagerApp::queueDraw() {
canvas->fillRect(
0, canvas->height() - STATUS_BAR_HEIGHT, canvas->width(), STATUS_BAR_HEIGHT, STATUS_BAR_FILL_COLOR
);

canvas->setCursor(STATUS_BAR_SAFE_DISTANCE, canvas->height() - 20 / 2); // FONT_Y / 2
canvas->setFont(FONT_8x13);

canvas->setTextBound(
STATUS_BAR_SAFE_DISTANCE, canvas->height() - STATUS_BAR_HEIGHT, STATUS_BAR_WIDTH, STATUS_BAR_HEIGHT
);
sToolBar = "";
if (selectedParts.size() > 0) {
canvas->printf(K_S_PART_MGR_SELECTED_ENTRIES_FMT, selectedParts.size());
sToolBar = StringFormat(K_S_PART_MGR_SELECTED_ENTRIES_FMT, selectedParts.size());
}

setToolBar(sToolBar);

App::queueDraw();
}
/////////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 3 additions & 11 deletions src/apps/partmanager/partmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@
#define PART_MGR_SELECTED_PART_ICON &selectedfile_img
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// TODO: Requires unification as additional feature of App
// StatusBar(ToolBar):
/////////////////////////////////////////////////////////////////////////////
#define STATUS_BAR_HEIGHT 30
#define STATUS_BAR_SAFE_DISTANCE 38
#define STATUS_BAR_WIDTH canvas->width() - STATUS_BAR_SAFE_DISTANCE * 2
#define STATUS_BAR_TEXT_COLOR lilka::colors::White
#define STATUS_BAR_FILL_COLOR lilka::colors::Black
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// Debug
/////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -106,4 +95,7 @@ class PartManagerApp : public App {
size_t lastProgress = 0;
// cursor of partListMenu as well as index in lilka::partitions
std::vector<size_t> selectedParts;

// ToolBar
String sToolBar = "";
};
27 changes: 27 additions & 0 deletions src/keira/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ String App::input(const String& title, const String& value, bool masked) {
return inputDialog.getValue();
}
///////////////////////////////////////////////////////////////////////////////
//========================================================================
// App UI Misc:
//========================================================================
// Set toolbar contents
void App::setToolBar(const String& toolbar) {
this->toolBarLabel = toolbar;
}
void App::setToolBarColor(uint16_t color, uint16_t bgcolor) {
this->toolBarColor = color;
this->toolBarBgColor = bgcolor;
}
//////////////////////////////////////////////////////////////////////////
//=============================================================================
// App Canvas management
//=============================================================================
Expand Down Expand Up @@ -211,6 +223,21 @@ void App::deinitCanvas() {
}
//-----------------------------------------------------------------------------
void App::queueDraw() {
// Draw toolbar on top of canvas
if (toolBarLabel != "") {
canvas->fillRect(0, canvas->height() - TOOL_BAR_HEIGHT, canvas->width(), TOOL_BAR_HEIGHT, this->toolBarBgColor);

canvas->setCursor(TOOL_BAR_SAFE_DISTANCE, canvas->height() - 20 / 2); // FONT_Y / 2
canvas->setFont(FONT_8x13);
canvas->setTextColor(this->toolBarColor);

canvas->setTextBound(
TOOL_BAR_SAFE_DISTANCE, canvas->height() - TOOL_BAR_HEIGHT, TOOL_BAR_WIDTH, TOOL_BAR_HEIGHT
);

canvas->printf(this->toolBarLabel.c_str());
}

KMTX_LOCK(canvasMutex);

// Detect if frame was skipped. Need to readjust priorities in this case
Expand Down
27 changes: 25 additions & 2 deletions src/keira/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#define APP_CAST(X) reinterpret_cast<App>(X)
#define APP_PCAST(X) reinterpret_cast<App*>(X)

// Toolbar
#define TOOL_BAR_HEIGHT 30
#define TOOL_BAR_SAFE_DISTANCE 38
#define TOOL_BAR_WIDTH canvas->width() - TOOL_BAR_SAFE_DISTANCE * 2

//============================================================================
// App Flags
//============================================================================
Expand Down Expand Up @@ -54,6 +59,8 @@ class App : public KeiraThread {
//========================================================================
void setFlags(AppFlags_t flags);
AppFlags_t getFlags();
//////////////////////////////////////////////////////////////////////////

//========================================================================
// App UI Dialogs:
//========================================================================
Expand All @@ -68,14 +75,23 @@ class App : public KeiraThread {
bool errnocheck();
// Simple lilka::InputDialog
String input(const String& title, const String& value = "", bool masked = false);
//////////////////////////////////////////////////////////////////////////

//========================================================================
// App UI Misc:
//========================================================================
// Set toolbar contents
void setToolBar(const String& toolbar);
// Set toolbar colors
void setToolBarColor(uint16_t color = lilka::colors::White, uint16_t bgcolor = lilka::colors::Black);
//////////////////////////////////////////////////////////////////////////

//========================================================================
// App Canvas management
//========================================================================
// Retrieves current redraw status. true indicates redraw needed
// Retrieves current redraw status. true indicates redraw needed
bool getRedraw();
// Set redraw status
// Set redraw status
void setRedraw(bool redraw);
// Initializes canvas, recreates canvas on flag changes
void initCanvas();
Expand All @@ -88,6 +104,13 @@ class App : public KeiraThread {
// TODO: lastFrame, FPS meter
private:
SemaphoreHandle_t canvasMutex = xSemaphoreCreateMutex();

bool redraw = false;

AppFlags_t flags = AppFlags::APP_FLAG_NONE;

// Toolbar:
String toolBarLabel;
uint16_t toolBarColor = lilka::colors::White;
uint16_t toolBarBgColor = lilka::colors::Black;
};
Loading