When plugged in change battery icon according to percent

pull/536/head
Alessandro Toia 3 years ago
parent 5adb4500c7
commit 8980ff46bc

@ -22,6 +22,10 @@ void create_fonts(const overlay_params& params, ImFont*& small_font, ImFont*& te
//0x2109, 0x2109, // Degree Fahrenheit
0,
};
// Load Icon file and merge to exisitng font
ImFontConfig config;
config.MergeMode = true;
static const ImWchar icon_ranges[] = { ICON_MIN_FK, ICON_MAX_FK, 0 };
ImVector<ImWchar> glyph_ranges;
ImFontGlyphRangesBuilder builder;
@ -56,13 +60,7 @@ void create_fonts(const overlay_params& params, ImFont*& small_font, ImFont*& te
// ImGui takes ownership of the data, no need to free it
if (!params.font_file.empty() && file_exists(params.font_file)) {
io.Fonts->AddFontFromFileTTF(params.font_file.c_str(), font_size, nullptr, same_font && same_size ? glyph_ranges.Data : default_range);
ImFontConfig config;
config.MergeMode = true;
config.GlyphMinAdvanceX = 13.0f;
static const ImWchar icon_ranges[] = { ICON_MIN_FK, ICON_MAX_FK, 0 };
io.Fonts->AddFontFromFileTTF("/usr/share/MangoHud/icons/forkawesome-webfont.ttf", 13.0f, &config, icon_ranges);
io.Fonts->AddFontFromFileTTF("/usr/share/MangoHud/icons/forkawesome-webfont.ttf", font_size, &config, icon_ranges);
if (params.no_small_font)
small_font = io.Fonts->Fonts[0];
else
@ -70,13 +68,7 @@ void create_fonts(const overlay_params& params, ImFont*& small_font, ImFont*& te
} else {
const char* ttf_compressed_base85 = GetDefaultCompressedFontDataTTFBase85();
io.Fonts->AddFontFromMemoryCompressedBase85TTF(ttf_compressed_base85, font_size, nullptr, default_range);
ImFontConfig config;
config.MergeMode = true;
config.GlyphMinAdvanceX = 13.0f;
static const ImWchar icon_ranges[] = { ICON_MIN_FK, ICON_MAX_FK, 0 };
io.Fonts->AddFontFromFileTTF("/usr/share/MangoHud/icons/forkawesome-webfont.ttf", 13.0f, &config, icon_ranges);
io.Fonts->AddFontFromFileTTF("/usr/share/MangoHud/icons/forkawesome-webfont.ttf", font_size, &config, icon_ranges);
if (params.no_small_font)
small_font = io.Fonts->Fonts[0];
else

@ -591,16 +591,22 @@ void HudElements::battery_percent(){
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_battery_percent] && HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_battery_power]){
ImGui::TableNextColumn();
if (Battery_Stats.isCharging() && !Battery_Stats.fullCharge()) {
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::Text("Plugged in");
ImGui::PopFont();
if (Battery_Stats.isCharging()) {
switch(int(Battery_Stats.current_percent)){
case 0 ... 33:
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%s", ICON_FK_BATTERY_QUARTER);
break;
case 34 ... 66:
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%s", ICON_FK_BATTERY_HALF);
break;
case 67 ... 99:
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%s", ICON_FK_BATTERY_THREE_QUARTERS);
break;
}
}
else if(int(Battery_Stats.current_percent) == 100 || Battery_Stats.fullCharge()) {
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::Text("Full Charge");
ImGui::PopFont();
else if(Battery_Stats.fullCharge() && !Battery_Stats.isCharging()) {
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%s", ICON_FK_BATTERY_FULL);
}
else {
right_aligned_text(HUDElements.colors.text, HUDElements.ralign_width, "%.1f", Battery_Stats.current_watt);

Loading…
Cancel
Save