mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-23 20:03:10 +00:00
added individual backgrounds for label and icon
This commit is contained in:
parent
2815a6e325
commit
58fb08ee49
2 changed files with 31 additions and 6 deletions
|
@ -101,7 +101,7 @@ void bar_redraw(struct bar* bar) {
|
|||
bool rtl = false;
|
||||
|
||||
if (bar_item->position == POSITION_LEFT) {
|
||||
icon_position = bar_left_final_item_x + bar_item->background.padding_left + 1;
|
||||
icon_position = bar_left_final_item_x + bar_item->background.padding_left;
|
||||
label_position = icon_position + text_get_length(&bar_item->icon);
|
||||
|
||||
if (!bar_item->has_const_width)
|
||||
|
@ -123,7 +123,7 @@ void bar_redraw(struct bar* bar) {
|
|||
else if (bar_item->position == POSITION_RIGHT) {
|
||||
rtl = true;
|
||||
label_position = bar_right_first_item_x - text_get_length(&bar_item->label) - bar_item->background.padding_right;
|
||||
icon_position = label_position - text_get_length(&bar_item->icon) - 1;
|
||||
icon_position = label_position - text_get_length(&bar_item->icon);
|
||||
|
||||
if (!bar_item->has_const_width)
|
||||
bar_right_first_item_x = icon_position - bar_item->background.padding_left;
|
||||
|
@ -143,7 +143,7 @@ void bar_redraw(struct bar* bar) {
|
|||
}
|
||||
}
|
||||
else if (bar_item->position == POSITION_CENTER) {
|
||||
icon_position = bar_center_first_item_x + bar_item->background.padding_left + 1;
|
||||
icon_position = bar_center_first_item_x + bar_item->background.padding_left;
|
||||
label_position = icon_position + text_get_length(&bar_item->icon);
|
||||
|
||||
if (!bar_item->has_const_width)
|
||||
|
|
27
src/text.c
27
src/text.c
|
@ -1,4 +1,5 @@
|
|||
#include "text.h"
|
||||
#include "background.h"
|
||||
#include "misc/helpers.h"
|
||||
#include <stdint.h>
|
||||
|
||||
|
@ -111,7 +112,8 @@ void text_clear_pointers(struct text* text) {
|
|||
uint32_t text_get_length(struct text* text) {
|
||||
if (!text->drawing) return 0;
|
||||
if (text->has_const_width) return text->custom_width;
|
||||
return (text->bounds.size.width + text->padding_left + text->padding_right) > 0 ? (text->bounds.size.width + text->padding_left + text->padding_right) : 0;
|
||||
int width = text->bounds.size.width + text->padding_left + text->padding_right;
|
||||
return width > 0 ? width : 0;
|
||||
}
|
||||
|
||||
uint32_t text_get_height(struct text* text) {
|
||||
|
@ -134,10 +136,18 @@ void text_destroy(struct text* text) {
|
|||
void text_calculate_bounds(struct text* text, uint32_t x, uint32_t y) {
|
||||
text->bounds.origin.x = x;
|
||||
text->bounds.origin.y = y - ((text->line.ascent - text->line.descent) / 2);
|
||||
|
||||
if (text->background.enabled) {
|
||||
text->background.bounds.size.width = text_get_length(text);
|
||||
text->background.bounds.size.height = text->background.overrides_height ? text->background.bounds.size.height : text->bounds.size.height;
|
||||
background_calculate_bounds(&text->background, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void text_draw(struct text* text, CGContextRef context) {
|
||||
if (!text->drawing) return;
|
||||
if (text->background.enabled)
|
||||
background_draw(&text->background, context);
|
||||
CGContextSetRGBFillColor(context, text->line.color.r, text->line.color.g, text->line.color.b, text->line.color.a);
|
||||
CGContextSetTextPosition(context, text->bounds.origin.x + text->padding_left, text->bounds.origin.y + text->y_offset);
|
||||
CTLineDraw(text->line.line, context);
|
||||
|
@ -176,9 +186,24 @@ static bool text_parse_sub_domain(struct text* text, FILE* rsp, struct token pro
|
|||
text->drawing = evaluate_boolean_state(get_token(&message), text->drawing);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
struct token subdom;
|
||||
struct token entry;
|
||||
get_key_value_pair(property.text, &subdom.text, &entry.text, '.');
|
||||
if (subdom.text && entry.text) {
|
||||
subdom.length = strlen(subdom.text);
|
||||
entry.length = strlen(entry.text);
|
||||
if (token_equals(subdom, SUB_DOMAIN_BACKGROUND))
|
||||
return background_parse_sub_domain(&text->background, rsp, entry, message);
|
||||
else {
|
||||
fprintf(rsp, "Invalid subdomain: %s \n", subdom.text);
|
||||
printf("Invalid subdomain: %s \n", subdom.text);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fprintf(rsp, "Unknown property: %s \n", property.text);
|
||||
printf("Unknown property: %s \n", property.text);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue