Blender
V5.3
source
blender
editors
interface
buttons
interface_label.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2026 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9
#include "
BLF_api.hh
"
10
11
#include "
BLI_rect.hh
"
12
13
#include "
interface_intern.hh
"
14
#include "
interface_label.hh
"
15
16
namespace
blender::ui
{
17
18
bool
button_label_is_multiline
(
const
Button
*button)
19
{
20
return
button->
type
==
ButtonType::Label
&&
21
static_cast<
const
ButtonLabel
*
>
(button)->label_type ==
ButtonLabelType::Multiline
;
22
}
23
24
void
label_multiline_wrap_lines
(
ButtonLabel
*button,
int
icon_pad)
25
{
26
const
float
aspect = button->
block
->
aspect
;
27
28
const
int
width = std::max<int>(std::ceil(
BLI_rctf_size_x
(&button->
rect
)) - icon_pad, 0) /
29
aspect;
30
StringRef
text = button->
str
;
31
text = text.
trim
();
32
/* Sometimes blocks are updated from old blocks before resolving the layout, so the button could
33
* have acquire old button wrap cache. */
34
if
(button->
wrap_cache
) {
35
TextWrapCache
&cache = *button->
wrap_cache
;
36
if
(!(cache.
aspect
== aspect && cache.
wrap_width
== width && cache.
text
== text)) {
37
button->
wrap_cache
.reset();
38
}
39
}
40
if
(!button->
wrap_cache
&& button->
block
->
oldblock
) {
41
int
i = 0;
42
for
(std::shared_ptr<TextWrapCache> &cache_ptr : button->
block
->
oldblock
->
text_wrap_cache
) {
43
TextWrapCache
&cache = *cache_ptr;
44
if
(cache.
aspect
== aspect && cache.
wrap_width
== width && cache.
text
== text) {
45
button->
wrap_cache
= cache_ptr;
46
break
;
47
}
48
i++;
49
}
50
if
(button->
wrap_cache
) {
51
button->
block
->
oldblock
->
text_wrap_cache
.remove(i);
52
}
53
}
54
if
(button->
wrap_cache
) {
55
button->
block
->
text_wrap_cache
.append(button->
wrap_cache
);
56
return
;
57
}
58
button->
wrap_cache
= std::make_unique<TextWrapCache>();
59
TextWrapCache
&cache = *button->
wrap_cache
;
60
cache.
text
= text;
61
cache.
wrap_width
= width;
62
cache.
aspect
= aspect;
63
64
button->
block
->
text_wrap_cache
.append(button->
wrap_cache
);
65
uiFontStyle
fstyle =
style_get
()->
widget
;
66
fontscale
(&fstyle.
points
, aspect);
67
fontstyle_set
(&fstyle);
68
cache.
wrapped_lines
=
BLF_string_wrap
(
69
fstyle.
uifont_id
, cache.
text
, width,
BLFWrapMode::HardLimit
);
70
}
71
72
}
// namespace blender::ui
BLF_api.hh
BLI_rect.hh
blender::StringRef
Definition
BLI_string_ref.hh:165
blender::blender::StringRefBase::trim
constexpr StringRef trim() const
Definition
BLI_string_ref.hh:414
interface_intern.hh
interface_label.hh
blender::ui
Definition
BKE_node.hh:82
blender::ui::style_get
const uiStyle * style_get()
Definition
interface_style.cc:412
blender::ui::fontstyle_set
void fontstyle_set(const uiFontStyle *fs)
Definition
interface_style.cc:608
blender::ui::ButtonLabelType::Multiline
@ Multiline
Definition
interface_intern.hh:504
blender::ui::fontscale
void fontscale(float *points, float aspect)
Definition
interface.cc:2319
blender::ui::ButtonType::Label
@ Label
Definition
UI_interface_c.hh:568
blender::ui::label_multiline_wrap_lines
void label_multiline_wrap_lines(ButtonLabel *button, int icon_pad)
Definition
interface_label.cc:24
blender::ui::button_label_is_multiline
bool button_label_is_multiline(const Button *button)
Definition
interface_label.cc:18
blender::BLF_string_wrap
Vector< StringRef > BLF_string_wrap(int fontid, StringRef str, const int max_pixel_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition
blf.cc:1103
blender::BLI_rctf_size_x
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition
BLI_rect.hh:211
blender::BLFWrapMode::HardLimit
@ HardLimit
Definition
BLF_enums.hh:30
blender::ui::Block::oldblock
Block * oldblock
Definition
interface_intern.hh:711
blender::ui::Block::aspect
float aspect
Definition
interface_intern.hh:735
blender::ui::Block::text_wrap_cache
Vector< std::shared_ptr< TextWrapCache > > text_wrap_cache
Definition
interface_intern.hh:707
blender::ui::ButtonLabel
Definition
interface_intern.hh:509
blender::ui::ButtonLabel::wrap_cache
std::shared_ptr< TextWrapCache > wrap_cache
Definition
interface_intern.hh:521
blender::ui::Button
Definition
interface_intern.hh:198
blender::ui::Button::type
ButtonType type
Definition
interface_intern.hh:207
blender::ui::Button::block
Block * block
Definition
interface_intern.hh:365
blender::ui::Button::rect
rctf rect
Definition
interface_intern.hh:238
blender::ui::Button::str
std::string str
Definition
interface_intern.hh:231
blender::ui::TextWrapCache
Definition
interface_intern.hh:376
blender::ui::TextWrapCache::aspect
float aspect
Definition
interface_intern.hh:378
blender::ui::TextWrapCache::wrap_width
int wrap_width
Definition
interface_intern.hh:377
blender::ui::TextWrapCache::wrapped_lines
Vector< StringRef > wrapped_lines
Definition
interface_intern.hh:380
blender::ui::TextWrapCache::text
std::string text
Definition
interface_intern.hh:379
uiFontStyle
Definition
DNA_theme_types.h:62
uiFontStyle::uifont_id
short uifont_id
Definition
DNA_theme_types.h:64
uiFontStyle::points
float points
Definition
DNA_theme_types.h:67
uiStyle::widget
uiFontStyle widget
Definition
DNA_theme_types.h:92
Generated on
for Blender by
doxygen
1.18.0