render: add function to set/update font
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Daniel Eklöf · committed by Daniel Eklöf · parent 13cac43 · Browse files · 3 files·+24 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+24 added−10 removed
- other:+24 added−10 removed
Provenance
- Commit
c7946c2- Tree
2670b19- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
13cac43
3 files changed+24 added−10 removed
modified:main.c+4 added-3 removed
401 unmodified lines402 else403 xdg_find_programs(terminal, apps);404 read_cache(apps);405 406- icon_reload_application_icons(themes, font->height, apps);407-408- if ((render = render_init(font, &render_options,406+ if ((render = render_init(&render_options,407 wayl_subpixel(wayl))) == NULL)408 goto out;409 410 if ((prompt = prompt_init(L"> ")) == NULL)2 unmodified lines413 if ((matches = matches_init(apps)) == NULL)414 goto out;415 416 matches_max_matches_set(matches, max_matches);417+ icon_reload_application_icons(themes, font->height, apps);418+ render_set_font(render, font);419+420 matches_update(matches, prompt);421 wayl_configure(wayl, render, prompt, matches, dmenu_mode);422 wayl_refresh(wayl);423 26 unmodified linesmodified:render.c+16 added-5 removed
108 unmodified lines109 render_prompt(const struct render *render, struct buffer *buf,110 const struct prompt *prompt)111 {112 struct fcft_font *font = render->font;113+ assert(font != NULL);114 115 const wchar_t *pprompt = prompt_prompt(prompt);116 const size_t prompt_len = wcslen(pprompt);117 68 unmodified lines186 render_match_list(const struct render *render, struct buffer *buf,187 const struct prompt *prompt, const struct matches *matches)188 {189 struct fcft_font *font = render->font;190+ assert(font != NULL);191+192 const double x_margin = render->options.x_margin;193 const double y_margin = render->options.y_margin;194 const double border_size = render->options.border_size;195 const size_t match_count = matches_get_count(matches);132 unmodified lines328 /* Application title */329 render_match_text(330 buf, &cur_x, y,331 match->application->title, match->start_title, wcslen(prompt_text(prompt)),329- render->font, subpixel,332+ font, subpixel,333 render->options.pix_text_color, render->options.pix_match_color);334 335 y += row_height;336 }337 }338 339 struct render *337-render_init(struct fcft_font *font, const struct render_options *options,340+render_init(const struct render_options *options,341 enum fcft_subpixel subpixel)342 {343 struct render *render = calloc(1, sizeof(*render));341- render->options = *options;342- render->font = font;343- render->subpixel = subpixel;344+ *render = (struct render){345+ .options = *options,346+ .subpixel = subpixel,347+ };348 349 /* TODO: the one providing the options should calculate these */350 render->options.pix_background_color = rgba2pixman(render->options.background_color);351 render->options.pix_border_color = rgba2pixman(render->options.border_color);3 unmodified lines355 return render;356 }357 358 void359+render_set_font(struct render *render, struct fcft_font *font)360+{361+ fcft_destroy(render->font);362+ render->font = font;363+}364+365+void366 render_destroy(struct render *render)367 {368 if (render == NULL)369 return;4 unmodified linesmodified:render.h+4 added-2 removed
32 unmodified lines33 pixman_color_t pix_selection_color;34 };35 36 struct render;37-struct render *render_init(struct fcft_font *font, const struct render_options *options,38- enum fcft_subpixel subpixel);37+struct render *render_init(38+ const struct render_options *options, enum fcft_subpixel subpixel);39 void render_destroy(struct render *render);40 41+void render_set_font(struct render *render, struct fcft_font *font);42+43 void render_background(const struct render *render, struct buffer *buf);44 45 void render_prompt(46 const struct render *render, struct buffer *buf,5 unmodified lines