Blender V5.0
interface_utils.cc File Reference
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fmt/format.h>
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "ED_screen.hh"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
#include "BLT_translation.hh"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_lib_id.hh"
#include "BKE_screen.hh"
#include "MEM_guardedalloc.h"
#include "RNA_access.hh"
#include "RNA_prototypes.hh"
#include "ANIM_action.hh"
#include "UI_interface_icons.hh"
#include "UI_interface_layout.hh"
#include "UI_resources.hh"
#include "UI_string_search.hh"
#include "UI_view2d.hh"
#include "WM_api.hh"
#include "WM_types.hh"
#include "interface_intern.hh"

Go to the source code of this file.

Classes

struct  CollItemSearch
struct  uiButStore
struct  uiButStoreElem

Functions

uiButuiDefAutoButR (uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int index, const std::optional< StringRef > name, int icon, int x, int y, int width, int height)
void uiDefAutoButsArrayR (uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, const int icon, const int x, const int y, const int tot_width, const int height)
eAutoPropButsReturn uiDefAutoButsRNA (uiLayout *layout, PointerRNA *ptr, bool(*check_prop)(PointerRNA *ptr, PropertyRNA *prop, void *user_data), void *user_data, PropertyRNA *prop_activate_init, const eButLabelAlign label_align, const bool compact)
void UI_but_func_identity_compare_set (uiBut *but, uiButIdentityCompareFunc cmp_fn)
static bool add_collection_search_item (CollItemSearch &cis, const bool requires_exact_data_name, const bool has_id_icon, uiSearchItems *items)
void ui_rna_collection_search_update_fn (const bContext *C, void *arg, const char *str, uiSearchItems *items, const bool is_first)
int UI_icon_from_id (const ID *id)
int UI_icon_from_report_type (int type)
int UI_icon_colorid_from_report_type (int type)
int UI_text_colorid_from_report_type (int type)
int UI_calc_float_precision (int prec, double value)
std::optional< std::string > UI_but_online_manual_id (const uiBut *but)
std::optional< std::string > UI_but_online_manual_id_from_active (const bContext *C)
static rctf ui_but_rect_to_view (const uiBut *but, const ARegion *region, const View2D *v2d)
static bool ui_view2d_cur_ensure_rect_in_view (View2D *v2d, const rctf *rect)
void UI_but_ensure_in_view (const bContext *C, ARegion *region, const uiBut *but)
Button Store

Modal Button Store API.

Store for modal operators & handlers to register button pointers which are maintained while drawing or nullptr when removed.

This is needed since button pointers are continuously freed and re-allocated.

uiButStoreUI_butstore_create (uiBlock *block)
void UI_butstore_free (uiBlock *block, uiButStore *bs_handle)
bool UI_butstore_is_valid (uiButStore *bs_handle)
bool UI_butstore_is_registered (uiBlock *block, uiBut *but)
void UI_butstore_register (uiButStore *bs_handle, uiBut **but_p)
void UI_butstore_unregister (uiButStore *bs_handle, uiBut **but_p)
bool UI_butstore_register_update (uiBlock *block, uiBut *but_dst, const uiBut *but_src)
void UI_butstore_clear (uiBlock *block)
void UI_butstore_update (uiBlock *block)

Function Documentation

◆ add_collection_search_item()

◆ UI_but_ensure_in_view()

void UI_but_ensure_in_view ( const bContext * C,
ARegion * region,
const uiBut * but )

Adjust the view so the rectangle of but is in view, with some extra margin.

It's important that this is only executed after buttons received their final uiBut.rect. E.g. UI_panels_end() modifies them, so if that is executed, this function must not be called before it.

Parameters
regionThe region the button is placed in. Make sure this is actually the one the button is placed in, not just the context region.

Definition at line 880 of file interface_utils.cc.

References BLI_rctf_pad(), C, ED_region_tag_redraw_no_rebuild(), View2D::flag, ui_but_rect_to_view(), UI_UNIT_X, ui_view2d_cur_ensure_rect_in_view(), UI_view2d_curRect_changed(), ARegion::v2d, and V2D_IS_INIT.

Referenced by ui_but_update_view_for_active(), and ui_textedit_begin().

◆ UI_but_func_identity_compare_set()

void UI_but_func_identity_compare_set ( uiBut * but,
uiButIdentityCompareFunc cmp_fn )

Callback to compare the identity of two buttons, used to identify buttons over redraws. If the callback returns true, the given buttons are considered to be matching and relevant state is preserved (copied from the old to the new button). If it returns false, it's considered non-matching and no further checks are done.

If this is set, it is always executed instead of the default comparisons. However it is only executed for buttons that have the same type and the same callback. So callbacks can assume the button types match.

Definition at line 439 of file interface_utils.cc.

