complete query rewrite

This commit is contained in:
Felix Kratz 2022-07-20 17:46:06 +02:00
parent b6079ff331
commit e8901eadeb
7 changed files with 80 additions and 26 deletions

View file

@ -731,11 +731,22 @@ void bar_item_serialize(struct bar_item* bar_item, FILE* rsp) {
}
fprintf(rsp, "\n\t}");
if (bar_item->type == BAR_COMPONENT_GROUP && bar_item->group) {
group_serialize(bar_item->group, rsp);
} else if (bar_item->type == BAR_COMPONENT_GRAPH) {
graph_serialize(&bar_item->graph, rsp);
if (bar_item->popup.num_items > 0) {
fprintf(rsp, ",\n\t\"popup\": {\n");
popup_serialize(&bar_item->popup, "\t\t", rsp);
fprintf(rsp, "\n\t}");
}
if (bar_item->type == BAR_COMPONENT_GROUP && bar_item->group) {
fprintf(rsp, ",\n\t\"bracket\": [\n");
group_serialize(bar_item->group, "\t\t", rsp);
fprintf(rsp, "\n\t]");
} else if (bar_item->type == BAR_COMPONENT_GRAPH) {
fprintf(rsp, ",\n\t\"graph\": {\n");
graph_serialize(&bar_item->graph, "\t\t", rsp);
fprintf(rsp, "\n\t}");
}
fprintf(rsp, "\n}\n");
}

View file

@ -106,23 +106,20 @@ void graph_draw(struct graph* graph, CGContextRef context) {
CGContextRestoreGState(context);
}
void graph_serialize(struct graph* graph, FILE* rsp) {
fprintf(rsp, ",\n"
"\t\"graph\": {\n"
"\t\t\"graph.color\": \"0x%x\",\n"
"\t\t\"graph.fill_color\": \"0x%x\",\n"
"\t\t\"graph.line_width\": \"%f\",\n"
"\t\t\"data\": [\n",
hex_from_rgba_color(graph->line_color),
hex_from_rgba_color(graph->fill_color),
graph->line_width);
void graph_serialize(struct graph* graph, char* indent, FILE* rsp) {
fprintf(rsp, "%s\"graph.color\": \"0x%x\",\n"
"%s\"graph.fill_color\": \"0x%x\",\n"
"%s\"graph.line_width\": \"%f\",\n"
"%s\"data\": [\n",
indent, hex_from_rgba_color(graph->line_color),
indent, hex_from_rgba_color(graph->fill_color),
indent, graph->line_width, indent);
int counter = 0;
for (int i = 0; i < graph->width; i++) {
if (counter++ > 0) fprintf(rsp, ",\n");
fprintf(rsp, "\t\t\t\"%f\"",
graph->y[i]);
fprintf(rsp, "%s\t\"%f\"", indent, graph->y[i]);
}
fprintf(rsp, "\n\t]\n\t}");
fprintf(rsp, "\n%s]", indent);
}
void graph_destroy(struct graph* graph) {

View file

@ -27,5 +27,5 @@ void graph_calculate_bounds(struct graph* graph, uint32_t x, uint32_t y);
void graph_draw(struct graph* graph, CGContextRef context);
void graph_destroy(struct graph* graph);
void graph_serialize(struct graph* graph, FILE* rsp);
void graph_serialize(struct graph* graph, char* indent, FILE* rsp);
bool graph_parse_sub_domain(struct graph* graph, FILE* rsp, struct token property, char* message);

View file

@ -93,17 +93,12 @@ void group_draw(struct group* group, CGContextRef context) {
background_draw(&group->members[0]->background, context);
}
void group_serialize(struct group* group, FILE* rsp) {
fprintf(rsp, ",\n"
"\t\"bracket\": [\n");
void group_serialize(struct group* group, char* indent, FILE* rsp) {
int counter = 0;
for (int i = 1; i < group->num_members; i++) {
if (!group->members[i]) continue;
if (counter++ > 0) fprintf(rsp, ",\n");
fprintf(rsp, "\t\t\"%s\"",
group->members[i]->name);
fprintf(rsp, "%s\"%s\"", indent, group->members[i]->name);
}
fprintf(rsp, "\n\t]");
}

View file

@ -20,4 +20,4 @@ void group_calculate_bounds(struct group* group, uint32_t x, uint32_t y, bool rt
void group_draw(struct group* group, CGContextRef context);
void group_destroy(struct group* group);
void group_serialize(struct group* group, FILE* rsp);
void group_serialize(struct group* group, char* indent, FILE* rsp);

View file

@ -319,6 +319,56 @@ void popup_destroy(struct popup* popup) {
popup_close_window(popup);
}
void popup_serialize(struct popup* popup, char* indent, FILE* rsp) {
char align[32] = { 0 };
switch (popup->align) {
case POSITION_LEFT:
snprintf(align, 32, "left");
break;
case POSITION_RIGHT:
snprintf(align, 32, "right");
break;
case POSITION_CENTER:
snprintf(align, 32, "center");
break;
case POSITION_BOTTOM:
snprintf(align, 32, "bottom");
break;
case POSITION_TOP:
snprintf(align, 32, "top");
break;
default:
snprintf(align, 32, "invalid");
break;
}
fprintf(rsp, "%s\"drawing\": \"%s\",\n"
"%s\"horizontal\": \"%s\",\n"
"%s\"height\": %d,\n"
"%s\"blur_radius\": %u,\n"
"%s\"y_offset\": %d,\n"
"%s\"align\": \"%s\",\n"
"%s\"background\": {\n",
indent, format_bool(popup->drawing),
indent, format_bool(popup->horizontal),
indent, popup->overrides_cell_size ? popup->cell_size : -1,
indent, popup->blur_radius,
indent, popup->y_offset,
indent, align, indent );
char deeper_indent[strlen(indent) + 2];
snprintf(deeper_indent, strlen(indent) + 2, "%s\t", indent);
background_serialize(&popup->background, deeper_indent, rsp, true);
fprintf(rsp, "\n%s},\n%s\"items\": [\n", indent, indent);
for (int i = 0; i < popup->num_items; i++) {
fprintf(rsp, "%s\t \"%s\"", indent, popup->items[i]->name);
if (i < popup->num_items - 1) fprintf(rsp, ",\n");
}
fprintf(rsp, "\n%s]", indent);
}
bool popup_parse_sub_domain(struct popup* popup, FILE* rsp, struct token property, char* message) {
if (token_equals(property, PROPERTY_YOFFSET)) {
popup->y_offset = token_to_int(get_token(&message));

View file

@ -40,4 +40,5 @@ void popup_calculate_bounds(struct popup* popup);
void popup_draw(struct popup* popup);
void popup_destroy(struct popup* popup);
void popup_serialize(struct popup* popup, char* indent, FILE* rsp);
bool popup_parse_sub_domain(struct popup* popup, FILE* rsp, struct token property, char* message);