mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-06-21 01:45:40 +02:00
Basic vertical rendering
- Add height attribute to most particles for height generation on the fly
This commit is contained in:
parent
37b5b02fc4
commit
60c18246d8
23 changed files with 286 additions and 158 deletions
100
particles/list.c
100
particles/list.c
|
@ -1,4 +1,5 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define LOG_MODULE "list"
|
||||
#define LOG_ENABLE_DBG 0
|
||||
|
@ -11,14 +12,17 @@
|
|||
struct private {
|
||||
struct particle **particles;
|
||||
size_t count;
|
||||
int left_spacing, right_spacing;
|
||||
bool vertical;
|
||||
int pre_spacing, post_spacing;
|
||||
};
|
||||
|
||||
struct eprivate {
|
||||
struct exposable **exposables;
|
||||
int *widths;
|
||||
int *heights;
|
||||
bool vertical;
|
||||
size_t count;
|
||||
int left_spacing, right_spacing;
|
||||
int pre_spacing, post_spacing;
|
||||
};
|
||||
|
||||
|
||||
|
@ -31,6 +35,7 @@ exposable_destroy(struct exposable *exposable)
|
|||
|
||||
free(e->exposables);
|
||||
free(e->widths);
|
||||
free(e->heights);
|
||||
free(e);
|
||||
exposable_default_destroy(exposable);
|
||||
}
|
||||
|
@ -42,25 +47,39 @@ begin_expose(struct exposable *exposable)
|
|||
bool have_at_least_one = false;
|
||||
|
||||
exposable->width = 0;
|
||||
exposable->height = 0;
|
||||
|
||||
for (size_t i = 0; i < e->count; i++) {
|
||||
struct exposable *ee = e->exposables[i];
|
||||
e->widths[i] = ee->begin_expose(ee);
|
||||
ee->begin_expose(ee);
|
||||
e->widths[i] = ee->width;
|
||||
e->heights[i] = ee->height;
|
||||
|
||||
assert(e->widths[i] >= 0);
|
||||
assert(e->widths[i] >= 0 && e->heights[i] >= 0);
|
||||
|
||||
if (e->widths[i] > 0) {
|
||||
exposable->width += e->left_spacing + e->widths[i] + e->right_spacing;
|
||||
if (e->widths[i] > 0 && e->heights[i] > 0) {
|
||||
if (e->vertical) {
|
||||
exposable->height += e->pre_spacing + e->heights[i] + e->post_spacing;
|
||||
if (e->widths[i] > exposable->width)
|
||||
exposable->width = e->widths[i];
|
||||
} else {
|
||||
exposable->width += e->pre_spacing + e->widths[i] + e->post_spacing;
|
||||
if (e->heights[i] > exposable->height)
|
||||
exposable->height = e->heights[i];
|
||||
}
|
||||
have_at_least_one = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (have_at_least_one) {
|
||||
exposable->width -= e->left_spacing + e->right_spacing;
|
||||
exposable->width += exposable->particle->left_margin;
|
||||
exposable->width += exposable->particle->right_margin;
|
||||
if(e->vertical)
|
||||
exposable->width -= e->pre_spacing + e->post_spacing;
|
||||
else
|
||||
exposable->height -= e->pre_spacing + e->post_spacing;
|
||||
exposable->width += exposable->particle->left_margin + exposable->particle->right_margin;
|
||||
exposable->height += exposable->particle->top_margin + exposable->particle->bottom_margin;
|
||||
} else
|
||||
assert(exposable->width == 0);
|
||||
assert(exposable->width == 0 && exposable->height == 0);
|
||||
|
||||
return exposable->width;
|
||||
}
|
||||
|
@ -70,20 +89,31 @@ expose(const struct exposable *exposable, pixman_image_t *pix, int x, int y, int
|
|||
{
|
||||
const struct eprivate *e = exposable->private;
|
||||
|
||||
exposable_render_deco(exposable, pix, x, y, height);
|
||||
exposable_render_deco(exposable, pix, x, y);
|
||||
|
||||
int left_margin = exposable->particle->left_margin;
|
||||
int left_spacing = e->left_spacing;
|
||||
int right_spacing = e->right_spacing;
|
||||
int pre_spacing = e->pre_spacing;
|
||||
int post_spacing = e->post_spacing;
|
||||
x += exposable->particle->left_margin;
|
||||
y += exposable->particle->top_margin;
|
||||
|
||||
x += left_margin - left_spacing;
|
||||
for (size_t i = 0; i < e->count; i++) {
|
||||
const struct exposable *ee = e->exposables[i];
|
||||
ee->expose(ee, pix, x + left_spacing, y, height);
|
||||
x += left_spacing + e->widths[i] + right_spacing;
|
||||
if (e->vertical) {
|
||||
y -= pre_spacing;
|
||||
for (size_t i = 0; i < e->count; i++) {
|
||||
const struct exposable *ee = e->exposables[i];
|
||||
ee->expose(ee, pix, x, y + pre_spacing, height);
|
||||
x += pre_spacing + e->heights[i] + post_spacing;
|
||||
}
|
||||
} else {
|
||||
x -= pre_spacing;
|
||||
for (size_t i = 0; i < e->count; i++) {
|
||||
const struct exposable *ee = e->exposables[i];
|
||||
ee->expose(ee, pix, x + pre_spacing, y, height);
|
||||
x += pre_spacing + e->widths[i] + post_spacing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: update for vertical lists
|
||||
static void
|
||||
on_mouse(struct exposable *exposable, struct bar *bar,
|
||||
enum mouse_event event, enum mouse_button btn, int x, int y)
|
||||
|
@ -110,7 +140,7 @@ on_mouse(struct exposable *exposable, struct bar *bar,
|
|||
return;
|
||||
}
|
||||
|
||||
px += e->left_spacing + e->exposables[i]->width + e->right_spacing;
|
||||
px += e->pre_spacing + e->exposables[i]->width + e->post_spacing;
|
||||
}
|
||||
|
||||
/* We're between sub-particles (or in the left/right margin) */
|
||||
|
@ -125,9 +155,11 @@ instantiate(const struct particle *particle, const struct tag_set *tags)
|
|||
struct eprivate *e = calloc(1, sizeof(*e));
|
||||
e->exposables = malloc(p->count * sizeof(*e->exposables));
|
||||
e->widths = calloc(p->count, sizeof(*e->widths));
|
||||
e->heights = calloc(p->count, sizeof(*e->heights));
|
||||
e->count = p->count;
|
||||
e->left_spacing = p->left_spacing;
|
||||
e->right_spacing = p->right_spacing;
|
||||
e->vertical = p->vertical;
|
||||
e->pre_spacing = p->pre_spacing;
|
||||
e->post_spacing = p->post_spacing;
|
||||
|
||||
for (size_t i = 0; i < p->count; i++) {
|
||||
const struct particle *pp = p->particles[i];
|
||||
|
@ -158,13 +190,14 @@ particle_destroy(struct particle *particle)
|
|||
struct particle *
|
||||
particle_list_new(struct particle *common,
|
||||
struct particle *particles[], size_t count,
|
||||
int left_spacing, int right_spacing)
|
||||
bool vertical, int pre_spacing, int post_spacing)
|
||||
{
|
||||
struct private *p = calloc(1, sizeof(*p));
|
||||
p->particles = malloc(count * sizeof(p->particles[0]));
|
||||
p->count = count;
|
||||
p->left_spacing = left_spacing;
|
||||
p->right_spacing = right_spacing;
|
||||
p->vertical = vertical;
|
||||
p->pre_spacing = pre_spacing;
|
||||
p->post_spacing = post_spacing;
|
||||
|
||||
for (size_t i = 0; i < count; i++)
|
||||
p->particles[i] = particles[i];
|
||||
|
@ -180,13 +213,16 @@ from_conf(const struct yml_node *node, struct particle *common)
|
|||
{
|
||||
const struct yml_node *items = yml_get_value(node, "items");
|
||||
const struct yml_node *spacing = yml_get_value(node, "spacing");
|
||||
const struct yml_node *_left_spacing = yml_get_value(node, "left-spacing");
|
||||
const struct yml_node *_right_spacing = yml_get_value(node, "right-spacing");
|
||||
const struct yml_node *_pre_spacing = yml_get_value(node, "pre-spacing");
|
||||
const struct yml_node *_post_spacing = yml_get_value(node, "post-spacing");
|
||||
const struct yml_node *_vertical = yml_get_value(node, "vertical");
|
||||
|
||||
int left_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
||||
_left_spacing != NULL ? yml_value_as_int(_left_spacing) : 0;
|
||||
int right_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
||||
_right_spacing != NULL ? yml_value_as_int(_right_spacing) : 2;
|
||||
int pre_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
||||
_pre_spacing != NULL ? yml_value_as_int(_pre_spacing) : 0;
|
||||
int post_spacing = spacing != NULL ? yml_value_as_int(spacing) :
|
||||
_post_spacing != NULL ? yml_value_as_int(_post_spacing) : 2;
|
||||
|
||||
bool vertical = _vertical != NULL ? yml_value_as_bool(_vertical) : false;
|
||||
|
||||
size_t count = yml_list_length(items);
|
||||
struct particle *parts[count];
|
||||
|
@ -200,7 +236,7 @@ from_conf(const struct yml_node *node, struct particle *common)
|
|||
it.node, (struct conf_inherit){common->font, common->font_shaping, common->foreground});
|
||||
}
|
||||
|
||||
return particle_list_new(common, parts, count, left_spacing, right_spacing);
|
||||
return particle_list_new(common, parts, count, vertical, pre_spacing, post_spacing);
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue