mirror of
https://github.com/FelixKratz/SketchyBar
synced 2025-02-16 20:48:26 +00:00
fix item width calculation
This commit is contained in:
parent
945a430d44
commit
70f14d8f20
3 changed files with 13 additions and 7 deletions
|
@ -170,7 +170,7 @@ Geometry Properties:
|
|||
* *associated_space*: on which space to show this item (can be multiple, not specifying anything will show item on all spaces)
|
||||
* *associated_display*: on which displays to show this item (can be multiple, not specifying anything will show item on all displays)
|
||||
* *width*: overrides the width of the item (useful for items which frequently change in width and thus move all other items) (values: width in points and *dynamic*)
|
||||
* *align*: aligns the content within a larger background (*left*, *center*, *right*, default: *left*)(Only on HEAD)
|
||||
* *align*: aligns the content within a larger background (either by setting a custom *width* or a background image) (*left*, *center*, *right*, default: *\<position\>*)(Only on HEAD)
|
||||
* *y_offset*: the vertical offset of this item (default: 0)
|
||||
|
||||
Icon properties:
|
||||
|
|
|
@ -226,6 +226,8 @@ void bar_item_set_type(struct bar_item* bar_item, char type) {
|
|||
|
||||
void bar_item_set_position(struct bar_item* bar_item, char position) {
|
||||
bar_item->position = position;
|
||||
if (position != POSITION_POPUP)
|
||||
bar_item->align = position;
|
||||
}
|
||||
|
||||
void bar_item_set_script(struct bar_item* bar_item, char* script) {
|
||||
|
@ -286,10 +288,12 @@ void bar_item_set_yoffset(struct bar_item* bar_item, int offset) {
|
|||
}
|
||||
|
||||
uint32_t bar_item_get_content_length(struct bar_item* bar_item) {
|
||||
return text_get_length(&bar_item->icon, false)
|
||||
int length = text_get_length(&bar_item->icon, false)
|
||||
+ text_get_length(&bar_item->label, false)
|
||||
+ (bar_item->has_graph ? graph_get_length(&bar_item->graph) : 0)
|
||||
+ (bar_item->has_alias ? alias_get_length(&bar_item->alias) : 0);
|
||||
|
||||
return length > 0 ? length : 0;
|
||||
}
|
||||
|
||||
uint32_t bar_item_get_length(struct bar_item* bar_item, bool ignore_override) {
|
||||
|
@ -297,7 +301,9 @@ uint32_t bar_item_get_length(struct bar_item* bar_item, bool ignore_override) {
|
|||
if (bar_item->background.enabled && bar_item->background.image.enabled && bar_item->background.image.bounds.size.width > content_length)
|
||||
content_length = bar_item->background.image.bounds.size.width;
|
||||
|
||||
if (bar_item->has_const_width && (!ignore_override || bar_item->custom_width > content_length)) return bar_item->custom_width - bar_item->background.padding_left - bar_item->background.padding_right;
|
||||
if (bar_item->has_const_width && (!ignore_override || bar_item->custom_width > content_length)) {
|
||||
return bar_item->custom_width;
|
||||
}
|
||||
return content_length;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,12 +48,12 @@ uint32_t group_get_length(struct group* group) {
|
|||
for (int i = 1; i < group->num_members; i++) {
|
||||
if (group->members[i]->drawing) {
|
||||
if (group->members[i]->position == POSITION_RIGHT) {
|
||||
if (i > 1) length += group->members[i]->background.padding_right;
|
||||
if (i < group->num_members - 1) length += group->members[i]->background.padding_left;
|
||||
if (i > 1 && !group->members[i]->has_const_width) length += group->members[i]->background.padding_right;
|
||||
if (i < group->num_members - 1 && !group->members[i]->has_const_width) length += group->members[i]->background.padding_left;
|
||||
}
|
||||
else {
|
||||
if (i > 1) length += group->members[i]->background.padding_left;
|
||||
if (i < group->num_members - 1) length += group->members[i]->background.padding_right;
|
||||
if (i > 1 && !group->members[i]->has_const_width) length += group->members[i]->background.padding_left;
|
||||
if (i < group->num_members - 1 && !group->members[i]->has_const_width) length += group->members[i]->background.padding_right;
|
||||
}
|
||||
length += bar_item_get_length(group->members[i], false);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue