# Changeset View

Changeset View

# Standalone View

Standalone View

# src/lib/elementary/efl_ui_relative.c

- This file was added.

1 | #include "efl_ui_relative_private.h" | ||||
---|---|---|---|---|---|

2 | | ||||

3 | #define MY_CLASS EFL_UI_RELATIVE_CLASS | ||||

4 | #define MY_CLASS_NAME "Efl.Ui.Relative" | ||||

5 | | ||||

6 | static void _child_height_calc(Efl_Ui_Relative_Child *child); | ||||

7 | static void _child_width_calc(Efl_Ui_Relative_Child *child); | ||||

8 | | ||||

9 | | ||||

10 | static Efl_Ui_Relative_Child * | ||||

11 | _relative_child_find(const Eina_Hash *children, Eo *target) | ||||

12 | { | ||||

13 | Efl_Ui_Relative_Child *child; | ||||

14 | | ||||

15 | child = eina_hash_find(children, &target); | ||||

16 | if (!child) | ||||

17 | ERR("target(%p(%s)) is not registered", target, efl_class_name_get(target)); | ||||

18 | | ||||

19 | return child; | ||||

20 | } | ||||

21 | | ||||

22 | static void | ||||

23 | _child_height_calc(Efl_Ui_Relative_Child *child) | ||||