References uiBut::identity_cmp_func.

Referenced by blender::ed::outliner::outliner_draw_overrides_restrictbuts().

◆ UI_but_online_manual_id()

◆ UI_but_online_manual_id_from_active()

std::optional< std::string > UI_but_online_manual_id_from_active ( const bContext * C)

◆ ui_but_rect_to_view()

rctf ui_but_rect_to_view ( const uiBut * but,
const ARegion * region,
const View2D * v2d )
static

◆ UI_butstore_clear()

void UI_butstore_clear ( uiBlock * block)

NULL all pointers, don't free since the owner needs to be able to inspect.

Definition at line 1009 of file interface_utils.cc.

References uiBlock::butstore, and LISTBASE_FOREACH.

Referenced by UI_block_free().

◆ UI_butstore_create()

uiButStore * UI_butstore_create ( uiBlock * block)

Create a new button store, the caller must manage and run UI_butstore_free

Definition at line 923 of file interface_utils.cc.

References BLI_addtail(), uiButStore::block, uiBlock::butstore, and MEM_callocN().

Referenced by ui_but_add_search(), and ui_multibut_states_create().

◆ UI_butstore_free()

◆ UI_butstore_is_registered()

bool UI_butstore_is_registered ( uiBlock * block,
uiBut * but )

Definition at line 959 of file interface_utils.cc.

References uiBlock::butstore, and LISTBASE_FOREACH.

Referenced by ui_but_free().

◆ UI_butstore_is_valid()

bool UI_butstore_is_valid ( uiButStore * bs_handle)

Definition at line 954 of file interface_utils.cc.

References uiButStore::block.

◆ UI_butstore_register()

void UI_butstore_register ( uiButStore * bs_handle,
uiBut ** but_p )

◆ UI_butstore_register_update()

bool UI_butstore_register_update ( uiBlock * block,
uiBut * but_dst,
const uiBut * but_src )

Update the pointer for a registered button.

Definition at line 993 of file interface_utils.cc.

References uiBlock::butstore, and LISTBASE_FOREACH.

Referenced by ui_but_update_from_old_block().

◆ UI_butstore_unregister()

void UI_butstore_unregister ( uiButStore * bs_handle,
uiBut ** but_p )

◆ UI_butstore_update()

void UI_butstore_update ( uiBlock * block)

Map freed buttons from the old block and update pointers.

Definition at line 1019 of file interface_utils.cc.

References BLI_assert, BLI_movelisttolist(), uiBlock::butstore, ELEM, ListBase::first, LIKELY, LISTBASE_FOREACH, uiBlock::oldblock, and ui_but_find_new().

Referenced by UI_block_update_from_old().

◆ UI_calc_float_precision()

int UI_calc_float_precision ( int prec,
double value )

Returns the best "UI" precision for given floating value, so that e.g. 10.000001 rather gets drawn as '10'...

Definition at line 745 of file interface_utils.cc.

References BLI_assert, CLAMP, e, fabs(), i, pow, and UI_PRECISION_FLOAT_MAX.

Referenced by outputNumInput(), and ui_but_calc_float_precision().

◆ UI_icon_colorid_from_report_type()

int UI_icon_colorid_from_report_type ( int type)

◆ UI_icon_from_id()

int UI_icon_from_id ( const ID * id)

◆ UI_icon_from_report_type()

int UI_icon_from_report_type ( int type)

◆ ui_rna_collection_search_update_fn()

◆ UI_text_colorid_from_report_type()

◆ ui_view2d_cur_ensure_rect_in_view()

bool ui_view2d_cur_ensure_rect_in_view ( View2D * v2d,
const rctf * rect )
static

To get a margin (typically wanted), add the margin to rect directly.

Based on file_ensure_inside_viewbounds(), could probably share code.

Returns
true if anything changed.

Definition at line 838 of file interface_utils.cc.

References BLI_assert, BLI_rctf_inside_rctf(), BLI_rctf_size_x(), BLI_rctf_size_y(), View2D::cur, rect_height(), rect_width(), rctf::xmax, rctf::xmin, rctf::ymax, and rctf::ymin.

Referenced by UI_but_ensure_in_view().

◆ uiDefAutoButR()

◆ uiDefAutoButsArrayR()

void uiDefAutoButsArrayR ( uiBlock * block,
PointerRNA * ptr,
PropertyRNA * prop,
const int icon,
const int x,
const int y,
const int tot_width,
const int height )

◆ uiDefAutoButsRNA()

eAutoPropButsReturn uiDefAutoButsRNA ( uiLayout * layout,
PointerRNA * ptr,
bool(* check_prop )(PointerRNA *ptr, PropertyRNA *prop, void *user_data),
void * user_data,
PropertyRNA * prop_activate_init,
eButLabelAlign label_align,
bool compact )