Merge pull request #73 from Jovvik/main

Added font size to bar
This commit is contained in:
vaxerski 2022-05-22 00:15:50 +02:00 committed by GitHub
commit 6cbb4bf312
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 13 deletions

View file

@ -413,9 +413,9 @@ void CStatusBar::destroy() {
m_bIsDestroyed = true; m_bIsDestroyed = true;
} }
int CStatusBar::getTextWidth(std::string text, std::string font) { int CStatusBar::getTextWidth(std::string text, std::string font, double size) {
cairo_select_font_face(m_pCairo, font.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_select_font_face(m_pCairo, font.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(m_pCairo, 12); cairo_set_font_size(m_pCairo, size);
cairo_text_extents_t textextents; cairo_text_extents_t textextents;
cairo_text_extents(m_pCairo, text.c_str(), &textextents); cairo_text_extents(m_pCairo, text.c_str(), &textextents);
@ -423,9 +423,9 @@ int CStatusBar::getTextWidth(std::string text, std::string font) {
return textextents.width + 1 /* pad */; return textextents.width + 1 /* pad */;
} }
void CStatusBar::drawText(Vector2D pos, std::string text, uint32_t color, std::string font) { void CStatusBar::drawText(Vector2D pos, std::string text, uint32_t color, std::string font, double size) {
cairo_select_font_face(m_pCairo, font.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_select_font_face(m_pCairo, font.c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(m_pCairo, 12); cairo_set_font_size(m_pCairo, size);
cairo_set_source_rgba(m_pCairo, RED(color), GREEN(color), BLUE(color), ALPHA(color)); cairo_set_source_rgba(m_pCairo, RED(color), GREEN(color), BLUE(color), ALPHA(color));
cairo_move_to(m_pCairo, pos.x, pos.y); cairo_move_to(m_pCairo, pos.x, pos.y);
cairo_show_text(m_pCairo, text.c_str()); cairo_show_text(m_pCairo, text.c_str());
@ -447,7 +447,8 @@ void CStatusBar::drawErrorScreen() {
else else
drawCairoRectangle(Vector2D(0, 0), m_vecSize, 0xFFaa1111); drawCairoRectangle(Vector2D(0, 0), m_vecSize, 0xFFaa1111);
drawText(Vector2D(1, getTextHalfY()), ConfigManager::parseError, 0xff000000, ConfigManager::getString("bar:font.main")); drawText(Vector2D(1, getTextHalfY()), ConfigManager::parseError, 0xff000000,
ConfigManager::getString("bar:font.main"), ConfigManager::getFloat("bar:font.size"));
// do all the drawing cuz we return later // do all the drawing cuz we return later
cairo_surface_flush(m_pCairoSurface); cairo_surface_flush(m_pCairoSurface);
@ -549,8 +550,8 @@ int CStatusBar::drawWorkspacesModule(SBarModule* mod, int off) {
drawCairoRectangle(Vector2D(off + m_vecSize.y * drawnWorkspaces, 0), Vector2D(m_vecSize.y, m_vecSize.y), WORKSPACE == MOUSEWORKSPACEID ? ConfigManager::getInt("bar:col.high") : ConfigManager::getInt("bar:col.bg")); drawCairoRectangle(Vector2D(off + m_vecSize.y * drawnWorkspaces, 0), Vector2D(m_vecSize.y, m_vecSize.y), WORKSPACE == MOUSEWORKSPACEID ? ConfigManager::getInt("bar:col.high") : ConfigManager::getInt("bar:col.bg"));
drawText(Vector2D(off + m_vecSize.y * drawnWorkspaces + m_vecSize.y / 2.f - getTextWidth(workspaceName, ConfigManager::getString("bar:font.main")) / 2.f, getTextHalfY()), drawText(Vector2D(off + m_vecSize.y * drawnWorkspaces + m_vecSize.y / 2.f - getTextWidth(workspaceName, ConfigManager::getString("bar:font.main"), ConfigManager::getFloat("bar:font.size")) / 2.f, getTextHalfY()),
workspaceName, WORKSPACE == MOUSEWORKSPACEID ? 0xFF111111 : 0xFFFFFFFF, ConfigManager::getString("bar:font.main")); workspaceName, WORKSPACE == MOUSEWORKSPACEID ? 0xFF111111 : 0xFFFFFFFF, ConfigManager::getString("bar:font.main"), ConfigManager::getFloat("bar:font.size"));
drawnWorkspaces++; drawnWorkspaces++;
} }
@ -640,8 +641,8 @@ int CStatusBar::drawModule(SBarModule* mod, int off) {
// We have the value, draw the module! // We have the value, draw the module!
const auto MODULEWIDTH = getTextWidth(mod->valueCalculated, ConfigManager::getString("bar:font.main")) + PAD; const auto MODULEWIDTH = getTextWidth(mod->valueCalculated, ConfigManager::getString("bar:font.main"), ConfigManager::getFloat("bar:font.size")) + PAD;
const auto ICONWIDTH = getTextWidth(mod->icon, ConfigManager::getString("bar:font.secondary")); const auto ICONWIDTH = getTextWidth(mod->icon, ConfigManager::getString("bar:font.secondary"), ConfigManager::getFloat("bar:font.size"));
if (!MODULEWIDTH || mod->accessValueCalculated(false) == "") if (!MODULEWIDTH || mod->accessValueCalculated(false) == "")
return 0; // empty module return 0; // empty module
@ -661,8 +662,10 @@ int CStatusBar::drawModule(SBarModule* mod, int off) {
drawCairoRectangle(position, Vector2D(MODULEWIDTH + ICONWIDTH, m_vecSize.y), mod->bgcolor); drawCairoRectangle(position, Vector2D(MODULEWIDTH + ICONWIDTH, m_vecSize.y), mod->bgcolor);
drawText(position + Vector2D(PAD / 2, getTextHalfY()), mod->icon, mod->color, ConfigManager::getString("bar:font.secondary")); drawText(position + Vector2D(PAD / 2, getTextHalfY()), mod->icon, mod->color,
drawText(position + Vector2D(PAD / 2 + ICONWIDTH, getTextHalfY()), mod->accessValueCalculated(false), mod->color, ConfigManager::getString("bar:font.main")); ConfigManager::getString("bar:font.secondary"), ConfigManager::getFloat("bar:font.size"));
drawText(position + Vector2D(PAD / 2 + ICONWIDTH, getTextHalfY()), mod->accessValueCalculated(false), mod->color,
ConfigManager::getString("bar:font.main"), ConfigManager::getFloat("bar:font.size"));
return MODULEWIDTH + ICONWIDTH; return MODULEWIDTH + ICONWIDTH;
} }

View file

@ -96,9 +96,9 @@ private:
cairo_surface_t* m_pCairoSurface = nullptr; cairo_surface_t* m_pCairoSurface = nullptr;
cairo_t* m_pCairo = nullptr; cairo_t* m_pCairo = nullptr;
void drawText(Vector2D, std::string, uint32_t, std::string); void drawText(Vector2D, std::string, uint32_t, std::string, double);
void drawCairoRectangle(Vector2D, Vector2D, uint32_t); void drawCairoRectangle(Vector2D, Vector2D, uint32_t);
int getTextWidth(std::string, std::string); int getTextWidth(std::string, std::string, double);
int drawModule(SBarModule*, int); int drawModule(SBarModule*, int);
int drawWorkspacesModule(SBarModule*, int); int drawWorkspacesModule(SBarModule*, int);
int getTextHalfY(); int getTextHalfY();

View file

@ -34,6 +34,7 @@ void ConfigManager::init() {
configValues["bar:height"].intValue = 15; configValues["bar:height"].intValue = 15;
configValues["bar:col.bg"].intValue = 0xFF111111; configValues["bar:col.bg"].intValue = 0xFF111111;
configValues["bar:col.high"].intValue = 0xFFFF3333; configValues["bar:col.high"].intValue = 0xFFFF3333;
configValues["bar:font.size"].floatValue = 12;
configValues["bar:font.main"].strValue = "Noto Sans"; configValues["bar:font.main"].strValue = "Noto Sans";
configValues["bar:font.secondary"].strValue = "Noto Sans"; configValues["bar:font.secondary"].strValue = "Noto Sans";
configValues["bar:mod_pad_in"].intValue = 4; configValues["bar:mod_pad_in"].intValue = 4;