Blender V5.3
interface.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cctype>
11#include <cfloat>
12#include <climits>
13#include <cmath>
14#include <cstddef> /* `offsetof()` */
15#include <cstring>
16
17#include <fmt/format.h>
18
19#include "MEM_guardedalloc.h"
20
21#include "DNA_listBase.h"
22#include "DNA_object_types.h"
23#include "DNA_scene_types.h"
24#include "DNA_screen_types.h"
25#include "DNA_userdef_types.h"
26
27#include "BLI_listbase.hh"
28#include "BLI_rect.hh"
29#include "BLI_set.hh"
30#include "BLI_string.hh"
31#include "BLI_string_utf8.hh"
32#include "BLI_vector.hh"
33
34#include "BLI_utildefines.hh"
35
36#include "BKE_animsys.hh"
37#include "BKE_context.hh"
38#include "BKE_idprop.hh"
39#include "BKE_report.hh"
40#include "BKE_scene.hh"
41#include "BKE_screen.hh"
42#include "BKE_unit.hh"
43
44#include "GPU_matrix.hh"
45#include "GPU_state.hh"
46
47#include "BLF_api.hh"
48#include "BLT_translation.hh"
49
50#include "UI_abstract_view.hh"
51#include "UI_interface.hh"
52#include "UI_interface_icons.hh"
54#include "UI_string_search.hh"
55#include "UI_view2d.hh"
56
57#include "IMB_imbuf.hh"
58
59#include "WM_api.hh"
60#include "WM_message.hh"
61#include "WM_types.hh"
62
63#include "RNA_access.hh"
64#include "RNA_enum_types.hh"
65
66#ifdef WITH_PYTHON
67# include "BPY_extern_run.hh"
68#endif
69
70#include "ED_numinput.hh"
71#include "ED_screen.hh"
72
74
75#include "CLG_log.h"
76
79#include "interface_intern.hh"
80
81namespace blender::ui {
82static CLG_LogRef LOG = {"ui"};
83
84/* prototypes. */
85static void def_but_rna__menu(bContext *C, Layout *layout, void *but_p);
86static void def_but_rna__panel_type(bContext * /*C*/, Layout *layout, void *arg);
87static void def_but_rna__menu_type(bContext * /*C*/, Layout *layout, void *but_p);
88
89/* avoid unneeded calls to button_value_get */
90#define BUT_VALUE_UNSET DBL_MAX
91#define UI_GET_BUT_VALUE_INIT(_but, _value) \
92 if (_value == DBL_MAX) { \
93 (_value) = button_value_get(_but); \
94 } \
95 ((void)0)
96
97#define B_NOP -1
98
105
106static void but_free(const bContext *C, Button *but);
107
108static bool but_is_unit_radians_ex(const UnitSettings *unit, const int unit_type)
109{
110 return (unit->system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION);
111}
112
113static bool but_is_unit_radians(const Button *but)
114{
115 const UnitSettings *unit = but->block->unit;
116 const int unit_type = button_unit_type_get(but);
117
118 return but_is_unit_radians_ex(unit, unit_type);
119}
120
121/* -------------------------------------------------------------------- */
124
125void block_to_region_fl(const ARegion *region, const Block *block, float *x, float *y)
126{
127 const int getsizex = BLI_rcti_size_x(&region->winrct) + 1;
128 const int getsizey = BLI_rcti_size_y(&region->winrct) + 1;
129
130 float gx = *x;
131 float gy = *y;
132
133 if (block->panel) {
134 gx += block->panel->ofsx;
135 gy += block->panel->ofsy;
136 }
137
138 *x = float(getsizex) *
139 (0.5f + 0.5f * (gx * block->winmat[0][0] + gy * block->winmat[1][0] + block->winmat[3][0]));
140 *y = float(getsizey) *
141 (0.5f + 0.5f * (gx * block->winmat[0][1] + gy * block->winmat[1][1] + block->winmat[3][1]));
142}
143
144void block_to_window_fl(const ARegion *region, const Block *block, float *x, float *y)
145{
146 block_to_region_fl(region, block, x, y);
147 *x += region->winrct.xmin;
148 *y += region->winrct.ymin;
149}
150
151void block_to_window(const ARegion *region, const Block *block, int *x, int *y)
152{
153 float fx = *x;
154 float fy = *y;
155
156 block_to_window_fl(region, block, &fx, &fy);
157
158 *x = int(lround(fx));
159 *y = int(lround(fy));
160}
161
162void block_to_region_rctf(const ARegion *region,
163 const Block *block,
164 rctf *rct_dst,
165 const rctf *rct_src)
166{
167 *rct_dst = *rct_src;
168 block_to_region_fl(region, block, &rct_dst->xmin, &rct_dst->ymin);
169 block_to_region_fl(region, block, &rct_dst->xmax, &rct_dst->ymax);
170}
171
172void block_to_window_rctf(const ARegion *region,
173 const Block *block,
174 rctf *rct_dst,
175 const rctf *rct_src)
176{
177 *rct_dst = *rct_src;
178 block_to_window_fl(region, block, &rct_dst->xmin, &rct_dst->ymin);
179 block_to_window_fl(region, block, &rct_dst->xmax, &rct_dst->ymax);
180}
181
182float block_to_window_scale(const ARegion *region, const Block *block)
183{
184 /* We could have function for this to avoid dummy arg. */
185 float min_y = 0, max_y = 1;
186 float dummy_x = 0.0f;
187 block_to_window_fl(region, block, &dummy_x, &min_y);
188 dummy_x = 0.0f;
189 block_to_window_fl(region, block, &dummy_x, &max_y);
190 return max_y - min_y;
191}
192
193void window_to_block_fl(const ARegion *region, const Block *block, float *x, float *y)
194{
195 const int getsizex = BLI_rcti_size_x(&region->winrct) + 1;
196 const int getsizey = BLI_rcti_size_y(&region->winrct) + 1;
197 const int sx = region->winrct.xmin;
198 const int sy = region->winrct.ymin;
199
200 const float a = 0.5f * float(getsizex) * block->winmat[0][0];
201 const float b = 0.5f * float(getsizex) * block->winmat[1][0];
202 const float c = 0.5f * float(getsizex) * (1.0f + block->winmat[3][0]);
203
204 const float d = 0.5f * float(getsizey) * block->winmat[0][1];
205 const float e = 0.5f * float(getsizey) * block->winmat[1][1];
206 const float f = 0.5f * float(getsizey) * (1.0f + block->winmat[3][1]);
207
208 const float px = *x - sx;
209 const float py = *y - sy;
210
211 *y = (a * (py - f) + d * (c - px)) / (a * e - d * b);
212 *x = (px - b * (*y) - c) / a;
213
214 if (block->panel) {
215 *x -= block->panel->ofsx;
216 *y -= block->panel->ofsy;
217 }
218}
219
220void window_to_block_rctf(const ARegion *region,
221 const Block *block,
222 rctf *rct_dst,
223 const rctf *rct_src)
224{
225 *rct_dst = *rct_src;
226 window_to_block_fl(region, block, &rct_dst->xmin, &rct_dst->ymin);
227 window_to_block_fl(region, block, &rct_dst->xmax, &rct_dst->ymax);
228}
229
230void window_to_block(const ARegion *region, const Block *block, int *x, int *y)
231{
232 float fx = *x;
233 float fy = *y;
234
235 window_to_block_fl(region, block, &fx, &fy);
236
237 *x = int(lround(fx));
238 *y = int(lround(fy));
239}
240
241void window_to_region(const ARegion *region, int *x, int *y)
242{
243 *x -= region->winrct.xmin;
244 *y -= region->winrct.ymin;
245}
246
247void window_to_region_rcti(const ARegion *region, rcti *rect_dst, const rcti *rct_src)
248{
249 rect_dst->xmin = rct_src->xmin - region->winrct.xmin;
250 rect_dst->xmax = rct_src->xmax - region->winrct.xmin;
251 rect_dst->ymin = rct_src->ymin - region->winrct.ymin;
252 rect_dst->ymax = rct_src->ymax - region->winrct.ymin;
253}
254
255void window_to_region_rctf(const ARegion *region, rctf *rect_dst, const rctf *rct_src)
256{
257 rect_dst->xmin = rct_src->xmin - region->winrct.xmin;
258 rect_dst->xmax = rct_src->xmax - region->winrct.xmin;
259 rect_dst->ymin = rct_src->ymin - region->winrct.ymin;
260 rect_dst->ymax = rct_src->ymax - region->winrct.ymin;
261}
262
263void region_to_window(const ARegion *region, int *x, int *y)
264{
265 *x += region->winrct.xmin;
266 *y += region->winrct.ymin;
267}
268
270 const ARegion *region, int region_x, int region_y, int *r_window_x, int *r_window_y)
271{
272 *r_window_x = region_x + region->winrct.xmin;
273 *r_window_y = region_y + region->winrct.ymin;
274}
275
276int Block::but_index(const Button *but) const
277{
278 BLI_assert(!this->buttons_ptrs.is_empty() && but);
279 auto index = std::distance(
280 this->buttons_ptrs.begin(),
281 std::ranges::find_if(this->buttons_ptrs, [but](const std::unique_ptr<Button> &test) {
282 return test.get() == but;
283 }));
284 BLI_assert(index != std::distance(this->buttons_ptrs.begin(), this->buttons_ptrs.end()));
285 return index;
286}
287
288Button *Block::next_but(const Button *but) const
289{
290 const int idx = this->but_index(but) + 1;
291 return idx < this->buttons_ptrs.size() ? this->buttons_ptrs[idx].get() : nullptr;
292}
293
294Button *Block::prev_but(const Button *but) const
295{
296 const int idx = this->but_index(but) - 1;
297 return idx >= 0 ? this->buttons_ptrs[idx].get() : nullptr;
298}
299
300void Block::remove_but(const Button *but)
301{
302 int64_t target_index = this->but_index(but);
303 this->buttons_ptrs.remove(target_index);
304}
305
307{
308 return !this->buttons_ptrs.is_empty() ? this->buttons_ptrs.first().get() : nullptr;
309}
310
312{
313 return !this->buttons_ptrs.is_empty() ? this->buttons_ptrs.last().get() : nullptr;
314}
315
316static void update_flexible_spacing(const ARegion *region, Block *block)
317{
318 int sepr_flex_len = 0;
319 for (const Button &but : block->buttons()) {
320 if (but.type == ButtonType::SeprSpacer) {
321 sepr_flex_len++;
322 }
323 }
324
325 if (sepr_flex_len == 0) {
326 return;
327 }
328
329 rcti rect;
330 button_to_pixelrect(&rect, region, block, block->buttons_ptrs.last().get());
331 const float buttons_width = std::ceil(float(rect.xmax) + 8.0f * UI_SCALE_FAC);
332 const float region_width = float(region->winx);
333
334 if (region_width <= buttons_width) {
335 return;
336 }
337
338 /* We could get rid of this loop if we agree on a max number of spacer */
339 Vector<int, 8> spacers_pos;
340 for (const Button &but : block->buttons()) {
341 if (but.type == ButtonType::SeprSpacer) {
342 button_to_pixelrect(&rect, region, block, &but);
343 spacers_pos.append(rect.xmax + int(8.0f * UI_SCALE_FAC));
344 }
345 }
346
347 const float view_scale_x = view2d_scale_get_x(&region->v2d);
348 const float segment_width = region_width / float(sepr_flex_len);
349 float offset = 0, remaining_space = region_width - buttons_width;
350 int i = 0;
351 for (Button &but : block->buttons()) {
352 BLI_rctf_translate(&but.rect, std::floor(offset / view_scale_x), 0.0f);
353 if (but.type == ButtonType::SeprSpacer) {
354 /* How much the next block overlap with the current segment */
355 int overlap = ((i == sepr_flex_len - 1) ? buttons_width - spacers_pos[i] :
356 (spacers_pos[i + 1] - spacers_pos[i]) / 2);
357 const int segment_end = segment_width * (i + 1);
358 const int spacer_end = segment_end - overlap;
359 const int spacer_sta = spacers_pos[i] + offset;
360 if (spacer_end > spacer_sta) {
361 const float step = min_ff(remaining_space, spacer_end - spacer_sta);
362 remaining_space -= step;
363 offset += step;
364 }
365 i++;
366 }
367 }
368 block_bounds_calc(block);
369}
370
371static void update_window_matrix(const wmWindow *window, const ARegion *region, Block *block)
372{
373 /* window matrix and aspect */
374 if (region && region->runtime->visible) {
375 /* Get projection matrix which includes View2D translation and zoom. */
377 block->aspect = 2.0f / fabsf(region->winx * block->winmat[0][0]);
378 }
379 else {
380 /* No sub-window created yet, for menus for example, so we use the main
381 * window instead, since buttons are created there anyway. */
382 const int2 win_size = WM_window_native_pixel_size(window);
383 const rcti winrct = {0, win_size[0] - 1, 0, win_size[1] - 1};
384
385 wmGetProjectionMatrix(block->winmat, &winrct);
386 block->aspect = 2.0f / fabsf(win_size[0] * block->winmat[0][0]);
387 }
388}
389
390void region_winrct_get_no_margin(const ARegion *region, rcti *r_rect)
391{
392 Block *block = region->runtime->uiblocks.first();
393 if (block && (block->flag & BLOCK_LOOP) && (block->flag & BLOCK_PIE_MENU) == 0) {
394 BLI_rcti_rctf_copy_floor(r_rect, &block->rect);
395 BLI_rcti_translate(r_rect, region->winrct.xmin, region->winrct.ymin);
396 }
397 else {
398 *r_rect = region->winrct;
399 }
400}
401
403
404/* -------------------------------------------------------------------- */
407
408void block_translate(Block *block, float x, float y)
409{
410 for (Button &but : block->buttons()) {
411 BLI_rctf_translate(&but.rect, x, y);
412 }
413
414 BLI_rctf_translate(&block->rect, x, y);
415}
416
417static bool but_is_row_alignment_group(const Button *left, const Button *right)
418{
419 const bool is_same_align_group = (left->alignnr && (left->alignnr == right->alignnr));
420 return is_same_align_group && (left->rect.xmin < right->rect.xmin);
421}
422
423static void block_bounds_calc_text(Block *block, float offset)
424{
425 if (block->buttons_ptrs.is_empty()) {
426 return;
427 }
428 const uiStyle *style = style_get();
429 std::unique_ptr<Button> *col_bt;
430 int i = 0, j, x1addval = offset;
431
432 fontstyle_set(&style->widget);
433 std::unique_ptr<Button> *end = block->buttons_ptrs.end();
434
435 std::unique_ptr<Button> *init_col_bt = block->buttons_ptrs.begin();
436 for (std::unique_ptr<Button> *bt = init_col_bt; bt < end; bt++) {
438 j = BLF_width(style->widget.uifont_id, (*bt)->drawstr.c_str(), (*bt)->drawstr.size());
439
440 i = std::max(j, i);
441 }
442
443 /* Skip all buttons that are in a horizontal alignment group.
444 * We don't want to split them apart (but still check the row's width and apply current
445 * offsets). */
446 if (bt + 1 < end && but_is_row_alignment_group((*bt).get(), bt[1].get())) {
447 int width = 0;
448 const int alignnr = (*bt)->alignnr;
449 for (col_bt = bt; col_bt < end && (*col_bt)->alignnr == alignnr; col_bt++) {
450 width += BLI_rctf_size_x(&(*col_bt)->rect);
451 (*col_bt)->rect.xmin += x1addval;
452 (*col_bt)->rect.xmax += x1addval;
453 }
454 i = std::max(width, i);
455 /* Give the following code the last button in the alignment group, there might have to be a
456 * split immediately after. */
457 bt = col_bt != end ? col_bt-- : nullptr;
458 }
459
460 if (bt < end && (bt + 1 < end) && (*bt)->rect.xmin < bt[1]->rect.xmin) {
461 /* End of this column, and it's not the last one. */
462 for (col_bt = init_col_bt; (col_bt - 1) != bt; col_bt++) {
463 (*col_bt)->rect.xmin = x1addval;
464 (*col_bt)->rect.xmax = x1addval + i + block->bounds;
465
466 button_update((*col_bt).get()); /* clips text again */
467 }
468
469 /* And we prepare next column. */
470 x1addval += i + block->bounds;
471 i = 0;
472 init_col_bt = col_bt;
473 }
474 }
475
476 /* Last column. */
477 for (col_bt = init_col_bt; col_bt < end; col_bt++) {
478 /* Recognize a horizontally arranged alignment group and skip its items. */
479 if ((col_bt + 1 < end) && but_is_row_alignment_group((*col_bt).get(), col_bt[1].get())) {
480 const int alignnr = (*col_bt)->alignnr;
481 for (; col_bt < end && (*col_bt)->alignnr == alignnr; col_bt++) {
482 /* pass */
483 }
484 }
485 if (col_bt == end) {
486 break;
487 }
488
489 (*col_bt)->rect.xmin = x1addval;
490 (*col_bt)->rect.xmax = max_ff(x1addval + i + block->bounds, offset + block->minbounds);
491
492 button_update((*col_bt).get()); /* clips text again */
493 }
494}
495
497{
498 if (block->buttons_ptrs.is_empty()) {
499 if (block->panel) {
500 block->rect.xmin = 0.0;
501 block->rect.xmax = block->panel->sizex;
502 block->rect.ymin = 0.0;
503 block->rect.ymax = block->panel->sizey;
504 }
505 }
506 else {
507
508 BLI_rctf_init_minmax(&block->rect);
509
510 for (const Button &bt : block->buttons()) {
511 BLI_rctf_union(&block->rect, &bt.rect);
512 }
513
514 block->rect.xmin -= block->bounds;
515 block->rect.ymin -= block->bounds;
516 block->rect.xmax += block->bounds;
517 block->rect.ymax += block->bounds;
518 }
519
520 block->rect.xmax = block->rect.xmin + max_ff(BLI_rctf_size_x(&block->rect), block->minbounds);
521
522 /* hardcoded exception... but that one is annoying with larger safety */
523 Button *bt = block->first_but();
524 const int xof = ((bt && STRPREFIX(bt->str.c_str(), "ERROR")) ? 10 : 40) * UI_SCALE_FAC;
525
526 block->safety.xmin = block->rect.xmin - xof;
527 block->safety.ymin = block->rect.ymin - xof;
528 block->safety.xmax = block->rect.xmax + xof;
529 block->safety.ymax = block->rect.ymax + xof;
530}
531
532static void block_bounds_calc_centered(wmWindow *window, Block *block)
533{
534 /* NOTE: this is used for the splash where window bounds event has not been
535 * updated by ghost, get the window bounds from ghost directly */
536
537 /* Clamp to the window size. */
538 const int2 win_size = WM_window_native_pixel_size(window);
539
540 block_bounds_calc(block);
541
542 const int width = BLI_rctf_size_x(&block->rect);
543 const int height = BLI_rctf_size_y(&block->rect);
544
545 const int startx = (win_size[0] * 0.5f) - (width * 0.5f);
546 const int starty = (win_size[1] * 0.5f) - (height * 0.5f);
547
548 block_translate(block, startx - block->rect.xmin, starty - block->rect.ymin);
549
550 /* now recompute bounds and safety */
551 block_bounds_calc(block);
552}
553
555{
556 const int2 xy(block->handle->region->winrct.xmin, block->handle->region->winrct.ymin);
557 const int margin = int(12.0f * UI_SCALE_FAC);
558 block_bounds_calc(block);
559 block_translate(block, xy[0] - block->rect.xmin + margin, xy[1] - block->rect.ymin + margin);
560 block_bounds_calc(block);
561}
562
564{
565 const int xy[2] = {
566 int(block->pie_data->pie_center_spawned[0]),
567 int(block->pie_data->pie_center_spawned[1]),
568 };
569
570 block_translate(block, xy[0], xy[1]);
571
572 /* now recompute bounds and safety */
573 block_bounds_calc(block);
574}
575
577 wmWindow *window, Block *block, BlockBoundsCalc bounds_calc, const int xy[2], int r_xy[2])
578{
579 const int oldbounds = block->bounds;
580
581 /* Place the default button under the cursor. */
582 if (bounds_calc == BLOCK_BOUNDS_POPUP_MOUSE) {
583 if (const Button *but = block_active_default_button_find(block)) {
584 block->bounds_offset[0] = -(but->rect.xmin + 0.8f * BLI_rctf_size_x(&but->rect));
585 block->bounds_offset[1] = -BLI_rctf_cent_y(&but->rect);
586 }
587 }
588
589 /* compute mouse position with user defined offset */
590 block_bounds_calc(block);
591
592 /* Clamp to the window size. */
593 const int2 win_size = WM_window_native_pixel_size(window);
594
595 int oldwidth = BLI_rctf_size_x(&block->rect);
596 int oldheight = BLI_rctf_size_y(&block->rect);
597
598 /* first we ensure wide enough text bounds */
599 if (bounds_calc == BLOCK_BOUNDS_POPUP_MENU) {
600 if (block->flag & BLOCK_LOOP) {
601 block->bounds = 2.5f * UI_UNIT_X;
602 block_bounds_calc_text(block, block->rect.xmin);
603 }
604 }
605
606 /* next we recompute bounds */
607 block->bounds = oldbounds;
608 block_bounds_calc(block);
609
610 /* and we adjust the position to fit within window */
611 const int width = BLI_rctf_size_x(&block->rect);
612 const int height = BLI_rctf_size_y(&block->rect);
613
614 /* avoid divide by zero below, caused by calling with no UI, but better not crash */
615 oldwidth = oldwidth > 0 ? oldwidth : std::max(1, width);
616 oldheight = oldheight > 0 ? oldheight : std::max(1, height);
617
618 /* offset block based on mouse position, user offset is scaled
619 * along in case we resized the block in block_bounds_calc_text */
620 rcti rect;
621 const int raw_x = rect.xmin = xy[0] + block->rect.xmin +
622 (block->bounds_offset[0] * width) / oldwidth;
623 int raw_y = rect.ymin = xy[1] + block->rect.ymin +
624 (block->bounds_offset[1] * height) / oldheight;
625 rect.xmax = rect.xmin + width;
626 rect.ymax = rect.ymin + height;
627
628 rcti rect_bounds;
629 const int margin = UI_SCREEN_MARGIN;
630 rect_bounds.xmin = margin;
631 rect_bounds.ymin = margin;
632 rect_bounds.xmax = win_size[0] - margin;
633 rect_bounds.ymax = win_size[1] - UI_POPUP_MENU_TOP;
634
635 int ofs_dummy[2];
636 BLI_rcti_clamp(&rect, &rect_bounds, ofs_dummy);
637 block_translate(block, rect.xmin - block->rect.xmin, rect.ymin - block->rect.ymin);
638
639 /* now recompute bounds and safety */
640 block_bounds_calc(block);
641
642 /* If given, adjust input coordinates such that they would generate real final popup position.
643 * Needed to handle correctly floating panels once they have been dragged around,
644 * see #52999. */
645 if (r_xy) {
646 r_xy[0] = xy[0] + block->rect.xmin - raw_x;
647 r_xy[1] = xy[1] + block->rect.ymin - raw_y;
648 }
649}
650
651void block_bounds_set_normal(Block *block, int addval)
652{
653 if (block == nullptr) {
654 return;
655 }
656
657 block->bounds = addval;
658 block->bounds_type = BLOCK_BOUNDS;
659}
660
661void block_bounds_set_text(Block *block, int addval)
662{
663 block->bounds = addval;
665}
666
667void block_bounds_set_popup(Block *block, int addval, const int bounds_offset[2])
668{
669 block->bounds = addval;
671 if (bounds_offset != nullptr) {
672 block->bounds_offset[0] = bounds_offset[0];
673 block->bounds_offset[1] = bounds_offset[1];
674 }
675 else {
676 block->bounds_offset[0] = 0;
677 block->bounds_offset[1] = 0;
678 }
679}
680
681void block_bounds_set_menu(Block *block, int addval, const int bounds_offset[2])
682{
683 block->bounds = addval;
685 if (bounds_offset != nullptr) {
686 copy_v2_v2_int(block->bounds_offset, bounds_offset);
687 }
688 else {
690 }
691}
692
693void block_bounds_set_centered(Block *block, int addval)
694{
695 block->bounds = addval;
697}
698
699void block_bounds_set_explicit(Block *block, int minx, int miny, int maxx, int maxy)
700{
701 block->rect.xmin = minx;
702 block->rect.ymin = miny;
703 block->rect.xmax = maxx;
704 block->rect.ymax = maxy;
706}
707
709
710/* -------------------------------------------------------------------- */
713
715{
716 if (but->type == ButtonType::Num) {
717 return (static_cast<ButtonNumber *>(but))->precision;
718 }
719 if (but->type == ButtonType::NumSlider) {
720 return (static_cast<ButtonNumberSlider *>(but))->precision;
721 }
723 return 1.0f;
724}
725
727{
728 if (but->type == ButtonType::Num) {
729 return (static_cast<ButtonNumber *>(but))->step_size;
730 }
731 if (but->type == ButtonType::NumSlider) {
732 return (static_cast<ButtonNumberSlider *>(but))->step_size;
733 }
735 return 1.0f;
736}
737
738static bool but_hide_fraction(Button *but, double value)
739{
740 /* Hide the fraction if both the value and the step are exact integers. */
741 if (floor(value) == value) {
743
744 if (floorf(step) == step) {
745 /* Don't hide if it has any unit except frame count. */
746 switch (button_unit_type_get(but)) {
747 case PROP_UNIT_NONE:
748 case PROP_UNIT_TIME:
749 return true;
750
751 default:
752 return false;
753 }
754 }
755 }
756
757 return false;
758}
759
760static int but_calc_float_precision(Button *but, double value)
761{
762 if (but_hide_fraction(but, value)) {
763 return 0;
764 }
765
766 int prec = int(but_get_float_precision(but));
767
768 /* first check for various special cases:
769 * * If button is radians, we want additional precision (see #39861).
770 * * If prec is not set, we fall back to a simple default */
771 if (but_is_unit_radians(but) && prec < 5) {
772 prec = 5;
773 }
774 else if (prec == -1) {
775 prec = (but->hardmax < 10.001f) ? 3 : 2;
776 }
777 else {
779 }
780
781 return calc_float_precision(prec, value);
782}
783
785
786/* -------------------------------------------------------------------- */
789
790bool button_rna_equals(const Button *a, const Button *b)
791{
792 return button_rna_equals_ex(a, &b->rnapoin, b->rnaprop, b->rnaindex);
793}
794
796 const PointerRNA *ptr,
797 const PropertyRNA *prop,
798 int index)
799{
800 if (but->rnapoin.data != ptr->data) {
801 return false;
802 }
803 if (but->rnaprop != prop || but->rnaindex != index) {
804 return false;
805 }
806
807 return true;
808}
809
810/* NOTE: if `but->poin` is allocated memory for every `uiDefBut*`, things fail. */
811static bool but_equals_old(const Button *but, const Button *oldbut)
812{
813 if (but->type != oldbut->type) {
814 return false;
815 }
816
817 if (but->identity_cmp_func) {
818 /* If the buttons have their own identity comparator callbacks (and they match), use this to
819 * determine equality. */
820 if (but->identity_cmp_func && (but->type == oldbut->type) &&
821 (but->identity_cmp_func == oldbut->identity_cmp_func))
822 {
823 /* Test if the comparison is symmetrical (if a == b then b == a), may help catch some issues.
824 */
825 BLI_assert(but->identity_cmp_func(but, oldbut) == but->identity_cmp_func(oldbut, but));
826
827 return but->identity_cmp_func(but, oldbut);
828 }
829 }
830
831 /* various properties are being compared here, hopefully sufficient
832 * to catch all cases, but it is simple to add more checks later */
833 if (but->retval != oldbut->retval) {
834 return false;
835 }
836 if (!button_rna_equals(but, oldbut)) {
837 return false;
838 }
839 if (but->func != oldbut->func) {
840 return false;
841 }
842 /* Compares the contained function pointers. Buttons with different apply functions can be
843 * considered to do different things, and as such do not equal each other. */
844 if (but->apply_func.target<void(bContext &)>() != oldbut->apply_func.target<void(bContext &)>())
845 {
846 return false;
847 }
848 if (but->funcN != oldbut->funcN) {
849 return false;
850 }
851 if (!ELEM(oldbut->func_arg1, oldbut, but->func_arg1)) {
852 return false;
853 }
854 if (!ELEM(oldbut->func_arg2, oldbut, but->func_arg2)) {
855 return false;
856 }
857 if (but->block_create_func != oldbut->block_create_func) {
858 return false;
859 }
860 if (!but->funcN &&
861 ((but->poin != oldbut->poin && reinterpret_cast<Button *>(oldbut->poin) != oldbut) ||
862 (but->pointype != oldbut->pointype)))
863 {
864 return false;
865 }
866 if (but->optype != oldbut->optype) {
867 return false;
868 }
869 if (but->dragtype != oldbut->dragtype) {
870 return false;
871 }
872
873 if (but->type == ButtonType::ViewItem) {
874 ButtonViewItem *but_item = static_cast<ButtonViewItem *>(const_cast<Button *>(but));
875 ButtonViewItem *oldbut_item = static_cast<ButtonViewItem *>(const_cast<Button *>(oldbut));
876 if (!but_item->view_item || !oldbut_item->view_item ||
877 !view_item_matches(*but_item->view_item, *oldbut_item->view_item))
878 {
879 return false;
880 }
881 }
882
883 if (but->type == ButtonType::Label) {
884 return static_cast<const ButtonLabel *>(but)->label_type ==
885 static_cast<const ButtonLabel *>(oldbut)->label_type;
886 }
887
888 return true;
889}
890
891static Button *but_find_old(Block *block_old,
892 const Button *but_new,
893 const Set<const Button *> &ignore_old_buttons)
894{
895 for (Button &but : block_old->buttons()) {
896 if (!ignore_old_buttons.contains(&but) && but_equals_old(but_new, &but)) {
897 return &but;
898 }
899 }
900 return nullptr;
901}
902
904{
905 return but_find_old(block_old, but_new, {});
906}
907
908static std::optional<int64_t> but_find_old_idx(Block *block_old,
909 const Button *but_new,
910 const Set<const Button *> &ignore_old_buttons = {})
911{
912 int64_t i = 0;
913 for (const Button &but : block_old->buttons()) {
914 if (!ignore_old_buttons.contains(&but) && but_equals_old(but_new, &but)) {
915 return i;
916 }
917 i++;
918 }
919 return std::nullopt;
920}
921
922Button *button_find_new(Block *block_new, const Button *but_old)
923{
924 for (Button &but : block_new->buttons()) {
925 if (but_equals_old(&but, but_old)) {
926 return &but;
927 }
928 }
929 return nullptr;
930}
931
932static bool but_extra_icons_equals_old(const ButtonExtraOpIcon *new_extra_icon,
933 const ButtonExtraOpIcon *old_extra_icon)
934{
935 return (new_extra_icon->optype_params->optype == old_extra_icon->optype_params->optype) &&
936 (new_extra_icon->icon == old_extra_icon->icon);
937}
938
940 const Button *old_but)
941{
942 for (ButtonExtraOpIcon &op_icon : old_but->extra_op_icons) {
943 if (but_extra_icons_equals_old(new_extra_icon, &op_icon)) {
944 return &op_icon;
945 }
946 }
947 return nullptr;
948}
949
950static void but_extra_icons_update_from_old_but(const Button *new_but, const Button *old_but)
951{
952 /* Specifically for keeping some state info for the active button. */
953 BLI_assert(old_but->active || old_but->semi_modal_state);
954
955 for (ButtonExtraOpIcon &new_extra_icon : new_but->extra_op_icons) {
956 ButtonExtraOpIcon *old_extra_icon = but_extra_icon_find_old(&new_extra_icon, old_but);
957 /* Keep the highlighting state, and let handling update it later. */
958 if (old_extra_icon) {
959 new_extra_icon.highlighted = old_extra_icon->highlighted;
960 }
961 }
962}
963
975{
976 BLI_assert(oldbut->active || oldbut->semi_modal_state);
977
978 /* flags from the buttons we want to refresh, may want to add more here... */
980 const int drawflag_copy = BUT_HAS_QUICK_TOOLTIP | BUT_NO_TOOLTIP;
981
982 /* still stuff needs to be copied */
983 oldbut->rect = but->rect;
984 oldbut->context = but->context; /* set by Layout */
985
986 /* drawing */
987 oldbut->icon = but->icon;
988 oldbut->iconadd = but->iconadd;
989 oldbut->alignnr = but->alignnr;
990 oldbut->custom_data = but->custom_data;
991
992 oldbut->text_direction = but->text_direction;
993
994 /* typically the same pointers, but not on undo/redo */
995 /* XXX some menu buttons store button itself in but->poin. Ugly */
996 if (oldbut->poin != reinterpret_cast<char *>(oldbut)) {
997 std::swap(oldbut->poin, but->poin);
998 std::swap(oldbut->func_argN, but->func_argN);
999 }
1000
1001 std::swap(oldbut->apply_func, but->apply_func);
1002
1003 std::swap(oldbut->pushed_state_func, but->pushed_state_func);
1004
1005 /* Move tooltip from new to old. */
1006 std::swap(oldbut->tip_func, but->tip_func);
1007 std::swap(oldbut->tip_arg, but->tip_arg);
1008 std::swap(oldbut->tip_custom_func, but->tip_custom_func);
1009 std::swap(oldbut->tip_arg_free, but->tip_arg_free);
1010 std::swap(oldbut->tip_quick_func, but->tip_quick_func);
1011
1012 oldbut->flag = (oldbut->flag & ~flag_copy) | (but->flag & flag_copy);
1013 oldbut->drawflag = (oldbut->drawflag & ~drawflag_copy) | (but->drawflag & drawflag_copy);
1014
1016 std::swap(but->extra_op_icons, oldbut->extra_op_icons);
1017
1018 std::swap(but->icon_overlay_text, oldbut->icon_overlay_text);
1019
1020 if (oldbut->type == ButtonType::SearchMenu) {
1021 ButtonSearch *search_oldbut = static_cast<ButtonSearch *>(oldbut),
1022 *search_but = static_cast<ButtonSearch *>(but);
1023
1024 std::swap(search_oldbut->arg, search_but->arg);
1025 }
1026 if (oldbut->type == ButtonType::Label) {
1027 auto *label_oldbut = static_cast<ButtonLabel *>(oldbut);
1028 auto *label_but = static_cast<ButtonLabel *>(but);
1029 std::swap(label_oldbut->wrap_cache, label_but->wrap_cache);
1030 std::swap(label_oldbut->markdown_cache, label_but->markdown_cache);
1031 std::swap(label_oldbut->max_lines, label_but->max_lines);
1032 }
1033
1034 /* copy hardmin for list rows to prevent 'sticking' highlight to mouse position
1035 * when scrolling without moving mouse (see #28432) */
1037 oldbut->hardmax = but->hardmax;
1038 }
1039
1040 switch (oldbut->type) {
1041 case ButtonType::Progress: {
1042 ButtonProgress *progress_oldbut = static_cast<ButtonProgress *>(oldbut);
1043 ButtonProgress *progress_but = static_cast<ButtonProgress *>(but);
1044 progress_oldbut->progress_factor = progress_but->progress_factor;
1045 break;
1046 }
1047 case ButtonType::SeprLine: {
1048 ButtonSeparatorLine *line_oldbut = static_cast<ButtonSeparatorLine *>(oldbut);
1049 ButtonSeparatorLine *line_but = static_cast<ButtonSeparatorLine *>(but);
1050 line_oldbut->is_vertical = line_but->is_vertical;
1051 break;
1052 }
1053 case ButtonType::Label: {
1054 ButtonLabel *label_oldbut = static_cast<ButtonLabel *>(oldbut);
1055 ButtonLabel *label_but = static_cast<ButtonLabel *>(but);
1056 label_oldbut->alpha_factor = label_but->alpha_factor;
1057 break;
1058 }
1059 case ButtonType::Scroll: {
1060 ButtonScrollBar *scroll_oldbut = static_cast<ButtonScrollBar *>(oldbut);
1061 ButtonScrollBar *scroll_but = static_cast<ButtonScrollBar *>(but);
1062 scroll_oldbut->visual_height = scroll_but->visual_height;
1063 break;
1064 }
1065 case ButtonType::Image: {
1066 ButtonImage *image_oldbut = static_cast<ButtonImage *>(oldbut);
1067 ButtonImage *image_but = static_cast<ButtonImage *>(but);
1068 std::swap(image_oldbut->key, image_but->key);
1069 break;
1070 }
1071 case ButtonType::ViewItem: {
1072 ButtonViewItem *view_item_oldbut = static_cast<ButtonViewItem *>(oldbut);
1073 ButtonViewItem *view_item_newbut = static_cast<ButtonViewItem *>(but);
1074 view_item_swap_button_pointers(*view_item_newbut->view_item, *view_item_oldbut->view_item);
1075 std::swap(view_item_newbut->view_item, view_item_oldbut->view_item);
1076 break;
1077 }
1078 case ButtonType::Text: {
1079 ButtonText *text_oldbut = static_cast<ButtonText *>(oldbut);
1080 ButtonText *text_newbut = static_cast<ButtonText *>(but);
1081 std::swap(text_oldbut->rename_func, text_newbut->rename_func);
1082 std::swap(text_oldbut->rename_full_func, text_newbut->rename_full_func);
1083 break;
1084 }
1085 default:
1086 break;
1087 }
1088
1089 /* move/copy string from the new button to the old */
1090 /* needed for alt+mouse wheel over enums */
1091 std::swap(but->str, oldbut->str);
1092
1093 if (but->dragpoin) {
1094 std::swap(but->dragpoin, oldbut->dragpoin);
1095 }
1096 if (but->imb) {
1097 std::swap(but->imb, oldbut->imb);
1098 }
1099
1100 /* NOTE: if layout hasn't been applied yet, it uses old button pointers... */
1101}
1102
1127 Set<const Button *> &matched_old_buttons,
1128 std::unique_ptr<Button> *but_uptr,
1129 std::optional<int64_t> *but_old_idx)
1130{
1131 Block *oldblock = block->oldblock;
1132 Button *but = but_uptr->get();
1133
1134#if 0
1135 /* Simple method - search every time. Keep this for easy testing of the "fast path." */
1136 Button *oldbut = but_find_old(oldblock, but, matched_old_buttons);
1137 UNUSED_VARS(but_old_p);
1138#else
1139 BLI_assert(!but_old_idx->has_value() ||
1140 oldblock->buttons_ptrs.index_range().contains(**but_old_idx));
1141
1142 /* As long as old and new buttons are aligned, avoid loop-in-loop (calling #but_find_old). */
1143 std::unique_ptr<Button> *oldbut_uptr;
1144 if (but_old_idx->has_value() &&
1145 /* Ignore previously matched buttons. */
1146 !matched_old_buttons.contains(oldblock->buttons_ptrs[**but_old_idx].get()) &&
1147 but_equals_old(but, oldblock->buttons_ptrs[**but_old_idx].get())) [[likely]]
1148 {
1149 oldbut_uptr = &oldblock->buttons_ptrs[**but_old_idx];
1150 }
1151 else {
1152 /* Fall back to block search. */
1153 *but_old_idx = but_find_old_idx(oldblock, but, matched_old_buttons);
1154 oldbut_uptr = but_old_idx->has_value() ? &oldblock->buttons_ptrs[**but_old_idx] : nullptr;
1155 }
1156 /* Increase for next iteration. */
1157 *but_old_idx = (but_old_idx->has_value() &&
1158 (but_old_idx->value() + 1 < oldblock->buttons_ptrs.size())) ?
1159 std::optional{but_old_idx->value() + 1} :
1160 std::nullopt;
1161#endif
1162
1163 bool found_active = false;
1164
1165 if (!oldbut_uptr) {
1166 return false;
1167 }
1168 Button *oldbut = oldbut_uptr->get();
1169
1170 BLI_assert(!matched_old_buttons.contains(oldbut));
1171
1172 if (oldbut->type == ButtonType::TextBox) {
1173 ButtonTextBox *textbox = static_cast<ButtonTextBox *>(but);
1174 ButtonTextBox *old_textbox = static_cast<ButtonTextBox *>(oldbut);
1175 textbox->last_total_lines = old_textbox->last_total_lines;
1176 /* Steal text wrap cache if the old textbox is not active. */
1177 if (!(oldbut->active || oldbut->semi_modal_state)) {
1178 textbox->wrap_cache = std::move(old_textbox->wrap_cache);
1179 textbox->placeholder_wrap_cache = std::move(old_textbox->placeholder_wrap_cache);
1180 }
1181 }
1182
1183 if (oldbut->active || oldbut->semi_modal_state) {
1184 /* Move button over from oldblock to new block. */
1185 oldbut_uptr->swap(*but_uptr);
1186 BLI_assert(but_uptr->get() == oldbut);
1187 /* `but` was moved to oldblock, taking oldbut place. */
1188 BLI_assert(!matched_old_buttons.contains(but));
1189 matched_old_buttons.add(but);
1190
1191 /* Add the old button to the button groups in the new block. */
1192 button_group_replace_but_ptr(block, but, oldbut);
1193 oldbut->block = block;
1194
1195 but_update_old_active_from_new(oldbut, but);
1196
1197 if (!block->butstore.is_empty()) {
1198 butstore_register_update(block, oldbut, but);
1199 }
1200
1201 found_active = true;
1202 }
1203 else {
1204 matched_old_buttons.add(oldbut);
1205 int64_t flag_copy = BUT_DRAG_MULTI;
1206
1207 /* Stupid special case: The active button may be inside (as in, overlapped on top) a row
1208 * button which we also want to keep highlighted then. */
1210 flag_copy |= UI_HOVER;
1211 }
1212
1213 but->flag = (but->flag & ~flag_copy) | (oldbut->flag & flag_copy);
1214 }
1215
1216 return found_active;
1217}
1218
1220
1221/* -------------------------------------------------------------------- */
1224
1226 const bContext *C, ARegion *region, Block *block, Button *but, const bool remove_on_failure)
1227{
1228 bool activate = false, found = false, isactive = false;
1229
1230 Block *oldblock = block->oldblock;
1231 if (!oldblock) {
1232 activate = true;
1233 }
1234 else {
1235 Button *oldbut = button_find_old(oldblock, but);
1236 if (oldbut) {
1237 found = true;
1238
1239 if (oldbut->active) {
1240 isactive = true;
1241 }
1242 }
1243 }
1244 if ((activate == true) || (found == false)) {
1245 /* There might still be another active button. */
1246 Button *old_active = region_find_active_but(region);
1247 if (old_active) {
1248 button_active_free(C, old_active);
1249 }
1250
1251 button_activate_event(const_cast<bContext *>(C), region, but);
1252 }
1253 else if ((found == true) && (isactive == false)) {
1254 if (remove_on_failure) {
1255 if (but->layout) {
1256 layout_remove_but(but->layout, but);
1257 }
1258 but_free(C, but);
1259 block->remove_but(but);
1260 }
1261 return false;
1262 }
1263
1264 return true;
1265}
1266
1267bool button_active_only(const bContext *C, ARegion *region, Block *block, Button *but)
1268{
1269 return button_active_only_ex(C, region, block, but, true);
1270}
1271
1273{
1274 /* Running this command before end-block has run, means buttons that open menus
1275 * won't have those menus correctly positioned, see #83539. */
1276 BLI_assert(block->endblock);
1277
1278 bool done = false;
1279 for (Button &but : block->buttons()) {
1280 if (but.flag & BUT_ACTIVATE_ON_INIT) {
1281 but.flag &= ~BUT_ACTIVATE_ON_INIT;
1282 if (button_is_editable(&but)) {
1283 if (button_active_only_ex(C, region, block, &but, false)) {
1284 done = true;
1285 break;
1286 }
1287 }
1288 }
1289 }
1290
1291 if (done) {
1292 /* Run this in a second pass since it's possible activating the button
1293 * removes the buttons being looped over. */
1294 for (Button &but : block->buttons()) {
1295 but.flag &= ~BUT_ACTIVATE_ON_INIT;
1296 }
1297 }
1298
1299 return done;
1300}
1301
1302void button_execute(const bContext *C, ARegion *region, Button *but)
1303{
1304 void *active_back;
1305 button_execute_begin(const_cast<bContext *>(C), region, but, &active_back);
1306 /* Value is applied in begin. No further action required. */
1307 button_execute_end(const_cast<bContext *>(C), region, but, active_back);
1308}
1309
1310/* use to check if we need to disable undo, but don't make any changes
1311 * returns false if undo needs to be disabled. */
1312static bool but_is_rna_undo(const Button *but)
1313{
1314 if (but->rnaprop == nullptr) {
1315 return true;
1316 }
1317
1318 /* No owner or type known. Assume we do not undo push as it may be a property from
1319 * the preferences stored outside datablocks. */
1320 if (!but->rnapoin.has_owner_id() || !but->rnapoin.has_type()) {
1321 return false;
1322 }
1323
1324 return ID_CHECK_UNDO(but->rnapoin.owner_id) &&
1326}
1327
1329
1330/* -------------------------------------------------------------------- */
1333
1334/* assigns automatic keybindings to menu items for fast access
1335 * (underline key in menu) */
1337{
1338 uint menu_key_mask = 0;
1339 int tot_missing = 0;
1340
1341 /* only do it before bounding */
1342 if (block->rect.xmin != block->rect.xmax) {
1343 return;
1344 }
1345
1346 for (int pass = 0; pass < 2; pass++) {
1347 /* 2 Passes: One for first letter only, second for any letter if the first pass fails.
1348 * Run first pass on all buttons so first word chars always get first priority. */
1349
1350 for (Button &but : block->buttons()) {
1351 if (!ELEM(but.type,
1359
1360 /* For PIE-menus. */
1361 ButtonType::Row) ||
1362 (but.flag & UI_HIDDEN))
1363 {
1364 continue;
1365 }
1366
1367 if (pass == 0 && ELEM(but.type, ButtonType::IconToggle, ButtonType::IconToggleN)) {
1368 /* Until 4.4, toggles did not get accelerator keys. Ignore them on the first pass to keep
1369 * the most-used accelerator keys (those on the first letter) the same. In general it seems
1370 * more desired to give operators priority over toggles. #134492 */
1371 continue;
1372 }
1373
1374 if (but.menu_key != '\0') {
1375 continue;
1376 }
1377
1378 if (but.str.empty()) {
1379 continue;
1380 }
1381
1382 const char *str_pt = but.str.c_str();
1383 uchar menu_key;
1384 do {
1385 menu_key = tolower(*str_pt);
1386 if ((menu_key >= 'a' && menu_key <= 'z') && !(menu_key_mask & 1 << (menu_key - 'a'))) {
1387 menu_key_mask |= 1 << (menu_key - 'a');
1388 break;
1389 }
1390
1391 if (pass == 0) {
1392 /* Skip to next delimiter on first pass (be picky) */
1393 while (isalpha(*str_pt)) {
1394 str_pt++;
1395 }
1396
1397 if (*str_pt) {
1398 str_pt++;
1399 }
1400 }
1401 else {
1402 /* just step over every char second pass and find first usable key */
1403 str_pt++;
1404 }
1405 } while (*str_pt);
1406
1407 if (*str_pt) {
1408 but.menu_key = menu_key;
1409 }
1410 else {
1411 /* run second pass */
1412 tot_missing++;
1413 }
1414
1415 /* if all keys have been used just exit, unlikely */
1416 if (menu_key_mask == (1 << 26) - 1) {
1417 return;
1418 }
1419 }
1420
1421 /* check if second pass is needed */
1422 if (!tot_missing) {
1423 break;
1424 }
1425 }
1426}
1427
1428void button_add_shortcut(Button *but, const char *shortcut_str, const bool do_strip)
1429{
1430 if (do_strip && (but->flag & BUT_HAS_SEP_CHAR)) {
1431 const size_t sep_index = but->str.find_first_of(UI_SEP_CHAR);
1432 if (sep_index != std::string::npos) {
1433 but->str = but->str.substr(0, sep_index);
1434 }
1435 but->flag &= ~BUT_HAS_SEP_CHAR;
1436 }
1437
1438 /* without this, just allow stripping of the shortcut */
1439 if (shortcut_str == nullptr) {
1440 return;
1441 }
1442
1443 but->str = fmt::format("{}" UI_SEP_CHAR_S "{}", but->str, shortcut_str);
1444 but->flag |= BUT_HAS_SEP_CHAR;
1445 button_update(but);
1446}
1447
1449
1450/* -------------------------------------------------------------------- */
1456
1457static std::optional<std::string> but_event_operator_string_from_operator(
1458 const bContext *C, wmOperatorCallParams *op_call_params)
1459{
1460 BLI_assert(op_call_params->optype != nullptr);
1461 IDProperty *prop = op_call_params->opptr ?
1462 static_cast<IDProperty *>(op_call_params->opptr->data) :
1463 nullptr;
1464
1466 C, op_call_params->optype->idname, op_call_params->opcontext, prop, true);
1467}
1468
1469static std::optional<std::string> but_event_operator_string_from_menu(const bContext *C,
1470 Button *but)
1471{
1472 MenuType *mt = button_menutype_get(but);
1473 BLI_assert(mt != nullptr);
1474
1475 /* Dummy, name is unimportant. */
1476 IDProperty *prop_menu = bke::idprop::create_group(__func__).release();
1477 IDP_AddToGroup(prop_menu, IDP_NewStringMaxSize(mt->idname, sizeof(mt->idname), "name"));
1478
1479 const std::optional<std::string> result = WM_key_event_operator_string(
1480 C, "WM_OT_call_menu", wm::OpCallContext::InvokeRegionWin, prop_menu, true);
1481
1482 IDP_FreeProperty(prop_menu);
1483 return result;
1484}
1485
1486static std::optional<std::string> but_event_operator_string_from_panel(const bContext *C,
1487 Button *but)
1488{
1491 BLI_assert(pt != nullptr);
1492
1493 /* Dummy, name is unimportant. */
1494 IDProperty *prop_panel = bke::idprop::create_group(__func__).release();
1495 IDP_AddToGroup(prop_panel, IDP_NewStringMaxSize(pt->idname, sizeof(pt->idname), "name"));
1496 IDP_AddToGroup(prop_panel, bke::idprop::create("space_type", pt->space_type).release());
1497 IDP_AddToGroup(prop_panel, bke::idprop::create("region_type", pt->region_type).release());
1498 BLI_SCOPED_DEFER([&]() { IDP_FreeProperty(prop_panel); });
1499
1500 for (int i = 0; i < 2; i++) {
1501 /* FIXME(@ideasman42): We can't reasonably search all configurations - long term. */
1502 IDP_ReplaceInGroup(prop_panel, bke::idprop::create("keep_open", i).release());
1503 std::optional<std::string> result = WM_key_event_operator_string(
1504 C, "WM_OT_call_panel", wm::OpCallContext::InvokeRegionWin, prop_panel, true);
1505 if (result) {
1506 return result;
1507 }
1508 }
1509
1510 return std::nullopt;
1511}
1512
1513static std::optional<std::string> but_event_operator_string(const bContext *C, Button *but)
1514{
1515 if (but->optype != nullptr) {
1516 wmOperatorCallParams params = {};
1517 params.optype = but->optype;
1518 params.opptr = but->opptr;
1519 params.opcontext = but->opcontext;
1521 }
1522 if (button_menutype_get(but) != nullptr) {
1524 }
1525 if (button_paneltype_get(but) != nullptr) {
1527 }
1528
1529 return std::nullopt;
1530}
1531
1532static std::optional<std::string> but_extra_icon_event_operator_string(
1533 const bContext *C, const ButtonExtraOpIcon *extra_icon)
1534{
1535 wmOperatorType *extra_icon_optype = button_extra_operator_icon_optype_get(extra_icon);
1536
1537 if (extra_icon_optype) {
1539 }
1540
1541 return std::nullopt;
1542}
1543
1544static std::optional<std::string> but_event_property_operator_string(const bContext *C,
1545 Button *but)
1546{
1547 /* Context toggle operator names to check. */
1548
1549 /* NOTE(@ideasman42): This function could use a refactor to generalize button type to operator
1550 * relationship as well as which operators use properties. */
1551 const char *ctx_toggle_opnames[] = {
1552 "WM_OT_context_toggle",
1553 "WM_OT_context_toggle_enum",
1554 "WM_OT_context_cycle_int",
1555 "WM_OT_context_cycle_enum",
1556 "WM_OT_context_cycle_array",
1557 "WM_OT_context_menu_enum",
1558 nullptr,
1559 };
1560
1561 const char *ctx_enum_opnames[] = {
1562 "WM_OT_context_set_enum",
1563 nullptr,
1564 };
1565
1566 const char *ctx_enum_opnames_for_Area_ui_type[] = {
1567 "SCREEN_OT_space_type_set_or_cycle",
1568 nullptr,
1569 };
1570
1571 const char **opnames = ctx_toggle_opnames;
1572 int opnames_len = ARRAY_SIZE(ctx_toggle_opnames);
1573
1574 int prop_enum_value = -1;
1575 bool prop_enum_value_ok = false;
1576 bool prop_enum_value_is_int = false;
1577 const char *prop_enum_value_id = "value";
1578 PointerRNA *ptr = &but->rnapoin;
1579 PropertyRNA *prop = but->rnaprop;
1580 int prop_index = but->rnaindex;
1581 if ((but->type == ButtonType::ButMenu) && (but->block->handle != nullptr)) {
1582 Button *but_parent = but->block->handle->popup_create_vars.but;
1583 if ((but_parent && but_parent->rnaprop) &&
1584 (RNA_property_type(but_parent->rnaprop) == PROP_ENUM) &&
1585 ELEM(but_parent->menu_create_func,
1589 {
1590 prop_enum_value = but->retval;
1591 ptr = &but_parent->rnapoin;
1592 prop = but_parent->rnaprop;
1593 prop_enum_value_ok = true;
1594
1595 opnames = ctx_enum_opnames;
1596 opnames_len = ARRAY_SIZE(ctx_enum_opnames);
1597 }
1598 }
1599 /* Don't use the button again. */
1600 but = nullptr;
1601
1602 if (prop == nullptr) {
1603 return std::nullopt;
1604 }
1605
1606 /* This version is only for finding hotkeys for properties.
1607 * These are set via a data-path which is appended to the context,
1608 * manipulated using operators (see #ctx_toggle_opnames). */
1609
1610 if (ptr->owner_id) {
1611 ID *id = ptr->owner_id;
1612
1613 if (GS(id->name) == ID_SCR) {
1614 if (RNA_struct_is_a(ptr->type, RNA_Area)) {
1615 /* data should be directly on here... */
1616 const char *prop_id = RNA_property_identifier(prop);
1617 /* Hack since keys access 'type', UI shows 'ui_type'. */
1618 if (STREQ(prop_id, "ui_type")) {
1619 prop_id = "type";
1620 prop_enum_value >>= 16;
1621 prop = RNA_struct_find_property(ptr, prop_id);
1622 prop_index = -1;
1623
1624 if (prop_enum_value == -1) {
1625 /* Get the current value for Editor menu. #100652 */
1626 prop_enum_value = RNA_property_enum_get(ptr, prop);
1627 prop_enum_value_ok = (prop_enum_value != -1);
1628 }
1629
1630 opnames = ctx_enum_opnames_for_Area_ui_type;
1631 opnames_len = ARRAY_SIZE(ctx_enum_opnames_for_Area_ui_type);
1632 prop_enum_value_id = "space_type";
1633 prop_enum_value_is_int = true;
1634 }
1635 }
1636 }
1637 }
1638
1639 /* There may be multiple data-paths to the same properties,
1640 * support different variations so key bindings are properly detected no matter which are used.
1641 */
1642 Vector<std::string, 2> data_path_variations;
1643
1644 {
1645 std::optional<std::string> data_path = WM_context_path_resolve_property_full(
1646 C, ptr, prop, prop_index);
1647
1648 /* Always iterate once, even if data-path isn't set. */
1649 data_path_variations.append(data_path.value_or(""));
1650
1651 if (data_path.has_value()) {
1652 StringRef data_path_ref = StringRef(data_path.value());
1653 if (data_path_ref.startswith("scene.tool_settings.")) {
1654 data_path_variations.append(data_path_ref.drop_known_prefix("scene."));
1655 }
1656 }
1657 }
1658
1659 /* We have a data-path! */
1660 for (int data_path_index = 0; data_path_index < data_path_variations.size(); data_path_index++) {
1661 const StringRefNull data_path = data_path_variations[data_path_index];
1662 if (!data_path.is_empty() || (prop_enum_value_ok && prop_enum_value_id)) {
1663 /* Create a property to host the "data_path" property we're sending to the operators. */
1664 IDProperty *prop_path = bke::idprop::create_group(__func__).release();
1665 BLI_SCOPED_DEFER([&]() { IDP_FreeProperty(prop_path); });
1666 if (!data_path.is_empty()) {
1667 IDP_AddToGroup(prop_path, bke::idprop::create("data_path", data_path).release());
1668 }
1669 if (prop_enum_value_ok) {
1670 const EnumPropertyItem *item;
1671 bool free;
1672 RNA_property_enum_items(const_cast<bContext *>(C), ptr, prop, &item, nullptr, &free);
1673 const int index = RNA_enum_from_value(item, prop_enum_value);
1674 if (index != -1) {
1675 IDProperty *prop_value;
1676 if (prop_enum_value_is_int) {
1677 const int value = item[index].value;
1678 prop_value = bke::idprop::create(prop_enum_value_id, value).release();
1679 }
1680 else {
1681 prop_value = bke::idprop::create(prop_enum_value_id, item[index].identifier).release();
1682 }
1683 IDP_AddToGroup(prop_path, prop_value);
1684 }
1685 else {
1686 opnames_len = 0; /* Do nothing. */
1687 }
1688 if (free) {
1689 MEM_delete(item);
1690 }
1691 }
1692
1693 /* check each until one works... */
1694
1695 for (int i = 0; (i < opnames_len) && (opnames[i]); i++) {
1696 const std::optional<std::string> str = WM_key_event_operator_string(
1697 C, opnames[i], wm::OpCallContext::InvokeRegionWin, prop_path, false);
1698 if (str) {
1699 return str;
1700 }
1701 }
1702 }
1703 }
1704
1705 return std::nullopt;
1706}
1707
1709
1710/* -------------------------------------------------------------------- */
1737
1738const char radial_dir_order[8] = {
1747};
1748
1749const char radial_dir_to_numpad[8] = {8, 9, 6, 3, 2, 1, 4, 7};
1750const short radial_dir_to_angle[8] = {90, 45, 0, 315, 270, 225, 180, 135};
1751
1752static std::string but_pie_direction_string(const Button *but)
1753{
1755 return fmt::to_string(int(radial_dir_to_numpad[but->pie_dir]));
1756}
1757
1759
1760/* -------------------------------------------------------------------- */
1763
1764static void menu_block_set_keymaps(const bContext *C, Block *block)
1765{
1767
1768 /* only do it before bounding */
1769 if (block->rect.xmin != block->rect.xmax) {
1770 return;
1771 }
1772 if (block->name == "splash") {
1773 return;
1774 }
1775
1776 if (block->flag & BLOCK_PIE_MENU) {
1777 for (Button &but : block->buttons()) {
1778 if (but.pie_dir != UI_RADIAL_NONE) {
1779 const std::string str = but_pie_direction_string(&but);
1780 button_add_shortcut(&but, str.c_str(), false);
1781 }
1782 }
1783 }
1784 else {
1785 for (Button &but : block->buttons()) {
1786 if (block->flag & BLOCK_SHOW_SHORTCUT_ALWAYS) {
1787 /* Skip icon-only buttons (as used in the toolbar). */
1788 if (but.drawstr[0] == '\0') {
1789 continue;
1790 }
1791 if (((block->flag & BLOCK_POPOVER) == 0) && but_is_tool(&but)) {
1792 /* For non-popovers, shown in shortcut only
1793 * (has special shortcut handling code). */
1794 continue;
1795 }
1796 }
1797 else if (but.emboss != EmbossType::Pulldown) {
1798 continue;
1799 }
1800
1801 if (const std::optional<std::string> str = but_event_operator_string(C, &but)) {
1802 button_add_shortcut(&but, str->c_str(), false);
1803 }
1804 else if (const std::optional<std::string> str = but_event_property_operator_string(C, &but))
1805 {
1806 button_add_shortcut(&but, str->c_str(), false);
1807 }
1808 }
1809 }
1810}
1811
1813
1814/* -------------------------------------------------------------------- */
1817
1819{
1821 bmain, &but->rnapoin, but->rnaprop, but->rnaindex);
1822
1823 if (flag_is_set(override_status, eRNAOverrideStatus::LibOverridden)) {
1824 but->flag |= BUT_OVERRIDDEN;
1825 }
1826 else {
1827 but->flag &= ~BUT_OVERRIDDEN;
1828 }
1829}
1830
1832
1833/* -------------------------------------------------------------------- */
1841
1851
1853 wmOperatorType *optype,
1854 wm::OpCallContext opcontext,
1855 int icon)
1856{
1857 auto *extra_op_icon = MEM_new_zeroed<ButtonExtraOpIcon>(__func__);
1858
1859 extra_op_icon->icon = icon;
1860 extra_op_icon->optype_params = MEM_new_zeroed<wmOperatorCallParams>(__func__);
1861 extra_op_icon->optype_params->optype = optype;
1862 extra_op_icon->optype_params->opptr = MEM_new<PointerRNA>(
1863 __func__, WM_operator_properties_create_ptr(extra_op_icon->optype_params->optype));
1864 extra_op_icon->optype_params->opcontext = opcontext;
1865 extra_op_icon->highlighted = false;
1866 extra_op_icon->disabled = false;
1867
1868 BLI_addtail(&but->extra_op_icons, extra_op_icon);
1869
1870 return extra_op_icon->optype_params->opptr;
1871}
1872
1874{
1876 MEM_delete(extra_icon->optype_params->opptr);
1877 MEM_delete(extra_icon->optype_params);
1878 MEM_delete(extra_icon);
1879}
1880
1882{
1883 for (ButtonExtraOpIcon &op_icon : but->extra_op_icons.items_mutable()) {
1885 }
1886 but->extra_op_icons.clear_no_delete();
1887}
1888
1890 const StringRefNull opname,
1891 wm::OpCallContext opcontext,
1892 int icon)
1893{
1894 wmOperatorType *optype = WM_operatortype_find(opname.c_str(), false);
1895
1896 if (optype) {
1897 return but_extra_operator_icon_add_ptr(but, optype, opcontext, icon);
1898 }
1899
1900 return nullptr;
1901}
1902
1904{
1905 return extra_icon ? extra_icon->optype_params->optype : nullptr;
1906}
1907
1909{
1910 return extra_icon->optype_params->opptr;
1911}
1912
1914{
1916 return ((but->flag & BUT_VALUE_CLEAR) && but->drawstr[0]);
1917}
1918
1920{
1922 return ((but->editstr == nullptr) && (but->drawstr[0] != '\0') && (but->flag & BUT_VALUE_CLEAR));
1923}
1924
1926{
1928
1929 if (but->rnaprop == nullptr) {
1930 return false;
1931 }
1932
1934 const short idcode = RNA_type_to_ID_code(type);
1935
1936 return ((but->editstr == nullptr) && (idcode == ID_OB || OB_DATA_SUPPORT_ID(idcode)));
1937}
1938
1940{
1941 if (but->type != ButtonType::SearchMenu || !(but->flag & BUT_VALUE_CLEAR)) {
1942 return false;
1943 }
1944 if (but->editstr != nullptr) {
1945 return false;
1946 }
1948 return false;
1949 }
1950 ButtonSearch *search_but = static_cast<ButtonSearch *>(but);
1951 if (!search_but->rnasearchprop) {
1952 return false;
1953 }
1954 const StructRNA *type = RNA_property_pointer_type(&search_but->rnasearchpoin,
1955 search_but->rnasearchprop);
1956 return type == RNA_Bone || type == RNA_EditBone || type == RNA_PoseBone;
1957}
1958
1960{
1961 switch (but->type) {
1962 case ButtonType::Text:
1965 }
1966 break;
1968 if ((but->flag & BUT_VALUE_CLEAR) == 0) {
1969 /* pass */
1970 }
1973 }
1976 }
1979 }
1980 break;
1981 default:
1982 break;
1983 }
1984
1986}
1987
1994{
1995 const PredefinedExtraOpIconType extra_icon = but_icon_extra_get(but);
1996 wmOperatorType *optype = nullptr;
1997 BIFIconID icon = ICON_NONE;
1998
1999 switch (extra_icon) {
2001 static wmOperatorType *id_eyedropper_ot = nullptr;
2002 if (!id_eyedropper_ot) {
2003 id_eyedropper_ot = WM_operatortype_find("UI_OT_eyedropper_id", false);
2004 }
2005 BLI_assert(id_eyedropper_ot);
2006
2007 optype = id_eyedropper_ot;
2008 icon = ICON_EYEDROPPER;
2009
2010 break;
2011 }
2013 static wmOperatorType *id_eyedropper_ot = nullptr;
2014 if (!id_eyedropper_ot) {
2015 id_eyedropper_ot = WM_operatortype_find("UI_OT_eyedropper_bone", false);
2016 }
2017 BLI_assert(id_eyedropper_ot);
2018
2019 optype = id_eyedropper_ot;
2020 icon = ICON_EYEDROPPER;
2021 break;
2022 }
2024 static wmOperatorType *clear_ot = nullptr;
2025 if (!clear_ot) {
2026 clear_ot = WM_operatortype_find("UI_OT_button_string_clear", false);
2027 }
2028 BLI_assert(clear_ot);
2029
2030 optype = clear_ot;
2031 icon = ICON_PANEL_CLOSE;
2032
2033 break;
2034 }
2035 default:
2036 break;
2037 }
2038
2039 if (optype) {
2040 for (ButtonExtraOpIcon &op_icon : but->extra_op_icons) {
2041 if ((op_icon.optype_params->optype == optype) && (op_icon.icon == icon)) {
2042 /* Don't add the same operator icon twice (happens if button is kept alive while active).
2043 */
2044 return;
2045 }
2046 }
2048 }
2049}
2050
2052
2053/* -------------------------------------------------------------------- */
2056
2058{
2059 if (!block->oldblock) {
2060 return;
2061 }
2062
2063 if (block->oldblock->butstore.is_empty() == false) {
2064 butstore_update(block);
2065 }
2066
2067 std::optional<int64_t> but_old_idx = block->oldblock->buttons_ptrs.is_empty() ? std::nullopt :
2068 std::optional{0};
2069 Set<const Button *> matched_old_buttons;
2070 matched_old_buttons.reserve(block->oldblock->buttons_ptrs.size());
2071 for (std::unique_ptr<Button> &but : block->buttons_ptrs) {
2072 if (but_update_from_old_block(block, matched_old_buttons, &but, &but_old_idx)) {
2073 button_update(but.get());
2074
2075 /* redraw dynamic tooltip if we have one open */
2076 if (but->tip_func) {
2077 button_tooltip_refresh(const_cast<bContext *>(C), but.get());
2078 }
2079 }
2080 }
2081 for (Button &but : block->oldblock->buttons()) {
2082 but_free(C, &but);
2083 }
2084 block->oldblock->buttons_ptrs.clear_and_shrink();
2085
2086 block->auto_open = block->oldblock->auto_open;
2087 block->auto_open_last = block->oldblock->auto_open_last;
2088 block->tooltipdisabled = block->oldblock->tooltipdisabled;
2090
2091 block->oldblock = nullptr;
2092}
2093
2094#ifndef NDEBUG
2098static void button_validate(const Button *but)
2099{
2100 /* Number buttons must have a click-step,
2101 * assert instead of correcting the value to ensure the caller knows what they're doing. */
2102 if (but->type == ButtonType::Num) {
2103 ButtonNumber *number_but = static_cast<ButtonNumber *>(const_cast<Button *>(but));
2104
2106 BLI_assert(int(number_but->step_size) > 0);
2107 }
2108 }
2109}
2110#endif
2111
2113 const Button *but,
2114 const wmOperatorCallParams *optype_params)
2115{
2116 bool result;
2117 int64_t old_but_flag = 0;
2118
2119 const bContextStore *previous_ctx = CTX_store_get(C);
2120 if (but) {
2121 old_but_flag = but->flag;
2122
2123 /* Temporarily make this button override the active one, in case the poll acts on the active
2124 * button. */
2125 const_cast<Button *>(but)->flag |= BUT_ACTIVE_OVERRIDE;
2126
2127 if (but->context) {
2128 CTX_store_set(C, but->context);
2129 }
2130 }
2131
2132 result = WM_operator_poll_context(C, optype_params->optype, optype_params->opcontext);
2133
2134 if (but) {
2135 BLI_assert_msg((but->flag & ~BUT_ACTIVE_OVERRIDE) == (old_but_flag & ~BUT_ACTIVE_OVERRIDE),
2136 "Operator polls shouldn't change button flags");
2137
2138 const_cast<Button *>(but)->flag = old_but_flag;
2139
2140 if (but->context) {
2141 CTX_store_set(C, previous_ctx);
2142 }
2143 }
2144
2145 return result;
2146}
2147
2149{
2150 const wm::OpCallContext opcontext = but ? but->opcontext : wm::OpCallContext::InvokeDefault;
2151 wmOperatorCallParams params = {};
2152 params.optype = ot;
2153 params.opcontext = opcontext;
2154 return button_context_poll_operator_ex(C, but, &params);
2155}
2156
2158{
2159 BLI_assert(region);
2160 BLI_assert(block->active);
2161 for (const std::function<void(const bContext &C, ui::Block &block)> &callback :
2163 {
2164 if (!block_is_search_only(block)) {
2165 callback(*C, *block);
2166 }
2167 }
2168 block->post_block_layout_fns_pending = false;
2169}
2170
2172 Main *bmain,
2173 wmWindow *window,
2174 Scene *scene,
2175 ARegion *region,
2176 Depsgraph *depsgraph,
2177 Block *block,
2178 const int xy[2],
2179 int r_xy[2],
2180 bool postpone_callbacks)
2181{
2182 BLI_assert(block->active);
2183
2184 /* Extend button data. This needs to be done before the block updating. */
2185 for (Button &but : block->buttons()) {
2187 }
2188
2189 block_update_from_old(C, block);
2190
2191 /* inherit flags from 'old' buttons that was drawn here previous, based
2192 * on matching buttons, we need this to make button event handling non
2193 * blocking, while still allowing buttons to be remade each redraw as it
2194 * is expected by blender code */
2195 for (Button &but : block->buttons()) {
2196 /* temp? Proper check for graying out */
2197 if (but.optype) {
2198 wmOperatorType *ot = but.optype;
2199
2200 if (ot == nullptr || !button_context_poll_operator(const_cast<bContext *>(C), ot, &but)) {
2201 but.flag |= BUT_DISABLED;
2202 }
2203 }
2204
2205 for (ButtonExtraOpIcon &op_icon : but.extra_op_icons) {
2206 if (!button_context_poll_operator_ex(const_cast<bContext *>(C), &but, op_icon.optype_params))
2207 {
2208 op_icon.disabled = true;
2209 }
2210 }
2211
2213 depsgraph, (scene) ? BKE_scene_frame_get(scene) : 0.0f);
2214 button_anim_flag(&but, &anim_eval_context);
2215 button_override_flag(bmain, &but);
2216 if (button_is_decorator(&but)) {
2218 }
2219
2220#ifndef NDEBUG
2221 button_validate(&but);
2222#endif
2223 }
2224
2225 /* handle pending stuff */
2226 if (block->layouts.first_) {
2227 block_layout_resolve(block);
2228 }
2229 block_align_calc(block, region);
2230 if ((block->flag & BLOCK_LOOP) && (block->flag & BLOCK_NUMSELECT) &&
2231 (block->flag & BLOCK_NO_ACCELERATOR_KEYS) == 0)
2232 {
2233 menu_block_set_keyaccels(block); /* could use a different flag to check */
2234 }
2235
2236 if (block->flag & (BLOCK_LOOP | BLOCK_SHOW_SHORTCUT_ALWAYS)) {
2237 menu_block_set_keymaps(C, block);
2238 }
2239
2240 /* after keymaps! */
2241 switch (block->bounds_type) {
2242 case BLOCK_BOUNDS_NONE:
2243 break;
2244 case BLOCK_BOUNDS:
2245 block_bounds_calc(block);
2246 break;
2247 case BLOCK_BOUNDS_TEXT:
2248 block_bounds_calc_text(block, 0.0f);
2249 break;
2251 if (block->handle->grab_xy_prev[0] == 0 && block->handle->grab_xy_prev[1] == 0) {
2252 block_bounds_calc_centered(window, block);
2253 }
2254 else {
2256 }
2257 break;
2260 break;
2261
2262 /* fallback */
2265 block_bounds_calc_popup(window, block, block->bounds_type, xy, r_xy);
2266 break;
2267 }
2268
2269 /* Update bounds of all views in this block. If this block is a panel, this will be done later in
2270 * #panels_end(), because buttons are offset there. */
2271 if (!block->panel) {
2272 block_views_end(region, block);
2273 }
2274
2275 if (block->rect.xmin == 0.0f && block->rect.xmax == 0.0f) {
2276 block_bounds_set_normal(block, 0);
2277 }
2278 if (block->flag & BUT_ALIGN) {
2279 block_align_end(block);
2280 }
2281
2282 update_flexible_spacing(region, block);
2283
2284 block->endblock = true;
2285 if (!postpone_callbacks) {
2286 /* Post layout callbacks are stored in region data, skip blocks created without a region (like
2287 * the `F3` search menu). */
2288 if (region) {
2289 block_post_layout_callbacks_exec(C, region, block);
2290 }
2291 }
2292 else {
2293 block->post_block_layout_fns_pending = true;
2294 }
2295}
2296
2297void block_end(const bContext *C, Block *block, bool postpone_callbacks)
2298{
2299 wmWindow *window = CTX_wm_window(C);
2300
2303 window,
2307 block,
2308 window->runtime->eventstate->xy,
2309 nullptr,
2310 postpone_callbacks);
2311}
2312
2314
2315/* -------------------------------------------------------------------- */
2318
2319void fontscale(float *points, float aspect)
2320{
2321 *points /= aspect;
2322}
2323
2324void button_to_pixelrect(rcti *rect, const ARegion *region, const Block *block, const Button *but)
2325{
2326 *rect = rect_to_pixelrect(region, block, (but) ? &but->rect : &block->rect);
2327}
2328
2329rcti rect_to_pixelrect(const ARegion *region, const Block *block, const rctf *src_rect)
2330{
2331 rctf rectf;
2332 block_to_window_rctf(region, block, &rectf, src_rect);
2333 rcti recti;
2334 BLI_rcti_rctf_copy_round(&recti, &rectf);
2335 BLI_rcti_translate(&recti, -region->winrct.xmin, -region->winrct.ymin);
2336 return recti;
2337}
2338
2339static bool but_pixelrect_in_view(const ARegion *region, const rcti *rect)
2340{
2341 rcti rect_winspace = *rect;
2342 BLI_rcti_translate(&rect_winspace, region->winrct.xmin, region->winrct.ymin);
2343 return BLI_rcti_isect(&region->winrct, &rect_winspace, nullptr);
2344}
2345
2346void block_draw(const bContext *C, Block *block)
2347{
2348 uiStyle style = *style_get_dpi(); /* XXX pass on as arg */
2349
2350 /* get menu region or area region */
2351 ARegion *region = CTX_wm_region_popup(C);
2352 if (!region) {
2353 region = CTX_wm_region(C);
2354 }
2355
2356 if (!block->endblock) {
2357 block_end(C, block);
2358 }
2359
2360 /* we set this only once */
2362
2363 /* scale fonts */
2364 fontscale(&style.paneltitle.points, block->aspect);
2365 fontscale(&style.grouplabel.points, block->aspect);
2366 fontscale(&style.widget.points, block->aspect);
2367 fontscale(&style.tooltip.points, block->aspect);
2368
2369 /* scale block min/max to rect */
2370 rcti rect;
2371 button_to_pixelrect(&rect, region, block, nullptr);
2372
2373 /* pixel space for AA widgets */
2377
2379
2380 int scissor[4];
2381 GPU_scissor_get(scissor);
2382
2383 /* back */
2384 if (block->flag & BLOCK_PIE_MENU) {
2385 draw_pie_center(block);
2386 }
2387 else if (block->flag & BLOCK_POPOVER) {
2388 draw_popover_back(region, &style, block, &rect);
2389 }
2390 else if (block->flag & BLOCK_LOOP) {
2391 draw_menu_back(&style, block, &rect);
2392 }
2393 else if (block->panel) {
2394 draw_aligned_panel(region,
2395 &style,
2396 block,
2397 &rect,
2399 panel_should_show_background(region, block->panel->type),
2401 }
2402 /* Shared layout panel backdrop style between redo region and popups. */
2403 if (block->panel && ELEM(region->regiontype, RGN_TYPE_HUD, RGN_TYPE_TEMPORARY)) {
2404 /* TODO: Add as theme color. */
2405 float subpanel_backcolor[4]{0.2f, 0.3f, 0.33f, 0.05f};
2406 const bTheme *btheme = theme::theme_get();
2407 const float aspect = block->panel->runtime->block->aspect;
2408 const float radius = btheme->tui.panel_roundness * U.widget_unit * 0.5f / aspect;
2409 draw_layout_panels_backdrop(region, block->panel, radius, subpanel_backcolor);
2410 }
2411
2414
2415 if (block->flag & (BLOCK_CLIPTOP | BLOCK_CLIPBOTTOM)) {
2416 const int arrow_size = UI_MENU_SCROLL_MOUSE / block->aspect;
2417 const int ymax = rect.ymax - ((block->flag & BLOCK_CLIPTOP) ? arrow_size : 0.0f);
2418 const int ymin = rect.ymin + ((block->flag & BLOCK_CLIPBOTTOM) ? arrow_size : 0.0f);
2419 GPU_scissor(rect.xmin, ymin, BLI_rcti_size_x(&rect), ymax - ymin);
2420 }
2421 /* widgets */
2422 for (Button &but : block->buttons()) {
2423 if (but.flag & (UI_HIDDEN | UI_SCROLLED)) {
2424 continue;
2425 }
2426
2427 button_to_pixelrect(&rect, region, block, &but);
2428 /* Optimization: Don't draw buttons that are not visible (outside view bounds). */
2429 if (!but_pixelrect_in_view(region, &rect)) {
2430 continue;
2431 }
2432
2433 /* Don't draw buttons that are wider than enclosing panel. #150173 */
2434 if (block->panel && block->panel->sizex > 0) {
2435 int panel_width = int(ceil(float(block->panel->sizex) / block->aspect));
2436 if (panel_should_show_background(region, block->panel->type)) {
2437 panel_width -= int(floor(UI_PANEL_MARGIN_X / block->aspect * 2.0f));
2438 }
2439 if (BLI_rcti_size_x(&rect) > int(float(panel_width) * 1.2f)) {
2440 continue;
2441 }
2442 }
2443
2444 /* XXX: figure out why invalid coordinates happen when closing render window */
2445 /* and material preview is redrawn in main window (temp fix for bug #23848) */
2446 if (rect.xmin < rect.xmax && rect.ymin < rect.ymax) {
2447 draw_button(C, region, &style, &but, &rect);
2448 }
2449 }
2450
2453 block_views_draw_overlays(region, block);
2454 GPU_scissor(scissor[0], scissor[1], scissor[2], scissor[3]);
2455
2456 /* restore matrix */
2459}
2460
2462
2463/* -------------------------------------------------------------------- */
2466
2467static void block_message_subscribe(ARegion *region, wmMsgBus *mbus, Block *block)
2468{
2469 Button *but_prev = nullptr;
2470 /* possibly we should keep the region this block is contained in? */
2471 for (Button &but : block->buttons()) {
2472 if (but.rnapoin.type && but.rnaprop) {
2473 /* quick check to avoid adding buttons representing a vector, multiple times. */
2474 if ((but_prev && (but_prev->rnaprop == but.rnaprop) &&
2475 (but_prev->rnapoin.type == but.rnapoin.type) &&
2476 (but_prev->rnapoin.data == but.rnapoin.data) &&
2477 (but_prev->rnapoin.owner_id == but.rnapoin.owner_id)) == false)
2478 {
2479 /* TODO: could make this into utility function. */
2480 wmMsgSubscribeValue value = {};
2481 value.owner = region;
2482 value.user_data = region;
2484 WM_msg_subscribe_rna(mbus, &but.rnapoin, but.rnaprop, &value, __func__);
2485 but_prev = &but;
2486 }
2487 }
2488 }
2489}
2490
2492{
2493 for (Block &block : region->runtime->uiblocks) {
2494 block_message_subscribe(region, mbus, &block);
2495 }
2496}
2497
2499
2500/* -------------------------------------------------------------------- */
2503
2504int button_is_pushed_ex(Button *but, double *value)
2505{
2506 int is_push = 0;
2507 if (but->pushed_state_func) {
2508 return but->pushed_state_func(*but);
2509 }
2510
2511 if (but->bit) {
2512 const bool state = !ELEM(
2514 int lvalue;
2515 UI_GET_BUT_VALUE_INIT(but, *value);
2516 lvalue = int(*value);
2517 if (UI_BITBUT_TEST(lvalue, (but->bitnr))) {
2518 is_push = state;
2519 }
2520 else {
2521 is_push = !state;
2522 }
2523 }
2524 else {
2525 switch (but->type) {
2526 case ButtonType::But:
2529 case ButtonType::Color:
2531 is_push = -1;
2532 break;
2534 case ButtonType::Toggle:
2537 UI_GET_BUT_VALUE_INIT(but, *value);
2538 if (*value != double(but->hardmin)) {
2539 is_push = true;
2540 }
2541 break;
2545 UI_GET_BUT_VALUE_INIT(but, *value);
2546 if (*value == 0.0) {
2547 is_push = true;
2548 }
2549 break;
2550 case ButtonType::Row:
2552 case ButtonType::Tab:
2553 if ((but->type == ButtonType::Tab) && but->rnaprop && but->custom_data) {
2554 /* Button.custom_data points to data this tab represents (e.g. workspace).
2555 * Button.rnapoin/prop store an active value (e.g. active workspace). */
2556 if (RNA_property_type(but->rnaprop) == PROP_POINTER) {
2557 const PointerRNA active_ptr = RNA_property_pointer_get(&but->rnapoin, but->rnaprop);
2558 if (active_ptr.data == but->custom_data) {
2559 is_push = true;
2560 }
2561 }
2562 break;
2563 }
2564 else if (but->optype) {
2565 break;
2566 }
2567
2568 UI_GET_BUT_VALUE_INIT(but, *value);
2569 /* support for rna enum buts */
2570 if (but->rnaprop && (RNA_property_flag(but->rnaprop) & PROP_ENUM_FLAG)) {
2571 if (int(*value) & int(but->hardmax)) {
2572 is_push = true;
2573 }
2574 }
2575 else {
2576 if (*value == double(but->hardmax)) {
2577 is_push = true;
2578 }
2579 }
2580 break;
2581 case ButtonType::ViewItem: {
2582 const auto *view_item_but = static_cast<const ButtonViewItem *>(but);
2583
2584 is_push = -1;
2585 if (view_item_but->view_item) {
2586 is_push = view_item_but->view_item->is_active();
2587 }
2588 break;
2589 }
2590 default:
2591 is_push = -1;
2592 break;
2593 }
2594 }
2595
2596 if ((but->drawflag & BUT_CHECKBOX_INVERT) && (is_push != -1)) {
2597 is_push = !bool(is_push);
2598 }
2599 return is_push;
2600}
2602{
2603 double value = BUT_VALUE_UNSET;
2604 return button_is_pushed_ex(but, &value);
2605}
2606
2607static void but_update_select_flag(Button *but, double *value)
2608{
2609 switch (button_is_pushed_ex(but, value)) {
2610 case true:
2611 but->flag |= UI_SELECT;
2612 break;
2613 case false:
2614 but->flag &= ~UI_SELECT;
2615 break;
2616 }
2617}
2618
2620
2621/* -------------------------------------------------------------------- */
2624
2625void block_lock_set(Block *block, bool val, const char *lockstr)
2626{
2627 if (val) {
2628 block->lock = val;
2629 block->lockstr = lockstr;
2630 }
2631}
2632
2634{
2635 block->lock = false;
2636 block->lockstr = nullptr;
2637}
2638
2640
2641/* -------------------------------------------------------------------- */
2647
2648void button_v3_get(Button *but, float vec[3])
2649{
2650 if (but->editvec) {
2651 copy_v3_v3(vec, but->editvec);
2652 }
2653
2654 if (but->rnaprop) {
2655 PropertyRNA *prop = but->rnaprop;
2656
2657 zero_v3(vec);
2658
2659 if (RNA_property_type(prop) == PROP_FLOAT) {
2661 RNA_property_float_get_array_at_most(&but->rnapoin, prop, vec, 3);
2662 }
2663 }
2664 else if (but->pointype == ButPointerType::Char) {
2665 const char *cp = but->poin;
2666 vec[0] = float(cp[0]) / 255.0f;
2667 vec[1] = float(cp[1]) / 255.0f;
2668 vec[2] = float(cp[2]) / 255.0f;
2669 }
2670 else if (but->pointype == ButPointerType::Float) {
2671 const float *fp = reinterpret_cast<float *>(but->poin);
2672 copy_v3_v3(vec, fp);
2673 }
2674 else {
2675 if (but->editvec == nullptr) {
2676 CLOG_WARN(&LOG, "%s: cannot get color, should never happen", __func__);
2677 zero_v3(vec);
2678 }
2679 }
2680
2681 if (but->type == ButtonType::Unitvec) {
2682 normalize_v3(vec);
2683 }
2684}
2685
2686void button_v3_set(Button *but, const float vec[3])
2687{
2688 if (but->editvec) {
2689 copy_v3_v3(but->editvec, vec);
2690 }
2691
2692 if (but->rnaprop) {
2693 PropertyRNA *prop = but->rnaprop;
2694
2695 if (RNA_property_type(prop) == PROP_FLOAT) {
2697 RNA_property_float_set_array_at_most(&but->rnapoin, prop, vec, 3);
2698 }
2699 }
2700 else if (but->pointype == ButPointerType::Char) {
2701 char *cp = but->poin;
2702 cp[0] = char(lround(vec[0] * 255.0f));
2703 cp[1] = char(lround(vec[1] * 255.0f));
2704 cp[2] = char(lround(vec[2] * 255.0f));
2705 }
2706 else if (but->pointype == ButPointerType::Float) {
2707 float *fp = reinterpret_cast<float *>(but->poin);
2708 copy_v3_v3(fp, vec);
2709 }
2710}
2711
2712void button_v4_get(Button *but, float vec[4])
2713{
2714 if (but->editvec) {
2715 copy_v4_v4(vec, but->editvec);
2716 }
2717
2718 if (but->rnaprop) {
2719 PropertyRNA *prop = but->rnaprop;
2720
2721 zero_v4(vec);
2722
2723 if (RNA_property_type(prop) == PROP_FLOAT) {
2725 RNA_property_float_get_array_at_most(&but->rnapoin, prop, vec, 4);
2726 }
2727 }
2728 else if (but->pointype == ButPointerType::Char) {
2729 const char *cp = but->poin;
2730 vec[0] = float(cp[0]) / 255.0f;
2731 vec[1] = float(cp[1]) / 255.0f;
2732 vec[2] = float(cp[2]) / 255.0f;
2733 vec[3] = float(cp[3]) / 255.0f;
2734 }
2735 else if (but->pointype == ButPointerType::Float) {
2736 const float *fp = reinterpret_cast<float *>(but->poin);
2737 copy_v4_v4(vec, fp);
2738 }
2739 else {
2740 if (but->editvec == nullptr) {
2741 CLOG_WARN(&LOG, "%s: can't get color, should never happen", __func__);
2742 zero_v4(vec);
2743 }
2744 }
2745}
2746
2747void button_v4_set(Button *but, const float vec[4])
2748{
2749 if (but->editvec) {
2750 copy_v4_v4(but->editvec, vec);
2751 }
2752
2753 if (but->rnaprop) {
2754 PropertyRNA *prop = but->rnaprop;
2755
2756 if (RNA_property_type(prop) == PROP_FLOAT) {
2758 RNA_property_float_set_array_at_most(&but->rnapoin, prop, vec, 4);
2759 }
2760 }
2761 else if (but->pointype == ButPointerType::Char) {
2762 char *cp = but->poin;
2763 cp[0] = char(lround(vec[0] * 255.0f));
2764 cp[1] = char(lround(vec[1] * 255.0f));
2765 cp[2] = char(lround(vec[2] * 255.0f));
2766 cp[3] = char(lround(vec[3] * 255.0f));
2767 }
2768 else if (but->pointype == ButPointerType::Float) {
2769 float *fp = reinterpret_cast<float *>(but->poin);
2770 copy_v4_v4(fp, vec);
2771 }
2772}
2773
2774bool button_is_float(const Button *but)
2775{
2776 if (but->pointype == ButPointerType::Float && but->poin) {
2777 return true;
2778 }
2779
2780 if (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_FLOAT) {
2781 return true;
2782 }
2783
2784 return false;
2785}
2786
2788{
2789 if (but->rnaprop) {
2790 return RNA_property_ui_scale(but->rnaprop);
2791 }
2792 return PROP_SCALE_LINEAR;
2793}
2794
2795bool button_is_bool(const Button *but)
2796{
2797 if (ELEM(but->type,
2806 {
2807 return true;
2808 }
2809
2810 if (but->rnaprop && RNA_property_type(but->rnaprop) == PROP_BOOLEAN) {
2811 return true;
2812 }
2813
2814 if ((but->rnaprop && RNA_property_type(but->rnaprop) == PROP_ENUM) &&
2815 (but->type == ButtonType::Row))
2816 {
2817 return true;
2818 }
2819
2820 return false;
2821}
2822
2823bool button_is_unit(const Button *but)
2824{
2825 const UnitSettings *unit = but->block->unit;
2826 const int unit_type = button_unit_type_get(but);
2827
2828 if (unit_type == PROP_UNIT_NONE) {
2829 return false;
2830 }
2831
2832#if 1 /* removed so angle buttons get correct snapping */
2833 if (but_is_unit_radians_ex(unit, unit_type)) {
2834 return false;
2835 }
2836#endif
2837
2838 /* for now disable time unit conversion */
2839 if (unit_type == PROP_UNIT_TIME) {
2840 return false;
2841 }
2842
2843 if (unit->system == USER_UNIT_NONE) {
2844 /* These types have units irrespective of scene units. */
2846 return false;
2847 }
2848 }
2849
2850 return true;
2851}
2852
2853bool button_is_compatible(const Button *but_a, const Button *but_b)
2854{
2855 if (but_a->type != but_b->type) {
2856 return false;
2857 }
2858 if (but_a->pointype != but_b->pointype) {
2859 return false;
2860 }
2861
2862 if (but_a->rnaprop) {
2863 if (RNA_property_type(but_a->rnaprop) != RNA_property_type(but_b->rnaprop)) {
2864 return false;
2865 }
2867 return false;
2868 }
2869 }
2870
2871 return true;
2872}
2873
2875{
2876 if (but->rnaprop == nullptr || RNA_struct_contains_property(&but->rnapoin, but->rnaprop)) {
2877 return true;
2878 }
2879 printf("property removed %s: %p\n", but->drawstr.c_str(), but->rnaprop);
2880 return false;
2881}
2882
2884{
2885 return (ELEM(but->type,
2890 (but->type == ButtonType::Menu && button_menu_step_poll(but)) ||
2891 (but->type == ButtonType::Color &&
2892 (static_cast<ButtonColor *>(const_cast<Button *>(but)))->is_palette_color) ||
2893 (but->menu_step_func != nullptr));
2894}
2895
2897{
2898 double value = 0.0;
2899
2900 if (but->editval) {
2901 return *(but->editval);
2902 }
2903 if (but->poin == nullptr && !but->rnapoin) {
2904 return 0.0;
2905 }
2906
2907 if (but->rnaprop) {
2908 PropertyRNA *prop = but->rnaprop;
2909
2910 BLI_assert(but->rnaindex != -1);
2911
2912 switch (RNA_property_type(prop)) {
2913 case PROP_BOOLEAN:
2914 if (RNA_property_array_check(prop)) {
2915 value = double(RNA_property_boolean_get_index(&but->rnapoin, prop, but->rnaindex));
2916 }
2917 else {
2918 value = double(RNA_property_boolean_get(&but->rnapoin, prop));
2919 }
2920 break;
2921 case PROP_INT:
2922 if (RNA_property_array_check(prop)) {
2923 value = RNA_property_int_get_index(&but->rnapoin, prop, but->rnaindex);
2924 }
2925 else {
2926 value = RNA_property_int_get(&but->rnapoin, prop);
2927 }
2928 break;
2929 case PROP_FLOAT:
2930 if (RNA_property_array_check(prop)) {
2931 value = RNA_property_float_get_index(&but->rnapoin, prop, but->rnaindex);
2932 }
2933 else {
2934 value = RNA_property_float_get(&but->rnapoin, prop);
2935 }
2936 break;
2937 case PROP_ENUM:
2938 value = RNA_property_enum_get(&but->rnapoin, prop);
2939 break;
2940 default:
2941 value = 0.0;
2942 break;
2943 }
2944 }
2945 else if (but->pointype == ButPointerType::Char) {
2946 value = *static_cast<char *>(but->poin);
2947 }
2948 else if (but->pointype == ButPointerType::Short) {
2949 value = *reinterpret_cast<short *>(but->poin);
2950 }
2951 else if (but->pointype == ButPointerType::Int) {
2952 value = *reinterpret_cast<int *>(but->poin);
2953 }
2954 else if (but->pointype == ButPointerType::Float) {
2955 value = *reinterpret_cast<float *>(but->poin);
2956 }
2957
2958 return value;
2959}
2960
2961void button_value_set(Button *but, double value)
2962{
2963 /* Value is a HSV value: convert to RGB. */
2964 if (but->rnaprop) {
2965 PropertyRNA *prop = but->rnaprop;
2966
2967 if (RNA_property_editable(&but->rnapoin, prop)) {
2968 switch (RNA_property_type(prop)) {
2969 case PROP_BOOLEAN:
2970 if (RNA_property_array_check(prop)) {
2971 RNA_property_boolean_set_index(&but->rnapoin, prop, but->rnaindex, value);
2972 }
2973 else {
2974 RNA_property_boolean_set(&but->rnapoin, prop, value);
2975 }
2976 break;
2977 case PROP_INT:
2978 if (RNA_property_array_check(prop)) {
2979 RNA_property_int_set_index(&but->rnapoin, prop, but->rnaindex, int(value));
2980 }
2981 else {
2982 RNA_property_int_set(&but->rnapoin, prop, int(value));
2983 }
2984 break;
2985 case PROP_FLOAT:
2986 if (RNA_property_array_check(prop)) {
2987 RNA_property_float_set_index(&but->rnapoin, prop, but->rnaindex, value);
2988 }
2989 else {
2990 RNA_property_float_set(&but->rnapoin, prop, value);
2991 }
2992 break;
2993 case PROP_ENUM:
2994 if (RNA_property_flag(prop) & PROP_ENUM_FLAG) {
2995 int ivalue = int(value);
2996 /* toggle for enum/flag buttons */
2997 ivalue ^= RNA_property_enum_get(&but->rnapoin, prop);
2998 RNA_property_enum_set(&but->rnapoin, prop, ivalue);
2999 }
3000 else {
3001 RNA_property_enum_set(&but->rnapoin, prop, value);
3002 }
3003 break;
3004 default:
3005 break;
3006 }
3007 }
3008
3009 /* we can't be sure what RNA set functions actually do,
3010 * so leave this unset */
3011 value = BUT_VALUE_UNSET;
3012 }
3013 else if (!bool(but->pointype)) {
3014 /* pass */
3015 }
3016 else {
3017 /* first do rounding */
3018 if (but->pointype == ButPointerType::Char) {
3019 value = round_db_to_uchar_clamp(value);
3020 }
3021 else if (but->pointype == ButPointerType::Short) {
3022 value = round_db_to_short_clamp(value);
3023 }
3024 else if (but->pointype == ButPointerType::Int) {
3025 value = round_db_to_int_clamp(value);
3026 }
3027 else if (but->pointype == ButPointerType::Float) {
3028 float fval = float(value);
3029 if (fval >= -0.00001f && fval <= 0.00001f) {
3030 /* prevent negative zero */
3031 fval = 0.0f;
3032 }
3033 value = fval;
3034 }
3035
3036 /* then set value with possible edit override */
3037 if (but->editval) {
3038 value = *but->editval = value;
3039 }
3040 else if (but->pointype == ButPointerType::Char) {
3041 value = *(static_cast<char *>(but->poin)) = char(value);
3042 }
3043 else if (but->pointype == ButPointerType::Short) {
3044 value = *(reinterpret_cast<short *>(but->poin)) = short(value);
3045 }
3046 else if (but->pointype == ButPointerType::Int) {
3047 value = *(reinterpret_cast<int *>(but->poin)) = int(value);
3048 }
3049 else if (but->pointype == ButPointerType::Float) {
3050 value = *(reinterpret_cast<float *>(but->poin)) = float(value);
3051 }
3052 }
3053
3054 but_update_select_flag(but, &value);
3055}
3056
3058{
3060 return but->hardmax;
3061 }
3062 return UI_MAX_DRAW_STR;
3063}
3064
3066{
3067 Button *return_but = nullptr;
3068
3070
3071 for (Button &but_iter : but->block->buttons()) {
3072 if (but_iter.editstr) {
3073 return_but = &but_iter;
3074 break;
3075 }
3076 }
3077
3078 return return_but;
3079}
3080
3081static double get_but_scale_unit(Button *but, double value)
3082{
3083 const UnitSettings *unit = but->block->unit;
3084 const int unit_type = button_unit_type_get(but);
3085
3086 /* Time unit is a bit special, not handled by #BKE_unit_value_scale() for now. */
3087 if (unit_type == PROP_UNIT_TIME) { /* WARNING: using evil_C :| */
3088 Scene *scene = CTX_data_scene(static_cast<const bContext *>(but->block->evil_C));
3089 return FRA2TIME(value);
3090 }
3091 return BKE_unit_value_scale(*unit, RNA_SUBTYPE_UNIT_VALUE(unit_type), value);
3092}
3093
3094void button_convert_to_unit_alt_name(Button *but, char *str, size_t str_maxncpy)
3095{
3096 if (!button_is_unit(but)) {
3097 return;
3098 }
3099
3100 const UnitSettings *unit = but->block->unit;
3101 const int unit_type = button_unit_type_get(but);
3102 char *orig_str;
3103
3104 orig_str = BLI_strdup(str);
3105
3107 str, str_maxncpy, orig_str, unit->system, RNA_SUBTYPE_UNIT_VALUE(unit_type));
3108
3109 MEM_delete(orig_str);
3110}
3111
3116 char *str,
3117 int str_maxncpy,
3118 double value,
3119 bool pad,
3120 int float_precision,
3121 bool do_suffix)
3122{
3123 const UnitSettings *unit = but->block->unit;
3124 const int unit_type = RNA_SUBTYPE_UNIT_VALUE(button_unit_type_get(but));
3125 int precision;
3126
3127 BLI_assert(unit->scale_length > 0.0f);
3128
3129 /* Use precision override? */
3130 if (float_precision == -1) {
3131 /* Sanity checks */
3132 precision = int(but_get_float_precision(but));
3133 if (precision > UI_PRECISION_FLOAT_MAX) {
3134 precision = UI_PRECISION_FLOAT_MAX;
3135 }
3136 else if (precision == -1) {
3137 precision = 2;
3138 }
3139 }
3140 else {
3141 precision = float_precision;
3142 }
3143
3145 str_maxncpy,
3146 get_but_scale_unit(but, value),
3147 precision,
3148 unit_type,
3149 *unit,
3150 pad,
3151 do_suffix);
3152}
3153
3154static float get_but_step_unit(Button *but, float step_default)
3155{
3156 const int unit_type = RNA_SUBTYPE_UNIT_VALUE(button_unit_type_get(but));
3157 const double step_orig = double(step_default) * double(UI_PRECISION_FLOAT_SCALE);
3158 /* Scaling up 'step_orig ' here is a bit arbitrary,
3159 * its just giving better scales from user POV */
3160 const double scale_step = get_but_scale_unit(but, step_orig * 10);
3161 const double step = BKE_unit_closest_scalar(scale_step, but->block->unit->system, unit_type);
3162
3163 /* -1 is an error value */
3164 if (step == -1.0f) {
3165 return step_default;
3166 }
3167
3168 const double scale_unit = get_but_scale_unit(but, 1.0);
3169 const double step_unit = BKE_unit_closest_scalar(
3170 scale_unit, but->block->unit->system, unit_type);
3171 double step_final;
3172
3173 BLI_assert(step > 0.0);
3174
3175 step_final = (step / scale_unit) / double(UI_PRECISION_FLOAT_SCALE);
3176
3177 if (step == step_unit) {
3178 /* Logic here is to scale by the original 'step_orig'
3179 * only when the unit step matches the scaled step.
3180 *
3181 * This is needed for units that don't have a wide range of scales (degrees for eg.).
3182 * Without this we can't select between a single degree, or a 10th of a degree.
3183 */
3184 step_final *= step_orig;
3185 }
3186
3187 return float(step_final);
3188}
3189
3190static std::string textbox_string_get(ButtonTextBox *textbox)
3191{
3192 BLI_assert(textbox->rnaprop);
3194 return RNA_property_string_get(&textbox->rnapoin, textbox->rnaprop);
3195}
3196
3201{
3202 const int unit_type = RNA_SUBTYPE_UNIT_VALUE(button_unit_type_get(button));
3203 if (BKE_unit_is_adaptive(*button->block->unit, unit_type)) {
3204 /* Include the unit in the edit string when the unit is adaptive. */
3205 return true;
3206 }
3207 PropertySubType subtype = PROP_NONE;
3208 if (button->rnaprop) {
3209 subtype = RNA_property_subtype(button->rnaprop);
3210 }
3211 if (subtype == PROP_TIME_ABSOLUTE) {
3212 /* Include the unit in the edit string when the property uses absolute time (independent of the
3213 * scene settings). */
3214 return true;
3215 }
3216 return false;
3217}
3218
3220 char *str,
3221 const size_t str_maxncpy,
3222 const int float_precision,
3223 const bool use_exp_float,
3224 bool *r_use_exp_float)
3225{
3226 if (r_use_exp_float) {
3227 *r_use_exp_float = false;
3228 }
3229
3231 const PropertyType type = RNA_property_type(but->rnaprop);
3232
3233 int buf_len;
3234 const char *buf = nullptr;
3235 if ((but->type == ButtonType::Tab) && (but->custom_data)) {
3237
3238 /* Button.custom_data points to data this tab represents (e.g. workspace).
3239 * Button.rnapoin/prop store an active value (e.g. active workspace). */
3241 but->rnapoin.owner_id, ptr_type, but->custom_data);
3242 buf = RNA_struct_name_get_alloc(&ptr, str, str_maxncpy, &buf_len);
3243 }
3244 else if (type == PROP_STRING) {
3245 /* RNA string */
3246 buf = RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, str_maxncpy, &buf_len);
3247 }
3248 else if (type == PROP_ENUM) {
3249 /* RNA enum */
3250 const int value = RNA_property_enum_get(&but->rnapoin, but->rnaprop);
3251 if (RNA_property_enum_name(static_cast<bContext *>(but->block->evil_C),
3252 &but->rnapoin,
3253 but->rnaprop,
3254 value,
3255 &buf))
3256 {
3257 BLI_strncpy(str, buf, str_maxncpy);
3258 buf = str;
3259 }
3260 }
3261 else if (type == PROP_POINTER) {
3262 /* RNA pointer */
3264 buf = RNA_struct_name_get_alloc(&ptr, str, str_maxncpy, &buf_len);
3265 }
3266 else {
3267 BLI_assert(0);
3268 }
3269
3270 if (buf == nullptr) {
3271 str[0] = '\0';
3272 }
3273 else if (buf != str) {
3274 BLI_assert(str_maxncpy <= buf_len + 1);
3275 /* string was too long, we have to truncate */
3276 if (but_is_utf8(but)) {
3277 BLI_strncpy_utf8(str, buf, str_maxncpy);
3278 }
3279 else {
3280 BLI_strncpy(str, buf, str_maxncpy);
3281 }
3282 MEM_delete(buf);
3283 }
3284 }
3285 else if (but->rnaprop && but->type == ButtonType::TextBox) {
3287 std::string buf = RNA_property_string_get(&but->rnapoin, but->rnaprop);
3288 BLI_strncpy_utf8(str, buf.data(), str_maxncpy);
3289 }
3291 /* string */
3292 if (but_is_utf8(but)) {
3293 BLI_strncpy_utf8(str, but->poin, str_maxncpy);
3294 }
3295 else {
3296 BLI_strncpy(str, but->poin, str_maxncpy);
3297 }
3298 return;
3299 }
3300 else if (button_anim_expression_get(but, str, str_maxncpy)) {
3301 /* driver expression */
3302 }
3303 else {
3304 /* number editing */
3305 const double value = button_value_get(but);
3306
3307 PropertySubType subtype = PROP_NONE;
3308 if (but->rnaprop) {
3309 subtype = RNA_property_subtype(but->rnaprop);
3310 }
3311
3312 if (button_is_float(but)) {
3313 int prec = float_precision;
3314
3315 if (float_precision == -1) {
3316 prec = but_calc_float_precision(but, value);
3317 }
3318 else if (!use_exp_float && but_hide_fraction(but, value)) {
3319 prec = 0;
3320 }
3321
3322 if (button_is_unit(but)) {
3323 const bool include_unit_suffix = button_edit_string_include_unit_suffix(but);
3324 get_but_string_unit(but, str, str_maxncpy, value, false, prec, include_unit_suffix);
3325 }
3326 else if (subtype == PROP_FACTOR) {
3327 if (U.factor_display_type == USER_FACTOR_AS_FACTOR) {
3328 BLI_snprintf_utf8(str, str_maxncpy, "%.*f", prec, value);
3329 }
3330 else {
3331 BLI_snprintf_utf8(str, str_maxncpy, "%.*f", std::max(0, prec - 2), value * 100);
3332 }
3333 }
3334 else {
3335 const int int_digits_num = integer_digits_f(value);
3336 if (use_exp_float) {
3337 if (int_digits_num < -6 || int_digits_num > 12) {
3338 BLI_snprintf_utf8(str, str_maxncpy, "%.*g", prec, value);
3339 if (r_use_exp_float) {
3340 *r_use_exp_float = true;
3341 }
3342 }
3343 else {
3344 prec -= int_digits_num;
3345 CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX);
3346 BLI_snprintf_utf8(str, str_maxncpy, "%.*f", prec, value);
3347 }
3348 }
3349 else {
3350 prec -= int_digits_num;
3351 CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX);
3352 BLI_snprintf_utf8(str, str_maxncpy, "%.*f", prec, value);
3353 }
3354 }
3355 }
3356 else {
3357 BLI_snprintf_utf8(str, str_maxncpy, "%d", int(value));
3358 }
3359 }
3360}
3361void button_string_get(Button *but, char *str, const size_t str_maxncpy)
3362{
3363 button_string_get_ex(but, str, str_maxncpy, -1, false, nullptr);
3364}
3365
3366char *button_string_get_dynamic(Button *but, int *r_str_size)
3367{
3368 char *str = nullptr;
3369 *r_str_size = 1;
3370
3372 const PropertyType type = RNA_property_type(but->rnaprop);
3373
3374 if (type == PROP_STRING) {
3375 /* RNA string */
3376 str = RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, nullptr, 0, r_str_size);
3377 (*r_str_size) += 1;
3378 }
3379 else if (type == PROP_ENUM) {
3380 /* RNA enum */
3381 const int value = RNA_property_enum_get(&but->rnapoin, but->rnaprop);
3382 const char *value_id;
3383 if (!RNA_property_enum_name(static_cast<bContext *>(but->block->evil_C),
3384 &but->rnapoin,
3385 but->rnaprop,
3386 value,
3387 &value_id))
3388 {
3389 value_id = "";
3390 }
3391
3392 *r_str_size = strlen(value_id) + 1;
3393 str = BLI_strdupn(value_id, *r_str_size);
3394 }
3395 else if (type == PROP_POINTER) {
3396 /* RNA pointer */
3398 str = RNA_struct_name_get_alloc(&ptr, nullptr, 0, r_str_size);
3399 (*r_str_size) += 1;
3400 }
3401 else {
3402 BLI_assert(0);
3403 }
3404 }
3405 else if (but->rnaprop && but->type == ButtonType::TextBox) {
3407 str = RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, nullptr, 0, r_str_size);
3408 *r_str_size += 1;
3409 }
3410 else {
3411 BLI_assert(0);
3412 }
3413
3414 if (str == nullptr) [[unlikely]] {
3415 /* should never happen, paranoid check */
3416 *r_str_size = 1;
3417 str = BLI_strdup("");
3418 BLI_assert(0);
3419 }
3420
3421 return str;
3422}
3423
3428#define UI_NUMBER_EVAL_ERROR_PREFIX RPT_("Error evaluating number, see Info editor for details")
3429
3431 bContext *C, const char *str, const int unit_type, const UnitSettings *unit, double *r_value)
3432{
3433 char *error = nullptr;
3434 const bool ok = user_string_to_number(C, str, *unit, unit_type, r_value, nullptr, true, &error);
3435 if (error) {
3436 ReportList *reports = CTX_wm_reports(C);
3437 BKE_reportf(reports, RPT_ERROR, "%s: %s", UI_NUMBER_EVAL_ERROR_PREFIX, error);
3438 MEM_delete(error);
3439 }
3440 return ok;
3441}
3442
3444 const char *str,
3445 const Button *but,
3446 double *r_value)
3447{
3448 const int unit_type = RNA_SUBTYPE_UNIT_VALUE(button_unit_type_get(but));
3449 const UnitSettings *unit = but->block->unit;
3450 return number_from_string_units(C, str, unit_type, unit, r_value);
3451}
3452
3453static bool number_from_string(bContext *C, const char *str, double *r_value)
3454{
3455 bool ok;
3456#ifdef WITH_PYTHON
3457 BPy_RunErrInfo err_info = {};
3458 err_info.reports = CTX_wm_reports(C);
3460 ok = BPY_run_string_as_number(C, nullptr, str, &err_info, r_value);
3461#else
3462 UNUSED_VARS(C);
3463 *r_value = atof(str);
3464 ok = true;
3465#endif
3466 return ok;
3467}
3468
3469static bool number_from_string_factor(bContext *C, const char *str, double *r_value)
3470{
3471 const int len = strlen(str);
3472 if (BLI_strn_endswith(str, "%", len)) {
3473 char *str_new = BLI_strdupn(str, len - 1);
3474 const bool success = number_from_string(C, str_new, r_value);
3475 MEM_delete(str_new);
3476 *r_value /= 100.0;
3477 return success;
3478 }
3479 if (!number_from_string(C, str, r_value)) {
3480 return false;
3481 }
3482 if (U.factor_display_type == USER_FACTOR_AS_PERCENTAGE) {
3483 *r_value /= 100.0;
3484 }
3485 return true;
3486}
3487
3488static bool number_from_string_percentage(bContext *C, const char *str, double *r_value)
3489{
3490 const int len = strlen(str);
3491 if (BLI_strn_endswith(str, "%", len)) {
3492 char *str_new = BLI_strdupn(str, len - 1);
3493 const bool success = number_from_string(C, str_new, r_value);
3494 MEM_delete(str_new);
3495 return success;
3496 }
3497 return number_from_string(C, str, r_value);
3498}
3499
3500bool button_string_eval_number(bContext *C, const Button *but, const char *str, double *r_value)
3501{
3502 if (str[0] == '\0') {
3503 *r_value = 0.0;
3504 return true;
3505 }
3506
3507 PropertySubType subtype = PROP_NONE;
3508 if (but->rnaprop) {
3509 subtype = RNA_property_subtype(but->rnaprop);
3510 }
3511
3512 if (button_is_float(but)) {
3513 if (button_is_unit(but)) {
3514 return number_from_string_units_with_but(C, str, but, r_value);
3515 }
3516 if (subtype == PROP_FACTOR) {
3517 return number_from_string_factor(C, str, r_value);
3518 }
3519 if (subtype == PROP_PERCENTAGE) {
3520 return number_from_string_percentage(C, str, r_value);
3521 }
3522 return number_from_string(C, str, r_value);
3523 }
3524 return number_from_string(C, str, r_value);
3525}
3526
3527bool button_string_set(bContext *C, Button *but, const char *str)
3528{
3529 if (but->rnaprop && but->rnapoin &&
3531 {
3532 if (RNA_property_editable(&but->rnapoin, but->rnaprop)) {
3533 const PropertyType type = RNA_property_type(but->rnaprop);
3534
3535 if (type == PROP_STRING) {
3536 /* RNA string, only set it if full rename callback is not defined, otherwise just store the
3537 * user-defined new name to call the callback later. */
3538 ButtonText *text_button = but->type == ButtonType::Text ? static_cast<ButtonText *>(but) :
3539 nullptr;
3540 if (text_button && text_button->rename_full_func) {
3541 text_button->rename_full_new = str;
3542 }
3543 else {
3545 }
3546 return true;
3547 }
3548
3549 if (type == PROP_POINTER) {
3550 if (str[0] == '\0') {
3551 RNA_property_pointer_set(&but->rnapoin, but->rnaprop, {}, nullptr);
3552 return true;
3553 }
3554
3555 ButtonSearch *search_but = (but->type == ButtonType::SearchMenu) ?
3556 static_cast<ButtonSearch *>(but) :
3557 nullptr;
3558 /* RNA pointer */
3559 PointerRNA rptr;
3560
3561 /* This is kind of hackish, in theory think we could only ever use the second member of
3562 * this if/else, since #searchbox_apply() is supposed to always set that pointer when
3563 * we are storing pointers... But keeping str search first for now,
3564 * to try to break as little as possible existing code. All this is band-aids anyway.
3565 * Fact remains, using `editstr` as main 'reference' over whole search button thingy
3566 * is utterly weak and should be redesigned IMHO, but that's not a simple task. */
3567 if (search_but && search_but->rnasearchprop &&
3569 &search_but->rnasearchpoin, search_but->rnasearchprop, str, &rptr))
3570 {
3571 RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr, nullptr);
3572 }
3573 else if (search_but && search_but->item_active != nullptr) {
3575 nullptr,
3577 search_but->item_active);
3578 RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr, nullptr);
3579 }
3580
3581 return true;
3582 }
3583
3584 if (type == PROP_ENUM) {
3585 int value;
3586 if (RNA_property_enum_value(static_cast<bContext *>(but->block->evil_C),
3587 &but->rnapoin,
3588 but->rnaprop,
3589 str,
3590 &value))
3591 {
3592 RNA_property_enum_set(&but->rnapoin, but->rnaprop, value);
3593 return true;
3594 }
3595 return false;
3596 }
3597 BLI_assert(0);
3598 }
3599 }
3600 else if (but->type == ButtonType::Tab) {
3601 if (but->rnaprop && but->custom_data) {
3603 PropertyRNA *prop;
3604
3605 /* Button.custom_data points to data this tab represents (e.g. workspace).
3606 * Button.rnapoin/prop store an active value (e.g. active workspace). */
3608 but->rnapoin.owner_id, ptr_type, but->custom_data);
3610 if (RNA_property_editable(&ptr, prop)) {
3611 RNA_property_string_set(&ptr, prop, str);
3612 }
3613 }
3614 }
3615 else if (but->type == ButtonType::Text) {
3616 /* string */
3617 if (!but->poin) {
3618 str = "";
3619 }
3620 else if (but_is_utf8(but)) {
3621 BLI_strncpy_utf8(but->poin, str, but->hardmax);
3622 }
3623 else {
3624 BLI_strncpy(but->poin, str, but->hardmax);
3625 }
3626
3627 return true;
3628 }
3629 else if (but->type == ButtonType::SearchMenu) {
3630 /* string */
3631 if (but_is_utf8(but)) {
3632 BLI_strncpy_utf8(but->poin, str, but->hardmax);
3633 }
3634 else {
3635 BLI_strncpy(but->poin, str, but->hardmax);
3636 }
3637 return true;
3638 }
3639 else if (button_anim_expression_set(but, str)) {
3640 /* driver expression */
3641 return true;
3642 }
3643 else if (str[0] == '#') {
3644 /* Shortcut to create new driver expression (versus immediate Python-execution). */
3645 return button_anim_expression_create(but, str + 1);
3646 }
3647 else {
3648 /* number editing */
3649 double value;
3650
3651 if (button_string_eval_number(C, but, str, &value) == false) {
3653 return false;
3654 }
3655
3656 if (!button_is_float(but)) {
3657 value = floor(value + 0.5);
3658 }
3659
3660 /* not that we use hard limits here */
3661 if (value < double(but->hardmin)) {
3662 value = but->hardmin;
3663 }
3664 if (value > double(but->hardmax)) {
3665 value = but->hardmax;
3666 }
3667
3668 button_value_set(but, value);
3669 return true;
3670 }
3671
3672 return false;
3673}
3674
3675static double soft_range_round_up(double value, double max)
3676{
3677 /* round up to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, ..
3678 * checking for 0.0 prevents floating point exceptions */
3679 const double newmax = (value != 0.0) ? pow(10.0, ceil(log(value) / M_LN10)) : 0.0;
3680
3681 if (newmax * 0.2 >= max && newmax * 0.2 >= value) {
3682 return newmax * 0.2;
3683 }
3684 if (newmax * 0.5 >= max && newmax * 0.5 >= value) {
3685 return newmax * 0.5;
3686 }
3687 return newmax;
3688}
3689
3690static double soft_range_round_down(double value, double max)
3691{
3692 /* round down to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, ..
3693 * checking for 0.0 prevents floating point exceptions */
3694 const double newmax = (value != 0.0) ? pow(10.0, floor(log(value) / M_LN10)) : 0.0;
3695
3696 if (newmax * 5.0 <= max && newmax * 5.0 <= value) {
3697 return newmax * 5.0;
3698 }
3699 if (newmax * 2.0 <= max && newmax * 2.0 <= value) {
3700 return newmax * 2.0;
3701 }
3702 return newmax;
3703}
3704
3706{
3707 if (but->rnaprop == nullptr) {
3708 return;
3709 }
3710
3711 const PropertyType type = RNA_property_type(but->rnaprop);
3712
3713 if (type == PROP_INT) {
3714 int imin, imax;
3715 RNA_property_int_range(&but->rnapoin, but->rnaprop, &imin, &imax);
3716 but->hardmin = imin;
3717 but->hardmax = imax;
3718 }
3719 else if (type == PROP_FLOAT) {
3720 float fmin, fmax;
3721 RNA_property_float_range(&but->rnapoin, but->rnaprop, &fmin, &fmax);
3722 but->hardmin = fmin;
3723 but->hardmax = fmax;
3724 }
3725}
3726
3728{
3729 /* This could be split up into functions which handle arrays and not. */
3730
3731 /* Ideally we would not limit this, but practically it's more than
3732 * enough. Worst case is very long vectors won't use a smart soft-range,
3733 * which isn't so bad. */
3734
3735 if (but->rnaprop) {
3736 const PropertyType type = RNA_property_type(but->rnaprop);
3737 const PropertySubType subtype = RNA_property_subtype(but->rnaprop);
3738 double softmin, softmax;
3739 // double step, precision; /* UNUSED. */
3740 double value_min;
3741 double value_max;
3742
3743 /* clamp button range to something reasonable in case
3744 * we get -inf/inf from RNA properties */
3745 if (type == PROP_INT) {
3746 const bool is_array = RNA_property_array_check(but->rnaprop);
3747 int imin, imax, istep;
3748
3749 RNA_property_int_ui_range(&but->rnapoin, but->rnaprop, &imin, &imax, &istep);
3750 softmin = std::max(imin, INT_MIN);
3751 softmax = std::min(imax, INT_MAX);
3752 // step = istep; /* UNUSED */
3753 // precision = 1; /* UNUSED */
3754
3755 if (is_array) {
3756 int value_range[2];
3757 RNA_property_int_get_array_range(&but->rnapoin, but->rnaprop, value_range);
3758 value_min = double(value_range[0]);
3759 value_max = double(value_range[1]);
3760 }
3761 else {
3762 value_min = value_max = button_value_get(but);
3763 }
3764 }
3765 else if (type == PROP_FLOAT) {
3766 const bool is_array = RNA_property_array_check(but->rnaprop);
3767 float fmin, fmax, fstep, fprecision;
3768
3769 RNA_property_float_ui_range(&but->rnapoin, but->rnaprop, &fmin, &fmax, &fstep, &fprecision);
3770 softmin = (fmin == -FLT_MAX) ? float(-1e4) : fmin;
3771 softmax = (fmax == FLT_MAX) ? float(1e4) : fmax;
3772 // step = fstep; /* UNUSED */
3773 // precision = fprecision; /* UNUSED */
3774
3775 /* Use shared min/max for array values, except for color alpha. */
3776 if (is_array && !(subtype == PROP_COLOR && but->rnaindex == 3)) {
3777 float value_range[2];
3778 RNA_property_float_get_array_range(&but->rnapoin, but->rnaprop, value_range);
3779 value_min = double(value_range[0]);
3780 value_max = double(value_range[1]);
3781 }
3782 else {
3783 value_min = value_max = button_value_get(but);
3784 }
3785 }
3786 else {
3787 return;
3788 }
3789
3790 /* if the value goes out of the soft/max range, adapt the range */
3791 if (value_min + 1e-10 < softmin) {
3792 if (value_min < 0.0) {
3793 softmin = -soft_range_round_up(-value_min, -softmin);
3794 }
3795 else {
3796 softmin = soft_range_round_down(value_min, softmin);
3797 }
3798
3799 softmin = std::max(softmin, double(but->hardmin));
3800 }
3801 if (value_max - 1e-10 > softmax) {
3802 if (value_max < 0.0) {
3803 softmax = -soft_range_round_down(-value_max, -softmax);
3804 }
3805 else {
3806 softmax = soft_range_round_up(value_max, softmax);
3807 }
3808
3809 if (softmax > double(but->hardmax)) {
3810 softmax = but->hardmax;
3811 }
3812 }
3813
3814 but->softmin = softmin;
3815 but->softmax = softmax;
3816 }
3817 else if (but->poin && bool(but->pointype & BUT_POIN_TYPES)) {
3818 float value = button_value_get(but);
3819 if (isfinite(value)) {
3820 CLAMP(value, but->hardmin, but->hardmax);
3821 but->softmin = min_ff(but->softmin, value);
3822 but->softmax = max_ff(but->softmax, value);
3823 }
3824 }
3825}
3826
3828
3829/* -------------------------------------------------------------------- */
3832
3839{
3840 switch (but->type) {
3842 ButtonSearch *search_but = static_cast<ButtonSearch *>(but);
3843 MEM_SAFE_DELETE(search_but->item_active_str);
3844
3845 break;
3846 }
3847 default:
3848 break;
3849 }
3850}
3851
3857static void but_free(const bContext *C, Button *but)
3858{
3859 if (but->opptr) {
3861 MEM_delete(but->opptr);
3862 }
3863
3864 if (but->func_argN) {
3865 but->func_argN_free_fn(but->func_argN);
3866 }
3867
3868 if (but->tip_arg_free) {
3869 but->tip_arg_free(but->tip_arg);
3870 }
3871
3872 if (but->hold_argN) {
3874 }
3875
3876 if (but->placeholder) {
3877 MEM_delete(but->placeholder);
3878 }
3879
3881
3882 if (but->semi_modal_state && but->semi_modal_state != but->active) {
3883 if (C) {
3884 /* XXX without this we're stuck in modal state with text edit cursor after closing popup.
3885 * Should exit active buttons as part of popup closing. */
3887 }
3888 else {
3890 }
3891 }
3892 if (but->active) {
3893 /* XXX solve later, buttons should be free-able without context ideally,
3894 * however they may have open tooltips or popup windows, which need to
3895 * be closed using a context pointer */
3896 if (C) {
3897 button_active_free(C, but);
3898 }
3899 else {
3901 }
3902 }
3903
3904 if ((but->type == ButtonType::Image) && but->poin) {
3905 IMB_freeImBuf(reinterpret_cast<ImBuf *>(but->poin));
3906 }
3907
3908 button_drag_free(but);
3910
3911 BLI_assert(butstore_is_registered(but->block, but) == false);
3912}
3913
3915{
3916 if (block->ui_operator_free) {
3917 /* This assumes the operator instance owns the pointer. This is not
3918 * true for all operators by default, but it can be copied when needed. */
3919 MEM_delete(block->ui_operator->ptr);
3920 MEM_delete(block->ui_operator);
3921 }
3922
3923 block->ui_operator_free = false;
3924 block->ui_operator = nullptr;
3925}
3926
3927void block_set_active_operator(Block *block, wmOperator *op, const bool free)
3928{
3929 if (op != block->ui_operator) {
3931
3932 block->ui_operator = op;
3933 block->ui_operator_free = free;
3934 }
3935}
3936
3937void block_free(const bContext *C, Block *block)
3938{
3940
3941 butstore_clear(block);
3942
3943 for (Button &but : block->buttons()) {
3944 but_free(C, &but);
3945 }
3946 block->buttons_ptrs.clear();
3947
3948 if (block->unit) {
3949 MEM_delete(block->unit);
3950 }
3951
3952 if (block->func_argN) {
3953 block->func_argN_free_fn(block->func_argN);
3954 }
3955
3957
3958 block->saferct.free_no_destruct();
3959 block->color_pickers.list.free_no_destruct();
3960 block->dynamic_listeners.free_no_destruct();
3961
3962 block_free_views(block);
3963
3964 MEM_delete(block);
3965}
3966
3968
3969/* -------------------------------------------------------------------- */
3972
3973void block_listen(const Block *block, const wmRegionListenerParams *listener_params)
3974{
3975 /* Note that #Block.active shouldn't be checked here, since notifier listening happens before
3976 * drawing, so there are no active blocks at this point. */
3977
3978 for (BlockDynamicListener &listener : block->dynamic_listeners) {
3979 listener.listener_func(listener_params);
3980 }
3981
3982 block_views_listen(block, listener_params);
3983}
3984
3985void blocklist_update_window_matrix(const bContext *C, const ListBaseT<Block> *lb)
3986{
3987 ARegion *region = CTX_wm_region(C);
3988 wmWindow *window = CTX_wm_window(C);
3989
3990 for (Block &block : *lb) {
3991 if (block.active) {
3992 update_window_matrix(window, region, &block);
3993 }
3994 }
3995}
3996
3997void blocklist_update_view_for_buttons(const bContext *C, const ListBaseT<Block> *lb)
3998{
3999 for (Block &block : *lb) {
4000 if (block.active) {
4002 }
4003 }
4004}
4005
4006void blocklist_draw(const bContext *C, const ListBaseT<Block> *lb)
4007{
4008 for (Block &block : *lb) {
4009 if (block.active) {
4010 block_draw(C, &block);
4011 }
4012 }
4013}
4014
4015void blocklist_free(const bContext *C, ARegion *region)
4016{
4017 ListBaseT<Block> *lb = &region->runtime->uiblocks;
4018 while (Block *block = static_cast<Block *>(BLI_pophead(lb))) {
4019 block_free(C, block);
4020 }
4021 region->runtime->block_name_map.clear();
4022}
4023
4025{
4026 ListBaseT<Block> *lb = &region->runtime->uiblocks;
4027
4028 for (Block &block : lb->items_mutable()) {
4029 if (!block.handle) {
4030 if (block.active) {
4031 block.active = false;
4032 }
4033 else {
4034 if (region->runtime->block_name_map.lookup_default(block.name, nullptr) == &block) {
4035 region->runtime->block_name_map.remove_as(block.name);
4036 }
4037 BLI_remlink(lb, &block);
4038 block_free(C, &block);
4039 }
4040 }
4041 }
4042}
4043
4045
4046/* -------------------------------------------------------------------- */
4049
4050void block_region_set(Block *block, ARegion *region)
4051{
4052 ListBaseT<Block> *lb = &region->runtime->uiblocks;
4053 Block *oldblock = nullptr;
4054
4055 /* each listbase only has one block with this name, free block
4056 * if is already there so it can be rebuilt from scratch */
4057 if (lb) {
4058 oldblock = region->runtime->block_name_map.lookup_default(block->name, nullptr);
4059
4060 if (oldblock) {
4061 oldblock->active = false;
4062 oldblock->panel = nullptr;
4063 oldblock->handle = nullptr;
4064 }
4065
4066 /* at the beginning of the list! for dynamical menus/blocks */
4067 BLI_addhead(lb, block);
4068 region->runtime->block_name_map.add_overwrite_as(block->name, block);
4069 }
4070
4071 block->oldblock = oldblock;
4072}
4073
4075 Scene *scene,
4076 wmWindow *window,
4077 ARegion *region,
4078 std::string name,
4079 EmbossType emboss)
4080{
4081 Block *block = MEM_new<Block>(__func__);
4082 block->active = true;
4083 block->emboss = emboss;
4084 block->evil_C = (void *)C; /* XXX */
4085
4086 if (scene) {
4087 /* store display device name, don't lookup for transformations yet
4088 * block could be used for non-color displays where looking up for transformation
4089 * would slow down redraw, so only lookup for actual transform when it's indeed
4090 * needed
4091 */
4093
4094 /* Copy to avoid crash when scene gets deleted with UI still open. */
4095 UnitSettings *unit = MEM_new<UnitSettings>(__func__);
4096 memcpy(unit, &scene->unit, sizeof(scene->unit));
4097 block->unit = unit;
4098 }
4099 else {
4101 }
4102
4103 block->name = std::move(name);
4104
4105 if (region) {
4106 block_region_set(block, region);
4107 }
4108
4109 /* Prevent reallocations on redraw, most of the time blocks layout will be the same. */
4110 if (block->oldblock) {
4111 block->buttons_ptrs.reserve(block->oldblock->buttons_ptrs.size());
4112 }
4113
4114 /* Set window matrix and aspect for region and OpenGL state. */
4115 update_window_matrix(window, region, block);
4116
4117 /* Tag as popup menu if not created within a region. */
4118 if (!(region && region->runtime->visible)) {
4119 block->auto_open = true;
4120 block->flag |= BLOCK_LOOP;
4121 }
4122
4123 return block;
4124}
4125
4126Block *block_begin(const bContext *C, ARegion *region, std::string name, EmbossType emboss)
4127{
4128 return block_begin(C, CTX_data_scene(C), CTX_wm_window(C), region, std::move(name), emboss);
4129}
4130
4132 void (*listener_func)(const wmRegionListenerParams *params))
4133{
4135 listener->listener_func = listener_func;
4136 BLI_addtail(&block->dynamic_listeners, listener);
4137}
4138
4140{
4141 return block->emboss;
4142}
4143
4145{
4146 block->emboss = emboss;
4147}
4148
4149void block_theme_style_set(Block *block, char theme_style)
4150{
4151 block->theme_style = theme_style;
4152}
4153
4154bool block_is_search_only(const Block *block)
4155{
4156 return block->flag & BLOCK_SEARCH_ONLY;
4157}
4158
4159void block_set_search_only(Block *block, bool search_only)
4160{
4161 SET_FLAG_FROM_TEST(block->flag, search_only, BLOCK_SEARCH_ONLY);
4162}
4163
4165
4166/* -------------------------------------------------------------------- */
4169
4170static void but_build_drawstr_float(Button *but, double value)
4171{
4172 PropertySubType subtype = PROP_NONE;
4173 if (but->rnaprop) {
4174 subtype = RNA_property_subtype(but->rnaprop);
4175 }
4176
4177 /* Change negative zero to regular zero, without altering anything else. */
4178 value += +0.0f;
4179
4180 if (value >= double(UI_FLOAT_VALUE_DISPLAY_MAX)) {
4181 but->drawstr = but->str + "inf";
4182 }
4183 else if (value <= double(UI_FLOAT_VALUE_DISPLAY_MIN)) {
4184 but->drawstr = but->str + "-inf";
4185 }
4186 else if (subtype == PROP_PERCENTAGE) {
4187 const int prec = but_calc_float_precision(but, value);
4188 but->drawstr = fmt::format("{}{:.{}f}%", but->str, value, prec);
4189 }
4190 else if (ELEM(subtype, PROP_PIXEL, PROP_PIXEL_DIAMETER)) {
4191 const int prec = but_calc_float_precision(but, value);
4192 but->drawstr = fmt::format("{}{:.{}f} px", but->str, value, prec);
4193 }
4194 else if (subtype == PROP_FACTOR) {
4195 const int precision = but_calc_float_precision(but, value);
4196
4197 if (U.factor_display_type == USER_FACTOR_AS_FACTOR) {
4198 but->drawstr = fmt::format("{}{:.{}f}", but->str, value, precision);
4199 }
4200 else {
4201 but->drawstr = fmt::format("{}{:.{}f}", but->str, value * 100, std::max(0, precision - 2));
4202 }
4203 }
4204 else if (button_is_unit(but)) {
4205 char new_str[UI_MAX_DRAW_STR];
4206 get_but_string_unit(but, new_str, sizeof(new_str), value, true, -1, true);
4207 but->drawstr = but->str + new_str;
4208 }
4209 else {
4210 const int prec = but_calc_float_precision(but, value);
4211 but->drawstr = fmt::format("{}{:.{}f}", but->str, value, prec);
4212 }
4213}
4214
4215static void but_build_drawstr_int(Button *but, int value)
4216{
4217 PropertySubType subtype = PROP_NONE;
4218 if (but->rnaprop) {
4219 subtype = RNA_property_subtype(but->rnaprop);
4220 }
4221
4222 but->drawstr = but->str + std::to_string(value);
4223
4224 if (subtype == PROP_PERCENTAGE) {
4225 but->drawstr += "%";
4226 }
4227 else if (ELEM(subtype, PROP_PIXEL, PROP_PIXEL_DIAMETER)) {
4228 but->drawstr += " px";
4229 }
4230}
4231
4237static void but_update_ex(Button *but, const bool validate)
4238{
4239 /* if something changed in the button */
4240 double value = BUT_VALUE_UNSET;
4241
4242 but_update_select_flag(but, &value);
4243
4244 /* only update soft range while not editing */
4245 if (!button_is_editing(but)) {
4246 if ((but->rnaprop != nullptr) || (but->poin && bool(but->pointype & BUT_POIN_TYPES))) {
4248 }
4249 }
4250
4251 /* test for min and max, icon sliders, etc */
4252 switch (but->type) {
4253 case ButtonType::Num:
4254 case ButtonType::Scroll:
4256 if (validate) {
4257 UI_GET_BUT_VALUE_INIT(but, value);
4258 if (value < double(but->hardmin)) {
4259 button_value_set(but, but->hardmin);
4260 }
4261 else if (value > double(but->hardmax)) {
4262 button_value_set(but, but->hardmax);
4263 }
4264
4265 /* max must never be smaller than min! Both being equal is allowed though */
4266 BLI_assert(but->softmin <= but->softmax && but->hardmin <= but->hardmax);
4267 }
4268 break;
4269
4272 if ((but->rnaprop == nullptr) || (RNA_property_flag(but->rnaprop) & PROP_ICONS_CONSECUTIVE))
4273 {
4275 but->drawflag |= BUT_ICON_REVERSE;
4276 }
4277
4278 but->iconadd = (but->flag & UI_SELECT) ? 1 : 0;
4279 }
4280 break;
4281
4282 /* quiet warnings for unhandled types */
4283 default:
4284 break;
4285 }
4286
4287 switch (but->type) {
4288 case ButtonType::Menu:
4289 if (BLI_rctf_size_x(&but->rect) >= (UI_UNIT_X * 2)) {
4290 /* only needed for menus in popup blocks that don't recreate buttons on redraw */
4291 if (but->block->flag & BLOCK_LOOP) {
4292 if (but->rnaprop && (RNA_property_type(but->rnaprop) == PROP_ENUM)) {
4293 const int value_enum = RNA_property_enum_get(&but->rnapoin, but->rnaprop);
4294
4295 EnumPropertyItem item;
4297 static_cast<bContext *>(but->block->evil_C),
4298 &but->rnapoin,
4299 but->rnaprop,
4300 value_enum,
4301 &item))
4302 {
4303 but->str = item.name;
4304 but->icon = item.icon;
4305 }
4306 }
4307 }
4308 but->drawstr = but->str;
4309 }
4310 break;
4311
4312 case ButtonType::Num:
4314 if (but->editstr) {
4315 break;
4316 }
4317 UI_GET_BUT_VALUE_INIT(but, value);
4318 if (button_is_float(but)) {
4319 but_build_drawstr_float(but, value);
4320 }
4321 else {
4322 but_build_drawstr_int(but, int(value));
4323 }
4324 break;
4325
4326 case ButtonType::Label:
4327 if (button_is_float(but)) {
4328 UI_GET_BUT_VALUE_INIT(but, value);
4329 const int prec = but_calc_float_precision(but, value);
4330 but->drawstr = fmt::format("{}{:.{}f}", but->str, value, prec);
4331 }
4332 else {
4333 but->drawstr = but->str;
4334 }
4335
4336 break;
4337
4339 if (!but->editstr) {
4340 but->drawstr = textbox_string_get(static_cast<ButtonTextBox *>(but));
4341 }
4342 break;
4343 case ButtonType::Text:
4345 if (!but->editstr) {
4346 char str[UI_MAX_DRAW_STR];
4348 but->drawstr = fmt::format("{}{}", but->str, str);
4349 }
4350 break;
4351
4352 case ButtonType::KeyEvent: {
4353 const char *str;
4354 if (but->flag & UI_SELECT) {
4355 str = IFACE_("Press a key");
4356 }
4357 else {
4358 UI_GET_BUT_VALUE_INIT(but, value);
4359 str = WM_key_event_string(short(value), false);
4360 }
4361 but->drawstr = fmt::format("{}{}", but->str, str);
4362 break;
4363 }
4365 if (but->flag & UI_SELECT) {
4366 const ButtonHotkeyEvent *hotkey_but = static_cast<ButtonHotkeyEvent *>(but);
4367
4368 if (hotkey_but->modifier_key) {
4369 /* Rely on #KM_NOTHING being zero for `type`, `val` ... etc. */
4370 wmKeyMapItem kmi_dummy = {nullptr};
4371 kmi_dummy.shift = (hotkey_but->modifier_key & KM_SHIFT) ? KM_MOD_HELD : KM_NOTHING;
4372 kmi_dummy.ctrl = (hotkey_but->modifier_key & KM_CTRL) ? KM_MOD_HELD : KM_NOTHING;
4373 kmi_dummy.alt = (hotkey_but->modifier_key & KM_ALT) ? KM_MOD_HELD : KM_NOTHING;
4374 kmi_dummy.oskey = (hotkey_but->modifier_key & KM_OSKEY) ? KM_MOD_HELD : KM_NOTHING;
4375 kmi_dummy.hyper = (hotkey_but->modifier_key & KM_HYPER) ? KM_MOD_HELD : KM_NOTHING;
4376
4377 but->drawstr = WM_keymap_item_to_string(&kmi_dummy, true).value_or("");
4378 }
4379 else {
4380 but->drawstr = IFACE_("Press a key");
4381 }
4382 }
4383 else {
4384 but->drawstr = but->str;
4385 }
4386
4387 break;
4388
4391 break;
4392 default:
4393 but->drawstr = but->str;
4394 break;
4395 }
4396
4397 /* if we are doing text editing, this will override the drawstr */
4398 if (but->editstr) {
4399 but->drawstr.clear();
4400 }
4401
4402 /* text clipping moved to widget drawing code itself */
4403}
4404
4406{
4407 but_update_ex(but, false);
4408}
4409
4411{
4412 but_update_ex(but, true);
4413}
4414
4416{
4417 /* if other align was active, end it */
4418 if (block->flag & BUT_ALIGN) {
4419 block_align_end(block);
4420 }
4421
4422 block->flag |= BUT_ALIGN_DOWN;
4423 block->alignnr++;
4424
4425 /* Buttons declared after this call will get this `alignnr`. */ /* XXX flag? */
4426}
4427
4429{
4430 block->flag &= ~BUT_ALIGN; /* all 4 flags */
4431}
4432
4437
4438void block_cm_to_display_space_v3(Block *block, float pixel[3])
4439{
4440 const ColorManagedDisplay *display = block_cm_display_get(block);
4441
4443}
4444
4446
4447/* -------------------------------------------------------------------- */
4450
4454static std::unique_ptr<Button> but_new(const ButtonType type)
4455{
4456 std::unique_ptr<Button> but{};
4457
4458 switch (type) {
4460 but = std::make_unique<ButtonTextBox>();
4461 break;
4462 case ButtonType::Text:
4463 but = std::make_unique<ButtonText>();
4464 break;
4465 case ButtonType::Num:
4466 but = std::make_unique<ButtonNumber>();
4467 break;
4469 but = std::make_unique<ButtonNumberSlider>();
4470 break;
4471 case ButtonType::Color:
4472 but = std::make_unique<ButtonColor>();
4473 break;
4475 but = std::make_unique<ButtonDecorator>();
4476 break;
4477 case ButtonType::Tab:
4478 but = std::make_unique<ButtonTab>();
4479 break;
4481 but = std::make_unique<ButtonSearch>();
4482 break;
4484 but = std::make_unique<ButtonProgress>();
4485 break;
4487 but = std::make_unique<ButtonSeparatorLine>();
4488 break;
4490 but = std::make_unique<ButtonHSVCube>();
4491 break;
4493 but = std::make_unique<ButtonColorBand>();
4494 break;
4495 case ButtonType::Curve:
4496 but = std::make_unique<ButtonCurveMapping>();
4497 break;
4499 but = std::make_unique<ButtonCurveProfile>();
4500 break;
4502 but = std::make_unique<ButtonHotkeyEvent>();
4503 break;
4505 but = std::make_unique<ButtonViewItem>();
4506 break;
4507 case ButtonType::Label:
4508 but = std::make_unique<ButtonLabel>();
4509 break;
4510 case ButtonType::Scroll:
4511 but = std::make_unique<ButtonScrollBar>();
4512 break;
4513 case ButtonType::Image:
4514 but = std::make_unique<ButtonImage>();
4515 break;
4516 case ButtonType::Menu:
4518 case ButtonType::Block:
4523 but = std::make_unique<ButtonMenu>();
4524 break;
4525 case ButtonType::But:
4526 but = std::make_unique<ButtonPush>();
4527 break;
4528 default:
4529 but = std::make_unique<Button>();
4530 break;
4531 }
4532
4533 but->type = type;
4534 return but;
4535}
4536
4541static Button *def_but(Block *block,
4542 ButtonTypeWithPointerType but_and_ptr_type,
4543 const StringRef str,
4544 int x,
4545 int y,
4546 short width,
4547 short height,
4548 void *poin,
4549 float min,
4550 float max,
4551 const std::optional<StringRef> tip)
4552{
4553 /* Allow negative separators. */
4554 BLI_assert((width >= 0 && height >= 0) || (but_and_ptr_type.but_type == ButtonType::Sepr));
4555
4556 if (bool(but_and_ptr_type.pointer_type & BUT_POIN_TYPES)) {
4557 /* A pointer is required. */
4558 if (poin == nullptr) {
4559 BLI_assert(0);
4560 return nullptr;
4561 }
4562 }
4563
4564 block->buttons_ptrs.append(but_new(but_and_ptr_type.but_type));
4565 Button *but = block->buttons_ptrs.last().get();
4566
4567 but->pointype = but_and_ptr_type.pointer_type & BUT_POIN_TYPES;
4568 but->bit = flag_is_set(but_and_ptr_type.pointer_type, ButPointerType::Bit);
4569 but->bitnr = but_and_ptr_type.bit_index;
4570
4571 but->retval = 0;
4572
4573 but->str = str;
4574
4575 but->rect.xmin = x;
4576 but->rect.ymin = y;
4577 but->rect.xmax = but->rect.xmin + width;
4578 but->rect.ymax = but->rect.ymin + height;
4579
4580 but->poin = static_cast<char *>(poin);
4581 but->hardmin = but->softmin = min;
4582 but->hardmax = but->softmax = max;
4583 but->tip = tip.value_or("");
4584
4585 but->disabled_info = block->lockstr;
4586 but->emboss = block->emboss;
4587
4588 but->block = block; /* pointer back, used for front-buffer status, and picker. */
4589
4590 if ((block->flag & BUT_ALIGN) && button_can_align(but)) {
4591 but->alignnr = block->alignnr;
4592 }
4593
4594 but->func = block->func;
4595 but->func_arg1 = block->func_arg1;
4596 but->func_arg2 = block->func_arg2;
4597
4598 but->funcN = block->funcN;
4599 if (block->func_argN) {
4600 but->func_argN = block->func_argN_copy_fn(block->func_argN);
4603 }
4604
4605 but->pos = -1; /* cursor invisible */
4606
4607 if (ELEM(but->type, ButtonType::Num, ButtonType::NumSlider)) { /* add a space to name */
4608 if (!but->str.empty() && but->str.size() < UI_MAX_NAME_STR - 2) {
4609 if (but->str[but->str.size() - 1] != ' ') {
4610 but->str += ' ';
4611 }
4612 }
4613 }
4614
4615 if (block->flag & BLOCK_PIE_MENU) {
4616 but->drawflag |= BUT_TEXT_LEFT;
4617 if (!but->str.empty()) {
4618 but->drawflag |= BUT_ICON_LEFT;
4619 }
4620 }
4621 else if (((block->flag & BLOCK_LOOP) && !block_is_popover(block) &&
4622 !(block->flag & BLOCK_QUICK_SETUP)) ||
4623 ELEM(but->type,
4632 {
4634 }
4635#ifdef USE_NUMBUTS_LR_ALIGN
4637 if (!but->str.empty()) {
4638 but->drawflag |= BUT_TEXT_LEFT;
4639 }
4640 }
4641#endif
4642
4643 but->drawflag |= (block->flag & BUT_ALIGN);
4644
4645 if (block->lock == true) {
4646 but->flag |= BUT_DISABLED;
4647 }
4648
4649 /* Keep track of `UI_interface_c.hh`. */
4650 if (ELEM(but->type,
4664 (but->type >= ButtonType::SearchMenu))
4665 {
4666 /* pass */
4667 }
4668 else {
4669 but->flag |= BUT_UNDO;
4670 }
4671
4672 if (ELEM(but->type, ButtonType::Color)) {
4674 }
4675
4676 if (block->curlayout) {
4677 layout_add_but(block->curlayout, but);
4678 }
4679
4680#ifdef WITH_PYTHON
4681 /* If the `UI_OT_editsource` is running, extract the source info from the button. */
4684 }
4685#endif
4686
4687 return but;
4688}
4689
4690void def_but_icon(Button *but, const int icon, const int64_t flag)
4691{
4692 if (icon) {
4694 static_cast<const bContext *>(but->block->evil_C), icon, (flag & BUT_ICON_PREVIEW) != 0);
4695 }
4696 but->icon = icon;
4697 but->flag |= flag;
4698
4699 if (!but->str.empty()) {
4700 but->drawflag |= BUT_ICON_LEFT;
4701 }
4702}
4703
4705{
4706 but->icon = ICON_NONE;
4707 but->flag &= ~UI_HAS_ICON;
4708 but->drawflag &= ~BUT_ICON_LEFT;
4709}
4710
4711static void def_but_rna__menu(bContext *C, Layout *layout, void *but_p)
4712{
4713 Block *block = layout->block();
4714 PopupBlockHandle *handle = block->handle;
4715 Button *but = static_cast<Button *>(but_p);
4716 const int current_value = RNA_property_enum_get(&but->rnapoin, but->rnaprop);
4717
4718 /* see comment in ui_item_enum_expand, re: `uiname`. */
4719 const EnumPropertyItem *item_array;
4720
4722
4723 bool free;
4724 RNA_property_enum_items_gettexted(static_cast<bContext *>(block->evil_C),
4725 &but->rnapoin,
4726 but->rnaprop,
4727 &item_array,
4728 nullptr,
4729 &free);
4730
4731 /* We don't want nested rows, cols in menus. */
4732 block_layout_set_current(block, layout);
4733
4734 int totitems = 0;
4735 int categories = 0;
4736 bool has_item_with_icon = false;
4737 int columns = 1;
4738 int rows = 0;
4739
4740 const wmWindow *win = CTX_wm_window(C);
4741
4742 /* Calculate the maximum number of rows that can fit in half the height of this window. */
4743 const float row_height = float(UI_UNIT_Y) / but->block->aspect;
4744 const float vertical_space = (float(WM_window_native_pixel_y(win)) / 2.0f) - (UI_UNIT_Y * 3.0f);
4745 const int max_rows = std::max(int(vertical_space / row_height) - 1, 1);
4746
4747 float text_width = 0.0f;
4748 BLF_size(BLF_default(), style_get()->widget.points * UI_SCALE_FAC);
4749 int col_rows = 0;
4750 float col_width = 0.0f;
4751
4752 for (const EnumPropertyItem *item = item_array; item->identifier; item++, totitems++) {
4753 col_rows++;
4754 if (col_rows > 1 && (col_rows > max_rows || (!item->identifier[0] && item->name))) {
4755 columns++;
4756 text_width += col_width;
4757 col_width = 0;
4758 col_rows = 0;
4759 }
4760 if (!item->identifier[0] && item->name) {
4761 categories++;
4762 /* The category name adds to the column length. */
4763 col_rows++;
4764 }
4765 if (item->icon) {
4766 has_item_with_icon = true;
4767 }
4768 if (item->name && item->name[0]) {
4769 float item_width = BLF_width(BLF_default(), item->name, BLF_DRAW_STR_DUMMY_MAX);
4770 col_width = std::max(col_width, item_width + (100.0f * UI_SCALE_FAC));
4771 }
4772 rows = std::max(rows, col_rows);
4773 }
4774 text_width += col_width;
4775 text_width /= but->block->aspect;
4776
4777 if (categories == 0) {
4778 /* Long lists without categories (section titles) can be wrapped
4779 * to any nice combination of columns and rows. First use (long-
4780 * standing) code that wraps most lists pleasantly. */
4781 columns = std::max((totitems + 20) / 20, 1);
4782 if (columns > 8) {
4783 columns = (totitems + 25) / 25;
4784 }
4785 /* If above results in more rows than can fit in available vertical
4786 * space, then break it into columns of rows of maximum length. */
4787 if ((totitems / columns) > max_rows) {
4788 columns = std::max((totitems + col_rows) / max_rows, 1);
4789 }
4790 rows = std::max(totitems / columns, 1);
4791 while (rows * columns < totitems) {
4792 rows++;
4793 }
4794 }
4795
4796 /* If the estimated width of the menu is wider than the width of
4797 * this window, then we have to collapse it to a single column. */
4798 if (columns > 1 && text_width > WM_window_native_pixel_x(win)) {
4799 columns = 1;
4800 rows = totitems;
4801 }
4802
4803 const char *title = RNA_property_ui_name(but->rnaprop, but->rnapoin ? &but->rnapoin : nullptr);
4804
4805 /* Is there a non-blank label before this button on the same row? */
4806 Button *but_prev = but->block->prev_but(but);
4807 const bool prior_label = but_prev && but_prev->type == ButtonType::Label && but_prev->str[0] &&
4808 but_prev->alignnr == but->alignnr;
4809
4810 /* When true, store a copy of the description and use the tool-tip callback to return that copy.
4811 * This way, further calls to #EnumPropertyRNA::item_fn which occur when evaluating shortcuts
4812 * don't cause strings to be freed. See #ui_but_event_property_operator_string, see: #129151.
4813 *
4814 * - This is *not* a generic fix for #126541,
4815 * references to strings still need to be held by Python.
4816 *
4817 * - Duplicating descriptions in most UI logic should be avoided.
4818 * Make an exception for menus as they aren't typically refreshed during animation
4819 * playback or other situations where the overhead would be noticeable.
4820 */
4821 const bool use_enum_copy_description = free &&
4822 ((RNA_property_is_idprop(but->rnaprop) == false) &&
4823 (RNA_property_py_data_get(but->rnaprop) != nullptr));
4824
4825 if (title && title[0] && (categories == 0) && (!but->str[0] || !prior_label)) {
4826 /* Show title when no categories and calling button has no text or prior label. */
4827 uiDefBut(
4828 block, ButtonType::Label, title, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, nullptr, 0.0, 0.0, "");
4829 layout->separator();
4830 }
4831
4832 /* NOTE: `item_array[...]` is reversed on access. */
4833
4834 /* create items */
4835 Layout &split = layout->split(0.0f, false);
4836
4837 bool new_column;
4838
4839 int column_end = 0;
4840 Layout *column = nullptr;
4841 for (int a = 0; a < totitems; a++) {
4842 new_column = (a == column_end);
4843 if (new_column) {
4844 /* start new column, and find out where it ends in advance, so we
4845 * can flip the order of items properly per column */
4846 column_end = totitems;
4847
4848 for (int b = a + 1; b < totitems; b++) {
4849 const EnumPropertyItem *item = &item_array[b];
4850
4851 /* new column on N rows or on separation label */
4852 if (((b - a) % rows == 0) || (columns > 1 && !item->identifier[0] && item->name)) {
4853 column_end = b;
4854 break;
4855 }
4856 }
4857
4858 column = &split.column(false);
4859 }
4860
4861 const EnumPropertyItem *item = &item_array[a];
4862
4863 if (new_column && (categories > 0) && (columns > 1) && item->identifier[0]) {
4864 column->label("", ICON_NONE);
4865 column->separator();
4866 }
4867
4868 if (!item->identifier[0]) {
4869 if (item->name || columns > 1) {
4870 if (item->icon) {
4871 column->label(item->name, item->icon);
4872 }
4873 else if (item->name) {
4874 /* Do not use Layout::label here, as our root layout is a menu one,
4875 * it will add a fake blank icon! */
4876 uiDefBut(block,
4878 item->name,
4879 0,
4880 0,
4881 UI_UNIT_X * 5,
4882 UI_UNIT_Y,
4883 nullptr,
4884 0.0,
4885 0.0,
4886 "");
4887 }
4888 }
4889 column->separator();
4890 }
4891 else {
4892 int icon = item->icon;
4893 std::optional<StringRef> description_static;
4894 if (!use_enum_copy_description) {
4895 description_static = item->description;
4896 }
4897
4898 /* Use blank icon if there is none for this item (but for some other one) to make sure labels
4899 * align. */
4900 if (icon == ICON_NONE && has_item_with_icon) {
4901 icon = ICON_BLANK1;
4902 }
4903
4904 Button *item_but;
4905 if (icon) {
4906 item_but = uiDefIconTextBut(block,
4908 icon,
4909 item->name,
4910 0,
4911 0,
4912 UI_UNIT_X * 5,
4913 UI_UNIT_Y,
4914 &handle->retvalue,
4915 description_static);
4916 }
4917 else {
4918 item_but = uiDefButV(block,
4920 item->name,
4921 0,
4922 0,
4923 UI_UNIT_X * 5,
4924 UI_UNIT_X,
4925 &handle->retvalue,
4926 0.0,
4927 0.0,
4928 description_static);
4929 }
4930 if (item->value == current_value) {
4931 item_but->flag |= UI_SELECT_DRAW;
4932 }
4933
4934 button_enum_prop_value_set(item_but, item->value);
4935
4936 if (use_enum_copy_description) {
4937 if (item->description && item->description[0]) {
4938 char *description_copy = BLI_strdup(item->description);
4940 item_but,
4941 [](bContext * /*C*/, void *argN, const StringRef /*tip*/) -> std::string {
4942 return static_cast<const char *>(argN);
4943 },
4944 description_copy,
4946 }
4947 }
4948 }
4949 }
4950
4951 block_layout_set_current(block, layout);
4952
4953 if (free) {
4954 MEM_delete(item_array);
4955 }
4956}
4957
4958static void def_but_rna__panel_type(bContext *C, Layout *layout, void *arg)
4959{
4960 PanelType *panel_type = static_cast<PanelType *>(arg);
4961 if (panel_type) {
4962 item_paneltype_func(C, layout, panel_type);
4963 }
4964 else {
4965 layout->label(RPT_("Missing Panel"), ICON_NONE);
4966 }
4967}
4968
4969void button_rna_menu_convert_to_panel_type(Button *but, const char *panel_type)
4970{
4972 // BLI_assert(but->menu_create_func == ui_def_but_rna__menu);
4973 // BLI_assert((void *)but->poin == but);
4974
4975 /* Any existing function argument and callback using it gets overwritten. */
4976 if (but->func_argN && but->func_argN_free_fn) {
4977 but->func_argN_free_fn(but->func_argN);
4978 }
4979 but->funcN = nullptr;
4980
4982 but->func_argN = BLI_strdup(panel_type);
4985}
4986
4988{
4990}
4991
4992static void def_but_rna__menu_type(bContext *C, Layout *layout, void *but_p)
4993{
4994 Button *but = static_cast<Button *>(but_p);
4995 const char *menu_type = static_cast<const char *>(but->func_argN);
4996 MenuType *mt = WM_menutype_find(menu_type, true);
4997 if (mt) {
4998 item_menutype_func(C, layout, mt);
4999 }
5000 else {
5001 char msg[256];
5002 SNPRINTF_UTF8(msg, RPT_("Missing Menu: %s"), menu_type);
5003 layout->label(msg, ICON_NONE);
5004 }
5005}
5006
5007void button_rna_menu_convert_to_menu_type(Button *but, const char *menu_type)
5008{
5011 BLI_assert((void *)but->poin == but);
5012
5013 /* Any existing function argument and callback using it gets overwritten. */
5014 if (but->func_argN && but->func_argN_free_fn) {
5015 but->func_argN_free_fn(but->func_argN);
5016 }
5017 but->funcN = nullptr;
5018
5022 but->func_argN = BLI_strdup(menu_type);
5023}
5024
5025static void but_submenu_enable(Block *block, Button *but)
5026{
5027 but->flag |= BUT_ICON_SUBMENU;
5029}
5030
5039static Button *def_but_rna(Block *block,
5040 ButtonType type,
5041 std::optional<StringRef> str,
5042 int x,
5043 int y,
5044 short width,
5045 short height,
5046 PointerRNA *ptr,
5047 PropertyRNA *prop,
5048 int index,
5049 float min,
5050 float max,
5051 std::optional<StringRef> tip)
5052{
5053 const PropertyType proptype = RNA_property_type(prop);
5054 int icon = 0;
5055 MenuCreateFunc func = nullptr;
5056
5058 BLI_assert(index == -1);
5059 }
5060
5061 /* use rna values if parameters are not specified */
5062 if ((proptype == PROP_ENUM) &&
5064 {
5065 bool free;
5066 const EnumPropertyItem *item;
5068 static_cast<bContext *>(block->evil_C), ptr, prop, &item, nullptr, &free);
5069
5070 int value;
5071 /* ButtonType::Menu is handled a little differently here */
5072 if (type == ButtonType::Menu) {
5073 value = RNA_property_enum_get(ptr, prop);
5074 }
5075 else {
5076 value = int(max);
5077 }
5078
5079 const int i = RNA_enum_from_value(item, value);
5080 if (i != -1) {
5081
5082 if (!str) {
5083 str = item[i].name;
5084#ifdef WITH_INTERNATIONAL
5086#endif
5087 }
5088
5089 icon = item[i].icon;
5090 }
5091 else {
5092 if (!str) {
5093 if (type == ButtonType::Menu) {
5094 str = "";
5095 }
5096 else {
5097 str = RNA_property_ui_name(prop);
5098 }
5099 }
5100 }
5101
5102 if (type == ButtonType::Menu) {
5103 func = def_but_rna__menu;
5104 }
5105
5106 if (free) {
5107 MEM_delete(item);
5108 }
5109 }
5110 else {
5111 if (!str) {
5112 str = RNA_property_ui_name(prop);
5113 }
5114 icon = RNA_property_ui_icon(prop);
5115 }
5116
5117 if (!tip && proptype != PROP_ENUM) {
5118 tip = RNA_property_ui_description(prop, ptr);
5119 }
5120
5121 float step = -1.0f;
5122 float precision = -1.0f;
5123 if (proptype == PROP_INT) {
5124 int hardmin, hardmax, softmin, softmax, int_step;
5125
5126 RNA_property_int_range(ptr, prop, &hardmin, &hardmax);
5127 RNA_property_int_ui_range(ptr, prop, &softmin, &softmax, &int_step);
5128
5129 if (!ELEM(type, ButtonType::Row, ButtonType::ListRow) && min == max) {
5130 min = hardmin;
5131 max = hardmax;
5132 }
5133 step = int_step;
5134 precision = 0;
5135 }
5136 else if (proptype == PROP_FLOAT) {
5137 float hardmin, hardmax, softmin, softmax;
5138
5139 RNA_property_float_range(ptr, prop, &hardmin, &hardmax);
5140 RNA_property_float_ui_range(ptr, prop, &softmin, &softmax, &step, &precision);
5141
5142 if (!ELEM(type, ButtonType::Row, ButtonType::ListRow) && min == max) {
5143 min = hardmin;
5144 max = hardmax;
5145 }
5146 }
5147 else if (proptype == PROP_STRING) {
5148 min = 0;
5150 /* NOTE: 'max' may be zero (code for dynamically resized array). */
5151 }
5152
5153 /* now create button */
5154 Button *but = def_but(block, type, *str, x, y, width, height, nullptr, min, max, tip);
5155
5156 if (but->type == ButtonType::Num) {
5157 /* Set default values, can be overridden later. */
5159 button_number_precision_set(but, precision);
5160 }
5161 else if (but->type == ButtonType::NumSlider) {
5162 /* Set default values, can be overridden later. */
5164 button_number_slider_precision_set(but, precision);
5165 }
5166
5167 but->rnapoin = *ptr;
5168 but->rnaprop = prop;
5169
5171 but->rnaindex = index;
5172 }
5173 else {
5174 but->rnaindex = 0;
5175 }
5176
5177 if (icon) {
5178 def_but_icon(but, icon, UI_HAS_ICON);
5179 }
5180
5181 if (type == ButtonType::Menu) {
5182 if (but->emboss == EmbossType::Pulldown) {
5183 but_submenu_enable(block, but);
5184 }
5185 }
5186 else if (type == ButtonType::SearchMenu) {
5187 if (proptype == PROP_POINTER) {
5188 /* Search buttons normally don't get undo, see: #54580. */
5189 but->flag |= BUT_UNDO;
5190 }
5191 }
5192
5193 const char *info;
5194 if (but->rnapoin && !RNA_property_editable_info(&but->rnapoin, prop, &info)) {
5195 button_disable(but, info);
5196 }
5197
5198 if (proptype == PROP_POINTER) {
5199 /* If the button shows an ID, automatically set it as focused in context so operators can
5200 * access it. */
5201 const PointerRNA pptr = RNA_property_pointer_get(ptr, prop);
5202 if (pptr && RNA_struct_is_ID(pptr.type)) {
5203 but->context = CTX_store_add(block->contexts, "id", &pptr);
5204 }
5205 }
5206
5207 if (but->flag & BUT_UNDO && (but_is_rna_undo(but) == false)) {
5208 but->flag &= ~BUT_UNDO;
5209 }
5210
5211 /* If this button uses units, calculate the step from this */
5212 if ((proptype == PROP_FLOAT) && button_is_unit(but)) {
5213 if (type == ButtonType::Num) {
5214 ButtonNumber *number_but = static_cast<ButtonNumber *>(but);
5215 number_but->step_size = get_but_step_unit(but, number_but->step_size);
5216 }
5217 if (type == ButtonType::NumSlider) {
5218 ButtonNumberSlider *number_but = static_cast<ButtonNumberSlider *>(but);
5219 number_but->step_size = get_but_step_unit(but, number_but->step_size);
5220 }
5221 }
5222
5223 if (func) {
5224 but->menu_create_func = func;
5225 but->poin = reinterpret_cast<char *>(but);
5226 }
5227
5228 return but;
5229}
5230
5232 ButtonType type,
5233 std::optional<StringRef> str,
5234 int x,
5235 int y,
5236 short width,
5237 short height,
5238 PointerRNA *ptr,
5239 const StringRefNull propname,
5240 int index,
5241 float min,
5242 float max,
5243 const std::optional<StringRef> tip)
5244{
5245 PropertyRNA *prop = RNA_struct_find_property(ptr, propname.c_str());
5246
5247 Button *but;
5248 if (prop) {
5249 but = def_but_rna(block, type, str, x, y, width, height, ptr, prop, index, min, max, tip);
5250 }
5251 else {
5252 but = def_but(block, type, propname, x, y, width, height, nullptr, min, max, tip);
5253
5254 button_disable(but, N_("Unknown Property"));
5255 }
5256
5257 return but;
5258}
5259
5261 ButtonType type,
5262 wmOperatorType *ot,
5263 wm::OpCallContext opcontext,
5264 const StringRef str,
5265 int x,
5266 int y,
5267 short width,
5268 short height,
5269 std::optional<StringRef> tip)
5270{
5271 if ((!tip || tip->is_empty()) && ot && ot->srna && !ot->get_description) {
5273 }
5274
5275 Button *but = def_but(block, type, str, x, y, width, height, nullptr, 0, 0, tip);
5276 button_operator_set(but, ot, opcontext);
5277
5278 /* Enable quick tooltip label if this is a tool button without a label. */
5279 if (str.is_empty() && !block_is_popover(block) && but_is_tool(but)) {
5281 }
5282
5283 if (!ot) {
5284 button_disable(but, "");
5285 }
5286
5287 return but;
5288}
5289
5291
5292/* -------------------------------------------------------------------- */
5295
5297 ButtonTypeWithPointerType but_and_ptr_type,
5298 const StringRef str,
5299 int x,
5300 int y,
5301 short width,
5302 short height,
5303 void *poin,
5304 float min,
5305 float max,
5306 const std::optional<StringRef> tip)
5307{
5308 Button *but = def_but(block, but_and_ptr_type, str, x, y, width, height, poin, min, max, tip);
5309
5310 button_update(but);
5311
5312 return but;
5313}
5314
5316 Block *block, void *imbuf, int x, int y, short width, short height, const uchar color[4])
5317{
5318 Button *but = def_but(block, ButtonType::Image, "", x, y, width, height, imbuf, 0, 0, "");
5319 if (color) {
5320 copy_v4_v4_uchar(but->col, color);
5321 }
5322 else {
5323 but->col[0] = 255;
5324 but->col[1] = 255;
5325 but->col[2] = 255;
5326 but->col[3] = 255;
5327 }
5328 button_update(but);
5329 return but;
5330}
5331
5332Button *uiDefButAlert(Block *block, AlertIcon icon, int x, int y, short width, short /*height*/)
5333{
5334 ImBuf *ibuf = icon_alert_imbuf_get(icon, float(width));
5335 if (ibuf) {
5336 if (icon == AlertIcon::Error) {
5337 uchar color[4];
5339 return uiDefButImage(block, ibuf, x, y, ibuf->x, ibuf->y, color);
5340 }
5341 const bTheme *btheme = theme::theme_get();
5342 return uiDefButImage(block, ibuf, x, y, ibuf->x, ibuf->y, btheme->tui.wcol_menu_back.text);
5343 }
5344 return nullptr;
5345}
5346
5348{
5349 but->retval = retval;
5350}
5351
5352void button_retval_set(Button *but, int retval)
5353{
5354 but->retval = retval;
5355}
5356
5358
5359/* -------------------------------------------------------------------- */
5362
5364 size_t maxncpy;
5367 const char *startname;
5368};
5369
5370AutoComplete *autocomplete_begin(const char *startname, size_t maxncpy)
5371{
5372 AutoComplete *autocpl;
5373
5374 autocpl = MEM_new_zeroed<AutoComplete>(__func__);
5375 autocpl->maxncpy = maxncpy;
5376 autocpl->matches = 0;
5377 autocpl->truncate = MEM_new_array_zeroed<char>(maxncpy, __func__);
5378 autocpl->startname = startname;
5379
5380 return autocpl;
5381}
5382
5384{
5385 char *truncate = autocpl->truncate;
5386 const char *startname = autocpl->startname;
5387 const int len_max = int(autocpl->maxncpy) - 1;
5388 int match_index = 0;
5389 for (int a = 0; a < len_max; a++) {
5390 /* Past the end of `name`, compare with its null terminator. */
5391 const char c = (a < name.size()) ? name[a] : '\0';
5392 if (startname[a] == 0 || startname[a] != c) {
5393 match_index = a;
5394 break;
5395 }
5396 }
5397
5398 /* found a match */
5399 if (startname[match_index] == 0) {
5400 autocpl->matches++;
5401 /* first match */
5402 if (truncate[0] == 0) {
5403 name.copy_utf8_truncated(truncate, autocpl->maxncpy);
5404 }
5405 else {
5406 /* remove from truncate what is not in bone->name */
5407 for (int a = 0; a < len_max; a++) {
5408 if (a == name.size()) {
5409 truncate[a] = 0;
5410 break;
5411 }
5412 if (truncate[a] != name[a]) {
5413 truncate[a] = 0;
5414 }
5415 }
5416 }
5417 }
5418}
5419
5420int autocomplete_end(AutoComplete *autocpl, char *autoname)
5421{
5422 int match = AUTOCOMPLETE_NO_MATCH;
5423 if (autocpl->truncate[0]) {
5424 if (autocpl->matches == 1) {
5426 }
5427 else {
5429 }
5430 BLI_strncpy(autoname, autocpl->truncate, autocpl->maxncpy);
5431 }
5432 else {
5433 if (autoname != autocpl->startname) { /* don't copy a string over itself */
5434 BLI_strncpy(autoname, autocpl->startname, autocpl->maxncpy);
5435 }
5436 }
5437
5438 MEM_delete(autocpl->truncate);
5439 MEM_delete(autocpl);
5440 return match;
5441}
5442
5444
5445/* -------------------------------------------------------------------- */
5448
5449#define PREVIEW_TILE_PAD (0.225f * UI_UNIT_X)
5450
5451int preview_tile_size_x(const int size_px)
5452{
5453 const float pad = PREVIEW_TILE_PAD;
5454 return round_fl_to_int((size_px / 20.0f) * UI_UNIT_X + 2.0f * pad);
5455}
5456
5457int preview_tile_size_y(const int size_px)
5458{
5459 const float font_height = UI_UNIT_Y;
5460 /* Add some extra padding to make things less tight vertically. */
5461 const float pad = PREVIEW_TILE_PAD;
5462
5463 return round_fl_to_int(preview_tile_size_y_no_label(size_px) + font_height + pad);
5464}
5465
5466int preview_tile_size_y_no_label(const int size_px)
5467{
5468 const float pad = PREVIEW_TILE_PAD;
5469 return round_fl_to_int((size_px / 20.0f) * UI_UNIT_Y + 2.0f * pad);
5470}
5471
5472#undef PREVIEW_TILE_PAD
5473
5475
5476/* -------------------------------------------------------------------- */
5479
5480static void but_update_and_icon_set(Button *but, int icon)
5481{
5482 if (icon) {
5483 def_but_icon(but, icon, UI_HAS_ICON);
5484 }
5485
5486 button_update(but);
5487}
5488
5490 ButtonType type,
5491 const std::optional<StringRef> str,
5492 int x,
5493 int y,
5494 short width,
5495 short height,
5496 PointerRNA *ptr,
5497 const StringRefNull propname,
5498 int index,
5499 float min,
5500 float max,
5501 const std::optional<StringRef> tip)
5502{
5504 block, type, str, x, y, width, height, ptr, propname, index, min, max, tip);
5505 button_update(but);
5506 return but;
5507}
5509 ButtonType type,
5510 const std::optional<StringRef> str,
5511 int x,
5512 int y,
5513 short width,
5514 short height,
5515 PointerRNA *ptr,
5516 PropertyRNA *prop,
5517 int index,
5518 float min,
5519 float max,
5520 const std::optional<StringRef> tip)
5521{
5522 Button *but = def_but_rna(
5523 block, type, str, x, y, width, height, ptr, prop, index, min, max, tip);
5524 button_update(but);
5525 return but;
5526}
5527
5529 ButtonType type,
5530 wmOperatorType *ot,
5531 wm::OpCallContext opcontext,
5532 const StringRef str,
5533 int x,
5534 int y,
5535 short width,
5536 short height,
5537 const std::optional<StringRef> tip)
5538{
5539 Button *but = def_but_operator_ptr(block, type, ot, opcontext, str, x, y, width, height, tip);
5540 button_update(but);
5541 return but;
5542}
5544 ButtonType type,
5545 const StringRefNull opname,
5546 wm::OpCallContext opcontext,
5547 std::optional<StringRef> str,
5548 int x,
5549 int y,
5550 short width,
5551 short height,
5552 const std::optional<StringRef> tip)
5553{
5554 wmOperatorType *ot = WM_operatortype_find(opname.c_str(), false);
5555 if (!str && ot == nullptr) {
5556 str = opname;
5557 }
5558 return uiDefButO_ptr(block, type, ot, opcontext, *str, x, y, width, height, tip);
5559}
5560
5562 ButtonTypeWithPointerType but_and_ptr_type,
5563 int icon,
5564 int x,
5565 int y,
5566 short width,
5567 short height,
5568 void *poin,
5569 float min,
5570 float max,
5571 const std::optional<StringRef> tip)
5572{
5573 Button *but = def_but(block, but_and_ptr_type, "", x, y, width, height, poin, min, max, tip);
5574 but_update_and_icon_set(but, icon);
5575 return but;
5576}
5578 ButtonType type,
5579 int icon,
5580 int x,
5581 int y,
5582 short width,
5583 short height,
5584 void *poin,
5585 float min,
5586 float max,
5587 const std::optional<StringRef> tip)
5588{
5589 Button *but = def_but(block, type, "", x, y, width, height, poin, min, max, tip);
5590 if (icon) {
5592
5593 /* Use the exact button size for the preview. Or do we need to let the caller control this? */
5595 but->drawflag &= ~BUT_ICON_LEFT;
5596 }
5597
5598 button_update(but);
5599 return but;
5600}
5602 ButtonType type,
5603 int icon,
5604 int x,
5605 int y,
5606 short width,
5607 short height,
5608 PointerRNA *ptr,
5609 const StringRefNull propname,
5610 int index,
5611 float min,
5612 float max,
5613 const std::optional<StringRef> tip)
5614{
5616 block, type, "", x, y, width, height, ptr, propname, index, min, max, tip);
5617 but_update_and_icon_set(but, icon);
5618 return but;
5619}
5621 ButtonType type,
5622 int icon,
5623 int x,
5624 int y,
5625 short width,
5626 short height,
5627 PointerRNA *ptr,
5628 PropertyRNA *prop,
5629 int index,
5630 float min,
5631 float max,
5632 const std::optional<StringRef> tip)
5633{
5634 Button *but = def_but_rna(block, type, "", x, y, width, height, ptr, prop, index, min, max, tip);
5635 but_update_and_icon_set(but, icon);
5636 return but;
5637}
5638
5640 ButtonType type,
5641 wmOperatorType *ot,
5642 wm::OpCallContext opcontext,
5643 int icon,
5644 int x,
5645 int y,
5646 short width,
5647 short height,
5648 const std::optional<StringRef> tip)
5649{
5650 Button *but = def_but_operator_ptr(block, type, ot, opcontext, "", x, y, width, height, tip);
5651 but_update_and_icon_set(but, icon);
5652 return but;
5653}
5655 ButtonType type,
5656 const StringRefNull opname,
5657 wm::OpCallContext opcontext,
5658 int icon,
5659 int x,
5660 int y,
5661 short width,
5662 short height,
5663 const std::optional<StringRef> tip)
5664{
5665 wmOperatorType *ot = WM_operatortype_find(opname.c_str(), false);
5666 return uiDefIconButO_ptr(block, type, ot, opcontext, icon, x, y, width, height, tip);
5667}
5668
5670 ButtonTypeWithPointerType but_and_ptr_type,
5671 int icon,
5672 const StringRef str,
5673 int x,
5674 int y,
5675 short width,
5676 short height,
5677 void *poin,
5678 const std::optional<StringRef> tip)
5679{
5680 Button *but = def_but(block, but_and_ptr_type, str, x, y, width, height, poin, 0.0f, 0.0f, tip);
5681 but_update_and_icon_set(but, icon);
5682 but->drawflag |= BUT_ICON_LEFT;
5683 return but;
5684}
5686 ButtonType type,
5687 int icon,
5688 const std::optional<StringRefNull> str,
5689 int x,
5690 int y,
5691 short width,
5692 short height,
5693 PointerRNA *ptr,
5694 StringRefNull propname,
5695 int index,
5696 const std::optional<StringRef> tip)
5697{
5699 block, type, str, x, y, width, height, ptr, propname, index, 0.0f, 0.0f, tip);
5700 but_update_and_icon_set(but, icon);
5701 but->drawflag |= BUT_ICON_LEFT;
5702 return but;
5703}
5705 ButtonType type,
5706 int icon,
5707 const std::optional<StringRef> str,
5708 int x,
5709 int y,
5710 short width,
5711 short height,
5712 PointerRNA *ptr,
5713 PropertyRNA *prop,
5714 int index,
5715 float min,
5716 float max,
5717 const std::optional<StringRef> tip)
5718{
5719 Button *but = def_but_rna(
5720 block, type, str, x, y, width, height, ptr, prop, index, min, max, tip);
5721 but_update_and_icon_set(but, icon);
5722 but->drawflag |= BUT_ICON_LEFT;
5723 return but;
5724}
5726 ButtonType type,
5727 wmOperatorType *ot,
5728 wm::OpCallContext opcontext,
5729 int icon,
5730 const StringRef str,
5731 int x,
5732 int y,
5733 short width,
5734 short height,
5735 const std::optional<StringRef> tip)
5736{
5737 Button *but = def_but_operator_ptr(block, type, ot, opcontext, str, x, y, width, height, tip);
5738 but_update_and_icon_set(but, icon);
5739 but->drawflag |= BUT_ICON_LEFT;
5740 return but;
5741}
5743 ButtonType type,
5744 const StringRefNull opname,
5745 wm::OpCallContext opcontext,
5746 int icon,
5747 const StringRef str,
5748 int x,
5749 int y,
5750 short width,
5751 short height,
5752 const std::optional<StringRef> tip)
5753{
5754 wmOperatorType *ot = WM_operatortype_find(opname.c_str(), false);
5755 if (str.is_empty()) {
5756 return uiDefIconButO_ptr(block, type, ot, opcontext, icon, x, y, width, height, tip);
5757 }
5758 return uiDefIconTextButO_ptr(block, type, ot, opcontext, icon, str, x, y, width, height, tip);
5759}
5760
5762 wmOperatorType *optype,
5763 wm::OpCallContext opcontext,
5764 const PointerRNA *opptr)
5765{
5766 but->optype = optype;
5767 but->opcontext = opcontext;
5768 but->flag &= ~BUT_UNDO; /* no need for but_is_rna_undo(), we never need undo here */
5769
5770 if (but->opptr) {
5771 MEM_delete(but->opptr);
5772 but->opptr = nullptr;
5773 }
5774 if (opptr) {
5775 but->opptr = MEM_new<PointerRNA>(__func__, *opptr);
5776 }
5777}
5778
5780{
5781 but->operator_never_call = true;
5782}
5783
5785
5786/* -------------------------------------------------------------------- */
5789
5790int blocklist_min_y_get(ListBaseT<Block> *lb)
5791{
5792 int min = 0;
5793
5794 for (Block &block : *lb) {
5795 if (&block == lb->first_ || block.rect.ymin < min) {
5796 min = block.rect.ymin;
5797 }
5798 }
5799
5800 return min;
5801}
5802
5803void block_direction_set(Block *block, char direction)
5804{
5805 block->direction = direction;
5806}
5807
5808void block_flag_enable(Block *block, int flag)
5809{
5810 block->flag |= flag;
5811}
5812
5813void block_flag_disable(Block *block, int flag)
5814{
5815 block->flag &= ~flag;
5816}
5817
5819{
5820 but->flag |= flag;
5821}
5822
5824{
5825 but->flag &= ~flag;
5826}
5827
5829{
5830 return (but->flag & flag) != 0;
5831}
5832
5833void button_drawflag_enable(Button *but, int flag)
5834{
5835 but->drawflag |= flag;
5836}
5837
5839{
5840 but->drawflag &= ~flag;
5841}
5842
5843void button_dragflag_enable(Button *but, int flag)
5844{
5845 but->dragflag |= flag;
5846}
5847
5849{
5850 but->dragflag &= ~flag;
5851}
5852
5853void button_disable(Button *but, const char *disabled_hint)
5854{
5856
5857 /* Only one disabled hint at a time currently. Don't override the previous one here. */
5858 if (but->disabled_info && but->disabled_info[0]) {
5859 return;
5860 }
5861
5862 but->disabled_info = disabled_hint;
5863}
5864
5866{
5867 copy_v4_v4_uchar(but->col, color);
5868}
5869
5874
5876{
5877 return button_is_color_gamma(&but);
5878}
5879
5880void button_placeholder_set(Button *but, const StringRef placeholder_text)
5881{
5882 MEM_SAFE_DELETE(but->placeholder);
5883 if (placeholder_text.is_empty()) {
5884 but->placeholder = nullptr;
5885 }
5886 else {
5887 but->placeholder = BLI_strdupn(placeholder_text.data(), placeholder_text.size());
5888 }
5889}
5890
5892{
5893 const char *placeholder = (but->placeholder) ? but->placeholder : nullptr;
5894
5895 if (!placeholder && but->rnaprop) {
5896 if (but->type == ButtonType::SearchMenu) {
5898 const short idcode = RNA_type_to_ID_code(type);
5899 if (idcode != 0) {
5900 RNA_enum_name(rna_enum_id_type_items, idcode, &placeholder);
5901 placeholder = CTX_IFACE_(BLT_I18NCONTEXT_ID_ID, placeholder);
5902 }
5903 else if (type && !STREQ(RNA_struct_identifier(type), "UnknownType")) {
5904 placeholder = RNA_struct_ui_name(type);
5905 }
5906 }
5907 else if (but->type == ButtonType::Text && but->icon == ICON_VIEWZOOM) {
5908 placeholder = CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Search");
5909 }
5910 }
5911
5912 return placeholder;
5913}
5914
5922
5924{
5925 return but->retval;
5926}
5927
5929{
5930 if (but->optype && !but->opptr) {
5931 but->opptr = MEM_new<PointerRNA>(__func__, WM_operator_properties_create_ptr(but->optype));
5932 }
5933
5934 return but->opptr;
5935}
5936
5938
5939/* -------------------------------------------------------------------- */
5942
5943void button_context_ptr_set(Block *block, Button *but, const StringRef name, const PointerRNA *ptr)
5944{
5945 bContextStore *ctx = CTX_store_add(block->contexts, name, ptr);
5946 ctx->used = true;
5947 but->context = ctx;
5948}
5949
5950void button_context_int_set(Block *block, Button *but, const StringRef name, const int64_t value)
5951{
5952 bContextStore *ctx = CTX_store_add(block->contexts, name, value);
5953 ctx->used = true;
5954 but->context = ctx;
5955}
5956
5958 const StringRef name,
5959 const StructRNA *type)
5960{
5961 return CTX_store_ptr_lookup(but->context, name, type);
5962}
5963
5964std::optional<StringRefNull> button_context_string_get(const Button *but, const StringRef name)
5965{
5966 if (!but->context) {
5967 return {};
5968 }
5969 return CTX_store_string_lookup(but->context, name);
5970}
5971
5972std::optional<int64_t> button_context_int_get(const Button *but, const StringRef name)
5973{
5974 if (!but->context) {
5975 return {};
5976 }
5977 return CTX_store_int_lookup(but->context, name);
5978}
5979
5981{
5982 return but->context;
5983}
5984
5985void button_unit_type_set(Button *but, const int unit_type)
5986{
5987 but->unit_type = uchar(RNA_SUBTYPE_UNIT_VALUE(unit_type));
5988}
5989
5991{
5992 const int ownUnit = int(but->unit_type);
5993
5994 /* own unit define always takes precedence over RNA provided, allowing for overriding
5995 * default value provided in RNA in a few special cases (i.e. Active Keyframe in Graph Edit)
5996 */
5997 /* XXX: this doesn't allow clearing unit completely, though the same could be said for icons */
5998 if ((ownUnit != 0) || (but->rnaprop == nullptr)) {
5999 return ownUnit << 16;
6000 }
6002}
6003
6004void block_func_handle_set(Block *block, BlockHandleFunc func, void *arg)
6005{
6006 block->handle_func = func;
6007 block->handle_func_arg = arg;
6008}
6009
6010void block_func_set(Block *block, ButtonHandleFunc func, void *arg1, void *arg2)
6011{
6012 block->func = func;
6013 block->func_arg1 = arg1;
6014 block->func_arg2 = arg2;
6015}
6016
6018 ButtonHandleNFunc funcN,
6019 void *argN,
6020 void *arg2,
6021 ButtonArgNFree func_argN_free_fn,
6022 ButtonArgNCopy func_argN_copy_fn)
6023{
6024 if (block->func_argN) {
6025 block->func_argN_free_fn(block->func_argN);
6026 }
6027
6028 block->funcN = funcN;
6029 block->func_argN = argN;
6030 block->func_argN_free_fn = func_argN_free_fn;
6031 block->func_argN_copy_fn = func_argN_copy_fn;
6032 block->func_arg2 = arg2;
6033}
6034
6036{
6037 return but->func_argN;
6038}
6039
6041 void *poin,
6042 void *argN,
6043 ButtonArgNFree func_argN_free_fn,
6044 ButtonArgNCopy func_argN_copy_fn)
6045{
6047 but->poin = reinterpret_cast<char *>(poin);
6048 if (but->func_argN) {
6049 but->func_argN_free_fn(but->func_argN);
6050 }
6051 but->func_argN = argN;
6052 but->func_argN_free_fn = func_argN_free_fn;
6053 but->func_argN_copy_fn = func_argN_copy_fn;
6054}
6055
6057 Button *but, std::function<void(bContext &C, StringRefNull oldname)> rename_func)
6058{
6060 auto *text_button = static_cast<ButtonText *>(but);
6061 text_button->rename_func = std::move(rename_func);
6062}
6063
6065 std::function<void(StringRefNull new_name)> rename_full_fun)
6066{
6068 auto *text_button = static_cast<ButtonText *>(but);
6069 text_button->rename_full_func = std::move(rename_full_fun);
6070}
6071
6073 std::function<void(const bContext *C, rcti *rect)> func)
6074{
6075 block->drawextra = std::move(func);
6076}
6077
6078void button_func_set(Button *but, ButtonHandleFunc func, void *arg1, void *arg2)
6079{
6080 but->func = func;
6081 but->func_arg1 = arg1;
6082 but->func_arg2 = arg2;
6083}
6084
6085void button_func_set(Button *but, std::function<void(bContext &)> func)
6086{
6087 but->apply_func = std::move(func);
6088}
6089
6091 ButtonHandleNFunc funcN,
6092 void *argN,
6093 void *arg2,
6094 ButtonArgNFree func_argN_free_fn,
6095 ButtonArgNCopy func_argN_copy_fn)
6096{
6097 if (but->func_argN) {
6098 but->func_argN_free_fn(but->func_argN);
6099 }
6100
6101 but->funcN = funcN;
6102 but->func_argN = argN;
6103 but->func_argN_free_fn = func_argN_free_fn;
6104 but->func_argN_copy_fn = func_argN_copy_fn;
6105 but->func_arg2 = arg2;
6106}
6107
6109{
6110 but->autocomplete_func = func;
6111 but->autofunc_arg = arg;
6112}
6113
6115{
6116 but->menu_step_func = func;
6117}
6118
6120{
6121 but->menu_no_hover_open = true;
6122}
6123
6124void button_func_quick_tooltip_set(Button *but, std::function<std::string(const Button *but)> func)
6125{
6126 but->tip_quick_func = std::move(func);
6128}
6129
6131{
6132 but->tip_func = func;
6133 if (but->tip_arg_free) {
6134 but->tip_arg_free(but->tip_arg);
6135 }
6136 but->tip_arg = arg;
6137 but->tip_arg_free = free_arg;
6138}
6139
6142 void *arg,
6143 FreeArgFunc free_arg)
6144{
6145 but->tip_custom_func = func;
6146 if (but->tip_arg_free) {
6147 but->tip_arg_free(but->tip_arg);
6148 }
6149 but->tip_arg = arg;
6150 but->tip_arg_free = free_arg;
6151}
6152
6153void button_func_pushed_state_set(Button *but, std::function<bool(const Button &)> func)
6154{
6155 but->pushed_state_func = std::move(func);
6156 button_update(but);
6157}
6158
6160
6161/* -------------------------------------------------------------------- */
6164
6166 BlockCreateFunc func,
6167 void *arg,
6168 const StringRef str,
6169 int x,
6170 int y,
6171 short width,
6172 short height,
6173 const std::optional<StringRef> tip)
6174{
6175 Button *but = def_but(block, ButtonType::Block, str, x, y, width, height, arg, 0.0, 0.0, tip);
6176 but->block_create_func = func;
6177 button_update(but);
6178 return but;
6179}
6180
6182 BlockCreateFunc func,
6183 void *argN,
6184 const StringRef str,
6185 int x,
6186 int y,
6187 short width,
6188 short height,
6189 const std::optional<StringRef> tip,
6190 ButtonArgNFree func_argN_free_fn,
6191 ButtonArgNCopy func_argN_copy_fn)
6192{
6193 Button *but = def_but(
6194 block, ButtonType::Block, str, x, y, width, height, nullptr, 0.0, 0.0, tip);
6195 but->block_create_func = func;
6196 if (but->func_argN) {
6197 but->func_argN_free_fn(but->func_argN);
6198 }
6199 but->func_argN = argN;
6200 but->func_argN_free_fn = func_argN_free_fn;
6201 but->func_argN_copy_fn = func_argN_copy_fn;
6202 button_update(but);
6203 return but;
6204}
6205
6207 MenuCreateFunc func,
6208 void *arg,
6209 const StringRef str,
6210 int x,
6211 int y,
6212 short width,
6213 short height,
6214 const std::optional<StringRef> tip)
6215{
6216 Button *but = def_but(block, ButtonType::Pulldown, str, x, y, width, height, arg, 0.0, 0.0, tip);
6217 but->menu_create_func = func;
6218 button_update(but);
6219 return but;
6220}
6221
6223 MenuCreateFunc func,
6224 void *arg,
6225 int icon,
6226 const StringRef str,
6227 int x,
6228 int y,
6229 short width,
6230 short height,
6231 const std::optional<StringRef> tip)
6232{
6233 Button *but = def_but(block, ButtonType::Pulldown, str, x, y, width, height, arg, 0.0, 0.0, tip);
6234
6235 def_but_icon(but, icon, UI_HAS_ICON);
6236
6237 but->drawflag |= BUT_ICON_LEFT;
6238 but_submenu_enable(block, but);
6239
6240 but->menu_create_func = func;
6241 button_update(but);
6242
6243 return but;
6244}
6245
6247 MenuCreateFunc func,
6248 void *arg,
6249 int icon,
6250 int x,
6251 int y,
6252 short width,
6253 short height,
6254 const std::optional<StringRef> tip)
6255{
6256 Button *but = def_but(block, ButtonType::Pulldown, "", x, y, width, height, arg, 0.0, 0.0, tip);
6257
6258 def_but_icon(but, icon, UI_HAS_ICON);
6259 but->drawflag &= ~BUT_ICON_LEFT;
6260
6261 but->menu_create_func = func;
6262 button_update(but);
6263
6264 return but;
6265}
6266
6268 BlockCreateFunc func,
6269 void *arg,
6270 int icon,
6271 int x,
6272 int y,
6273 short width,
6274 short height,
6275 const std::optional<StringRef> tip)
6276{
6277 Button *but = def_but(block, ButtonType::Block, "", x, y, width, height, arg, 0.0, 0.0, tip);
6278
6279 def_but_icon(but, icon, UI_HAS_ICON);
6280
6281 but->drawflag |= BUT_ICON_LEFT;
6282
6283 but->block_create_func = func;
6284 button_update(but);
6285
6286 return but;
6287}
6288
6290
6291/* -------------------------------------------------------------------- */
6294
6296 void *arg,
6297 int icon,
6298 int maxncpy,
6299 int x,
6300 int y,
6301 short width,
6302 short height,
6303 const std::optional<StringRef> tip)
6304{
6305 Button *but = def_but(
6306 block, ButtonType::SearchMenu, "", x, y, width, height, arg, 0.0, maxncpy, tip);
6307
6308 def_but_icon(but, icon, UI_HAS_ICON);
6309
6311
6312 button_update(but);
6313
6314 return but;
6315}
6316
6318 ButtonSearchCreateFn search_create_fn,
6319 ButtonSearchUpdateFn search_update_fn,
6320 void *arg,
6321 const bool free_arg,
6322 FreeArgFunc search_arg_free_fn,
6323 ButtonHandleFunc search_exec_fn,
6324 void *active)
6325{
6326 ButtonSearch *search_but = static_cast<ButtonSearch *>(but);
6327
6329
6330 /* needed since callers don't have access to internal functions
6331 * (as an alternative we could expose it) */
6332 if (search_create_fn == nullptr) {
6333 search_create_fn = searchbox_create_generic;
6334 }
6335
6336 search_but->popup_create_fn = search_create_fn;
6337 search_but->items_update_fn = search_update_fn;
6338 search_but->item_active = active;
6339
6340 if (free_arg && !search_arg_free_fn) {
6341 search_arg_free_fn = MEM_delete_void;
6342 }
6343 search_but->arg = std::shared_ptr<void>(
6344 arg,
6345 search_arg_free_fn ?
6346 search_arg_free_fn :
6347 [](void *) { /* Pointer does not need freeing, do nothing in the deleter callback. */ });
6348
6349 if (search_exec_fn) {
6350#ifndef NDEBUG
6351 if (but->func) {
6352 /* watch this, can be cause of much confusion, see: #47691 */
6353 printf("%s: warning, overwriting button callback with search function callback!\n",
6354 __func__);
6355 }
6356#endif
6357 /* Handling will pass the active item as arg2 later, so keep it nullptr here. */
6358 if (free_arg) {
6359 /* XXX This is only done so `but_equals_old()` can recognize this button over redraws,
6360 * otherwise interaction breaks entirely. Unlike #button_funcN_set(), #button_func_set() sets
6361 * arg1, which takes part in the comparison, so the pointer needs to be stable over redraws.
6362 * #button_funcN_set() doesn't set it, but takes ownership of the memory and frees it later.
6363 * So give it a duplicate of the memory. */
6364 button_funcN_set(but, search_exec_fn, MEM_dupalloc_void(search_but->arg.get()), nullptr);
6365 }
6366 else {
6367 button_func_set(but, search_exec_fn, search_but->arg.get(), nullptr);
6368 }
6369 }
6370
6371 /* search buttons show red-alert if item doesn't exist, not for menus. Don't do this for
6372 * buttons where any result is valid anyway, since any string will be valid anyway. */
6373 if (0 == (but->block->flag & BLOCK_LOOP) && !search_but->results_are_suggestions) {
6374 /* skip empty buttons, not all buttons need input, we only show invalid */
6375 if (!but->drawstr.empty()) {
6376 button_search_refresh(search_but);
6377 }
6378 }
6379}
6380
6382{
6383 ButtonSearch *but_search = static_cast<ButtonSearch *>(but);
6385
6386 but_search->item_context_menu_fn = context_menu_fn;
6387}
6388
6389void button_func_search_set_sep_string(Button *but, const char *search_sep_string)
6390{
6391 ButtonSearch *but_search = static_cast<ButtonSearch *>(but);
6393
6394 but_search->item_sep_string = search_sep_string;
6395}
6396
6398{
6399 ButtonSearch *but_search = static_cast<ButtonSearch *>(but);
6401
6402 but_search->item_tooltip_fn = tooltip_fn;
6403}
6404
6406{
6407 ButtonSearch *but_search = static_cast<ButtonSearch *>(but);
6409 but_search->listen_fn = listen_fn;
6410}
6411
6413{
6414 ButtonSearch *but_search = static_cast<ButtonSearch *>(but);
6416
6417 but_search->results_are_suggestions = value;
6418}
6419
6420/* Callbacks for operator search button. */
6422 const bContext *C, void *but, const char *str, SearchItems *items, const bool /*is_first*/)
6423{
6424 wmOperatorType *ot = (static_cast<Button *>(but))->optype;
6425 PropertyRNA *prop = ot->prop;
6426
6427 if (prop == nullptr) {
6428 printf("%s: %s has no enum property set\n", __func__, ot->idname);
6429 }
6430 else if (RNA_property_type(prop) != PROP_ENUM) {
6431 printf("%s: %s \"%s\" is not an enum property\n",
6432 __func__,
6433 ot->idname,
6435 }
6436 else {
6437 /* Will create it if needed! */
6438 PointerRNA *ptr = button_operator_ptr_ensure(static_cast<Button *>(but));
6439
6440 bool do_free;
6441 const EnumPropertyItem *all_items;
6443 const_cast<bContext *>(C), ptr, prop, &all_items, nullptr, &do_free);
6444
6446
6447 for (const EnumPropertyItem *item = all_items; item->identifier; item++) {
6448 search.add(item->name, item);
6449 }
6450
6451 const Vector<const EnumPropertyItem *> filtered_items = search.query(str);
6452 for (const EnumPropertyItem *item : filtered_items) {
6453 /* NOTE: need to give the index rather than the
6454 * identifier because the enum can be freed */
6455 if (!search_item_add(items, item->name, POINTER_FROM_INT(item->value), item->icon, 0, 0)) {
6456 break;
6457 }
6458 }
6459
6460 if (do_free) {
6461 MEM_delete(all_items);
6462 }
6463 }
6464}
6465
6466static void operator_enum_search_exec_fn(bContext * /*C*/, void *but, void *arg2)
6467{
6468 wmOperatorType *ot = (static_cast<Button *>(but))->optype;
6469 /* Will create it if needed! */
6470 PointerRNA *opptr = button_operator_ptr_ensure(static_cast<Button *>(but));
6471
6472 if (ot) {
6473 if (ot->prop) {
6474 RNA_property_enum_set(opptr, ot->prop, POINTER_AS_INT(arg2));
6475 /* We do not call op from here, will be called by button code.
6476 * apply_but_funcs_after() (in `interface_handlers.cc`)
6477 * called this func before checking operators,
6478 * because one of its parameters is the button itself! */
6479 }
6480 else {
6481 printf("%s: op->prop for '%s' is nullptr\n", __func__, ot->idname);
6482 }
6483 }
6484}
6485
6487 wmOperatorType *ot,
6488 IDProperty *properties,
6489 void *arg,
6490 int icon,
6491 int maxncpy,
6492 int x,
6493 int y,
6494 short width,
6495 short height,
6496 const std::optional<StringRef> tip)
6497{
6498 Button *but = uiDefSearchBut(block, arg, icon, maxncpy, x, y, width, height, tip);
6502 but,
6503 false,
6504 nullptr,
6506 nullptr);
6507
6508 but->optype = ot;
6510
6511 if (properties) {
6513 /* Copy id-properties. */
6514 ptr->data = IDP_CopyProperty(properties);
6515 }
6516
6517 return but;
6518}
6519
6521
6522/* -------------------------------------------------------------------- */
6525
6526void button_hint_drawstr_set(Button *but, const char *string)
6527{
6528 button_add_shortcut(but, string, false);
6529}
6530
6531void button_icon_scale_set(Button *but, const float scale)
6532{
6533 but->icon_scale = scale;
6534}
6535
6536void button_icon_indicator_number_set(Button *but, const int indicator_number)
6537{
6539}
6540
6541void button_icon_indicator_set(Button *but, const char *string)
6542{
6543 STRNCPY_UTF8(but->icon_overlay_text.text, string);
6544}
6545
6550
6551void button_node_link_set(Button *but, bNodeSocket *socket, const float draw_color[4])
6552{
6553 but->flag |= BUT_NODE_LINK;
6554 but->custom_data = socket;
6555 rgba_float_to_uchar(but->col, draw_color);
6556}
6557
6559{
6560 ButtonPush *but_push = static_cast<ButtonPush *>(but);
6562
6563 but_push->draw_as_overlay = value;
6564}
6565
6566void button_number_step_size_set(Button *but, float step_size)
6567{
6568 ButtonNumber *but_number = static_cast<ButtonNumber *>(but);
6570
6571 but_number->step_size = step_size;
6572 BLI_assert(step_size > 0);
6573}
6574
6575void button_number_precision_set(Button *but, float precision)
6576{
6577 ButtonNumber *but_number = static_cast<ButtonNumber *>(but);
6579
6580 but_number->precision = precision;
6581 /* -1 is a valid value, UI code figures out an appropriate precision then. */
6582 BLI_assert(precision > -2);
6583}
6584
6586{
6587 ButtonNumberSlider *but_number = static_cast<ButtonNumberSlider *>(but);
6589
6590 but_number->step_size = step_size;
6591 BLI_assert(step_size > 0);
6592}
6593
6595{
6596 ButtonNumberSlider *but_number = static_cast<ButtonNumberSlider *>(but);
6598
6599 but_number->precision = precision;
6600 /* -1 is a valid value, UI code figures out an appropriate precision then. */
6601 BLI_assert(precision > -2);
6602}
6603
6604void button_label_alpha_factor_set(Button *but, const float alpha_factor)
6605{
6606 ButtonLabel *but_label = reinterpret_cast<ButtonLabel *>(but);
6608 but_label->alpha_factor = alpha_factor;
6609}
6610
6611void button_label_draw_icon_border_set(Button *but, const bool use_icon_border)
6612{
6613 ButtonLabel *but_label = reinterpret_cast<ButtonLabel *>(but);
6615 but_label->draw_icon_border = use_icon_border;
6616}
6617
6618void button_search_preview_grid_size_set(Button *but, int rows, int cols)
6619{
6621 ButtonSearch *but_search = reinterpret_cast<ButtonSearch *>(but);
6622 but_search->preview_rows = rows;
6623 but_search->preview_cols = cols;
6624}
6625
6627 const std::optional<int> draw_width,
6628 const std::optional<int> draw_height)
6629{
6631 ButtonViewItem *but_view_item = reinterpret_cast<ButtonViewItem *>(but);
6632 but_view_item->draw_width = draw_width.value_or(0);
6633 but_view_item->draw_height = draw_height.value_or(0);
6634}
6635
6637{
6638 wmEvent event;
6639 wm_event_init_from_window(win, &event);
6640
6641 event.type = EVT_BUT_OPEN;
6642 event.val = KM_PRESS;
6643 event.flag = static_cast<eWM_EventFlag>(0);
6644 event.customdata = but;
6645 event.customdata_free = false;
6646
6647 WM_event_add(win, &event);
6648}
6649
6651{
6652 but->hold_func = func;
6653 but->hold_argN = argN;
6654}
6655
6657
6658/* -------------------------------------------------------------------- */
6661
6662std::optional<EnumPropertyItem> button_rna_enum_item_get(bContext &C, Button &but)
6663{
6664 PointerRNA *ptr = nullptr;
6665 PropertyRNA *prop = nullptr;
6666 int value = 0;
6667 if (but.rnaprop && RNA_property_type(but.rnaprop) == PROP_ENUM) {
6668 ptr = &but.rnapoin;
6669 prop = but.rnaprop;
6670 value = ELEM(but.type, ButtonType::Row, ButtonType::Tab) ? int(but.hardmax) :
6671 int(button_value_get(&but));
6672 }
6673 else if (but.optype) {
6674 wmOperatorType *ot = but.optype;
6675
6676 /* So the context is passed to `itemf` functions. */
6678 WM_operator_properties_sanitize(opptr, false);
6679
6680 /* If the default property of the operator is an enum and is set, fetch the tooltip of the
6681 * selected value so that "Snap" and "Mirror" operator menus in the Animation Editors will
6682 * show tooltips for the different operations instead of the meaningless generic tooltip. */
6683 if (ot->prop && RNA_property_type(ot->prop) == PROP_ENUM) {
6684 if (RNA_struct_contains_property(opptr, ot->prop)) {
6685 ptr = opptr;
6686 prop = ot->prop;
6687 value = RNA_property_enum_get(opptr, ot->prop);
6688 }
6689 }
6690 }
6691
6692 if (!ptr || !prop) {
6693 return std::nullopt;
6694 }
6695
6696 EnumPropertyItem item;
6697 if (!RNA_property_enum_item_from_value_gettexted(&C, ptr, prop, value, &item)) {
6698 return std::nullopt;
6699 }
6700
6701 return item;
6702}
6703
6705{
6706 if (!but.rnaprop) {
6707 return {};
6708 }
6709 return RNA_property_identifier(but.rnaprop);
6710}
6711
6713{
6714 if (but.rnaprop && but.rnapoin) {
6716 }
6717 if (but.optype) {
6718 return but.optype->idname;
6719 }
6721 if (MenuType *mt = button_menutype_get(&but)) {
6722 return mt->idname;
6723 }
6724 }
6725 if (but.type == ButtonType::Popover) {
6726 if (PanelType *pt = button_paneltype_get(&but)) {
6727 return pt->idname;
6728 }
6729 }
6730 return {};
6731}
6732
6734{
6735 if (!but.str.empty()) {
6736 size_t str_len = but.str.size();
6737 if (but.flag & BUT_HAS_SEP_CHAR) {
6738 const size_t sep_index = but.str.find_first_of(UI_SEP_CHAR);
6739 if (sep_index != std::string::npos) {
6740 str_len = sep_index;
6741 }
6742 }
6743 return but.str.substr(0, str_len);
6744 }
6745
6746 return button_string_get_rna_label(but);
6747}
6748
6750{
6751 if (but.type == ButtonType::ViewItem) {
6752 const auto &view_item_but = static_cast<const ButtonViewItem &>(but);
6753 if (view_item_but.view_item == nullptr) {
6754 return "";
6755 }
6756 const AbstractView &tree_view = view_item_but.view_item->get_view();
6757 return IFACE_(tree_view.get_context_menu_title());
6758 }
6759 return button_string_get_label(but);
6760}
6761
6763{
6764 if (!but.tip_quick_func) {
6765 return {};
6766 }
6767 return but.tip_quick_func(&but);
6768}
6769
6771{
6772 if (but.rnaprop) {
6773 return RNA_property_ui_name(but.rnaprop, &but.rnapoin);
6774 }
6775 if (but.optype) {
6777 return WM_operatortype_name(but.optype, opptr);
6778 }
6780 if (MenuType *mt = button_menutype_get(&but)) {
6781 return CTX_TIP_(mt->translation_context, mt->label);
6782 }
6783
6784 if (wmOperatorType *ot = button_operatortype_get_from_enum_menu(&but, nullptr)) {
6785 return WM_operatortype_name(ot, nullptr);
6786 }
6787
6788 if (PanelType *pt = button_paneltype_get(&but)) {
6789 return CTX_TIP_(pt->translation_context, pt->label);
6790 }
6791 }
6792 return {};
6793}
6794
6796{
6797 if (but.rnaprop) {
6799 }
6800 if (but.optype) {
6802 }
6804 if (MenuType *mt = button_menutype_get(&but)) {
6805 return RNA_struct_translation_context(mt->rna_ext.srna);
6806 }
6807 }
6809}
6810
6812{
6813 if (but.tip_func) {
6814 return but.tip_func(&C, but.tip_arg, but.tip);
6815 }
6816 if (!but.tip.is_empty()) {
6817 return but.tip;
6818 }
6819 return button_string_get_rna_tooltip(C, but);
6820}
6821
6823{
6824 if (but.rnaprop) {
6825 const char *t = RNA_property_ui_description(but.rnaprop, &but.rnapoin);
6826 if (t && t[0]) {
6827 return t;
6828 }
6829 }
6830 else if (but.optype) {
6832 const bContextStore *previous_ctx = CTX_store_get(&C);
6833 CTX_store_set(&C, but.context);
6834 std::string tmp = WM_operatortype_description(&C, but.optype, opptr);
6835 CTX_store_set(&C, previous_ctx);
6836 return tmp;
6837 }
6839 if (MenuType *mt = button_menutype_get(&but)) {
6840 /* Not all menus are from Python. */
6841 if (mt->rna_ext.srna) {
6842 const char *t = RNA_struct_ui_description(mt->rna_ext.srna);
6843 if (t && t[0]) {
6844 return t;
6845 }
6846 }
6847 }
6848
6849 if (wmOperatorType *ot = button_operatortype_get_from_enum_menu(&but, nullptr)) {
6850 return WM_operatortype_description(&C, ot, nullptr);
6851 }
6852 }
6853
6854 return {};
6855}
6856
6858{
6859 return but_event_operator_string(&C, &but).value_or("");
6860}
6861
6863{
6864 return but_event_property_operator_string(&C, &but).value_or("");
6865}
6866
6868{
6871 return WM_operatortype_name(optype, opptr);
6872}
6873
6875{
6878 return WM_operatortype_description(&C, optype, opptr);
6879}
6880
6882 const ButtonExtraOpIcon &extra_icon)
6883{
6884 return but_extra_icon_event_operator_string(&C, &extra_icon).value_or("");
6885}
6886
6888
6889/* -------------------------------------------------------------------- */
6892
6893void init()
6894{
6896}
6897
6899{
6900 /* Initialize UI variables from values set in the preferences. */
6901 style_init();
6902}
6903
6905{
6906 style_init();
6907}
6908
6910{
6911 if (BLF_has_variable_weight(0)) {
6912 return;
6913 }
6914
6915 uiStyle *style = U.uistyles.first();
6916 const int weight = BLF_default_weight(0);
6917 style->paneltitle.character_weight = weight;
6918 style->grouplabel.character_weight = weight;
6919 style->widget.character_weight = weight;
6920 style->tooltip.character_weight = weight;
6921}
6922
6923void exit()
6924{
6927}
6928
6933
6935
6936/* -------------------------------------------------------------------- */
6939
6940int button_text_padding(const Button *button)
6941{
6942 return round_fl_to_int((UI_TEXT_MARGIN_X * U.widget_unit) / button->block->aspect);
6943}
6944
6945std::string button_get_link(const Button *button, bContext *C)
6946{
6948 if (STREQ(button->optype->idname, "WM_OT_url_open")) {
6949 return RNA_string_get(button->opptr, "url");
6950 }
6951#ifdef WITH_PYTHON
6952 const char *expr_imports[] = {"bpy", nullptr};
6953 char expr[256];
6954
6955 PropertyRNA *prop = RNA_struct_find_property(button->opptr, "type");
6956
6957 const int active_item = RNA_property_enum_get(button->opptr, prop);
6958 EnumPropertyItem item;
6959 const bool found = RNA_property_enum_item_from_value(C, button->opptr, prop, active_item, &item);
6960 if (!found) {
6961 return "";
6962 }
6964 expr, "bpy.types.WM_OT_url_open_preset.lookup_url_from_type('%s')", item.identifier);
6965 char *expr_result = nullptr;
6966 std::string link;
6967 if (BPY_run_string_as_string(C, expr_imports, expr, nullptr, &expr_result)) {
6968 link = expr_result;
6969 MEM_delete(expr_result);
6970 }
6971 return link;
6972#else
6973 return "";
6974#endif
6975}
6976
6978
6979} // namespace blender::ui
#define ATTR_FALLTHROUGH
#define BLF_DRAW_STR_DUMMY_MAX
Definition BLF_api.hh:456
#define M_LN10
#define BLI_SCOPED_DEFER(function_to_defer)
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
#define BLT_I18NCONTEXT_ID_WINDOWMANAGER
#define RPT_(msgid)
#define BLT_I18NCONTEXT_ID_ID
#define CTX_IFACE_(context, msgid)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
#define CTX_TIP_(context, msgid)
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define ID_CHECK_UNDO(id)
Definition DNA_ID.h:686
These structs are the foundation for all linked lists in the library system.
Object is a sort of wrapper for general info.
#define OB_DATA_SUPPORT_ID(_id_type)
#define FRA2TIME(a)
#define UI_SCALE_FAC
Read Blender memory allocation and freeing.
#define RNA_SUBTYPE_UNIT_VALUE(subtype)
Definition RNA_types.hh:268
#define RNA_SUBTYPE_UNIT(subtype)
Definition RNA_types.hh:266
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_SEP_CHAR_S
#define AUTOCOMPLETE_FULL_MATCH
#define UI_SEP_CHAR
#define AUTOCOMPLETE_PARTIAL_MATCH
#define AUTOCOMPLETE_NO_MATCH
#define UI_PANEL_MARGIN_X
#define UI_PRECISION_FLOAT_MAX
#define UI_PRECISION_FLOAT_SCALE
#define UI_FLOAT_VALUE_DISPLAY_MAX
#define button_is_decorator(but)
#define UI_SCREEN_MARGIN
#define UI_UNIT_X
#define UI_FLOAT_VALUE_DISPLAY_MIN
#define BUT_POIN_TYPES
#define UI_MAX_DRAW_STR
#define UI_MAX_NAME_STR
#define KM_MOD_HELD
Definition WM_types.hh:339
int pad[32 - sizeof(int)]
#define CLAMP(a, b, c)
#define STRPREFIX(a, b)
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define POINTER_FROM_INT(i)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define POINTER_AS_INT(i)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
void activate(bool forceActivation=false) const
btScalar max
void reserve(const int64_t n)
Definition BLI_set.hh:656
bool contains(const Key &key) const
Definition BLI_set.hh:310
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr const char * c_str() const
constexpr StringRef drop_known_prefix(StringRef prefix) const
constexpr StringRef()
constexpr bool startswith(StringRef prefix) const
constexpr bool is_empty() const
constexpr int64_t size() const
constexpr const char * data() const
void copy_utf8_truncated(char *dst, int64_t dst_size) const
Definition string_ref.cc:28
void append(const T &value)
void add(const StringRef str, T *user_data, const int weight=0)
Vector< T * > query(const StringRef query) const
std::string get_context_menu_title() const
#define str(s)
#define FLT_MAX
#define INT_MAX
#define log
#define pow
#define floor
#define ceil
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
#define PREVIEW_TILE_PAD
#define UI_GET_BUT_VALUE_INIT(_but, _value)
Definition interface.cc:91
#define BUT_VALUE_UNSET
Definition interface.cc:90
#define UI_NUMBER_EVAL_ERROR_PREFIX
#define UI_POPUP_MENU_TOP
#define UI_BITBUT_TEST(a, b)
#define UI_TEXT_MARGIN_X
#define UI_MENU_SCROLL_MOUSE
const int state
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRef prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
void free(Subdiv *subdiv)
Definition subdiv.cc:192
std::string ptr_type(const ResourceString &str)
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:68
void get_color_4ubv(int colorid, unsigned char col[4])
const bTheme * theme_get()
void button_execute_begin(bContext *, ARegion *region, Button *but, void **active_back)
void interface_tag_script_reload()
static std::optional< std::string > but_event_operator_string(const bContext *C, Button *but)
void butstore_clear(Block *block)
bool button_context_poll_operator_ex(bContext *C, const Button *but, const wmOperatorCallParams *optype_params)
void button_search_preview_grid_size_set(Button *but, int rows, int cols)
Button * uiDefIconTextBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, int icon, StringRef str, int x, int y, short width, short height, void *poin, std::optional< StringRef > tip)
void icon_text_overlay_init_from_count(IconTextOverlay *text_overlay, const int icon_indicator_number)
void block_lock_set(Block *block, bool val, const char *lockstr)
void item_menutype_func(bContext *C, Layout *layout, void *arg_mt)
static bool but_icon_extra_is_visible_search_eyedropper(Button *but)
static double soft_range_round_up(double value, double max)
void resources_init()
Definition resources.cc:55
Button * uiDefSearchButO_ptr(Block *block, wmOperatorType *ot, IDProperty *properties, void *arg, int icon, int maxncpy, int x, int y, short width, short height, std::optional< StringRef > tip)
std::string button_extra_icon_string_get_tooltip(bContext &C, const ButtonExtraOpIcon &extra_icon)
void button_anim_decorate_update_from_flag(ButtonDecorator *but)
static std::optional< std::string > but_event_operator_string_from_panel(const bContext *C, Button *but)
void block_direction_set(Block *block, char direction)
void butstore_update(Block *block)
void button_update_view_for_active(const bContext *C, const Block *block)
void blocklist_free(const bContext *C, ARegion *region)
std::string button_string_get_tooltip(bContext &C, Button &but)
int button_unit_type_get(const Button *but)
void button_search_refresh(ButtonSearch *but)
int button_string_get_maxncpy(Button *but)
ImBuf * icon_alert_imbuf_get(AlertIcon icon, float size)
static int but_calc_float_precision(Button *but, double value)
Definition interface.cc:760
static float but_get_float_step_size(Button *but)
Definition interface.cc:726
void button_execute_end(bContext *C, ARegion *, Button *but, void *active_back)
void(*)(bContext *C, Layout *layout, void *arg1) MenuCreateFunc
Button * uiDefButR(Block *block, ButtonType type, std::optional< StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, StringRefNull propname, int index, float min, float max, std::optional< StringRef > tip)
static void operator_enum_search_update_fn(const bContext *C, void *but, const char *str, SearchItems *items, const bool)
Button * uiDefIconButR(Block *block, ButtonType type, int icon, int x, int y, short width, short height, PointerRNA *ptr, StringRefNull propname, int index, float min, float max, std::optional< StringRef > tip)
static void but_predefined_extra_operator_icons_add(Button *but)
Button * uiDefIconTextButR(Block *block, ButtonType type, int icon, std::optional< StringRefNull > str, int x, int y, short width, short height, PointerRNA *ptr, StringRefNull propname, int index, std::optional< StringRef > tip)
void button_menu_disable_hover_open(Button *but)
void button_func_search_set_results_are_suggestions(Button *but, bool value)
void button_extra_operator_icons_free(Button *but)
bool button_supports_cycling(const Button *but)
static void but_submenu_enable(Block *block, Button *but)
void button_active_free(const bContext *C, Button *but)
void button_v4_set(Button *but, const float vec[4])
void button_anim_flag(Button *but, const AnimationEvalContext *anim_eval_context)
wmOperatorType * button_extra_operator_icon_optype_get(const ButtonExtraOpIcon *extra_icon)
void button_group_replace_but_ptr(Block *block, const Button *old_but_ptr, Button *new_but)
static bool number_from_string_factor(bContext *C, const char *str, double *r_value)
static void but_update_ex(Button *but, const bool validate)
void block_to_region_rctf(const ARegion *region, const Block *block, rctf *rct_dst, const rctf *rct_src)
Definition interface.cc:162
void button_string_get(Button *but, char *str, const size_t str_maxncpy)
void(*)(bContext *C, void *argN, void *arg2) ButtonHandleNFunc
void button_dragflag_disable(Button *but, int flag)
void button_label_draw_icon_border_set(Button *but, bool use_icon_border)
void(*)(bContext *C, void *arg1, void *arg2) ButtonHandleFunc
void block_set_search_only(Block *block, bool search_only)
bool button_menu_draw_as_popover(const Button *but)
void def_but_icon_clear(Button *but)
void block_to_window(const ARegion *region, const Block *block, int *x, int *y)
Definition interface.cc:151
bool button_rna_equals(const Button *a, const Button *b)
Definition interface.cc:790
void button_func_menu_step_set(Button *but, MenuStepFunc func)
void button_func_set(Button *but, std::function< void(bContext &)> func)
void button_v4_get(Button *but, float vec[4])
static void def_but_rna__menu_type(bContext *, Layout *layout, void *but_p)
void widgetbase_draw_cache_begin()
int button_is_pushed_ex(Button *but, double *value)
void window_to_block_rctf(const ARegion *region, const Block *block, rctf *rct_dst, const rctf *rct_src)
Definition interface.cc:220
void block_views_listen(const Block *block, const wmRegionListenerParams *listener_params)
void resources_free()
Definition resources.cc:60
const ColorManagedDisplay * block_cm_display_get(Block *block)
bool panel_should_show_background(const ARegion *region, const PanelType *panel_type)
bool button_menu_step_poll(const Button *but)
const char * button_placeholder_get(Button *but)
void button_value_set(Button *but, double value)
void button_range_set_hard(Button *but)
void blocklist_update_window_matrix(const bContext *C, const ListBaseT< ui::Block > *lb)
int calc_float_precision(int prec, double value)
void button_func_search_set_sep_string(Button *but, const char *search_sep_string)
const uiStyle * style_get()
static std::string textbox_string_get(ButtonTextBox *textbox)
void block_translate(Block *block, float x, float y)
Definition interface.cc:408
void block_bounds_set_normal(Block *block, int addval)
Definition interface.cc:651
const char radial_dir_to_numpad[8]
int blocklist_min_y_get(ListBaseT< ui::Block > *lb)
static bool button_edit_string_include_unit_suffix(const Button *button)
std::string button_string_get_rna_label(Button &but)
void button_retval_set(Button *but, int retval)
void button_unit_type_set(Button *but, int unit_type)
Button * uiDefIconTextButO_ptr(Block *block, ButtonType type, wmOperatorType *ot, wm::OpCallContext opcontext, int icon, StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip)
std::string button_context_menu_title_from_button(Button &but)
void draw_aligned_panel(const ARegion *region, const uiStyle *style, const Block *block, const rcti *rect, bool show_pin, bool show_background, bool region_search_filter_active)
static void but_build_drawstr_float(Button *but, double value)
void button_context_ptr_set(Block *block, Button *but, StringRef name, const PointerRNA *ptr)
void button_semi_modal_state_free(const bContext *C, Button *but)
void block_lock_clear(Block *block)
std::string button_string_get_rna_label_context(const Button &but)
static bool but_icon_extra_is_visible_bone_eyedropper(Button *but)
void update_text_styles()
void button_update_edited(Button *but)
bool button_is_float(const Button *but)
void button_icon_indicator_color_set(Button *but, const uchar color[4])
void button_activate_event(bContext *C, ARegion *region, Button *but)
static void but_free_type_specific(Button *but)
static float get_but_step_unit(Button *but, float step_default)
void layout_remove_but(Layout *layout, const Button *but)
static std::optional< std::string > but_event_property_operator_string(const bContext *C, Button *but)
void text_button_func_rename_full_set(Button *but, std::function< void(StringRefNull new_name)> rename_full_func)
static CLG_LogRef LOG
Definition interface.cc:82
Button * button_find_old(Block *block_old, const Button *but_new)
Definition interface.cc:903
void layout_add_but(Layout *layout, Button *but)
static void block_message_subscribe(ARegion *region, wmMsgBus *mbus, Block *block)
int preview_tile_size_y_no_label(const int size_px=96)
void init_userdef()
void block_update_from_old(const bContext *C, Block *block)
void block_cm_to_display_space_v3(Block *block, float pixel[3])
static bool but_icon_extra_is_visible_text_clear(const Button *but)
void button_poin_menu_argN_set(Button *but, void *poin, void *argN, ButtonArgNFree func_argN_free_fn, ButtonArgNCopy func_argN_copy_fn)
void window_to_block(const ARegion *region, const Block *block, int *x, int *y)
Definition interface.cc:230
std::string button_string_get_rna_property_identifier(const Button &but)
void button_operator_set_never_call(Button *but)
void block_views_draw_overlays(const ARegion *region, const Block *block)
PointerRNA * button_operator_ptr_ensure(Button *but)
void block_align_begin(Block *block)
@ PREDEFINED_EXTRA_OP_ICON_CLEAR
@ PREDEFINED_EXTRA_OP_ICON_EYEDROPPER
@ PREDEFINED_EXTRA_OP_ICON_BONE_EYEDROPPER
@ PREDEFINED_EXTRA_OP_ICON_NONE
static void block_bounds_calc_popup(wmWindow *window, Block *block, BlockBoundsCalc bounds_calc, const int xy[2], int r_xy[2])
Definition interface.cc:576
void(*)(void *arg) FreeArgFunc
void block_to_region_fl(const ARegion *region, const Block *block, float *x, float *y)
Definition interface.cc:125
bool button_is_compatible(const Button *but_a, const Button *but_b)
void button_number_step_size_set(Button *but, float step_size)
bool button_anim_expression_create(Button *but, const char *str)
void window_to_region_rctf(const ARegion *region, rctf *rect_dst, const rctf *rct_src)
Definition interface.cc:255
float block_to_window_scale(const ARegion *region, const Block *block)
Definition interface.cc:182
void text_button_func_rename_set(Button *but, std::function< void(bContext &C, StringRefNull oldname)> rename_func)
void block_free(const bContext *C, Block *block)
void block_post_layout_callbacks_exec(const bContext *C, ARegion *region, Block *block)
void block_to_window_fl(const ARegion *region, const Block *block, float *x, float *y)
Definition interface.cc:144
void fontstyle_set(const uiFontStyle *fs)
void autocomplete_update_name(AutoComplete *autocpl, StringRef name)
wmOperatorType * button_operatortype_get_from_enum_menu(Button *but, PropertyRNA **r_prop)
void button_func_pushed_state_set(Button *but, std::function< bool(const Button &)> func)
bool butstore_register_update(Block *block, Button *but_dst, const Button *but_src)
void button_color_set(Button *but, const uchar color[4])
static PredefinedExtraOpIconType but_icon_extra_get(Button *but)
void block_views_end(ARegion *region, const Block *block)
void draw_popover_back(ARegion *region, uiStyle *style, Block *block, const rcti *rect)
static PointerRNA * but_extra_operator_icon_add_ptr(Button *but, wmOperatorType *optype, wm::OpCallContext opcontext, int icon)
Button * uiDefIconPreviewBut(Block *block, ButtonType type, int icon, int x, int y, short width, short height, void *poin, float min, float max, std::optional< StringRef > tip)
std::optional< EnumPropertyItem > button_rna_enum_item_get(bContext &C, Button &but)
void block_end_ex(const bContext *C, Main *bmain, wmWindow *window, Scene *scene, ARegion *region, Depsgraph *depsgraph, Block *block, const int xy[2]=nullptr, int r_xy[2]=nullptr, bool postpone_callbacks=false)
static void get_but_string_unit(Button *but, char *str, int str_maxncpy, double value, bool pad, int float_precision, bool do_suffix)
Button * region_find_active_but(ARegion *region) ATTR_WARN_UNUSED_RESULT
void button_icon_scale_set(Button *but, float scale)
void block_flag_enable(Block *block, int flag)
static void def_but_rna__menu(bContext *C, Layout *layout, void *but_p)
void button_enum_prop_value_set(Button *but, int retval)
static void menu_block_set_keymaps(const bContext *C, Block *block)
PropertyScaleType button_scale_type(const Button *but)
static Button * def_but_rna_propname(Block *block, ButtonType type, std::optional< StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, const StringRefNull propname, int index, float min, float max, const std::optional< StringRef > tip)
void block_listen(const Block *block, const wmRegionListenerParams *listener_params)
ARegion *(*)(bContext *C, ARegion *region, const rcti *item_rect, void *arg, void *active) ButtonSearchTooltipFn
void blocklist_draw(const bContext *C, const ListBaseT< ui::Block > *lb)
std::string button_string_get_tooltip_label(const Button &but)
const ColorManagedDisplay * button_cm_display_get(Button &but)
static void but_update_old_active_from_new(Button *oldbut, Button *but)
Definition interface.cc:974
static void block_bounds_calc_centered_pie(Block *block)
Definition interface.cc:563
static void button_validate(const Button *but)
void fontscale(float *points, float aspect)
void(*)(bContext *C, ARegion *butregion, Button *but) ButtonHandleHoldFunc
static Button * def_but(Block *block, ButtonTypeWithPointerType but_and_ptr_type, const StringRef str, int x, int y, short width, short height, void *poin, float min, float max, const std::optional< StringRef > tip)
static bool but_icon_extra_is_visible_search_unlink(const Button *but)
rcti rect_to_pixelrect(const ARegion *region, const Block *block, const rctf *src_rect)
static void but_extra_operator_icon_free(ButtonExtraOpIcon *extra_icon)
void button_focus_on_enter_event(wmWindow *win, Button *but)
Button * uiDefIconButO(Block *block, ButtonType type, StringRefNull opname, wm::OpCallContext opcontext, int icon, int x, int y, short width, short height, std::optional< StringRef > tip)
Button * uiDefBlockBut(Block *block, BlockCreateFunc func, void *arg, StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip)
const uiStyle * style_get_dpi()
PanelType * button_paneltype_get(const Button *but)
bool(*)(bContext *C, int direction, void *arg1) MenuStepFunc
static std::optional< std::string > but_extra_icon_event_operator_string(const bContext *C, const ButtonExtraOpIcon *extra_icon)
void widgetbase_draw_cache_end()
void button_label_alpha_factor_set(Button *but, float alpha_factor)
Button * button_drag_multi_edit_get(Button *but)
Button * uiDefIconButR_prop(Block *block, ButtonType type, int icon, int x, int y, short width, short height, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, std::optional< StringRef > tip)
void interface_tag_script_reload_queries()
void button_range_set_soft(Button *but)
void button_func_quick_tooltip_set(Button *but, std::function< std::string(const Button *but)> func)
static double soft_range_round_down(double value, double max)
void block_bounds_set_explicit(Block *block, int minx, int miny, int maxx, int maxy)
Definition interface.cc:699
bool but_is_utf8(const Button *but)
static void block_bounds_calc_text(Block *block, float offset)
Definition interface.cc:423
void button_func_tooltip_custom_set(Button *but, ButtonToolTipCustomFunc func, void *arg, FreeArgFunc free_arg)
void draw_menu_back(uiStyle *style, Block *block, const rcti *rect)
bool button_anim_expression_set(Button *but, const char *str)
void button_drawflag_enable(Button *but, int flag)
EmbossType block_emboss_get(Block *block)
bool view_item_matches(const AbstractViewItem &a, const AbstractViewItem &b)
bool button_is_bool(const Button *but)
void block_bounds_set_text(Block *block, int addval)
Definition interface.cc:661
bool block_active_only_flagged_buttons(const bContext *C, ARegion *region, Block *block)
void region_to_window(const ARegion *region, int *x, int *y)
Definition interface.cc:263
bool button_anim_expression_get(Button *but, char *str, size_t str_maxncpy)
bool butstore_is_registered(Block *block, Button *but)
void block_align_calc(Block *block, const ARegion *region)
Button * uiDefIconTextMenuBut(Block *block, MenuCreateFunc func, void *arg, int icon, StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip)
static void but_update_select_flag(Button *but, double *value)
void button_number_precision_set(Button *but, float precision)
void view_item_swap_button_pointers(AbstractViewItem &a, AbstractViewItem &b)
static void update_flexible_spacing(const ARegion *region, Block *block)
Definition interface.cc:316
void button_hint_drawstr_set(Button *but, const char *string)
std::optional< StringRefNull > button_context_string_get(const Button *but, StringRef name)
static bool but_equals_old(const Button *but, const Button *oldbut)
Definition interface.cc:811
std::string button_string_get_label(Button &but)
void button_disable(Button *but, const char *disabled_hint)
void button_func_tooltip_set(Button *but, ButtonToolTipFunc func, void *arg, FreeArgFunc free_arg)
bool button_flag_is_set(Button *but, int64_t flag)
void button_flag_enable(Button *but, int64_t flag)
static Button * def_but_operator_ptr(Block *block, ButtonType type, wmOperatorType *ot, wm::OpCallContext opcontext, const StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip)
void button_string_get_ex(Button *but, char *str, const size_t str_maxncpy, const int float_precision, const bool use_exp_float, bool *r_use_exp_float)
static std::unique_ptr< Button > but_new(const ButtonType type)
Block * block_begin(const bContext *C, ARegion *region, std::string name, EmbossType emboss)
void(*)(bContext *C, void *arg, int event) BlockHandleFunc
void button_rna_menu_convert_to_menu_type(Button *but, const char *menu_type)
Button * uiDefBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, StringRef str, int x, int y, short width, short height, void *poin, float min, float max, std::optional< StringRef > tip)
Button * uiDefButO(Block *block, ButtonType type, StringRefNull opname, wm::OpCallContext opcontext, const std::optional< StringRef > str, int x, int y, short width, short height, std::optional< StringRef > tip)
int(*)(bContext *C, char *str, void *arg) ButtonCompleteFunc
bool button_string_eval_number(bContext *C, const Button *but, const char *str, double *r_value)
static void update_window_matrix(const wmWindow *window, const ARegion *region, Block *block)
Definition interface.cc:371
ARegion *(*)(bContext *C, ARegion *butregion, ButtonSearch *search_but) ButtonSearchCreateFn
static void operator_enum_search_exec_fn(bContext *, void *but, void *arg2)
bool editsource_enable_check()
void button_v3_get(Button *but, float vec[3])
void block_to_window_rctf(const ARegion *region, const Block *block, rctf *rct_dst, const rctf *rct_src)
Definition interface.cc:172
Block *(*)(bContext *C, ARegion *region, void *arg1) BlockCreateFunc
std::optional< int64_t > button_context_int_get(const Button *but, StringRef name)
void *(*)(const void *argN) ButtonArgNCopy
bool block_is_popover(const Block *block) ATTR_WARN_UNUSED_RESULT
std::string button_string_get_rna_struct_identifier(const Button &but)
Button * uiDefSearchBut(Block *block, void *arg, int icon, int maxncpy, int x, int y, short width, short height, std::optional< StringRef > tip)
static bool but_is_row_alignment_group(const Button *left, const Button *right)
Definition interface.cc:417
void button_placeholder_set(Button *but, StringRef placeholder_text)
static bool but_is_unit_radians_ex(const UnitSettings *unit, const int unit_type)
Definition interface.cc:108
Button * uiDefButR_prop(Block *block, ButtonType type, std::optional< StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, std::optional< StringRef > tip)
void window_to_region(const ARegion *region, int *x, int *y)
Definition interface.cc:241
void button_number_slider_precision_set(Button *but, float precision)
bool panel_category_tabs_is_visible(const ARegion *region)
void block_theme_style_set(Block *block, char theme_style)
void blocklist_free_inactive(const bContext *C, ARegion *region)
void button_to_pixelrect(rcti *rect, const ARegion *region, const Block *block, const Button *but)
void button_context_int_set(Block *block, Button *but, StringRef name, int64_t value)
bool button_active_only_ex(const bContext *C, ARegion *region, Block *block, Button *but, bool remove_on_failure)
void button_node_link_set(Button *but, bNodeSocket *socket, const float draw_color[4])
bool block_is_search_only(const Block *block)
std::string button_string_get_operator_keymap(bContext &C, Button &but)
void block_align_end(Block *block)
static std::optional< std::string > but_event_operator_string_from_operator(const bContext *C, wmOperatorCallParams *op_call_params)
bool button_rna_equals_ex(const Button *but, const PointerRNA *ptr, const PropertyRNA *prop, int index)
Definition interface.cc:795
Button * uiDefButAlert(Block *block, AlertIcon icon, int x, int y, short width, short height)
bool button_active_only(const bContext *C, ARegion *region, Block *block, Button *but)
Button * uiDefMenuBut(Block *block, MenuCreateFunc func, void *arg, StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip)
void button_funcN_set(Button *but, ButtonHandleNFunc funcN, void *argN, void *arg2, ButtonArgNFree func_argN_free_fn=MEM_delete_void, ButtonArgNCopy func_argN_copy_fn=MEM_dupalloc_void)
Button * button_find_new(Block *block_new, const Button *but_old)
Definition interface.cc:922
static bool number_from_string_units_with_but(bContext *C, const char *str, const Button *but, double *r_value)
void button_tooltip_refresh(bContext *C, Button *but)
Button * uiDefIconTextButO(Block *block, ButtonType type, StringRefNull, wm::OpCallContext opcontext, int icon, StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip)
double button_value_get(Button *but)
bool search_item_add(SearchItems *items, StringRef name, void *poin, int iconid, int64_t but_flag, uint8_t name_prefix_offset)
PointerRNA * button_extra_operator_icon_opptr_get(const ButtonExtraOpIcon *extra_icon)
float view2d_scale_get_x(const View2D *v2d)
Definition view2d.cc:1902
static void but_build_drawstr_int(Button *but, int value)
static void block_free_active_operator(Block *block)
void block_emboss_set(Block *block, EmbossType emboss)
static std::optional< std::string > but_event_operator_string_from_menu(const bContext *C, Button *but)
void block_func_set(Block *block, ButtonHandleFunc func, void *arg1, void *arg2)
static bool number_from_string(bContext *C, const char *str, double *r_value)
void region_winrct_get_no_margin(const ARegion *region, rcti *r_rect)
Definition interface.cc:390
void draw_pie_center(Block *block)
std::string button_extra_icon_string_get_label(const ButtonExtraOpIcon &extra_icon)
bool button_string_set(bContext *C, Button *but, const char *str)
Button * uiDefIconTextButR_prop(Block *block, ButtonType type, int icon, std::optional< StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, std::optional< StringRef > tip)
void item_paneltype_func(bContext *C, Layout *layout, void *arg_pt)
bool button_is_editable(const Button *but) ATTR_WARN_UNUSED_RESULT
void block_flag_disable(Block *block, int flag)
Button * uiDefIconMenuBut(Block *block, MenuCreateFunc func, void *arg, int icon, int x, int y, short width, short height, std::optional< StringRef > tip)
void block_draw(const bContext *C, Block *block)
std::string button_string_get_rna_tooltip(bContext &C, Button &but)
void button_flag_disable(Button *but, int64_t flag)
static void block_bounds_calc_centered(wmWindow *window, Block *block)
Definition interface.cc:532
static void but_update_and_icon_set(Button *but, int icon)
void block_end(const bContext *C, Block *block, bool postpone_callbacks=false)
void window_to_region_rcti(const ARegion *region, rcti *rect_dst, const rcti *rct_src)
Definition interface.cc:247
int2 block_layout_resolve(Block *block)
Button * uiDefButO_ptr(Block *block, ButtonType type, wmOperatorType *ot, wm::OpCallContext opcontext, StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip)
void reinit_font()
void button_icon_indicator_number_set(Button *but, const int indicator_number)
void editsource_active_but_test(Button *but)
static void def_but_rna__panel_type(bContext *, Layout *layout, void *arg)
void button_convert_to_unit_alt_name(Button *but, char *str, size_t str_maxncpy)
std::string button_extra_icon_string_get_operator_keymap(const bContext &C, const ButtonExtraOpIcon &extra_icon)
void block_func_handle_set(Block *block, BlockHandleFunc func, void *arg)
const char radial_dir_order[8]
void def_but_icon(Button *but, const int icon, const int64_t flag)
char * button_string_get_dynamic(Button *but, int *r_str_size)
static bool but_is_unit_radians(const Button *but)
Definition interface.cc:113
void block_bounds_set_popup(Block *block, int addval, const int bounds_offset[2])
Definition interface.cc:667
bool button_opens_link(const Button *button)
void button_operator_set(Button *but, wmOperatorType *optype, wm::OpCallContext opcontext, const PointerRNA *opptr=nullptr)
void block_set_active_operator(Block *block, wmOperator *op, const bool free)
void button_drawflag_disable(Button *but, int flag)
ARegion * searchbox_create_generic(bContext *C, ARegion *butregion, ButtonSearch *search_but)
static bool but_is_rna_undo(const Button *but)
bool button_is_color_gamma(Button &but)
std::string button_string_get_property_keymap(bContext &C, Button &but)
Button * uiDefIconBut(Block *block, ButtonTypeWithPointerType but_and_ptr_type, int icon, int x, int y, short width, short height, void *poin, float min, float max, std::optional< StringRef > tip)
static std::optional< int64_t > but_find_old_idx(Block *block_old, const Button *but_new, const Set< const Button * > &ignore_old_buttons={})
Definition interface.cc:908
void block_region_set(Block *block, ARegion *region)
const bContextStore * button_context_get(const Button *but)
void button_icon_indicator_set(Button *but, const char *string)
void block_bounds_set_menu(Block *block, int addval, const int bounds_offset[2])
Definition interface.cc:681
int button_text_padding(const Button *button)
void button_number_slider_step_size_set(Button *but, float step_size)
void button_override_flag(Main *bmain, Button *but)
void * button_func_argN_get(const Button *but)
static bool but_update_from_old_block(Block *block, Set< const Button * > &matched_old_buttons, std::unique_ptr< Button > *but_uptr, std::optional< int64_t > *but_old_idx)
static void menu_block_set_keyaccels(Block *block)
static ButtonExtraOpIcon * but_extra_icon_find_old(const ButtonExtraOpIcon *new_extra_icon, const Button *old_but)
Definition interface.cc:939
void but_handle_data_free(HandleButtonData **data)
void button_v3_set(Button *but, const float vec[3])
static void block_bounds_calc_post_centered(Block *block)
Definition interface.cc:554
int preview_tile_size_y(const int size_px=96)
PointerRNA * button_extra_operator_icon_add(Button *but, StringRefNull opname, wm::OpCallContext opcontext, int icon)
void(*)(bContext &C, TooltipData &data, Button *but, void *argN) ButtonToolTipCustomFunc
MenuType * button_menutype_get(const Button *but)
void window_to_block_fl(const ARegion *region, const Block *block, float *x, float *y)
Definition interface.cc:193
static bool but_hide_fraction(Button *but, double value)
Definition interface.cc:738
void region_message_subscribe(ARegion *region, wmMsgBus *mbus)
bool button_can_align(const Button *but)
static bool number_from_string_percentage(bContext *C, const char *str, double *r_value)
void(*)(const bContext *C, void *arg, const char *str, SearchItems *items, bool is_first) ButtonSearchUpdateFn
void draw_layout_panels_backdrop(const ARegion *region, const Panel *panel, const float radius, float subpanel_backcolor[4])
Button * uiDefBlockButN(Block *block, BlockCreateFunc func, void *argN, StringRef str, int x, int y, short width, short height, std::optional< StringRef > tip, ButtonArgNFree func_argN_free_fn=MEM_delete_void, ButtonArgNCopy func_argN_copy_fn=MEM_dupalloc_void)
bool button_context_poll_operator(bContext *C, wmOperatorType *ot, const Button *but)
int button_is_pushed(Button *but)
Button * uiDefButV(Block *block, ButtonType type, StringRef str, int x, int y, short width, short height, T *poin, float min, float max, std::optional< StringRef > tip)
void button_func_complete_set(Button *but, ButtonCompleteFunc func, void *arg)
static void but_extra_icons_update_from_old_but(const Button *new_but, const Button *old_but)
Definition interface.cc:950
std::string(*)(bContext *C, void *argN, StringRef tip) ButtonToolTipFunc
void block_add_dynamic_listener(Block *block, void(*listener_func)(const wmRegionListenerParams *params))
int button_return_value_get(Button *but)
Button * uiDefIconBlockBut(Block *block, BlockCreateFunc func, void *arg, int icon, int x, int y, short width, short height, std::optional< StringRef > tip)
void button_dragflag_enable(Button *but, int flag)
void block_layout_set_current(Block *block, Layout *layout)
void button_func_hold_set(Button *but, ButtonHandleHoldFunc func, void *argN)
AutoComplete * autocomplete_begin(const char *startname, size_t maxncpy)
bool button_is_editing(const Button *but)
std::string button_get_link(const Button *button, bContext *C)
void block_bounds_calc(Block *block)
Definition interface.cc:496
const short radial_dir_to_angle[8]
static std::string but_pie_direction_string(const Button *but)
void blocklist_update_view_for_buttons(const bContext *C, const ListBaseT< ui::Block > *lb)
void(*)(void *argN) ButtonArgNFree
const PointerRNA * button_context_ptr_get(const Button *but, StringRef name, const StructRNA *type=nullptr)
void button_rna_menu_convert_to_panel_type(Button *but, const char *panel_type)
Button * uiDefIconButO_ptr(Block *block, ButtonType type, wmOperatorType *ot, wm::OpCallContext opcontext, int icon, int x, int y, short width, short height, std::optional< StringRef > tip)
void block_bounds_set_centered(Block *block, int addval)
Definition interface.cc:693
void icon_ensure_deferred(const bContext *C, int icon_id, bool big)
static double get_but_scale_unit(Button *but, double value)
void button_update(Button *but)
void button_func_search_set_context_menu(Button *but, ButtonSearchContextMenuFn context_menu_fn)
static bool number_from_string_units(bContext *C, const char *str, const int unit_type, const UnitSettings *unit, double *r_value)
bool(*)(bContext *C, void *arg, void *active, const wmEvent *event) ButtonSearchContextMenuFn
void button_view_item_draw_size_set(Button *but, const std::optional< int > draw_width=std::nullopt, const std::optional< int > draw_height=std::nullopt)
void button_func_search_set(Button *but, ButtonSearchCreateFn search_create_fn, ButtonSearchUpdateFn search_update_fn, void *arg, bool free_arg, FreeArgFunc search_arg_free_fn, ButtonHandleFunc search_exec_fn, void *active)
void button_func_search_set_tooltip(Button *but, ButtonSearchTooltipFn tooltip_fn)
void button_add_shortcut(Button *but, const char *shortcut_str, const bool do_strip)
const Button * block_active_default_button_find(const Block *block)
void block_funcN_set(Block *block, ButtonHandleNFunc funcN, void *argN, void *arg2, ButtonArgNFree func_argN_free_fn=MEM_delete_void, ButtonArgNCopy func_argN_copy_fn=MEM_dupalloc_void)
static bool but_pixelrect_in_view(const ARegion *region, const rcti *rect)
void button_drag_free(Button *but)
static bool but_extra_icons_equals_old(const ButtonExtraOpIcon *new_extra_icon, const ButtonExtraOpIcon *old_extra_icon)
Definition interface.cc:932
static Button * def_but_rna(Block *block, ButtonType type, std::optional< StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, PropertyRNA *prop, int index, float min, float max, std::optional< StringRef > tip)
void block_free_views(Block *block)
bool but_is_tool(const Button *but)
void(*)(const wmRegionListenerParams *params, void *arg) ButtonSearchListenFn
static void but_free(const bContext *C, Button *but)
bool button_is_rna_valid(Button *but)
void button_pushbutton_draw_as_overlay_set(Button *but, bool value)
void button_func_search_set_listen(Button *but, ButtonSearchListenFn listen_fn)
void button_execute(const bContext *C, ARegion *region, Button *but)
static float but_get_float_precision(Button *but)
Definition interface.cc:714
int autocomplete_end(AutoComplete *autocpl, char *autoname)
int preview_tile_size_x(const int size_px=96)
Button * uiDefButImage(Block *block, void *imbuf, int x, int y, short width, short height, const uchar color[4])
void button_type_set_menu_from_pulldown(Button *but)
void button_func_drawextra_set(Block *block, std::function< void(const bContext *C, rcti *rect)> func)
static Button * but_find_old(Block *block_old, const Button *but_new, const Set< const Button * > &ignore_old_buttons)
Definition interface.cc:891
void draw_button(const bContext *C, ARegion *region, uiStyle *style, Button *but, rcti *rect)
bool button_is_unit(const Button *but)
MINLINE float min_ff(float a, float b)
MINLINE unsigned char round_db_to_uchar_clamp(double a)
char * RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
UserDef U
Definition blender.cc:58
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
__int64 int64_t
Definition BKE_text.h:90
void wmOrtho2_region_pixelspace(const ARegion *region)
double BKE_unit_value_scale(const UnitSettings &settings, int unit_type, double value)
Definition unit.cc:1963
void WM_report_banner_show(wmWindowManager *wm, wmWindow *win)
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
std::optional< std::string > WM_context_path_resolve_property_full(const bContext *C, const PointerRNA *ptr, PropertyRNA *prop, int index)
void RNA_property_float_get_array_range(PointerRNA *ptr, PropertyRNA *prop, float values[2])
void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:737
const EnumPropertyItem rna_enum_id_type_items[]
Definition rna_ID.cc:33
void RNA_property_float_get_array_at_most(PointerRNA *ptr, PropertyRNA *prop, float *values, int values_num)
const PointerRNA * CTX_store_ptr_lookup(const bContextStore *store, StringRef name, const StructRNA *type=nullptr)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:835
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
void WM_operator_properties_sanitize(PointerRNA *ptr, const bool no_context)
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
bool BPY_run_string_as_number(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, double *r_value) ATTR_NONNULL(1
MINLINE int round_fl_to_int(float a)
void RNA_property_int_get_array_range(PointerRNA *ptr, PropertyRNA *prop, int values[2])
bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest)
int WM_window_native_pixel_y(const wmWindow *win)
void WM_operator_properties_free(PointerRNA *ptr)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void GPU_matrix_identity_set()
const char * RNA_property_identifier(const PropertyRNA *prop)
MINLINE int round_db_to_int_clamp(double a)
bool RNA_property_editable_info(const PointerRNA *ptr, PropertyRNA *prop, const char **r_info)
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:788
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:986
bool RNA_property_enum_name(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_name)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
void BLF_batch_draw_begin()
Definition blf.cc:536
@ PROP_UNIT_TIME_ABSOLUTE
Definition RNA_types.hh:228
@ PROP_UNIT_ROTATION
Definition RNA_types.hh:226
@ PROP_UNIT_NONE
Definition RNA_types.hh:221
@ PROP_UNIT_TIME
Definition RNA_types.hh:227
MenuType * WM_menutype_find(const StringRef idname, bool quiet)
bContextStore * CTX_store_add(Vector< std::unique_ptr< bContextStore > > &contexts, StringRef name, const PointerRNA *ptr)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
short RNA_type_to_ID_code(const StructRNA *type)
int bool bool bool BLI_strn_endswith(const char *__restrict str, const char *__restrict end, size_t str_len) ATTR_NONNULL(1
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_enum_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *r_value)
void void void BLI_movelisttolist(ListBase *dst, ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:32
wmWindow * CTX_wm_window(const bContext *C)
char * RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
const char * RNA_property_translation_context(const PropertyRNA *prop)
std::optional< std::string > WM_key_event_operator_string(const bContext *C, const char *opname, wm::OpCallContext opcontext, IDProperty *properties, const bool is_strict)
const char * RNA_struct_ui_name(const StructRNA *type)
int WM_window_native_pixel_x(const wmWindow *win)
void BLI_rcti_rctf_copy_round(struct rcti *dst, const struct rctf *src)
PropertyScaleType RNA_property_ui_scale(PropertyRNA *prop)
bool BLI_rcti_clamp(struct rcti *rect, const struct rcti *rect_bounds, int r_xy[2])
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
void MEM_delete_void(void *vmemh)
AnimationEvalContext BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float eval_time) ATTR_WARN_UNUSED_RESULT
Definition anim_sys.cc:602
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
const char * WM_key_event_string(const short type, const bool compact)
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:259
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_array_check(PropertyRNA *prop)
const bContextStore * CTX_store_get(const bContext *C)
MINLINE void zero_v4(float r[4])
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
MINLINE int integer_digits_f(float f)
PropertyType RNA_property_type(PropertyRNA *prop)
bool RNA_property_undo_check(const PropertyRNA *prop, const StructRNA *type)
void BLF_size(int fontid, float size)
Definition blf.cc:445
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void * MEM_dupalloc_void(const void *vmemh) ATTR_WARN_UNUSED_RESULT
PropertyScaleType
Definition RNA_types.hh:251
@ PROP_SCALE_LINEAR
Definition RNA_types.hh:253
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< int32_t, 2 > int2
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
StructRNA * RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
unsigned char uchar
Definition BKE_text.h:58
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
bool user_string_to_number(bContext *C, const char *str, const UnitSettings &unit, int type, double *r_value, double *r_value_no_units, bool use_single_line_error, char **r_error)
Definition numinput.cc:284
std::optional< int64_t > CTX_store_int_lookup(const bContextStore *store, StringRef name)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
float BKE_scene_frame_get(const Scene *scene)
Definition scene.cc:2595
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
int BLF_default()
void GPU_scissor_get(int coords[4])
Definition gpu_state.cc:253
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
wmWindowManager * CTX_wm_manager(const bContext *C)
bool RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
bool RNA_struct_contains_property(PointerRNA *ptr, PropertyRNA *prop_test)
int BLF_default_weight(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:357
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:580
int RNA_property_flag(PropertyRNA *prop)
bool RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void BLI_rctf_init_minmax(struct rctf *rect)
Definition rct.cc:494
@ USER_FACTOR_AS_PERCENTAGE
bool RNA_property_is_idprop(const PropertyRNA *prop)
bool RNA_property_enum_item_from_value_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
bool WM_operator_poll_context(bContext *C, wmOperatorType *ot, wm::OpCallContext context)
void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
void RNA_property_float_set_array_at_most(PointerRNA *ptr, PropertyRNA *prop, const float *values, int values_num)
eRNAOverrideStatus RNA_property_override_library_status(Main *bmain, PointerRNA *ptr, PropertyRNA *prop, const int index)
size_t BKE_unit_value_as_string(char *str, int str_maxncpy, double value, int prec, int type, const UnitSettings &settings, bool pad, bool do_unit_suffix)
Definition unit.cc:1929
bool BLF_has_variable_weight(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:366
PropertyRNA * RNA_struct_name_property(const StructRNA *type)
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
MINLINE void zero_v3(float r[3])
void BLF_batch_draw_end()
Definition blf.cc:549
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
double BKE_unit_closest_scalar(double value, int system, int type)
Definition unit.cc:2545
bool RNA_property_enum_item_from_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
void BLI_rctf_union(struct rctf *rct_a, const struct rctf *rct_b)
bool RNA_struct_is_ID(const StructRNA *type)
int BIFIconID
Definition ED_asset.hh:30
const char * RNA_struct_identifier(const StructRNA *type)
void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
std::optional< std::string > WM_keymap_item_to_string(const wmKeyMapItem *kmi, const bool compact)
void WM_msg_subscribe_rna(wmMsgBus *mbus, PointerRNA *ptr, const PropertyRNA *prop, const wmMsgSubscribeValue *msg_val_params, const char *id_repr)
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
wmEvent * WM_event_add(wmWindow *win, const wmEvent *event_to_add)
MINLINE float normalize_v3(float n[3])
PropertySubType RNA_property_subtype(PropertyRNA *prop)
const char * RNA_struct_ui_description(const StructRNA *type)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void GPU_scissor(int x, int y, int width, int height)
Definition gpu_state.cc:178
void IMB_colormanagement_scene_linear_to_display_v3(float pixel[3], const ColorManagedDisplay *display, ColorManagedDisplaySpace display_space=DISPLAY_SPACE_DRAW)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
MINLINE void zero_v2_int(int r[2])
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Main * CTX_data_main(const bContext *C)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
void GPU_matrix_pop_projection()
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
int2 WM_window_native_pixel_size(const wmWindow *win)
const char * RNA_property_ui_description(const PropertyRNA *prop, const PointerRNA *ptr)
MINLINE float max_ff(float a, float b)
const char * IMB_colormanagement_display_get_default_name()
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.hh:198
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_ENUM_FLAG
Definition RNA_types.hh:474
@ PROP_ICONS_REVERSE
Definition RNA_types.hh:400
@ PROP_ICONS_CONSECUTIVE
Definition RNA_types.hh:399
ARegion * CTX_wm_region_popup(const bContext *C)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
@ KM_NOTHING
Definition WM_types.hh:323
bool RNA_property_editable(const PointerRNA *ptr, PropertyRNA *prop)
std::optional< StringRefNull > CTX_store_string_lookup(const bContextStore *store, StringRef name)
void BLI_rctf_translate(struct rctf *rect, float x, float y)
Definition rct.cc:587
void BKE_unit_name_to_alt(char *str, int str_maxncpy, const char *orig_str, int system, int type)
Definition unit.cc:2504
void wmGetProjectionMatrix(float mat[4][4], const rcti *winrct)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Scene * CTX_data_scene(const bContext *C)
const ColorManagedDisplay * IMB_colormanagement_display_get_named(const char *name)
IDProperty * IDP_NewStringMaxSize(const char *st, size_t st_maxncpy, StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:400
int RNA_property_ui_icon(const PropertyRNA *prop)
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE short round_db_to_short_clamp(double a)
void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision)
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
@ RGN_FLAG_SEARCH_FILTER_ACTIVE
std::string RNA_string_get(PointerRNA *ptr, const char *name)
void ED_region_do_msg_notify_tag_redraw(bContext *C, wmMsgSubscribeKey *msg_key, wmMsgSubscribeValue *msg_val)
Definition area.cc:394
std::string WM_operatortype_description(bContext *C, wmOperatorType *ot, PointerRNA *properties)
const float(* GPU_matrix_projection_get(float m[4][4]))[4]
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, bool value)
void CTX_store_set(bContext *C, const bContextStore *store)
@ PROP_PERCENTAGE
Definition RNA_types.hh:307
@ PROP_TIME_ABSOLUTE
Definition RNA_types.hh:311
@ PROP_FACTOR
Definition RNA_types.hh:308
@ PROP_PIXEL_DIAMETER
Definition RNA_types.hh:350
ReportList * CTX_wm_reports(const bContext *C)
int RNA_property_string_maxlength(PropertyRNA *prop)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
void GPU_matrix_pop()
void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
void GPU_matrix_push_projection()
bool BKE_unit_is_adaptive(const UnitSettings &settings, int type)
Definition unit.cc:2652
ARegion * CTX_wm_region(const bContext *C)
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
void wm_event_init_from_window(wmWindow *win, wmEvent *event)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void GPU_matrix_push()
const char * RNA_property_ui_name(const PropertyRNA *prop, const PointerRNA *ptr)
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
const char * RNA_struct_translation_context(const StructRNA *type)
ocio::Display ColorManagedDisplay
void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
bool bool bool bool BPY_run_string_as_string(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value) ATTR_NONNULL(1
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BLI_rcti_rctf_copy_floor(struct rcti *dst, const struct rctf *src)
void * RNA_property_py_data_get(PropertyRNA *prop)
#define floorf
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
uiWidgetColors wcol_menu_back
float panel_roundness
ThemeUI tui
bke::ARegionRuntime * runtime
eRegion_Type regiontype
char idname[BKE_ST_MAXNAME]
char idname[BKE_ST_MAXNAME]
struct PanelType * type
struct Panel_Runtime * runtime
bool has_type() const
Definition RNA_types.hh:180
StructRNA * type
Definition RNA_types.hh:63
bool has_owner_id() const
Definition RNA_types.hh:186
struct UnitSettings unit
ColorManagedDisplaySettings display_settings
Vector< std::function< void(const bContext &C, ui::Block &Block)> > post_block_layout_fns
ListBaseT< ui::Block > uiblocks
Map< std::string, ui::Block * > block_name_map
void(*) listener_func(const wmRegionListenerParams *params)
ButtonHandleNFunc funcN
std::function< void(const bContext *, rcti *)> drawextra
Button * last_but() const
Definition interface.cc:311
int but_index(const Button *but) const
Definition interface.cc:276
ListBaseT< LayoutRoot > layouts
Vector< std::unique_ptr< bContextStore > > contexts
ListBaseT< SafetyRect > saferct
ListBaseT< ButStore > butstore
Vector< std::unique_ptr< Button > > buttons_ptrs
BlockBoundsCalc bounds_type
Button * first_but() const
Definition interface.cc:306
Button * prev_but(const Button *but) const
Definition interface.cc:294
std::ranges::transform_view< std::ranges::ref_view< const Vector< std::unique_ptr< Button > > >, Button &(*)(const std::unique_ptr< Button > &)> buttons() const
BlockHandleFunc handle_func
const UnitSettings * unit
Button * next_but(const Button *but) const
Definition interface.cc:288
ListBaseT< BlockDynamicListener > dynamic_listeners
std::unique_ptr< PieMenuData > pie_data
ButtonArgNFree func_argN_free_fn
PopupBlockHandle * handle
ButtonHandleFunc func
void remove_but(const Button *but)
Definition interface.cc:300
ButtonArgNCopy func_argN_copy_fn
ColorPickerData color_pickers
wmOperatorCallParams * optype_params
ButtonSearchCreateFn popup_create_fn
std::shared_ptr< void > arg
ButtonSearchListenFn listen_fn
ButtonSearchContextMenuFn item_context_menu_fn
ButtonSearchTooltipFn item_tooltip_fn
ButtonSearchUpdateFn items_update_fn
std::unique_ptr< TextWrapCache > placeholder_wrap_cache
std::unique_ptr< TextWrapCache > wrap_cache
std::function< void(StringRefNull new_name)> rename_full_func
std::function< void(bContext &, StringRefNull)> rename_func
wm::OpCallContext opcontext
ButtonIdentityCompareFunc identity_cmp_func
ButtonArgNFree func_argN_free_fn
ButtonToolTipCustomFunc tip_custom_func
ButtonHandleFunc func
std::function< void(bContext &)> apply_func
ButtonToolTipFunc tip_func
eWM_DragDataType dragtype
ButtonCompleteFunc autocomplete_func
std::function< std::string(const Button *)> tip_quick_func
ButtonHandleHoldFunc hold_func
TextDirection text_direction
RadialDirection pie_dir
IconTextOverlay icon_overlay_text
MenuCreateFunc menu_create_func
ButtonArgNCopy func_argN_copy_fn
HandleButtonData * semi_modal_state
BlockCreateFunc block_create_func
wmOperatorType * optype
const bContextStore * context
HandleButtonData * active
ButtonHandleNFunc funcN
ListBaseT< ButtonExtraOpIcon > extra_op_icons
std::function< bool(const Button &)> pushed_state_func
ListBaseT< ColorPicker > list
void label(StringRef name, int icon)
Layout & split(float percentage, bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
wm::OpCallContext opcontext
Definition WM_types.hh:1246
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1197
bke::WindowRuntime * runtime
uiFontStyle tooltip
uiFontStyle paneltitle
uiFontStyle grouplabel
uiFontStyle widget
unsigned char text[4]
#define N_(msgid)