24 | { | ||||

25 | Efl_Ui_Relative_Calc_Params *calc = &child->calc; | ||||

26 | | ||||

27 | if (calc->state[RELATIVE_CALC_Y] == RELATIVE_CALC_DONE) | ||||

28 | return; | ||||

29 | | ||||

30 | if (calc->state[RELATIVE_CALC_Y] == RELATIVE_CALC_ON) | ||||

31 | { | ||||

32 | ERR("Y-axis circular dependency when calculating part \"%s\"(%p).", efl_class_name_get(child->obj), child->obj); | ||||

33 | return; | ||||

34 | } | ||||

35 | | ||||

36 | calc->state[RELATIVE_CALC_Y] = RELATIVE_CALC_ON; | ||||

37 | _child_height_calc(calc->left.y); | ||||

38 | | ||||

39 | calc->state[RELATIVE_CALC_Y] = RELATIVE_CALC_ON; | ||||

40 | _child_height_calc(calc->right.y); | ||||

41 | | ||||

42 | calc->space.y = calc->left.y->calc.want.y + | ||||

43 | (calc->left.y->calc.want.h * child->rel.left_y_relative); | ||||

44 | calc->space.h = (calc->right.y->calc.want.y + | ||||

45 | (calc->right.y->calc.want.h * child->rel.right_y_relative)) - calc->space.y; | ||||

46 | | ||||

47 | if (calc->fill[RELATIVE_CALC_Y] && (calc->weight[RELATIVE_CALC_Y] > 0)) | ||||

48 | calc->want.h = calc->space.h; | ||||

49 | | ||||

50 | //calculate aspect | ||||

51 | if ((calc->aspect.w > 0) && (calc->aspect.h > 0)) | ||||

52 | { | ||||

53 | int temph; | ||||

54 | switch (calc->aspect_type) | ||||

55 | { | ||||

56 | case EFL_GFX_SIZE_HINT_ASPECT_HORIZONTAL: | ||||

57 | _child_width_calc(child); | ||||

58 | calc->want.h = calc->want.w * calc->aspect.h / calc->aspect.w; | ||||

59 | break; | ||||

60 | case EFL_GFX_SIZE_HINT_ASPECT_VERTICAL: | ||||

61 | calc->want.w = calc->want.h * calc->aspect.w / calc->aspect.h; | ||||

62 | break; | ||||

63 | case EFL_GFX_SIZE_HINT_ASPECT_BOTH: | ||||

64 | if ((calc->state[RELATIVE_CALC_X] != RELATIVE_CALC_ON) && | ||||

65 | (calc->state[RELATIVE_CALC_X] != RELATIVE_CALC_ON)) | ||||

66 | _child_width_calc(child); | ||||

67 | temph = calc->want.w * calc->aspect.h / calc->aspect.w; | ||||

68 | if (temph > calc->want.h) | ||||

69 | { | ||||

70 | temph = calc->want.h; | ||||

71 | calc->want.w = temph * calc->aspect.w / calc->aspect.h; | ||||

72 | } | ||||

73 | else | ||||

74 | calc->want.h = temph; | ||||

75 | break; | ||||

76 | default: | ||||

77 | if ((calc->state[RELATIVE_CALC_X] != RELATIVE_CALC_ON) && | ||||

78 | (calc->state[RELATIVE_CALC_X] != RELATIVE_CALC_ON)) | ||||

79 | _child_width_calc(child); | ||||

80 | temph = calc->want.w * calc->aspect.h / calc->aspect.w; | ||||

81 | if (temph < calc->want.h) | ||||

82 | { | ||||

83 | temph = calc->want.h; | ||||

84 | calc->want.w = temph * calc->aspect.w / calc->aspect.h; | ||||

85 | } | ||||

86 | else | ||||

87 | calc->want.h = temph; | ||||

88 | } | ||||

89 | | ||||

90 | //calculate max size | ||||

91 | if (calc->max.w >= 0 && calc->want.w > calc->max.w) | ||||

92 | { | ||||

93 | calc->want.w = calc->max.w; | ||||

94 | calc->want.h = calc->want.w * calc->aspect.h / calc->aspect.w; | ||||

95 | } | ||||

96 | if (calc->max.h >= 0 && calc->want.h > calc->max.h) | ||||

97 | { | ||||

98 | calc->want.h = calc->max.h; | ||||

99 | calc->want.w = calc->want.h * calc->aspect.w / calc->aspect.h; | ||||

100 | } | ||||

101 | //calculate min size | ||||

102 | if (calc->want.w < calc->min.w) | ||||

103 | { | ||||

104 | calc->want.w = calc->min.w; | ||||

105 | calc->want.h = calc->want.w * calc->aspect.h / calc->aspect.w; | ||||

106 | } | ||||

107 | if (calc->want.h < calc->min.h) | ||||

108 | { | ||||

109 | calc->want.h = calc->min.h; | ||||

110 | calc->want.w = calc->want.h * calc->aspect.w / calc->aspect.h; | ||||

111 | } | ||||

112 | | ||||

113 | //calculate align | ||||

114 | calc->want.x = calc->space.x + (calc->space.w - calc->want.w) * calc->align[RELATIVE_CALC_X]; | ||||

115 | } | ||||

116 | else | ||||

117 | { | ||||

118 | if ((calc->aspect.w <= 0) ^ (calc->aspect.h <= 0)) | ||||

119 | ERR("Invalid aspect parameter for obj(%p), aspect(%d, %d) ", | ||||

120 | child->obj, calc->aspect.w, calc->aspect.h); | ||||

121 | | ||||

122 | if (calc->max.h >= 0 && calc->want.h > calc->max.h) | ||||

123 | calc->want.h = calc->max.h; | ||||

124 | | ||||

125 | if (calc->want.h < calc->min.h) | ||||

126 | calc->want.h = calc->min.h; | ||||

127 | } | ||||

128 | | ||||

129 | //calculate align | ||||

130 | calc->want.y = calc->space.y + (calc->space.h - calc->want.h) * calc->align[RELATIVE_CALC_Y]; | ||||

131 | | ||||

132 | child->calc.state[RELATIVE_CALC_Y] = RELATIVE_CALC_DONE; | ||||

133 | } | ||||

134 | | ||||

135 | static void | ||||

136 | _child_width_calc(Efl_Ui_Relative_Child *child) | ||||

