forked from external/yambar
particle/list: optionally destroy sub particles
This was always done before. Now that it is optional, one can for example generate lists dynamically, using the same set of base particles over and over again.
This commit is contained in:
parent
24313ea75a
commit
c5d3e934b4
3 changed files with 16 additions and 5 deletions
3
config.c
3
config.c
|
@ -166,7 +166,8 @@ particle_list_from_config(const struct yml_node *node,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct particle *list = particle_list_new(
|
struct particle *list = particle_list_new(
|
||||||
parts, count, left_spacing, right_spacing, left_margin, right_margin);
|
parts, count, left_spacing, right_spacing, left_margin, right_margin,
|
||||||
|
true);
|
||||||
|
|
||||||
free(parts);
|
free(parts);
|
||||||
return list;
|
return list;
|
||||||
|
|
|
@ -5,6 +5,7 @@ struct particle_private {
|
||||||
struct particle **particles;
|
struct particle **particles;
|
||||||
size_t count;
|
size_t count;
|
||||||
int left_spacing, right_spacing;
|
int left_spacing, right_spacing;
|
||||||
|
bool has_ownership;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct exposable_private {
|
struct exposable_private {
|
||||||
|
@ -93,8 +94,12 @@ static void
|
||||||
particle_destroy(struct particle *particle)
|
particle_destroy(struct particle *particle)
|
||||||
{
|
{
|
||||||
struct particle_private *p = particle->private;
|
struct particle_private *p = particle->private;
|
||||||
for (size_t i = 0; i < p->count; i++)
|
|
||||||
p->particles[i]->destroy(p->particles[i]);
|
if (p->has_ownership) {
|
||||||
|
for (size_t i = 0; i < p->count; i++)
|
||||||
|
p->particles[i]->destroy(p->particles[i]);
|
||||||
|
}
|
||||||
|
|
||||||
free(p->particles);
|
free(p->particles);
|
||||||
free(p);
|
free(p);
|
||||||
free(particle);
|
free(particle);
|
||||||
|
@ -103,13 +108,15 @@ particle_destroy(struct particle *particle)
|
||||||
struct particle *
|
struct particle *
|
||||||
particle_list_new(
|
particle_list_new(
|
||||||
struct particle *particles[], size_t count,
|
struct particle *particles[], size_t count,
|
||||||
int left_spacing, int right_spacing, int left_margin, int right_margin)
|
int left_spacing, int right_spacing, int left_margin, int right_margin,
|
||||||
|
bool take_ownership)
|
||||||
{
|
{
|
||||||
struct particle_private *p = malloc(sizeof(*p));
|
struct particle_private *p = malloc(sizeof(*p));
|
||||||
p->particles = malloc(count * sizeof(p->particles[0]));
|
p->particles = malloc(count * sizeof(p->particles[0]));
|
||||||
p->count = count;
|
p->count = count;
|
||||||
p->left_spacing = left_spacing;
|
p->left_spacing = left_spacing;
|
||||||
p->right_spacing = right_spacing;
|
p->right_spacing = right_spacing;
|
||||||
|
p->has_ownership = take_ownership;
|
||||||
|
|
||||||
for (size_t i = 0; i < count; i++)
|
for (size_t i = 0; i < count; i++)
|
||||||
p->particles[i] = particles[i];
|
p->particles[i] = particles[i];
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include "../particle.h"
|
#include "../particle.h"
|
||||||
|
|
||||||
struct particle *particle_list_new(
|
struct particle *particle_list_new(
|
||||||
struct particle *particles[], size_t count,
|
struct particle *particles[], size_t count,
|
||||||
int left_spacing, int right_spacing, int left_margin, int right_margin);
|
int left_spacing, int right_spacing, int left_margin, int right_margin,
|
||||||
|
bool take_ownership);
|
||||||
|
|
Loading…
Add table
Reference in a new issue