Smallcase folders part 1
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
#include "Display/UI/HostBlock/HostBlock.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "Display/UI/Bar/Orientation.h"
|
||||
#include "Display/UI/Bar/Style.h"
|
||||
#include "Display/UI/Theme/Theme.h"
|
||||
#include "Display/Graphics/Color.h"
|
||||
#include "Display/UI/Text/Helpers.h"
|
||||
|
||||
namespace display::ui::hostblock
|
||||
{
|
||||
HostBlock::HostBlock()
|
||||
: cpuBar(
|
||||
CPU_BAR_WIDTH,
|
||||
CPU_BAR_HEIGHT,
|
||||
display::ui::bar::Orientation::Vertical,
|
||||
display::ui::bar::Style{display::graphics::Color{40, 40, 40}, display::graphics::Color{0, 180, 0}, display::graphics::Color{80, 80, 80}, true}),
|
||||
memBar(
|
||||
BLOCK_WIDTH - PADDING * 2,
|
||||
MEM_BAR_HEIGHT,
|
||||
display::ui::bar::Orientation::Horizontal,
|
||||
display::ui::bar::Style{display::graphics::Color{40, 40, 40}, display::graphics::Color{0, 120, 200}, display::graphics::Color{80, 80, 80}, true})
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
void HostBlock::draw(
|
||||
display::graphics::Framebuffer &fb,
|
||||
display::ui::text::Renderer &text,
|
||||
int x, int y,
|
||||
const std::string &hostname,
|
||||
const metrics::Host &metrics)
|
||||
{
|
||||
// ===== Block background =====
|
||||
fb.fillRect(x, y, BLOCK_WIDTH, BLOCK_HEIGHT, display::ui::theme::hostblock::BACKGROUND);
|
||||
fb.drawRect(x, y, BLOCK_WIDTH, BLOCK_HEIGHT, display::ui::theme::hostblock::BORDER);
|
||||
|
||||
int cursorY = y + PADDING;
|
||||
|
||||
// ===== Header =====
|
||||
fb.fillRect(
|
||||
x + PADDING,
|
||||
cursorY,
|
||||
BLOCK_WIDTH - PADDING * 2,
|
||||
HEADER_HEIGHT,
|
||||
display::ui::theme::hostblock::HEADER);
|
||||
|
||||
text.drawTextOutlined(
|
||||
fb,
|
||||
x + PADDING + 2,
|
||||
cursorY + HEADER_HEIGHT - 3,
|
||||
hostname,
|
||||
display::ui::theme::text::TEXT,
|
||||
display::ui::theme::text::OUTLINE,
|
||||
// display::ui::text::Font{"LiberationSans-Regular", HEADER_FONT_SIZE});
|
||||
// display::ui::text::Font{"PixelFive-Regular", 5});
|
||||
display::ui::text::Font{std::string(HEADER_FONT_NAME.begin(), HEADER_FONT_NAME.end()), HEADER_FONT_SIZE});
|
||||
|
||||
cursorY += HEADER_HEIGHT + SECTION_GAP;
|
||||
|
||||
// ===== CPU bars =====
|
||||
int cpuCount = std::min<int>(metrics.cpu.coreLoads.size(),
|
||||
CPU_MAX_PER_ROW * CPU_ROWS);
|
||||
|
||||
for (int i = 0; i < cpuCount; ++i)
|
||||
{
|
||||
int row = i / CPU_MAX_PER_ROW;
|
||||
int col = i % CPU_MAX_PER_ROW;
|
||||
|
||||
int bx = x + PADDING +
|
||||
col * (CPU_BAR_WIDTH + CPU_BAR_GAP);
|
||||
|
||||
int by = cursorY +
|
||||
row * (CPU_BAR_HEIGHT + CPU_BAR_GAP);
|
||||
|
||||
float value = std::clamp(metrics.cpu.coreLoads[i] / 100.0f, 0.0f, 1.0f);
|
||||
|
||||
cpuBar.draw(fb, bx, by, value);
|
||||
}
|
||||
|
||||
cursorY += CPU_ROWS * CPU_BAR_HEIGHT +
|
||||
(CPU_ROWS - 1) * CPU_BAR_GAP +
|
||||
SECTION_GAP;
|
||||
|
||||
// ===== Memory bar =====
|
||||
float memValue, swapValue = 0.0f;
|
||||
if (metrics.memory.mem_total > 0)
|
||||
memValue = metrics.memory.mem_used / metrics.memory.mem_total;
|
||||
|
||||
memBar.draw(
|
||||
fb,
|
||||
x + PADDING,
|
||||
cursorY,
|
||||
std::clamp(memValue, 0.0f, 1.0f));
|
||||
text.drawTextOutlined(fb,
|
||||
x + MEM_BAR_TEXT_PADDING_X,
|
||||
cursorY + 8,
|
||||
"M: " + display::ui::text::formatFloat(metrics.memory.mem_used / 1073741824) + "/" + display::ui::text::formatFloat(metrics.memory.mem_total / 1073741824),
|
||||
display::ui::theme::text::TEXT,
|
||||
display::ui::theme::text::OUTLINE,
|
||||
display::ui::text::Font{"PixelFive-Regular", 5});
|
||||
|
||||
cursorY += MEM_BAR_HEIGHT + SECTION_GAP;
|
||||
|
||||
if (metrics.memory.swap_total > 0)
|
||||
{
|
||||
swapValue = metrics.memory.swap_used / metrics.memory.swap_total;
|
||||
|
||||
memBar.draw(
|
||||
fb,
|
||||
x + PADDING,
|
||||
cursorY,
|
||||
std::clamp(swapValue, 0.0f, 1.0f));
|
||||
text.drawTextOutlined(fb,
|
||||
x + MEM_BAR_TEXT_PADDING_X,
|
||||
cursorY + 8,
|
||||
"S: " + display::ui::text::formatFloat(metrics.memory.swap_used / 1073741824) + "/" + display::ui::text::formatFloat(metrics.memory.swap_total / 1073741824),
|
||||
display::ui::theme::text::TEXT,
|
||||
display::ui::theme::text::OUTLINE,
|
||||
display::ui::text::Font{"PixelFive-Regular", 5});
|
||||
|
||||
cursorY += MEM_BAR_HEIGHT + SECTION_GAP;
|
||||
}
|
||||
|
||||
// ===== Disk bar =====
|
||||
int diskCount = metrics.disks.size();
|
||||
|
||||
for (int i = 0; i < diskCount; ++i)
|
||||
{
|
||||
int by = cursorY +
|
||||
i * (MEM_BAR_HEIGHT + SECTION_GAP);
|
||||
|
||||
float value = std::clamp(metrics.disks[i].used / metrics.disks[i].total, 0.0f, 1.0f);
|
||||
|
||||
memBar.draw(fb, x + PADDING, by, value);
|
||||
text.drawTextOutlined(fb,
|
||||
x + MEM_BAR_TEXT_PADDING_X,
|
||||
by + 8,
|
||||
metrics.disks[i].name + ": " + display::ui::text::formatFloat(metrics.disks[i].used / 1073741824) + "/" + display::ui::text::formatFloat(metrics.disks[i].total / 1073741824),
|
||||
display::ui::theme::text::TEXT,
|
||||
display::ui::theme::text::OUTLINE,
|
||||
display::ui::text::Font{"PixelFive-Regular", 5});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user