137 | { | ||||

138 | Efl_Ui_Relative_Calc_Params *calc = &child->calc; | ||||

139 | | ||||

140 | if (calc->state[RELATIVE_CALC_X] == RELATIVE_CALC_DONE) | ||||

141 | return; | ||||

142 | | ||||

143 | if (calc->state[RELATIVE_CALC_X] == RELATIVE_CALC_ON) | ||||

144 | { | ||||

145 | ERR("X-axis circular dependency when calculating part \"%s\"(%p).", efl_class_name_get(child->obj), child->obj); | ||||

146 | return; | ||||

147 | } | ||||

148 | | ||||

149 | calc->state[RELATIVE_CALC_X] = RELATIVE_CALC_ON; | ||||

150 | _child_width_calc(calc->left.x); | ||||

151 | | ||||

152 | calc->state[RELATIVE_CALC_X] = RELATIVE_CALC_ON; | ||||

153 | _child_width_calc(calc->right.x); | ||||

154 | | ||||

155 | calc->space.x = calc->left.x->calc.want.x + | ||||

156 | (calc->left.x->calc.want.w * child->rel.left_x_relative); | ||||

157 | calc->space.w = (calc->right.x->calc.want.x + | ||||

158 | (calc->right.x->calc.want.w * child->rel.right_x_relative)) - calc->space.x; | ||||

159 | | ||||

160 | if (calc->fill[RELATIVE_CALC_X] && (calc->weight[RELATIVE_CALC_X] > 0)) | ||||

161 | calc->want.w = calc->space.w; | ||||

162 | | ||||

163 | //calculate aspect | ||||

164 | if ((calc->aspect.w > 0) && (calc->aspect.h > 0)) | ||||

165 | { | ||||

166 | int temph; | ||||

167 | switch (calc->aspect_type) | ||||

168 | { | ||||

169 | case EFL_GFX_SIZE_HINT_ASPECT_HORIZONTAL: | ||||

170 | calc->want.h = calc->want.w * calc->aspect.h / calc->aspect.w; | ||||

171 | break; | ||||

172 | case EFL_GFX_SIZE_HINT_ASPECT_VERTICAL: | ||||

173 | _child_height_calc(child); | ||||

174 | calc->want.w = calc->want.h * calc->aspect.w / calc->aspect.h; | ||||

175 | break; | ||||

176 | case EFL_GFX_SIZE_HINT_ASPECT_BOTH: | ||||

177 | if ((calc->state[RELATIVE_CALC_Y] != RELATIVE_CALC_ON) && | ||||

178 | (calc->state[RELATIVE_CALC_Y] != RELATIVE_CALC_ON)) | ||||

179 | _child_height_calc(child); | ||||

180 | temph = calc->want.w * calc->aspect.h / calc->aspect.w; | ||||

181 | if (temph > calc->want.h) | ||||

182 | { | ||||

183 | temph = calc->want.h; | ||||

184 | calc->want.w = temph * calc->aspect.w / calc->aspect.h; | ||||

185 | } | ||||

186 | else | ||||

187 | calc->want.h = temph; | ||||

188 | break; | ||||

189 | default: | ||||

190 | if ((calc->state[RELATIVE_CALC_Y] != RELATIVE_CALC_ON) && | ||||

191 | (calc->state[RELATIVE_CALC_Y] != RELATIVE_CALC_ON)) | ||||

192 | _child_height_calc(child); | ||||

193 | temph = calc->want.w * calc->aspect.h / calc->aspect.w; | ||||

194 | if (temph < calc->want.h) | ||||

195 | { | ||||

196 | temph = calc->want.h; | ||||

197 | calc->want.w = temph * calc->aspect.w / calc->aspect.h; | ||||

198 | } | ||||

199 | else | ||||

200 | calc->want.h = temph; | ||||

201 | } | ||||

202 | | ||||

203 | //calculate max size | ||||

204 | if (calc->max.w >= 0 && calc->want.w > calc->max.w) | ||||

205 | { | ||||

206 | calc->want.w = calc->max.w; | ||||

207 | calc->want.h = calc->want.w * calc->aspect.h / calc->aspect.w; | ||||

208 | } | ||||

209 | if (calc->max.h >= 0 && calc->want.h > calc->max.h) | ||||

210 | { | ||||

211 | calc->want.h = calc->max.h; | ||||

212 | calc->want.w = calc->want.h * calc->aspect.w / calc->aspect.h; | ||||

213 | } | ||||

214 | //calculate min size | ||||

215 | if (calc->want.w < calc->min.w) | ||||

216 | { | ||||

217 | calc->want.w = calc->min.w; | ||||

218 | calc->want.h = calc->want.w * calc->aspect.h / calc->aspect.w; | ||||

219 | } | ||||

220 | if (calc->want.h < calc->min.h) | ||||

221 | { | ||||

222 | calc->want.h = calc->min.h; | ||||

223 | calc->want.w = calc->want.h * calc->aspect.w / calc->aspect.h; | ||||

224 | } | ||||

225 | | ||||

226 | //calculate align | ||||

227 | calc->want.y = calc->space.y + (calc->space.h - calc->want.h) * calc->align[RELATIVE_CALC_Y]; | ||||

228 | } | ||||

229 | else | ||||

230 | { | ||||

231 | if ((calc->aspect.w <= 0) ^ (calc->aspect.h <= 0)) | ||||

232 | ERR("Invalid aspect parameter for obj(%p), aspect(%d, %d) ", | ||||

233 | child->obj, calc->aspect.w, calc->aspect.h); | ||||

234 | | ||||

235 | if (calc->max.w >= 0 && calc->want.w > calc->max.w) | ||||

236 | calc->want.w = calc->max.w; | ||||

237 | | ||||

238 | if (calc->want.w < calc->min.w) | ||||

239 | calc->want.w = calc->min.w; | ||||

240 | } | ||||

241 | | ||||

242 | //calculate align | ||||

243 | calc->want.x = calc->space.x + (calc->space.w - calc->want.w) * calc->align[RELATIVE_CALC_X]; | ||||

244 | | ||||

245 | child->calc.state[RELATIVE_CALC_X] = RELATIVE_CALC_DONE; | ||||

246 | } | ||||

