Skip to content

Commit

Permalink
A POC of a battery icon indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
proconsule committed Feb 27, 2022
1 parent 5595a86 commit aa5fe27
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/custom_widgets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#include <imgui.h>
#include <stdint.h>

void batteryIcon(ImVec2 pos,bool absolute,uint32_t batlevel);
27 changes: 27 additions & 0 deletions source/UI/custom_widgets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "custom_widgets.h"

void batteryIcon(ImVec2 pos,bool absolute,uint32_t batlevel){

ImVec2 iconsize = ImVec2(50.0f, 20.0f);

ImVec2 canvas_p0 = ImGui::GetCursorScreenPos();
if(absolute){
canvas_p0 = pos;
}
ImVec2 canvas_pnew = ImVec2(canvas_p0.x+3.0,canvas_p0.y+3.0f);
ImVec2 canvas_p1 = ImVec2(canvas_p0.x+iconsize.x, canvas_p0.y + iconsize.y);
ImVec2 batteryfill = ImVec2(canvas_p0.x+(float)batlevel*(iconsize.x-3.0f)/100.0f, canvas_p0.y-3.0 + iconsize.y);
ImVec2 batteryicon_p0 = ImVec2(canvas_p1.x,canvas_p0.y+5.0f);
ImVec2 batteryicon_p1 = ImVec2(canvas_p1.x+5.0,canvas_p0.y+15.0f);



//ImDrawList* draw_list = ImGui::GetWindowDrawList();
ImGui::GetForegroundDrawList()->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(0, 0, 0, 255));
ImGui::GetForegroundDrawList()->AddRectFilled(canvas_pnew, batteryfill, IM_COL32(50, 255, 50, 255));
ImGui::GetForegroundDrawList()->AddRect(canvas_p0, canvas_p1, IM_COL32(255, 255, 255, 255));

ImGui::GetForegroundDrawList()->AddRectFilled(batteryicon_p0, batteryicon_p1, IM_COL32(255, 255, 255, 255));


}
6 changes: 6 additions & 0 deletions source/UI/mainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#include "Enigma2.h"
#include "curldownloader.h"

#include "custom_widgets.h"

namespace Windows {
void MainMenuWindow(bool *focus, bool *first_item) {
Windows::SetupMainWindow();
std::vector<std::string> topmenu = configini->topmenu;
batteryIcon(ImVec2(1200.0f,5.0f),true,35);
if (ImGui::Begin(nxmpTitle.c_str(), nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse)) {
static int selected = -1;
for (unsigned int n = 0; n < topmenu.size(); n++){
Expand Down Expand Up @@ -170,8 +173,11 @@ namespace Windows {
g.NavDisableMouseHover = true;
*first_item = false;
}

}

Windows::ExitMainWindow();

}
}

0 comments on commit aa5fe27

Please sign in to comment.