@@ -521,6 +521,20 @@ void scene_menu_calc_bbox(struct scene_obj_menu *menu,
*/
int scene_txtin_init(struct scene_txtin *tin, uint size, uint line_chars);
+/**
+ * scene_txtin_arrange() - Arrange common parts of a text-input object
+ *
+ * Sets the label position and SCENEOF_POINT flag
+ *
+ * @scn: Scene containing the object
+ * @arr: Arrangement info
+ * @obj: Object to arrange
+ * @tin: Text-input info
+ * Return: x position for edit object (positive), or -ve on error
+ */
+int scene_txtin_arrange(struct scene *scn, struct expo_arrange_info *arr,
+ struct scene_obj *obj, struct scene_txtin *tin);
+
/**
* scene_txtin_calc_bbox() - Calculate bounding box for a text-input object
*
@@ -79,35 +79,21 @@ int scene_txted_calc_dims(struct scene_obj_txtedit *ted, struct udevice *cons)
int scene_txted_arrange(struct scene *scn, struct expo_arrange_info *arr,
struct scene_obj_txtedit *ted)
{
- const bool open = ted->obj.flags & SCENEOF_OPEN;
- const struct expo_theme *theme = &scn->expo->theme;
- bool point;
- int x, y;
+ int x;
int ret;
- x = ted->obj.req_bbox.x0;
- y = ted->obj.req_bbox.y0;
- if (ted->tin.label_id) {
- ret = scene_obj_set_pos(scn, ted->tin.label_id, x, y);
- if (ret < 0)
- return log_msg_ret("tit", ret);
-
- x += arr->label_width + theme->textline_label_margin_x;
- }
+ x = scene_txtin_arrange(scn, arr, &ted->obj, &ted->tin);
+ if (x < 0)
+ return log_msg_ret("arr", x);
/* constrain the edit text to fit within the textedit bbox */
- ret = scene_obj_set_bbox(scn, ted->tin.edit_id, x, y,
+ ret = scene_obj_set_bbox(scn, ted->tin.edit_id, x, ted->obj.req_bbox.y0,
ted->obj.req_bbox.x1, ted->obj.req_bbox.y1);
if (ret < 0)
return log_msg_ret("edi", ret);
- point = scn->highlight_id == ted->obj.id;
- point &= !open;
- scene_obj_flag_clrset(scn, ted->tin.edit_id, SCENEOF_POINT,
- point ? SCENEOF_POINT : 0);
-
ted->obj.dims.x = x - ted->obj.req_bbox.x0;
- ted->obj.dims.y = y - ted->obj.req_bbox.y0;
+ ted->obj.dims.y = 0;
scene_obj_set_size(scn, ted->obj.id, ted->obj.dims.x, ted->obj.dims.y);
return 0;
@@ -71,37 +71,24 @@ int scene_textline_calc_dims(struct scene_obj_textline *tline,
int scene_textline_arrange(struct scene *scn, struct expo_arrange_info *arr,
struct scene_obj_textline *tline)
{
- const bool open = tline->obj.flags & SCENEOF_OPEN;
- const struct expo_theme *theme = &scn->expo->theme;
- bool point;
+ struct scene_obj *edit;
int x, y;
int ret;
- x = tline->obj.req_bbox.x0;
+ x = scene_txtin_arrange(scn, arr, &tline->obj, &tline->tin);
+ if (x < 0)
+ return log_msg_ret("arr", x);
+
y = tline->obj.req_bbox.y0;
- if (tline->tin.label_id) {
- struct scene_obj *edit;
-
- ret = scene_obj_set_pos(scn, tline->tin.label_id, x, y);
- if (ret < 0)
- return log_msg_ret("tit", ret);
-
- x += arr->label_width + theme->textline_label_margin_x;
- ret = scene_obj_set_pos(scn, tline->tin.edit_id, x, y);
- if (ret < 0)
- return log_msg_ret("til", ret);
-
- edit = scene_obj_find(scn, tline->tin.edit_id, SCENEOBJT_NONE);
- if (!edit)
- return log_msg_ret("tie", -ENOENT);
- x += edit->dims.x;
- y += edit->dims.y;
- }
+ ret = scene_obj_set_pos(scn, tline->tin.edit_id, x, y);
+ if (ret < 0)
+ return log_msg_ret("pos", ret);
- point = scn->highlight_id == tline->obj.id;
- point &= !open;
- scene_obj_flag_clrset(scn, tline->tin.edit_id, SCENEOF_POINT,
- point ? SCENEOF_POINT : 0);
+ edit = scene_obj_find(scn, tline->tin.edit_id, SCENEOBJT_NONE);
+ if (!edit)
+ return log_msg_ret("fnd", -ENOENT);
+ x += edit->dims.x;
+ y += edit->dims.y;
tline->obj.dims.x = x - tline->obj.req_bbox.x0;
tline->obj.dims.y = y - tline->obj.req_bbox.y0;
@@ -27,6 +27,32 @@ int scene_txtin_init(struct scene_txtin *tin, uint size, uint line_chars)
return 0;
}
+int scene_txtin_arrange(struct scene *scn, struct expo_arrange_info *arr,
+ struct scene_obj *obj, struct scene_txtin *tin)
+{
+ const bool open = obj->flags & SCENEOF_OPEN;
+ const struct expo_theme *theme = &scn->expo->theme;
+ bool point;
+ int x;
+ int ret;
+
+ x = obj->req_bbox.x0;
+ if (tin->label_id) {
+ ret = scene_obj_set_pos(scn, tin->label_id, x, obj->req_bbox.y0);
+ if (ret < 0)
+ return log_msg_ret("lab", ret);
+
+ x += arr->label_width + theme->textline_label_margin_x;
+ }
+
+ point = scn->highlight_id == obj->id;
+ point &= !open;
+ scene_obj_flag_clrset(scn, tin->edit_id, SCENEOF_POINT,
+ point ? SCENEOF_POINT : 0);
+
+ return x;
+}
+
void scene_txtin_calc_bbox(struct scene_obj *obj, struct scene_txtin *tin,
struct vidconsole_bbox *bbox,
struct vidconsole_bbox *edit_bbox)