AUTO_LT_SYNC
[tore.git] / pytx / txbox.c
blob8e3568253999dd79b2a641c1368c0ad17342fb5e
1 /*
2 * listbox.c - box, a container
4 * Written by Joshua Davis
5 * Copyright (c) Josh Davis 2008
6 */
8 #include <ncurses.h>
9 #include <panel.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include "txbox.h"
13 #include "txops.h"
14 #include "list.h"
16 void tx_box_adjust(TXObj *obj) {
17 int dyn, sta, size, start, left;
18 TXObj *entry;
19 TX_EXT(TXBox, box);
20 dyn = (obj->flags & TX_BOX_VERT) ? obj->h : obj->w;
21 sta = (obj->flags & TX_BOX_VERT) ? obj->w : obj->h;
22 start = (obj->flags & TX_BOX_VERT) ? obj->y : obj->x;
23 left = box->count;
25 list_for_each_entry(entry, &box->node, node) {
26 size = (entry->size_cb) ? entry->size_cb(entry, sta, dyn) : dyn / left;
27 if (obj->flags & TX_BOX_VERT) tx_obj_size_set(entry, obj->x, start, obj->w, size);
28 if (obj->flags & TX_BOX_HORZ) tx_obj_size_set(entry, start, obj->y, size, obj->h);
29 //tx_obj_resize(entry);
30 dyn -= size;
31 start += size;
32 left--;
36 void tx_box_add(TXObj *obj, TXObj *add) {
37 TX_EXT(TXBox, box);
39 list_add_tail(&add->node, &box->node);
40 box->count++;
43 int tx_box_draw(TXObj *obj) {
44 TX_EXT(TXBox, box);
45 TXObj *entry;
47 list_for_each_entry(entry, &box->node, node) {
48 entry->draw_cb(entry);
51 return 0;
54 void tx_box_rsze(TXObj *obj) {
55 tx_box_adjust(obj);
58 void tx_box_init(TXObj *obj) {
59 obj->extend = calloc(1, sizeof(TXBox));
60 TX_EXT(TXBox, box);
61 obj->draw_cb = tx_box_draw;
62 obj->rsze_cb = tx_box_rsze;
63 list_init(&box->node);