particle/empty: placeholder particle, renders nothing

But may have margins.
This commit is contained in:
Daniel Eklöf 2018-12-27 14:21:33 +01:00
parent 99008c5ad9
commit ce895ac44f
4 changed files with 69 additions and 1 deletions

View file

@ -40,6 +40,7 @@ add_executable(f00bar
decorations/stack.c decorations/stack.h
decorations/underline.c decorations/underline.h
particles/empty.c particles/empty.h
particles/list.c particles/list.h
particles/map.c particles/map.h
particles/ramp.c particles/ramp.h

View file

@ -13,6 +13,7 @@
#include "decorations/underline.h"
#include "particle.h"
#include "particles/empty.h"
#include "particles/list.h"
#include "particles/map.h"
#include "particles/ramp.h"
@ -164,6 +165,21 @@ deco_from_config(const struct yml_node *node)
assert(false);
}
static struct particle *
particle_empty_from_config(const struct yml_node *node,
const struct font *parent_font)
{
const struct yml_node *left_margin = yml_get_value(node, "left_margin");
const struct yml_node *right_margin = yml_get_value(node, "right_margin");
assert(left_margin == NULL || yml_is_scalar(left_margin));
assert(right_margin == NULL || yml_is_scalar(right_margin));
return particle_empty_new(
left_margin != NULL ? yml_value_as_int(left_margin) : 0,
right_margin != NULL ? yml_value_as_int(right_margin) : 0);
}
static struct particle *
particle_string_from_config(const struct yml_node *node,
const struct font *parent_font)
@ -318,7 +334,9 @@ particle_from_config(const struct yml_node *node, const struct font *parent_font
const char *type = yml_value_as_string(pair.key);
struct particle *ret = NULL;
if (strcmp(type, "string") == 0)
if (strcmp(type, "empty") == 0)
ret = particle_empty_from_config(pair.value, parent_font);
else if (strcmp(type, "string") == 0)
ret = particle_string_from_config(pair.value, parent_font);
else if (strcmp(type, "list") == 0)
ret = particle_list_from_config(pair.value, parent_font);

45
particles/empty.c Normal file
View file

@ -0,0 +1,45 @@
#include "empty.h"
#include <stdlib.h>
static void
exposable_destroy(struct exposable *exposable)
{
free(exposable);
}
static int
begin_expose(struct exposable *exposable, cairo_t *cr)
{
exposable->width = exposable->particle->left_margin +
exposable->particle->right_margin;
return exposable->width;
}
static void
expose(const struct exposable *exposable, cairo_t *cr, int x, int y, int height)
{
const struct deco *deco = exposable->particle->deco;
if (deco != NULL)
deco->expose(deco, cr, x, y, exposable->width, height);
}
static struct exposable *
instantiate(const struct particle *particle, const struct tag_set *tags)
{
struct exposable *exposable = malloc(sizeof(*exposable));
exposable->particle = particle;
exposable->destroy = &exposable_destroy;
exposable->begin_expose = &begin_expose;
exposable->expose = &expose;
return exposable;
}
struct particle *
particle_empty_new(int left_margin, int right_margin)
{
struct particle *particle = particle_common_new(left_margin, right_margin);
particle->destroy = &particle_default_destroy;
particle->instantiate = &instantiate;
return particle;
}

4
particles/empty.h Normal file
View file

@ -0,0 +1,4 @@
#pragma once
#include "../particle.h"
struct particle *particle_empty_new(int left_margin, int right_margin);