This commit is contained in:
2025-12-25 13:00:42 +00:00
parent f5dc0ccbc9
commit 86947912dc
58 changed files with 959 additions and 328 deletions
+21 -19
View File
@@ -4,38 +4,40 @@ namespace Display::Graphics
{
Renderer::Renderer(Framebuffer &framebuffer, Model::HostRegistry &registry)
: framebuffer(framebuffer),
registry(registry),
barMem(200, 10)
registry(registry)
{
}
void Renderer::render()
{
// очистка экрана
framebuffer.clear(Color{0, 0, 0});
int y = 10; // начальная вертикальная позиция
int lineHeight = 24; // высота строки (подбираем под шрифт)
int blocksPerRow =
(SCREEN_WIDTH + BLOCK_GAP) / (Display::UI::HostBlock::BLOCK_WIDTH + BLOCK_GAP);
if (blocksPerRow < 1)
blocksPerRow = 1;
int index = 0;
for (auto &[host, m] : registry.snapshot())
{
// рисуем фон строки
framebuffer.fillRect(10, y - 18, 300, lineHeight, Color{0, 64, 0});
int col = index % blocksPerRow;
int row = index / blocksPerRow;
// формируем строку
std::string line = host + " " + std::to_string(int(m.cpu.loads.at(0))) +
"% " + std::to_string(int(m.memory.used / 1024 / 1024)) +
"/" + std::to_string(int(m.memory.total / 1024 / 1024)) +
" " + std::to_string(int(m.disks.at(0).used / 1024 / 1024)) +
"/" + std::to_string(int(m.disks.at(0).total / 1024 / 1024));
int x = START_X + col * (Display::UI::HostBlock::BLOCK_WIDTH + BLOCK_GAP);
int y = START_Y + row * (Display::UI::HostBlock::BLOCK_HEIGHT + BLOCK_GAP);
// выводим текст на экран
textRenderer.drawText(framebuffer, 12, y, line, Color{255, 255, 255});
hostblock.draw(
framebuffer,
textRenderer,
x,
y,
host,
m);
float mem = (float)m.memory.used / (float)m.memory.total;
barMem.draw(framebuffer, 10, y + 35, mem);
y += lineHeight; // переход на следующую строку
++index;
}
framebuffer.present();
}
} // namespace Display::Graphics