Blender V5.0
interface_style.cc File Reference
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
#include "DNA_userdef_types.h"
#include "BLI_listbase.h"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
#include "BKE_global.hh"
#include "BLF_api.hh"
#include "CLG_log.h"
#include "interface_intern.hh"

Go to the source code of this file.

Functions

static void fontstyle_set_ex (const uiFontStyle *fs, const float dpi_fac)
static uiStyleui_style_new (ListBase *styles, const char *name, short uifont_id)
static uiFontuifont_to_blfont (int id)
void UI_fontstyle_draw_ex (const uiFontStyle *fs, const rcti *rect, const char *str, const size_t str_len, const uchar col[4], const uiFontStyleDraw_Params *fs_params, int *r_xofs, int *r_yofs, ResultBLF *r_info)
void UI_fontstyle_draw (const uiFontStyle *fs, const rcti *rect, const char *str, const size_t str_len, const uchar col[4], const uiFontStyleDraw_Params *fs_params)
void UI_fontstyle_draw_multiline_clipped_ex (const uiFontStyle *fs, const rcti *rect, const char *str, const uchar col[4], const eFontStyle_Align align, int *r_xofs, int *r_yofs, ResultBLF *r_info)
void UI_fontstyle_draw_multiline_clipped (const uiFontStyle *fs, const rcti *rect, const char *str, const uchar col[4], const eFontStyle_Align align)
void UI_fontstyle_draw_rotated (const uiFontStyle *fs, const rcti *rect, const char *str, const uchar col[4])
void UI_fontstyle_draw_simple (const uiFontStyle *fs, float x, float y, const char *str, const uchar col[4])
void UI_fontstyle_draw_simple_backdrop (const uiFontStyle *fs, float x, float y, const blender::StringRef str, const float col_fg[4], const float col_bg[4])
const uiStyleUI_style_get ()
const uiStyleUI_style_get_dpi ()
int UI_fontstyle_string_width (const uiFontStyle *fs, const char *str)
int UI_fontstyle_string_width_with_block_aspect (const uiFontStyle *fs, const StringRef str, const float aspect)
int UI_fontstyle_height_max (const uiFontStyle *fs)
void uiStyleInit ()
void UI_fontstyle_set (const uiFontStyle *fs)

Variables

static CLG_LogRef LOG = {"ui.font"}

Function Documentation

◆ fontstyle_set_ex()

◆ UI_fontstyle_draw()

void UI_fontstyle_draw ( const uiFontStyle * fs,
const rcti * rect,
const char * str,
const size_t str_len,
const uchar col[4],
const uiFontStyleDraw_Params * fs_params )

◆ UI_fontstyle_draw_ex()

◆ UI_fontstyle_draw_multiline_clipped()

void UI_fontstyle_draw_multiline_clipped ( const uiFontStyle * fs,
const rcti * rect,
const char * str,
const uchar col[4],
eFontStyle_Align align )

Draws text with wrapping and shortening using "..." so that it fits into the given rectangle.

Definition at line 301 of file interface_style.cc.

References col, str, and UI_fontstyle_draw_multiline_clipped_ex().

Referenced by file_draw_string_mulitline_clipped().

◆ UI_fontstyle_draw_multiline_clipped_ex()

◆ UI_fontstyle_draw_rotated()

◆ UI_fontstyle_draw_simple()

void UI_fontstyle_draw_simple ( const uiFontStyle * fs,
float x,
float y,
const char * str,
const uchar col[4] )

Similar to UI_fontstyle_draw but ignore alignment, shadow & no clipping rect.

For drawing on-screen labels.

Definition at line 369 of file interface_style.cc.

References BLF_color4ubv(), BLF_draw(), BLF_DRAW_STR_DUMMY_MAX, BLF_position(), col, str, UI_fontstyle_set(), uiFontStyle::uifont_id, x, and y.

Referenced by ANIM_channel_draw(), draw_current_frame(), file_draw_list(), blender::ed::outliner::outliner_draw_tree_element(), and wm_drag_draw_item_name().

◆ UI_fontstyle_draw_simple_backdrop()

◆ UI_fontstyle_height_max()

int UI_fontstyle_height_max ( const uiFontStyle * fs)

◆ UI_fontstyle_set()

◆ UI_fontstyle_string_width()

int UI_fontstyle_string_width ( const uiFontStyle * fs,
const char * str )

◆ UI_fontstyle_string_width_with_block_aspect()

int UI_fontstyle_string_width_with_block_aspect ( const uiFontStyle * fs,
blender::StringRef str,
float aspect )

Return the width of str with the spacing & kerning of fs with aspect (representing uiBlock.aspect) applied.

