Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "top" option to icon_position rule and hide_text rule #985

Merged
merged 21 commits into from
Jan 22, 2022
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
536adf0
add icon_position rule, add top as possible value
m-bartlett Jan 8, 2022
7f9db5a
support ICON_TOP initial implementation
m-bartlett Jan 9, 2022
39a7d1c
center progress bar
m-bartlett Jan 10, 2022
4357000
remove commented lines
m-bartlett Jan 15, 2022
46c691e
add hide_text notification rule and documentation
m-bartlett Jan 15, 2022
7d5f465
change icon_position to enum in notification struct
m-bartlett Jan 15, 2022
bc91854
implement hide_text compatibily with icon_position
m-bartlett Jan 15, 2022
0e388bb
add test for icon_position & hide_text
m-bartlett Jan 16, 2022
5ef58f6
minor formatting
m-bartlett Jan 16, 2022
cfada42
simplify hide_text boolean checks
m-bartlett Jan 16, 2022
87a8b60
simplify ternary width check
m-bartlett Jan 16, 2022
db460c7
remove unintentional newline
m-bartlett Jan 16, 2022
1c1e89b
remove icon_position global setting
m-bartlett Jan 17, 2022
20d2ffe
use default icons for icon_position & hide_text tests
m-bartlett Jan 17, 2022
4bdf2ab
use text_icon_padding when icon_position == ICON_TOP
m-bartlett Jan 17, 2022
cf3393e
undo enum init leading to incorrect default overriding
m-bartlett Jan 17, 2022
80a7e28
fix config with incorrect enum init default values
m-bartlett Jan 17, 2022
903719c
simplify layout_get_height
m-bartlett Jan 22, 2022
e0189e6
restore text_icon_padding functions with icon-conditionals
m-bartlett Jan 22, 2022
7d56731
default icon_position = left
m-bartlett Jan 22, 2022
b20544a
add padding demonstration to icon_position tests
m-bartlett Jan 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 44 additions & 14 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static struct color layout_get_sepcolor(struct colored_layout *cl,
}
}

static int get_text_icon_padding()
static int get_horizontal_text_icon_padding()
{
if (settings.text_icon_padding) {
return settings.text_icon_padding;
Expand All @@ -176,6 +176,15 @@ static int get_text_icon_padding()
}
}

static int get_vertical_text_icon_padding()
{
if (settings.text_icon_padding) {
return settings.text_icon_padding;
} else {
return settings.padding;
}
}