247 | | ||||

248 | static void | ||||

249 | _hash_free_cb(void *data) | ||||

250 | { | ||||

251 | Efl_Ui_Relative_Child *child = data; | ||||

252 | | ||||

253 | free(child); | ||||

254 | } | ||||

255 | | ||||

256 | static Eina_Bool | ||||

257 | _hash_free_foreach_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, | ||||

258 | void *data, void *fdata EINA_UNUSED) | ||||

259 | { | ||||

260 | _hash_free_cb(data); | ||||

261 | | ||||

262 | return EINA_TRUE; | ||||

263 | } | ||||

264 | | ||||

265 | static Eina_Bool | ||||

266 | _hash_child_calc_foreach_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, | ||||

267 | void *data, void *fdata EINA_UNUSED) | ||||

268 | { | ||||

269 | Efl_Ui_Relative_Child *child = data; | ||||

270 | Efl_Ui_Relative_Calc_Params *calc = &child->calc; | ||||

271 | | ||||

272 | if (child->obj == child->layout) | ||||

273 | return EINA_TRUE; | ||||

274 | | ||||

275 | _child_width_calc(child); | ||||

276 | _child_height_calc(child); | ||||

277 | | ||||

278 | efl_gfx_entity_geometry_set(child->obj, calc->want); | ||||

279 | return EINA_TRUE; | ||||

280 | } | ||||

281 | | ||||

282 | | ||||

283 | static Eina_Bool | ||||

284 | _hash_child_init_foreach_cb(const Eina_Hash *hash, const void *key EINA_UNUSED, | ||||

285 | void *data, void *fdata EINA_UNUSED) | ||||

286 | { | ||||

287 | Efl_Ui_Relative_Child *child = data; | ||||

288 | Efl_Ui_Relative_Calc_Params *calc = &(child->calc); | ||||

289 | | ||||

290 | calc->left.x = _relative_child_find(hash, child->rel.left_x); | ||||

291 | calc->left.y = _relative_child_find(hash, child->rel.left_y); | ||||

292 | calc->right.x = _relative_child_find(hash, child->rel.right_x); | ||||

293 | calc->right.y = _relative_child_find(hash, child->rel.right_y); | ||||

294 | | ||||

295 | if (child->obj == child->layout) | ||||

296 | { | ||||

297 | calc->want = efl_gfx_entity_geometry_get(child->obj); | ||||

298 | calc->state[RELATIVE_CALC_X] = RELATIVE_CALC_DONE; | ||||

299 | calc->state[RELATIVE_CALC_Y] = RELATIVE_CALC_DONE; | ||||

300 | return EINA_TRUE; | ||||

301 | } | ||||

302 | | ||||

303 | calc->state[RELATIVE_CALC_X] = RELATIVE_CALC_NONE; | ||||

304 | calc->state[RELATIVE_CALC_Y] = RELATIVE_CALC_NONE; | ||||

305 | | ||||

306 | efl_gfx_size_hint_weight_get(child->obj, &calc->weight[0], &calc->weight[1]); | ||||

307 | efl_gfx_size_hint_align_get(child->obj, &calc->align[0], &calc->align[1]); | ||||

308 | efl_gfx_size_hint_fill_get(child->obj, &calc->fill[0], &calc->fill[1]); | ||||

309 | efl_gfx_size_hint_aspect_get(child->obj, &calc->aspect_type, &calc->aspect); | ||||

310 | efl_gfx_size_hint_margin_get(child->obj, &calc->margin[0], &calc->margin[1], | ||||

311 | &calc->margin[2], &calc->margin[3]); | ||||

312 | calc->max = efl_gfx_size_hint_max_get(child->obj); | ||||

313 | calc->min = efl_gfx_size_hint_combined_min_get(child->obj); | ||||

314 | calc->want = EINA_RECT_EMPTY(); | ||||

315 | | ||||

316 | return EINA_TRUE; | ||||

317 | } | ||||

