exposable: add a 'width' member, set (at latest) in begin_expose()

This commit is contained in:
Daniel Eklöf 2018-12-26 16:37:11 +01:00
parent a745436ee2
commit ce68bdb59d
4 changed files with 26 additions and 22 deletions

View file

@ -12,21 +12,21 @@ struct private {
}; };
static int static int
dynlist_begin_expose(const struct exposable *exposable, cairo_t *cr) dynlist_begin_expose(struct exposable *exposable, cairo_t *cr)
{ {
const struct private *e = exposable->private; const struct private *e = exposable->private;
int width = 0; exposable->width = 0;
for (size_t i = 0; i < e->count; i++) { for (size_t i = 0; i < e->count; i++) {
struct exposable *ee = e->exposables[i]; struct exposable *ee = e->exposables[i];
e->widths[i] = ee->begin_expose(ee, cr); e->widths[i] = ee->begin_expose(ee, cr);
width += e->left_spacing + e->widths[i] + e->right_spacing; exposable->width += e->left_spacing + e->widths[i] + e->right_spacing;
} }
width -= e->left_spacing + e->right_spacing; exposable->width -= e->left_spacing + e->right_spacing;
return width; return exposable->width;
} }
static void static void

View file

@ -26,8 +26,10 @@ struct exposable {
const struct particle *particle; const struct particle *particle;
void *private; void *private;
int width; /* Should be set by begin_expose(), at latest */
void (*destroy)(struct exposable *exposable); void (*destroy)(struct exposable *exposable);
int (*begin_expose)(const struct exposable *exposable, cairo_t *cr); int (*begin_expose)(struct exposable *exposable, cairo_t *cr);
void (*expose)(const struct exposable *exposable, cairo_t *cr, void (*expose)(const struct exposable *exposable, cairo_t *cr,
int x, int y, int height); int x, int y, int height);
}; };

View file

@ -15,22 +15,22 @@ struct exposable_private {
}; };
static int static int
begin_expose(const struct exposable *exposable, cairo_t *cr) begin_expose(struct exposable *exposable, cairo_t *cr)
{ {
const struct exposable_private *e = exposable->private; const struct exposable_private *e = exposable->private;
int width = exposable->particle->left_margin; exposable->width = exposable->particle->left_margin;
for (size_t i = 0; i < e->count; i++) { for (size_t i = 0; i < e->count; i++) {
struct exposable *ee = e->exposables[i]; struct exposable *ee = e->exposables[i];
e->widths[i] = ee->begin_expose(ee, cr); e->widths[i] = ee->begin_expose(ee, cr);
width += e->left_spacing + e->widths[i] + e->right_spacing; exposable->width += e->left_spacing + e->widths[i] + e->right_spacing;
} }
width -= e->left_spacing + e->right_spacing; exposable->width -= e->left_spacing + e->right_spacing;
width += exposable->particle->right_margin; exposable->width += exposable->particle->right_margin;
return width; return exposable->width;
} }
static void static void
@ -38,6 +38,10 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
{ {
const struct exposable_private *e = exposable->private; const struct exposable_private *e = exposable->private;
const struct deco *deco = exposable->particle->deco;
if (deco != NULL)
deco->expose(deco, cr, x, y, exposable->width, height);
int left_margin = exposable->particle->left_margin; int left_margin = exposable->particle->left_margin;
int left_spacing = e->left_spacing; int left_spacing = e->left_spacing;
int right_spacing = e->right_spacing; int right_spacing = e->right_spacing;

View file

@ -12,7 +12,7 @@ struct private {
}; };
static int static int
begin_expose(const struct exposable *exposable, cairo_t *cr) begin_expose(struct exposable *exposable, cairo_t *cr)
{ {
const struct private *e = exposable->private; const struct private *e = exposable->private;
@ -20,9 +20,11 @@ begin_expose(const struct exposable *exposable, cairo_t *cr)
cairo_text_extents_t extents; cairo_text_extents_t extents;
cairo_scaled_font_text_extents(scaled, e->text, &extents); cairo_scaled_font_text_extents(scaled, e->text, &extents);
return (exposable->particle->left_margin + exposable->width = (exposable->particle->left_margin +
extents.x_advance + extents.x_advance +
exposable->particle->right_margin); exposable->particle->right_margin);
return exposable->width;
} }
static void static void
@ -47,12 +49,8 @@ expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
&clusters, &num_clusters, &cluster_flags); &clusters, &num_clusters, &cluster_flags);
const struct deco *deco = exposable->particle->deco; const struct deco *deco = exposable->particle->deco;
if (deco != NULL) { if (deco != NULL)
int width = (exposable->particle->left_margin + deco->expose(deco, cr, x, y, exposable->width, height);
extents.x_advance +
exposable->particle->right_margin);
deco->expose(deco, cr, x, y, width, height);
}
cairo_set_source_rgba(cr, cairo_set_source_rgba(cr,
e->foreground.red, e->foreground.red,