From 8be5d35b0d848a57920808231d6107cdc17ed1fc Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 21 Sep 2022 11:53:49 +0900 Subject: [PATCH] [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. --- include/QF/ui/view.h | 15 +++++++++++++++ libs/ui/view.c | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/QF/ui/view.h b/include/QF/ui/view.h index 2a1e42bb7..2ae69e3d7 100644 --- a/include/QF/ui/view.h +++ b/include/QF/ui/view.h @@ -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)). diff --git a/libs/ui/view.c b/libs/ui/view.c index 3ffc70662..0676840cd 100644 --- a/libs/ui/view.c +++ b/libs/ui/view.c @@ -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) {