318 | | ||||

319 | static void | ||||

320 | _on_size_hints_changed(void *data EINA_UNUSED, Evas *e EINA_UNUSED, | ||||

321 | Evas_Object *obj, void *event_info EINA_UNUSED) | ||||

322 | { | ||||

323 | efl_pack_layout_request(obj); | ||||

324 | } | ||||

325 | | ||||

326 | EOLIAN static void | ||||

327 | _efl_ui_relative_efl_pack_layout_layout_update(Eo *obj, Efl_Ui_Relative_Data *pd EINA_UNUSED) | ||||

328 | { | ||||

329 | eina_hash_foreach(pd->children, _hash_child_init_foreach_cb, NULL); | ||||

330 | eina_hash_foreach(pd->children, _hash_child_calc_foreach_cb, NULL); | ||||

331 | | ||||

332 | efl_event_callback_call(obj, EFL_PACK_EVENT_LAYOUT_UPDATED, NULL); | ||||

333 | } | ||||

334 | | ||||

335 | EOLIAN static void | ||||

336 | _efl_ui_relative_efl_pack_layout_layout_request(Eo *obj, Efl_Ui_Relative_Data *pd EINA_UNUSED) | ||||

337 | { | ||||

338 | efl_canvas_group_need_recalculate_set(obj, EINA_TRUE); | ||||

339 | } | ||||

340 | | ||||

341 | EOLIAN static void | ||||

342 | _efl_ui_relative_efl_canvas_group_group_calculate(Eo *obj, Efl_Ui_Relative_Data *pd EINA_UNUSED) | ||||

343 | { | ||||

344 | efl_pack_layout_update(obj); | ||||

345 | } | ||||

346 | | ||||

347 | EOLIAN static void | ||||

348 | _efl_ui_relative_efl_gfx_entity_size_set(Eo *obj, Efl_Ui_Relative_Data *pd EINA_UNUSED, Eina_Size2D sz) | ||||

349 | { | ||||

350 | efl_gfx_entity_size_set(efl_super(obj, MY_CLASS), sz); | ||||

351 | efl_canvas_group_change(obj); | ||||

352 | } | ||||

353 | | ||||

354 | EOLIAN static void | ||||

355 | _efl_ui_relative_efl_gfx_entity_position_set(Eo *obj, Efl_Ui_Relative_Data *pd EINA_UNUSED, Eina_Position2D pos) | ||||

356 | { | ||||

357 | efl_gfx_entity_position_set(efl_super(obj, MY_CLASS), pos); | ||||

358 | efl_canvas_group_change(obj); | ||||

359 | } | ||||

360 | | ||||

361 | EOLIAN static void | ||||

362 | _efl_ui_relative_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Relative_Data *pd EINA_UNUSED) | ||||

363 | { | ||||

364 | Eo *rect = efl_add(EFL_CANVAS_RECTANGLE_CLASS, obj); | ||||

365 | efl_ui_widget_resize_object_set(obj, rect); | ||||

366 | evas_object_static_clip_set(rect, EINA_TRUE); | ||||

367 | efl_canvas_object_pass_events_set(rect, EINA_TRUE); | ||||

368 | efl_gfx_color_set(rect, 0, 0, 0, 0); | ||||

369 | | ||||

370 | evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _on_size_hints_changed, NULL); | ||||