static bool have_progress_bar(const struct colored_layout *cl)
{
return (cl->n->progress >= 0 && settings.progress_bar == true &&
Expand Down Expand Up @@ -220,8 +229,8 @@ static void layout_setup_pango(PangoLayout *layout, int width, int height,
// @param height Height of the layout
static void layout_setup(struct colored_layout *cl, int width, int height, double scale)
{
int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_text_icon_padding() : 0;
int text_width = width - icon_width - 2 * settings.h_padding;
int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_horizontal_text_icon_padding() : 0;
int text_width = width - 2 * settings.h_padding - (cl->n->icon_position != ICON_TOP ? icon_width : 0);
int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0;
int max_text_height = MAX(0, settings.height - progress_bar_height - 2 * settings.padding);
layout_setup_pango(cl->l, text_width, max_text_height, cl->n->word_wrap, cl->n->ellipsize, cl->n->alignment);
Expand All @@ -242,12 +251,18 @@ static struct dimensions calculate_notification_dimensions(struct colored_layout
struct dimensions dim = { 0 };
layout_setup(cl, settings.width.max, settings.height, scale);

int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_text_icon_padding() : 0;
int icon_width = cl->icon? get_icon_width(cl->icon, scale) + get_horizontal_text_icon_padding() : 0;
int icon_height = cl->icon? get_icon_height(cl->icon, scale) : 0;
int progress_bar_height = have_progress_bar(cl) ? settings.progress_bar_height + settings.padding : 0;
get_text_size(cl->l, &dim.text_width, &dim.text_height, scale);

dim.h = MAX(icon_height, dim.text_height);
if (cl->n->icon_position == ICON_TOP && cl->n->icon) {
// dim.h = icon_height + dim.text_height + settings.padding*2 + get_vertical_text_icon_padding();
dim.h = icon_height + dim.text_height + get_vertical_text_icon_padding();
} else {
dim.h = MAX(icon_height, dim.text_height);
}

dim.h += progress_bar_height;
dim.w = dim.text_width + icon_width + 2 * settings.h_padding;

Expand Down Expand Up @@ -335,7 +350,7 @@ static struct colored_layout *layout_from_notification(cairo_t *c, struct notifi

struct colored_layout *cl = layout_init_shared(c, n);

if (settings.icon_position != ICON_OFF && n->icon) {
if (n->icon_position != ICON_OFF && n->icon) {
cl->icon = n->icon;
} else {
cl->icon = NULL;
Expand Down Expand Up @@ -399,17 +414,22 @@ static GSList *create_layouts(cairo_t *c)

static int layout_get_height(struct colored_layout *cl, double scale)
{
int h;
int h_text;
int h_icon = 0;
int h_progress_bar = 0;
get_text_size(cl->l, NULL, &h, scale);
get_text_size(cl->l, NULL, &h_text, scale);
if (cl->icon)
h_icon = get_icon_height(cl->icon, scale);
if (have_progress_bar(cl)){
h_progress_bar = settings.progress_bar_height + settings.padding;
}

int res = MAX(h, h_icon) + h_progress_bar;
int res = MAX(h_text, h_icon) + h_progress_bar;

if (cl->n->icon_position == ICON_TOP && cl->n->icon) {
res = h_icon + h_text + h_progress_bar + get_vertical_text_icon_padding();
}

return res;
}

Expand Down Expand Up @@ -594,9 +614,10 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, dou
const int h = layout_get_height(cl, scale);
LOG_D("Layout height %i", h);
int h_without_progress_bar = h;
if (have_progress_bar(cl)){
if (have_progress_bar(cl)) {
h_without_progress_bar -= settings.progress_bar_height + settings.padding;
}

int h_text;
get_text_size(cl->l, NULL, &h_text, scale);

Expand All @@ -615,8 +636,10 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, dou
} // else VERTICAL_CENTER

// icon position
if (settings.icon_position == ICON_LEFT) {
text_x = get_icon_width(cl->icon, scale) + settings.h_padding + get_text_icon_padding();
if (cl->n->icon_position == ICON_LEFT) {
text_x = get_icon_width(cl->icon, scale) + settings.h_padding + get_horizontal_text_icon_padding();
} else if (cl->n->icon_position == ICON_TOP) {
text_y = get_icon_height(cl->icon, scale) + settings.padding + get_vertical_text_icon_padding();
} // else ICON_RIGHT
}
cairo_move_to(c, round(text_x * scale), round(text_y * scale));
Expand All @@ -643,8 +666,13 @@ static void render_content(cairo_t *c, struct colored_layout *cl, int width, dou
} // else VERTICAL_CENTER

// icon position
if (settings.icon_position == ICON_LEFT) {
if (cl->n->icon_position == ICON_LEFT) {
image_x = settings.h_padding;
} else if (cl->n->icon_position == ICON_TOP) {
image_y = settings.padding;
image_x = width/2 - image_width/2;
// image_x = settings.h_padding + image_width/2;
// image_x = image_width/2;
} // else ICON_RIGHT

cairo_set_source_surface(c, cl->icon, round(image_x * scale), round(image_y * scale));
Expand Down Expand Up @@ -701,11 +729,13 @@ static struct dimensions layout_render(cairo_surface_t *srf,
bool last)
{
double scale = output->get_scale();
const int cl_h = layout_get_height(cl, scale);

int h_text = 0;
get_text_size(cl->l, NULL, &h_text, scale);

const int cl_h = layout_get_height(cl, scale);


int bg_width = 0;
int bg_height = MIN(settings.height, (2 * settings.padding) + cl_h);

Expand Down