mirror of
https://github.com/FelixKratz/SketchyBar
synced 2024-11-23 11:53:02 +00:00
allow popup.background.image and align popup elements properly
This commit is contained in:
parent
e22990e94b
commit
4ce61977e6
2 changed files with 49 additions and 9 deletions
|
@ -27,6 +27,8 @@ struct rgba_color {
|
|||
float a;
|
||||
};
|
||||
|
||||
static struct rgba_color g_transparent = { 0 };
|
||||
|
||||
struct token {
|
||||
char *text;
|
||||
unsigned int length;
|
||||
|
|
52
src/popup.c
52
src/popup.c
|
@ -22,8 +22,40 @@ void popup_init(struct popup* popup) {
|
|||
void popup_calculate_bounds(struct popup* popup) {
|
||||
uint32_t y = popup->background.border_width;
|
||||
uint32_t x = 0;
|
||||
uint32_t total_item_width = 0;
|
||||
uint32_t width = 0;
|
||||
uint32_t height = 0;
|
||||
|
||||
if (popup->background.enabled
|
||||
&& popup->background.image.enabled) {
|
||||
width = popup->background.image.bounds.size.width;
|
||||
}
|
||||
|
||||
if (popup->horizontal) {
|
||||
for (int j = 0; j < popup->num_items; j++) {
|
||||
struct bar_item* bar_item = popup->items[j];
|
||||
if (!bar_item->drawing) continue;
|
||||
uint32_t cell_height = bar_item_get_height(bar_item) > popup->cell_size
|
||||
? bar_item_get_height(bar_item)
|
||||
: popup->cell_size;
|
||||
|
||||
total_item_width += bar_item->background.padding_right
|
||||
+ bar_item->background.padding_left
|
||||
+ bar_item_get_length(bar_item, false);
|
||||
|
||||
if (cell_height > height && popup->horizontal) height = cell_height;
|
||||
}
|
||||
|
||||
if (popup->background.enabled
|
||||
&& popup->background.image.enabled) {
|
||||
if (popup->background.image.bounds.size.height > height)
|
||||
height = popup->background.image.bounds.size.height;
|
||||
|
||||
x = (width - total_item_width) / 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (int j = 0; j < popup->num_items; j++) {
|
||||
struct bar_item* bar_item = NULL;
|
||||
if (popup->horizontal) bar_item = popup->items[j];
|
||||
|
@ -36,18 +68,23 @@ void popup_calculate_bounds(struct popup* popup) {
|
|||
uint32_t item_width = bar_item->background.padding_right
|
||||
+ bar_item->background.padding_left
|
||||
+ bar_item_calculate_bounds(bar_item,
|
||||
cell_height,
|
||||
popup->horizontal
|
||||
? height
|
||||
: cell_height,
|
||||
x,
|
||||
y + cell_height / 2);
|
||||
y + (popup->horizontal
|
||||
? height
|
||||
: cell_height) / 2);
|
||||
|
||||
if (item_width > width && !popup->horizontal) width = item_width;
|
||||
if (cell_height > height && popup->horizontal) height = cell_height;
|
||||
if (popup->horizontal) x += item_width;
|
||||
else y += cell_height;
|
||||
}
|
||||
|
||||
if (popup->horizontal) {
|
||||
if (!popup->background.enabled || !popup->background.image.enabled) {
|
||||
width = x;
|
||||
}
|
||||
y += height;
|
||||
}
|
||||
y += popup->background.border_width;
|
||||
|
@ -136,11 +173,12 @@ void popup_draw(struct popup* popup) {
|
|||
popup->background.bounds.size.height}});
|
||||
draw_rect(popup->window.context,
|
||||
popup->background.bounds,
|
||||
&popup->background.color,
|
||||
popup->background.corner_radius,
|
||||
popup->background.border_width,
|
||||
&popup->background.border_color,
|
||||
&g_transparent,
|
||||
0,
|
||||
0,
|
||||
&g_transparent,
|
||||
true );
|
||||
background_draw(&popup->background, popup->window.context);
|
||||
|
||||
for (int i = 0; i < popup->num_items; i++) {
|
||||
struct bar_item* bar_item = popup->items[i];
|
||||
|
|
Loading…
Reference in a new issue