371 | efl_canvas_group_add(efl_super(obj, MY_CLASS)); | ||||

372 | elm_widget_sub_object_parent_add(obj); | ||||

373 | | ||||

374 | elm_widget_highlight_ignore_set(obj, EINA_TRUE); | ||||

375 | } | ||||

376 | | ||||

377 | EOLIAN static Eo * | ||||

378 | _efl_ui_relative_efl_object_constructor(Eo *obj, Efl_Ui_Relative_Data *pd) | ||||

379 | { | ||||

380 | obj = efl_constructor(efl_super(obj, MY_CLASS)); | ||||

381 | efl_canvas_object_type_set(obj, MY_CLASS_NAME); | ||||

382 | efl_access_object_access_type_set(obj, EFL_ACCESS_TYPE_SKIPPED); | ||||

383 | efl_access_object_role_set(obj, EFL_ACCESS_ROLE_FILLER); | ||||

384 | | ||||

385 | pd->children = eina_hash_pointer_new(_hash_free_cb); | ||||

386 | efl_ui_relative_register(obj, obj, NULL); | ||||

387 | | ||||

388 | return obj; | ||||

389 | } | ||||

390 | | ||||

391 | EOLIAN static void | ||||

392 | _efl_ui_relative_efl_object_destructor(Eo *obj, Efl_Ui_Relative_Data *pd) | ||||

393 | { | ||||

394 | eina_hash_free(pd->children); | ||||

395 | efl_destructor(efl_super(obj, MY_CLASS)); | ||||

396 | } | ||||

397 | | ||||

398 | EOLIAN static void | ||||

399 | _efl_ui_relative_left_x_set(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child, Eo *target) | ||||

400 | { | ||||

401 | Efl_Ui_Relative_Child *rc; | ||||

402 | | ||||

403 | rc = _relative_child_find(pd->children, child); | ||||

404 | if (!rc) return; | ||||

405 | | ||||

406 | rc->rel.left_x = target; | ||||

407 | } | ||||

408 | | ||||

409 | EOLIAN static Eo * | ||||

410 | _efl_ui_relative_left_x_get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child) | ||||

411 | { | ||||

412 | Efl_Ui_Relative_Child *rc; | ||||

413 | | ||||

414 | rc = _relative_child_find(pd->children, child); | ||||

415 | if (!rc) return NULL; | ||||

416 | | ||||

417 | return rc->rel.left_x; | ||||

418 | } | ||||

419 | | ||||

420 | EOLIAN static void | ||||

421 | _efl_ui_relative_left_y_set(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child, Eo *target) | ||||

422 | { | ||||

423 | Efl_Ui_Relative_Child *rc; | ||||

424 | | ||||

425 | rc = _relative_child_find(pd->children, child); | ||||

426 | if (!rc) return; | ||||

427 | | ||||

428 | rc->rel.left_y = target; | ||||

429 | } | ||||

430 | | ||||

431 | EOLIAN static Eo * | ||||

432 | _efl_ui_relative_left_y_get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child) | ||||

433 | { | ||||

434 | Efl_Ui_Relative_Child *rc; | ||||

435 | | ||||

436 | rc = _relative_child_find(pd->children, child); | ||||

437 | if (!rc) return NULL; | ||||

438 | | ||||

439 | return rc->rel.left_y; | ||||

440 | } | ||||

441 | EOLIAN static void | ||||

442 | _efl_ui_relative_left_x_relative_set(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child, double relative) | ||||

443 | { | ||||

444 | Efl_Ui_Relative_Child *rc; | ||||

445 | | ||||

446 | rc = _relative_child_find(pd->children, child); | ||||

447 | if (!rc) return; | ||||

448 | | ||||

449 | rc->rel.left_x_relative = relative; | ||||

450 | } | ||||

451 | | ||||

452 | EOLIAN static double | ||||

453 | _efl_ui_relative_left_x_relative_get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child) | ||||

454 | { | ||||

455 | Efl_Ui_Relative_Child *rc; | ||||

456 | | ||||

457 | rc = _relative_child_find(pd->children, child); | ||||

458 | if (!rc) return 0; | ||||

459 | | ||||

460 | return rc->rel.left_x_relative; | ||||

461 | } | ||||

462 | | ||||

463 | EOLIAN static void | ||||

