Skip to content

Commit 4228c1d

Browse files
ret2libcradare
authored andcommitted
core/graph: remove some dup code and fix mini nodes
1 parent 1e37795 commit 4228c1d

File tree

2 files changed

+35
-72
lines changed

2 files changed

+35
-72
lines changed

libr/core/graph.c

+34-71
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static const char *mousemodes[] = {
3333
#define SMALLNODE_MIN_WIDTH 8
3434
#define SMALLNODE_TITLE_LEN 4
3535
#define SMALLNODE_CENTER_X 3
36+
#define MININODE_MIN_WIDTH 16
3637

3738
#define ZOOM_STEP 10
3839
#define ZOOM_DEFAULT 100
@@ -163,6 +164,9 @@ static void update_node_dimension(const RGraph *g, int is_small, int zoom) {
163164
if (is_small) {
164165
n->h = 1;
165166
n->w = SMALLNODE_MIN_WIDTH;
167+
} else if (n->is_mini) {
168+
n->h = 1;
169+
n->w = MININODE_MIN_WIDTH;
166170
} else {
167171
unsigned int len;
168172
n->w = r_str_bounds (n->body, (int *) &n->h);
@@ -183,46 +187,8 @@ static void update_node_dimension(const RGraph *g, int is_small, int zoom) {
183187
}
184188
}
185189

186-
static void small_RANode_print(const RAGraph *g, const RANode *n, int cur) {
187-
char title[TITLE_LEN];
188-
int x, delta_x = 0;
189-
190-
if (!G (n->x + SMALLNODE_CENTER_X, n->y) &&
191-
!G (n->x + SMALLNODE_CENTER_X + n->w, n->y)) {
192-
return;
193-
}
194-
195-
x = n->x + SMALLNODE_CENTER_X + g->can->sx;
196-
if (x < 0) {
197-
delta_x = -x;
198-
}
199-
G (n->x + SMALLNODE_CENTER_X + delta_x, n->y);
200-
201-
if (cur) {
202-
W (&SMALLNODE_TEXT_CUR[delta_x]);
203-
(void) G (-g->can->sx, -g->can->sy + 2);
204-
snprintf (title, sizeof (title) - 1,
205-
"%s:", n->title);
206-
W (title);
207-
(void) G (-g->can->sx, -g->can->sy + 3);
208-
W (n->body);
209-
} else {
210-
char *str = "____";
211-
if (n->title) {
212-
int l = strlen (n->title);
213-
214-
str = n->title;
215-
if (l > SMALLNODE_TITLE_LEN) {
216-
str += l - SMALLNODE_TITLE_LEN;
217-
}
218-
}
219-
snprintf (title, sizeof (title) - 1, "[_%s_]", str);
220-
W (title + delta_x);
221-
}
222-
return;
223-
}
224-
225-
static void mini_RANode_print(const RAGraph *g, const RANode *n, int cur) {
190+
static void small_RANode_print(const RAGraph *g, const RANode *n,
191+
int cur, bool print_details) {
226192
char title[TITLE_LEN];
227193
int x, delta_x = 0;
228194

@@ -239,15 +205,31 @@ static void mini_RANode_print(const RAGraph *g, const RANode *n, int cur) {
239205
return;
240206
}
241207

242-
if (cur) {
243-
W (&SMALLNODE_TEXT_CUR[delta_x]);
244-
snprintf (title, sizeof (title) - 1,
245-
"[ %s ]", n->title);
246-
W (title);
208+
if (print_details) {
209+
if (cur) {
210+
W (&SMALLNODE_TEXT_CUR[delta_x]);
211+
(void) G (-g->can->sx, -g->can->sy + 2);
212+
snprintf (title, sizeof (title) - 1,
213+
"[ %s ]", n->title);
214+
W (title);
215+
(void) G (-g->can->sx, -g->can->sy + 3);
216+
W (n->body);
217+
} else {
218+
char *str = "____";
219+
if (n->title) {
220+
int l = strlen (n->title);
221+
222+
str = n->title;
223+
if (l > SMALLNODE_TITLE_LEN) {
224+
str += l - SMALLNODE_TITLE_LEN;
225+
}
226+
}
227+
snprintf (title, sizeof (title) - 1, "__%s__", str);
228+
W (title + delta_x);
229+
}
247230
} else {
248-
W (&SMALLNODE_TEXT_CUR[delta_x]);
249231
snprintf (title, sizeof (title) - 1,
250-
" %s ", n->title);
232+
cur ? "[ %s ]" : " %s ", n->title);
251233
W (title);
252234
}
253235
return;
@@ -2275,30 +2257,10 @@ static void agraph_update_seek(RAGraph *g, RANode *n, int force) {
22752257

22762258
static void agraph_print_node(const RAGraph *g, RANode *n) {
22772259
const int cur = g->curnode && get_anode (g->curnode) == n;
2278-
if (is_mini (g)) {
2279-
small_RANode_print (g, n, cur);
2260+
if (is_mini (g) || n->is_mini) {
2261+
small_RANode_print (g, n, cur, is_mini (g));
22802262
} else {
2281-
if (n->mini) {
2282-
n->w = strlen (n->title) + 4;
2283-
n->h = 1;
2284-
#if 1
2285-
mini_RANode_print (g, n, cur);
2286-
#else
2287-
small_RANode_print (g, n, cur);
2288-
#endif
2289-
} else {
2290-
if (n->h < 4) {
2291-
int titlen = strlen (n->title);
2292-
n->w = r_str_bounds (n->body, (int *) &n->h);
2293-
if (titlen > n->w) {
2294-
n->w = titlen + 6;
2295-
} else {
2296-
n->w += 4;
2297-
}
2298-
n->h += 3;
2299-
}
2300-
normal_RANode_print (g, n, cur);
2301-
}
2263+
normal_RANode_print (g, n, cur);
23022264
}
23032265
}
23042266

@@ -2500,7 +2462,8 @@ static void agraph_merge_child(RAGraph *g, int idx) {
25002462

25012463
static void agraph_toggle_mini(RAGraph *g) {
25022464
RANode *n = get_anode (g->curnode);
2503-
n->mini = !n->mini;
2465+
n->is_mini = !n->is_mini;
2466+
g->need_update_dim = 1;
25042467
agraph_refresh (r_cons_singleton ()->event_data);
25052468
agraph_set_layout ((RAGraph *) g, r_cons_singleton ()->is_interactive);
25062469
}

libr/include/r_cons.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ typedef struct r_ascii_node_t {
633633
int is_dummy;
634634
int is_reversed;
635635
int klass;
636-
bool mini;
636+
bool is_mini;
637637
} RANode;
638638

639639
#define R_AGRAPH_MODE_NORMAL 0

0 commit comments

Comments
 (0)