diff --git a/include/QF/view.h b/include/QF/view.h index 601f9ba87..b611af050 100644 --- a/include/QF/view.h +++ b/include/QF/view.h @@ -63,6 +63,7 @@ struct view_s { view_t *view_new (int xp, int yp, int xl, int yl, grav_t grav); +void view_insert (view_t *par, view_t *view, int pos); void view_add (view_t *par, view_t *view); void view_remove (view_t *par, view_t *view); void view_delete (view_t *view); diff --git a/libs/console/view.c b/libs/console/view.c index 0454bcba1..58f6dbe36 100644 --- a/libs/console/view.c +++ b/libs/console/view.c @@ -116,9 +116,15 @@ setgeometry (view_t *view) } void -view_add (view_t *par, view_t *view) +view_insert (view_t *par, view_t *view, int pos) { view->parent = par; + if (pos < 0) + pos = par->num_children + 1 + pos; + if (pos < 0) + pos = 0; + if (pos > par->num_children) + pos = par->num_children; if (par->num_children == par->max_children) { par->max_children += 8; par->children = realloc (par->children, @@ -126,10 +132,19 @@ view_add (view_t *par, view_t *view) memset (par->children + par->num_children, 0, (par->max_children - par->num_children) * sizeof (view_t *)); } - par->children[par->num_children++] = view; + memmove (par->children + pos + 1, par->children + pos, + (par->num_children - pos) * sizeof (view_t *)); + par->num_children++; + par->children[pos] = view; setgeometry (view); } +void +view_add (view_t *par, view_t *view) +{ + view_insert (par, view, -1); +} + void view_remove (view_t *par, view_t *view) {