464 | _efl_ui_relative_left_y_relative_set(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child, double relative) | ||||

465 | { | ||||

466 | Efl_Ui_Relative_Child *rc; | ||||

467 | | ||||

468 | rc = _relative_child_find(pd->children, child); | ||||

469 | if (!rc) return; | ||||

470 | | ||||

471 | rc->rel.left_y_relative = relative; | ||||

472 | } | ||||

473 | | ||||

474 | EOLIAN static double | ||||

475 | _efl_ui_relative_left_y_relative_get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child) | ||||

476 | { | ||||

477 | Efl_Ui_Relative_Child *rc; | ||||

478 | | ||||

479 | rc = _relative_child_find(pd->children, child); | ||||

480 | if (!rc) return 0; | ||||

481 | | ||||

482 | return rc->rel.left_y_relative; | ||||

483 | } | ||||

484 | | ||||

485 | EOLIAN static void | ||||

486 | _efl_ui_relative_right_x_set(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child, Eo *target) | ||||

487 | { | ||||

488 | Efl_Ui_Relative_Child *rc; | ||||

489 | | ||||

490 | rc = _relative_child_find(pd->children, child); | ||||

491 | if (!rc) return; | ||||

492 | | ||||

493 | rc->rel.right_x = target; | ||||

494 | } | ||||

495 | | ||||

496 | EOLIAN static Eo * | ||||

497 | _efl_ui_relative_right_x_get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child) | ||||

498 | { | ||||

499 | Efl_Ui_Relative_Child *rc; | ||||

500 | | ||||

501 | rc = _relative_child_find(pd->children, child); | ||||

502 | if (!rc) return NULL; | ||||

503 | | ||||

504 | return rc->rel.right_x; | ||||

505 | } | ||||

506 | | ||||

507 | EOLIAN static void | ||||

508 | _efl_ui_relative_right_y_set(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child, Eo *target) | ||||

509 | { | ||||

510 | Efl_Ui_Relative_Child *rc; | ||||

511 | | ||||

512 | rc = _relative_child_find(pd->children, child); | ||||

513 | if (!rc) return; | ||||

514 | | ||||

515 | rc->rel.right_y = target; | ||||

516 | } | ||||

517 | | ||||

518 | EOLIAN static Eo * | ||||

519 | _efl_ui_relative_right_y_get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child) | ||||

520 | { | ||||

521 | Efl_Ui_Relative_Child *rc; | ||||

522 | | ||||

523 | rc = _relative_child_find(pd->children, child); | ||||

524 | if (!rc) return NULL; | ||||

525 | | ||||

526 | return rc->rel.right_y; | ||||

527 | } | ||||

528 | EOLIAN static void | ||||

529 | _efl_ui_relative_right_x_relative_set(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child, double relative) | ||||

530 | { | ||||

531 | Efl_Ui_Relative_Child *rc; | ||||

532 | | ||||

533 | rc = _relative_child_find(pd->children, child); | ||||

534 | if (!rc) return; | ||||

535 | | ||||

536 | rc->rel.right_x_relative = relative; | ||||

537 | } | ||||

538 | | ||||

539 | EOLIAN static double | ||||

540 | _efl_ui_relative_right_x_relative_get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child) | ||||

541 | { | ||||

542 | Efl_Ui_Relative_Child *rc; | ||||

543 | | ||||

544 | rc = _relative_child_find(pd->children, child); | ||||

545 | if (!rc) return 0; | ||||

546 | | ||||

547 | return rc->rel.right_x_relative; | ||||

548 | } | ||||

549 | | ||||

550 | EOLIAN static void | ||||

551 | _efl_ui_relative_right_y_relative_set(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child, double relative) | ||||

552 | { | ||||

553 | Efl_Ui_Relative_Child *rc; | ||||

554 | | ||||

555 | rc = _relative_child_find(pd->children, child); | ||||

556 | if (!rc) return; | ||||

557 | | ||||

558 | rc->rel.right_y_relative = relative; | ||||

559 | } | ||||

560 | | ||||

561 | EOLIAN static double | ||||

562 | _efl_ui_relative_right_y_relative_get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child) | ||||