When calculating text width, the UI layout logic calculate widths without scale, only applying scale when drawing. This causes problems for fonts since kerning at smaller sizes often makes them wider than a scaled down version of the larger text. Resolve this by calculating the text at the on-screen size, returning the result scaled back to 1:1. See #92361.

Definition at line 454 of file interface_style.cc.

References BLF_width(), fontstyle_set_ex(), str, UI_SCALE_FAC, and uiFontStyle::uifont_id.

Referenced by ui_text_icon_width_ex().

◆ UI_style_get()

◆ UI_style_get_dpi()

const uiStyle * UI_style_get_dpi ( )

Read a style (with the current DPI applied).

Definition at line 421 of file interface_style.cc.

References uiStyle::boxspace, uiStyle::buttonspacex, uiStyle::buttonspacey, uiStyle::columnspace, uiStyle::grouplabel, uiStyle::panelouter, uiStyle::panelspace, uiStyle::paneltitle, uiFontStyle::shadx, uiFontStyle::shady, uiStyle::templatespace, uiStyle::tooltip, UI_SCALE_FAC, UI_style_get(), and uiStyle::widget.

Referenced by blender::ed::asset::shelf::add_tab_button(), block_create_autorun_warning(), button_section_bounds_calc(), colorband_tools_fn(), blender::ed::space_node::draw_tree_path(), ed_panel_draw(), ED_region_header_layout(), ED_region_image_metadata_draw(), ED_region_info_draw_multiline(), ED_region_property_search(), ED_time_scrub_channel_search_draw(), blender::ed::spreadsheet::get_index_column_width(), blender::ed::asset::shelf::main_region_padding_y(), menu_add_shortcut(), menu_change_shortcut(), menu_items_from_ui_create(), blender::ed::space_node::node_update_basis_buttons(), blender::ed::space_node::node_update_basis_from_declaration(), blender::ed::space_node::node_update_basis_socket(), blender::ui::padded_item_height(), blender::ed::asset::shelf::region_layout(), blender::ui::region_views_find_drop_target_at(), uiLayoutItemPanelBody::resolve_impl(), uiLayoutItemPanelHeader::resolve_impl(), blender::ed::spreadsheet::spreadsheet_footer_region_draw(), template_ID_tabs(), blender::ed::vse::text_size_get(), ui_alert_create(), UI_block_draw(), ui_offset_panel_block(), UI_pie_menu_begin(), ui_popover_create_block(), ui_popover_panel_create(), ui_popup_menu_create_block(), uiItemsAlertBox(), blender::ed::outliner::unused_message_popup_width_compute(), wm_block_about_create(), wm_block_create_redo(), wm_block_dialog_create(), wm_block_insert_unicode_create(), wm_block_splash_create(), and wm_operator_ui_create().

◆ ui_style_new()

uiStyle * ui_style_new ( ListBase * styles,
const char * name,
short uifont_id )
static

This is a complete set of layout rules, the 'state' of the Layout Engine. Multiple styles are possible, defined via C or Python. Styles get a name, and will typically get activated per region type, like Header, or Listview or Toolbar. Properties of Style definitions are:

  • default column properties, internal spacing, aligning, min/max width
  • button alignment rules (for groups)
  • label placement rules
  • internal labeling or external labeling default
  • default minimum widths for buttons/labels (in amount of characters)
  • font types, styles and relative sizes for Panel titles, labels, etc.

Definition at line 61 of file interface_style.cc.

References BLI_addtail(), uiStyle::boxspace, uiStyle::buttonspacex, uiStyle::buttonspacey, uiFontStyle::character_weight, uiStyle::columnspace, uiStyle::grouplabel, MEM_callocN(), name, uiStyle::name, uiStyle::panelouter, uiStyle::panelspace, uiStyle::paneltitle, uiStyle::panelzoom, uiFontStyle::points, uiFontStyle::shadow, uiFontStyle::shadowalpha, uiFontStyle::shadowcolor, uiFontStyle::shadx, uiFontStyle::shady, STRNCPY_UTF8, uiStyle::templatespace, uiStyle::tooltip, UI_DEFAULT_TEXT_POINTS, UI_DEFAULT_TITLE_POINTS, UI_DEFAULT_TOOLTIP_POINTS, uiFontStyle::uifont_id, and uiStyle::widget.

Referenced by uiStyleInit().

◆ uifont_to_blfont()

uiFont * uifont_to_blfont ( int id)
static

Definition at line 115 of file interface_style.cc.

References uiFont::next, U, and uiFont::uifont_id.

Referenced by fontstyle_set_ex().

◆ uiStyleInit()

Variable Documentation

◆ LOG

CLG_LogRef LOG = {"ui.font"}
static

Definition at line 38 of file interface_style.cc.