align property for popup menus

This commit is contained in:
Felix Kratz 2021-12-19 22:31:39 +01:00
parent 7363b011b8
commit f8c5d107b6
3 changed files with 13 additions and 3 deletions

View file

@ -30,7 +30,13 @@ void bar_calculate_popup_anchor_for_bar_item(struct bar* bar, struct bar_item* b
bar_item->popup.cell_size = bar->frame.size.height;
popup_calculate_bounds(&bar_item->popup);
CGPoint anchor = bar->origin;
anchor.x += bar_item->icon.bounds.origin.x - bar_item->background.padding_left;
if (bar_item->popup.align == POSITION_CENTER) {
anchor.x += bar_item->icon.bounds.origin.x + bar_item->background.padding_left / 2 + (bar_item_get_length(bar_item, false) - bar_item->popup.background.bounds.size.width) / 2;
} else if (bar_item->popup.align == POSITION_LEFT) {
anchor.x += bar_item->icon.bounds.origin.x - bar_item->background.padding_left;
} else {
anchor.x += bar_item->icon.bounds.origin.x + bar_item_get_length(bar_item, false) - bar_item->popup.background.bounds.size.width;
}
anchor.y += (g_bar_manager.position == POSITION_BOTTOM ? (-bar->frame.size.height - bar_item->popup.background.bounds.size.height) : bar->frame.size.height);
if (anchor.x + bar_item->popup.background.bounds.size.width > bar->frame.size.width) {
anchor.x = bar->frame.size.width - bar_item->popup.background.bounds.size.width;

View file

@ -13,6 +13,7 @@ void popup_init(struct popup* popup) {
popup->anchor = (CGPoint){0, 0};
popup->y_offset = 0;
popup->adid = 0;
popup->align = POSITION_LEFT;
popup->num_items = 0;
popup->cell_size = 30;
@ -46,7 +47,6 @@ void popup_calculate_bounds(struct popup* popup) {
if ((popup->background.bounds.size.width != width + 2) || (popup->background.bounds.size.height != y - popup->cell_size / 2)) {
popup->background.bounds.size.width = width + 2;
popup->background.bounds.size.height = y - popup->cell_size / 2;
printf("Resizing\n");
popup_resize(popup);
}
@ -135,7 +135,6 @@ void popup_set_drawing(struct popup* popup, bool drawing) {
void popup_draw(struct popup* popup) {
if (!popup->drawing) return;
printf("Drawing....\n");
SLSOrderWindow(g_connection, popup->id, -1, 0);
draw_rect(popup->context, popup->frame, &popup->background.color, popup->background.corner_radius, popup->background.border_width, &popup->background.border_color, true);
@ -175,6 +174,10 @@ static bool popup_parse_sub_domain(struct popup* popup, FILE* rsp, struct token
} else if (token_equals(property, PROPERTY_HORIZONTAL)) {
popup->horizontal = evaluate_boolean_state(get_token(&message), popup->horizontal);
return true;
} else if (token_equals(property, PROPERTY_ALIGN)) {
popup->align = get_token(&message).text[0];
printf("Align: %c \n", popup->align);
return true;
}
else {
struct key_value_pair key_value_pair = get_key_value_pair(property.text, '.');

View file

@ -13,6 +13,7 @@ struct popup {
CGContextRef context;
CGRect frame;
struct background background;
char align;
uint32_t num_items;
struct bar_item** items;