Blender V5.3
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
16namespace blender::ui {
17
19{
20 return button->type == ButtonType::Label &&
21 static_cast<const ButtonLabel *>(button)->label_type == ButtonLabelType::Multiline;
22}
23
24void 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);
69 fstyle.uifont_id, cache.text, width, BLFWrapMode::HardLimit);
70}
71
72} // namespace blender::ui
constexpr StringRef trim() const
const uiStyle * style_get()
void fontstyle_set(const uiFontStyle *fs)
void fontscale(float *points, float aspect)
void label_multiline_wrap_lines(ButtonLabel *button, int icon_pad)
bool button_label_is_multiline(const Button *button)
Vector< StringRef > BLF_string_wrap(int fontid, StringRef str, const int max_pixel_width, BLFWrapMode mode=BLFWrapMode::Minimal)
Definition blf.cc:1103
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
Vector< std::shared_ptr< TextWrapCache > > text_wrap_cache
std::shared_ptr< TextWrapCache > wrap_cache
Vector< StringRef > wrapped_lines
uiFontStyle widget