[ui] Add support for setting view data early

view_new sets the geometry, but any setgeometry that need a valid data
pointer would get null. It might be better to always have the data
pointer, but I didn't feel like doing such a change at this stage as
there are quite a lot of calls to view_new. Thus view_new_data which
sets the data pointer before calling setgeometry.
This commit is contained in:
Bill Currie 2022-09-21 11:53:49 +09:00
parent e407cfa918
commit 8be5d35b0d
2 changed files with 23 additions and 1 deletions

View file

@ -137,6 +137,21 @@ struct view_s {
*/
view_t *view_new (int xp, int yp, int xl, int yl, grav_t grav);
/** Create a new view. view_t::draw is set to view_draw() and the view is made
visible. All coordinates are set appropriately for the new view being a
root view. All other fields not set by the parameters are 0.
\param xp The X coordinate of the view's origin.
\param yp The Y coordinate of the view's origin.
\param xl The width of the view.
\param yl The height of the view.
\param grav The gravity of the view. determines the view's origin and
its positioning within the view's parent.
\param data Pointer with which the view\s data pointer will be
initialized.
*/
view_t *view_new_data (int xp, int yp, int xl, int yl, grav_t grav, void *data);
/** Insert a view into a parent view at the specified location. If \c pos is
negative, it is taken to be relative to the end of the parent's list of
views (view_insert (par, view, -1) is equivalent to view_add (par, view)).

View file

@ -143,7 +143,7 @@ setgeometry (view_t *view)
}
VISIBLE view_t *
view_new (int xp, int yp, int xl, int yl, grav_t grav)
view_new_data (int xp, int yp, int xl, int yl, grav_t grav, void *data)
{
view_t *view = calloc (1, sizeof (view_t));
view->xpos = xp;
@ -153,10 +153,17 @@ view_new (int xp, int yp, int xl, int yl, grav_t grav)
view->gravity = grav;
view->visible = 1;
view->draw = view_draw;
view->data = data;
setgeometry (view);
return view;
}
VISIBLE view_t *
view_new (int xp, int yp, int xl, int yl, grav_t grav)
{
return view_new_data (xp, yp, xl, yl, grav, 0);
}
VISIBLE void
view_insert (view_t *par, view_t *view, int pos)
{