Add arrows
This commit is contained in:
@@ -74,6 +74,7 @@ namespace config::server
|
|||||||
cfg.style.hostblock.disks.font.size = std::stoi(ini.get("style", "hostblock.disks.font.size", "5"));
|
cfg.style.hostblock.disks.font.size = std::stoi(ini.get("style", "hostblock.disks.font.size", "5"));
|
||||||
cfg.style.hostblock.disks.font.padding = std::stoi(ini.get("style", "hostblock.disks.font.padding", "8"));
|
cfg.style.hostblock.disks.font.padding = std::stoi(ini.get("style", "hostblock.disks.font.padding", "8"));
|
||||||
|
|
||||||
|
cfg.style.hostblock.networks.label_width = std::stoi(ini.get("style", "hostblock.networks.label_width", "8"));
|
||||||
cfg.style.hostblock.networks.width = std::stoi(ini.get("style", "hostblock.networks.width", "8"));
|
cfg.style.hostblock.networks.width = std::stoi(ini.get("style", "hostblock.networks.width", "8"));
|
||||||
cfg.style.hostblock.networks.height = std::stoi(ini.get("style", "hostblock.networks.height", "16"));
|
cfg.style.hostblock.networks.height = std::stoi(ini.get("style", "hostblock.networks.height", "16"));
|
||||||
cfg.style.hostblock.networks.gap_h = std::stoi(ini.get("style", "hostblock.networks.gap_h", "4"));
|
cfg.style.hostblock.networks.gap_h = std::stoi(ini.get("style", "hostblock.networks.gap_h", "4"));
|
||||||
|
|||||||
@@ -67,8 +67,9 @@ namespace config::server
|
|||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
int width = 8;
|
int label_width = 20;
|
||||||
int height = 16;
|
int width = 20;
|
||||||
|
int height = 11;
|
||||||
int gap_h = 4;
|
int gap_h = 4;
|
||||||
int gap_v = 4;
|
int gap_v = 4;
|
||||||
int max_per_row = 4;
|
int max_per_row = 4;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "display/ui/theme/Theme.h"
|
#include "display/ui/theme/Theme.h"
|
||||||
#include "display/ui/text/Helpers.h"
|
#include "display/ui/text/Helpers.h"
|
||||||
#include "display/graphics/Color.h"
|
#include "display/graphics/Color.h"
|
||||||
|
#include "display/ui/text/Arrow.h"
|
||||||
|
|
||||||
namespace display::ui::hostblock
|
namespace display::ui::hostblock
|
||||||
{
|
{
|
||||||
@@ -58,14 +59,14 @@ namespace display::ui::hostblock
|
|||||||
cursorY,
|
cursorY,
|
||||||
config.hostblock.width - config.hostblock.padding * 2,
|
config.hostblock.width - config.hostblock.padding * 2,
|
||||||
config.hostblock.header.height,
|
config.hostblock.header.height,
|
||||||
online ? display::ui::theme::hostblock::HEADER : display::graphics::Red());
|
display::ui::theme::hostblock::HEADER);
|
||||||
|
|
||||||
text.drawTextOutlined(
|
text.drawTextOutlined(
|
||||||
fb,
|
fb,
|
||||||
x + config.hostblock.padding + 2,
|
x + config.hostblock.padding + 2,
|
||||||
cursorY + config.hostblock.header.height - 1,
|
cursorY + config.hostblock.header.height - 1,
|
||||||
hostname,
|
hostname,
|
||||||
online ? display::ui::theme::text::TEXT : display::ui::theme::text::OFFLINE,
|
online ? display::ui::theme::text::TEXT : display::graphics::Red(),
|
||||||
display::ui::theme::text::OUTLINE,
|
display::ui::theme::text::OUTLINE,
|
||||||
display::ui::text::Font{config.hostblock.header.font.name, config.hostblock.header.font.size});
|
display::ui::text::Font{config.hostblock.header.font.name, config.hostblock.header.font.size});
|
||||||
|
|
||||||
@@ -95,8 +96,10 @@ namespace display::ui::hostblock
|
|||||||
cpuTempBar.draw(fb, bx + config.hostblock.cpu.width - 1, by, value, 0, online);
|
cpuTempBar.draw(fb, bx + config.hostblock.cpu.width - 1, by, value, 0, online);
|
||||||
}
|
}
|
||||||
|
|
||||||
cursorY += config.hostblock.cpu.rows * config.hostblock.cpu.height +
|
int rowsUsed = (cpuCount + config.hostblock.cpu.max_per_row - 1) / config.hostblock.cpu.max_per_row;
|
||||||
(config.hostblock.cpu.rows - 1) * config.hostblock.cpu.gap_v +
|
|
||||||
|
cursorY += rowsUsed * config.hostblock.cpu.height +
|
||||||
|
(rowsUsed > 0 ? (rowsUsed - 1) * config.hostblock.cpu.gap_v : 0) +
|
||||||
config.hostblock.gap;
|
config.hostblock.gap;
|
||||||
|
|
||||||
// ===== Memory bar =====
|
// ===== Memory bar =====
|
||||||
@@ -176,16 +179,17 @@ namespace display::ui::hostblock
|
|||||||
int col = i % config.hostblock.networks.max_per_row;
|
int col = i % config.hostblock.networks.max_per_row;
|
||||||
|
|
||||||
int bx = x + config.hostblock.padding +
|
int bx = x + config.hostblock.padding +
|
||||||
col * (config.hostblock.networks.width * 2 + config.hostblock.networks.gap_h);
|
col * (config.hostblock.networks.label_width + config.hostblock.networks.width * 2 + config.hostblock.networks.gap_h);
|
||||||
|
|
||||||
int by = cursorY +
|
int by = cursorY +
|
||||||
row * (config.hostblock.networks.height + config.hostblock.networks.gap_v);
|
row * (config.hostblock.networks.height + config.hostblock.networks.gap_v);
|
||||||
|
|
||||||
float value_rx = std::clamp(network.rxBps / std::max(network.rxMaxBps, 1048576.0f), 0.0f, 1.0f);
|
float value_rx = std::clamp(network.rxBps / quantizeScale(network.rxMaxBps), 0.0f, 1.0f);
|
||||||
float value_tx = std::clamp(network.txBps / std::max(network.txMaxBps, 1048576.0f), 0.0f, 1.0f);
|
float value_tx = std::clamp(network.txBps / quantizeScale(network.txMaxBps), 0.0f, 1.0f);
|
||||||
|
|
||||||
netBar.draw(fb, bx, by, value_rx, 0, network.online && online, true);
|
fb.drawRect(bx, by, config.hostblock.networks.label_width, config.hostblock.networks.height, display::ui::theme::bar::BORDER);
|
||||||
netBar.draw(fb, bx + config.hostblock.networks.width, by, value_tx, 0, network.online && online);
|
netBar.draw(fb, bx + config.hostblock.networks.label_width, by, value_rx, 0, network.online && online, true);
|
||||||
|
netBar.draw(fb, bx + config.hostblock.networks.width + config.hostblock.networks.label_width, by, value_tx, 0, network.online && online);
|
||||||
|
|
||||||
text.drawTextOutlined(fb,
|
text.drawTextOutlined(fb,
|
||||||
bx + config.hostblock.networks.font.padding,
|
bx + config.hostblock.networks.font.padding,
|
||||||
@@ -194,6 +198,27 @@ namespace display::ui::hostblock
|
|||||||
network.online && online ? display::ui::theme::text::TEXT : display::ui::theme::text::OFFLINE,
|
network.online && online ? display::ui::theme::text::TEXT : display::ui::theme::text::OFFLINE,
|
||||||
display::ui::theme::text::OUTLINE,
|
display::ui::theme::text::OUTLINE,
|
||||||
display::ui::text::Font{config.hostblock.networks.font.name, config.hostblock.networks.font.size});
|
display::ui::text::Font{config.hostblock.networks.font.name, config.hostblock.networks.font.size});
|
||||||
|
text.drawBitmapOutlined(fb,
|
||||||
|
bx + config.hostblock.networks.label_width + config.hostblock.networks.width / 2 - 3,
|
||||||
|
by + 3,
|
||||||
|
display::ui::text::ARROW_DOWN,
|
||||||
|
network.online && online ? display::ui::theme::text::TEXT : display::ui::theme::text::OFFLINE,
|
||||||
|
display::ui::theme::text::OUTLINE);
|
||||||
|
text.drawBitmapOutlined(fb,
|
||||||
|
bx + config.hostblock.networks.width + config.hostblock.networks.label_width + config.hostblock.networks.width / 2 - 2,
|
||||||
|
by + 3,
|
||||||
|
display::ui::text::ARROW_UP,
|
||||||
|
network.online && online ? display::ui::theme::text::TEXT : display::ui::theme::text::OFFLINE,
|
||||||
|
display::ui::theme::text::OUTLINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float HostBlock::quantizeScale(float v)
|
||||||
|
{
|
||||||
|
if (v < 1024.0f)
|
||||||
|
return 1024.0f;
|
||||||
|
if (v < 1048576.0f)
|
||||||
|
return 1048576.0f;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,5 +30,6 @@ namespace display::ui::hostblock
|
|||||||
display::ui::bar::Bar cpuTempBar;
|
display::ui::bar::Bar cpuTempBar;
|
||||||
display::ui::bar::Bar memBar;
|
display::ui::bar::Bar memBar;
|
||||||
display::ui::bar::Bar netBar;
|
display::ui::bar::Bar netBar;
|
||||||
|
float quantizeScale(float v);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace display::ui::text
|
||||||
|
{
|
||||||
|
constexpr uint8_t ARROW_UP[5][5] = {
|
||||||
|
{0, 0, 1, 0, 0},
|
||||||
|
{0, 1, 1, 1, 0},
|
||||||
|
{1, 0, 1, 0, 1},
|
||||||
|
{0, 0, 1, 0, 0},
|
||||||
|
{0, 0, 1, 0, 0},
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr uint8_t ARROW_DOWN[5][5] = {
|
||||||
|
{0, 0, 1, 0, 0},
|
||||||
|
{0, 0, 1, 0, 0},
|
||||||
|
{1, 0, 1, 0, 1},
|
||||||
|
{0, 1, 1, 1, 0},
|
||||||
|
{0, 0, 1, 0, 0},
|
||||||
|
};
|
||||||
|
} // namespace display::ui::text
|
||||||
@@ -82,5 +82,25 @@ namespace display::ui::text
|
|||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
void Renderer::drawBitmapOutlined(display::graphics::Framebuffer &fb, int x, int y,
|
||||||
|
const uint8_t bitmap[5][5],
|
||||||
|
const display::graphics::Color &color,
|
||||||
|
const display::graphics::Color &outline)
|
||||||
|
{
|
||||||
|
// outline
|
||||||
|
for (int dx = -1; dx <= 1; ++dx)
|
||||||
|
for (int dy = -1; dy <= 1; ++dy)
|
||||||
|
if (dx != 0 || dy != 0)
|
||||||
|
for (int row = 0; row < 5; ++row)
|
||||||
|
for (int col = 0; col < 5; ++col)
|
||||||
|
if (bitmap[row][col])
|
||||||
|
fb.setPixel(x + col + dx, y + row + dy, outline);
|
||||||
|
|
||||||
|
// main
|
||||||
|
for (int row = 0; row < 5; ++row)
|
||||||
|
for (int col = 0; col < 5; ++col)
|
||||||
|
if (bitmap[row][col])
|
||||||
|
fb.setPixel(x + col, y + row, color);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace display::ui::text
|
} // namespace display::ui::text
|
||||||
@@ -16,7 +16,7 @@ namespace display::ui::text
|
|||||||
public:
|
public:
|
||||||
void drawText(display::graphics::Framebuffer &fb, int x, int y, const std::string &text, const display::graphics::Color &color = display::graphics::Color{255, 255, 255}, const Font &font = {"LiberationSans-Regular", 12});
|
void drawText(display::graphics::Framebuffer &fb, int x, int y, const std::string &text, const display::graphics::Color &color = display::graphics::Color{255, 255, 255}, const Font &font = {"LiberationSans-Regular", 12});
|
||||||
void drawTextOutlined(display::graphics::Framebuffer &fb, int x, int y, const std::string &text, const display::graphics::Color &colorText = display::graphics::Color{255, 255, 255}, const display::graphics::Color &colorOutline = display::graphics::Color{0, 0, 0}, const Font &font = {"LiberationSans-Regular", 12});
|
void drawTextOutlined(display::graphics::Framebuffer &fb, int x, int y, const std::string &text, const display::graphics::Color &colorText = display::graphics::Color{255, 255, 255}, const display::graphics::Color &colorOutline = display::graphics::Color{0, 0, 0}, const Font &font = {"LiberationSans-Regular", 12});
|
||||||
|
void drawBitmapOutlined(display::graphics::Framebuffer &fb, int x, int y, const uint8_t bitmap[5][5], const display::graphics::Color &color, const display::graphics::Color &outline);
|
||||||
// int measureWidth(const std::string &text);
|
// int measureWidth(const std::string &text);
|
||||||
// int measureHeight(const std::string &text);
|
// int measureHeight(const std::string &text);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user