Configurable colors
This commit is contained in:
parent
4c0b1f31fe
commit
120af1612f
4 changed files with 26 additions and 7 deletions
19
src/bar.cpp
19
src/bar.cpp
|
|
@ -44,9 +44,6 @@ void Bar::layerSurfaceConfigure(uint32_t serial, uint32_t width, uint32_t height
|
|||
_bufs.emplace(width, height, WL_SHM_FORMAT_XRGB8888);
|
||||
render();
|
||||
}
|
||||
static QBrush inactiveBg = {QColor::fromRgb(0, 0, 0)};
|
||||
static QBrush activeBg = QBrush {QColor::fromRgb(0, 0, 255)};
|
||||
static QPen fg = QPen {QBrush {QColor::fromRgb(255, 255, 255)}, 1};
|
||||
|
||||
void Bar::render()
|
||||
{
|
||||
|
|
@ -58,29 +55,37 @@ void Bar::render()
|
|||
QImage::Format_ARGB32
|
||||
};
|
||||
auto painter = QPainter {&img};
|
||||
_painter = &painter;
|
||||
auto font = painter.font();
|
||||
font.setBold(true);
|
||||
font.setPixelSize(18);
|
||||
painter.setFont(font);
|
||||
painter.setPen(fg);
|
||||
|
||||
painter.fillRect(0, 0, img.width(), img.height(), activeBg);
|
||||
setColorScheme(colorActive);
|
||||
painter.fillRect(0, 0, img.width(), img.height(), painter.brush());
|
||||
_fontMetrics.emplace(painter.font());
|
||||
_textY = _fontMetrics->ascent() + paddingY;
|
||||
renderTags(painter);
|
||||
|
||||
_painter = nullptr;
|
||||
wl_surface_attach(_surface, _bufs->buffer(), 0, 0);
|
||||
wl_surface_commit(_surface);
|
||||
_bufs->flip();
|
||||
}
|
||||
|
||||
void Bar::setColorScheme(const ColorScheme &scheme)
|
||||
{
|
||||
_painter->setBrush(QBrush {scheme.bg});
|
||||
_painter->setPen(QPen {QBrush {scheme.fg}, 1});
|
||||
}
|
||||
|
||||
void Bar::renderTags(QPainter &painter)
|
||||
{
|
||||
auto x = 0;
|
||||
for (const auto &tag : _tags) {
|
||||
auto size = textWidth(tag.name) + paddingX*2;
|
||||
auto& bg = tag.active ? activeBg : inactiveBg;
|
||||
painter.fillRect(x, 0, size, barSize, bg);
|
||||
setColorScheme(tag.active ? colorActive : colorInactive);
|
||||
painter.fillRect(x, 0, size, barSize, _painter->brush());
|
||||
painter.drawText(paddingX+x, _textY, tag.name);
|
||||
x += size;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue