Files
esDashboard/src/display/graphics/Renderer.cpp
T
2026-01-09 21:58:48 +00:00

50 lines
1.4 KiB
C++

#include "display/graphics/Renderer.h"
namespace display::graphics
{
Renderer::Renderer(Framebuffer &framebuffer, model::HostRegistry &registry, config::server::StyleConfig &config)
: framebuffer(framebuffer),
registry(registry),
config(config),
textRenderer(std::make_unique<display::ui::text::Renderer>()),
header(std::make_unique<display::ui::header::Header>(config)),
hostblock(std::make_unique<display::ui::hostblock::HostBlock>(config))
{
}
void Renderer::render()
{
framebuffer.clear(Color{0, 0, 0});
header->draw(framebuffer, *textRenderer, START_X, START_Y);
int blocksPerRow =
(SCREEN_WIDTH + config.gap) / (config.hostblock.width + config.gap);
if (blocksPerRow < 1)
blocksPerRow = 1;
int index = 0;
for (auto &[host, m] : registry.snapshot())
{
int col = index % blocksPerRow;
int row = index / blocksPerRow;
int x = START_X + col * (config.hostblock.width + config.gap);
int y = START_Y + config.header.height + config.gap + row * (config.hostblock.height + config.gap);
hostblock->draw(
framebuffer,
*textRenderer,
x,
y,
host,
m);
++index;
}
framebuffer.present();
}
} // namespace display::graphics