MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / fillBatteryIcon

Method fillBatteryIcon

src/components/themes/BaseTheme.cpp:74–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74void BaseTheme::fillBatteryIcon(const GfxRenderer& renderer, Rect rect, uint16_t percentage) const {
75 const bool charging = gpio.isUsbConnected();
76
77 const int maxFillWidth = rect.width - 5;
78 const int fillHeight = rect.height - 4;
79 if (maxFillWidth <= 0 || fillHeight <= 0) {
80 return;
81 }
82 // +1 to round up so we always fill at least one pixel
83 int filledWidth = percentage * maxFillWidth / 100 + 1;
84 if (filledWidth > maxFillWidth) {
85 filledWidth = maxFillWidth;
86 }
87
88 // When charging, ensure minimum fill so lightning bolt is fully visible
89 constexpr int minFillForBolt = 8;
90 if (charging && filledWidth < minFillForBolt) {
91 filledWidth = std::min(minFillForBolt, maxFillWidth);
92 }
93
94 renderer.fillRect(rect.x + 2, rect.y + 2, filledWidth, fillHeight);
95
96 if (charging) {
97 drawBatteryLightningBolt(renderer, rect.x + 4, rect.y + 2);
98 }
99}
100
101void BaseTheme::drawBatteryLeft(const GfxRenderer& renderer, Rect rect, const bool showPercentage) const {
102 // Left aligned: icon on left, percentage on right (reader mode)

Callers

nothing calls this directly

Calls 2

isUsbConnectedMethod · 0.80
fillRectMethod · 0.80

Tested by

no test coverage detected