563 | { | ||||

564 | Efl_Ui_Relative_Child *rc; | ||||

565 | | ||||

566 | rc = _relative_child_find(pd->children, child); | ||||

567 | if (!rc) return 0; | ||||

568 | | ||||

569 | return rc->rel.right_y_relative; | ||||

570 | } | ||||

571 | | ||||

572 | EOLIAN static Efl_Ui_Relative_Relation | ||||

573 | _efl_ui_relative_relation_get(const Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Eo *child) | ||||

574 | { | ||||

575 | Efl_Ui_Relative_Child *rc; | ||||

576 | | ||||

577 | rc = _relative_child_find(pd->children, child); | ||||

578 | if (!rc) | ||||

579 | return (Efl_Ui_Relative_Relation) { NULL, NULL, 0.0, 0.0, NULL, NULL, 0.0, 0.0 }; | ||||

580 | | ||||

581 | return rc->rel; | ||||

582 | } | ||||

583 | | ||||

584 | EOLIAN static void | ||||

585 | _efl_ui_relative_relation_init(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd EINA_UNUSED, Efl_Ui_Relative_Relation *rel) | ||||

586 | { | ||||

587 | *rel = (Efl_Ui_Relative_Relation) { obj, obj, 0.0, 0.0, obj, obj, 1.0, 1.0 }; | ||||

588 | } | ||||

589 | | ||||

590 | EOLIAN static Eina_Bool | ||||

591 | _efl_ui_relative_register(Eo *obj, Efl_Ui_Relative_Data *pd, Efl_Object *child, Efl_Ui_Relative_Relation *rel) | ||||

592 | { | ||||

593 | Efl_Ui_Relative_Child *rc; | ||||

594 | | ||||

595 | rc = calloc(1, sizeof(Efl_Ui_Relative_Child)); | ||||

596 | if (!rc) return EINA_FALSE; | ||||

597 | | ||||

598 | rc->obj = child; | ||||

599 | rc->layout = obj; | ||||

600 | | ||||

601 | if (obj == child) | ||||

602 | { | ||||

603 | efl_ui_relative_relation_init(obj, &rc->rel); | ||||

604 | rc->calc.state[RELATIVE_CALC_X] = RELATIVE_CALC_DONE; | ||||

605 | rc->calc.state[RELATIVE_CALC_Y] = RELATIVE_CALC_DONE; | ||||

606 | } | ||||

607 | else | ||||

608 | { | ||||

609 | if (rel) rc->rel = *rel; | ||||

610 | else efl_ui_relative_relation_init(obj, &rc->rel); | ||||

611 | | ||||

612 | efl_ui_widget_sub_object_add(obj, child); | ||||

613 | efl_canvas_group_member_add(obj, child); | ||||

614 | efl_canvas_group_change(obj); | ||||

615 | } | ||||

616 | | ||||

617 | eina_hash_add(pd->children, &child, rc); | ||||

618 | | ||||

619 | return EINA_TRUE; | ||||

620 | } | ||||

621 | | ||||

622 | EOLIAN static void | ||||

623 | _efl_ui_relative_unregister(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd, Efl_Object *child) | ||||

624 | { | ||||

625 | if (!eina_hash_del_by_key(pd->children, &child)) | ||||

626 | ERR("child(%p(%s)) is not registered", child, efl_class_name_get(child)); | ||||

627 | } | ||||

628 | | ||||

629 | EOLIAN static void | ||||

630 | _efl_ui_relative_unregister_all(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd) | ||||

631 | { | ||||

632 | eina_hash_foreach(pd->children, _hash_free_foreach_cb, NULL); | ||||

633 | } | ||||

634 | | ||||

635 | EOLIAN static Eina_Iterator * | ||||

636 | _efl_ui_relative_children_iterate(Eo *obj EINA_UNUSED, Efl_Ui_Relative_Data *pd) | ||||

637 | { | ||||

638 | return eina_hash_iterator_data_new(pd->children); | ||||

639 | } | ||||

640 | | ||||

641 | /* Internal EO APIs and hidden overrides */ | ||||

642 | | ||||

643 | #define EFL_UI_RELATIVE_EXTRA_OPS \ | ||||

644 | EFL_CANVAS_GROUP_ADD_OPS(efl_ui_relative) | ||||

645 | | ||||

646 | #include "efl_ui_relative.eo.c" |