Blender V5.3
interface_label_markdown.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
5#include <cfloat>
6#include <md4c.h>
7
8#include "BKE_context.hh"
9
10#include "DNA_theme_types.h"
11#include "DNA_userdef_types.h"
12
13#include "BLF_api.hh"
14
15#include "BLI_color.hh"
16#include "BLI_index_range.hh"
17#include "BLI_math_base.hh"
18#include "BLI_rect.hh"
19#include "BLI_string_utf8.hh"
20
21#include "BLT_translation.hh"
22
23#include "GPU_immediate.hh"
24#include "GPU_state.hh"
25
26#include "RNA_access.hh"
27
28#include "UI_resources.hh"
29
30#include "WM_api.hh"
31#include "WM_types.hh"
32
33#include "interface_intern.hh"
35
36#include <fmt/format.h>
37
38namespace blender::ui {
39
41 float margin_top = 0.0f;
42 float margin_bottom = 0.0f;
43};
44
46 float size_factor = 1.0f;
47 int weight = 400;
48 bool italic = false;
49 float margin_top = 0.0f;
50 float margin_bottom = 0.0f;
51};
52
54 float margin_top = 0.0f;
55 float margin_bottom = 0.0f;
56 float item_spacing_loose = 0.0f;
57 float item_spacing_tight = 0.0f;
58 float nested_margin_top = 0.0f;
59};
60
62
63namespace md_style {
64
65static std::array<MdHeaderStyle, 6> headers = {
66 MdHeaderStyle{.size_factor = 1.50f,
67 .weight = 700,
68 .italic = false,
69 .margin_top = 1.00f,
70 .margin_bottom = 0.50f},
71 MdHeaderStyle{.size_factor = 1.40f,
72 .weight = 600,
73 .italic = false,
74 .margin_top = 0.50f,
75 .margin_bottom = 0.50f},
76 MdHeaderStyle{.size_factor = 1.20f,
77 .weight = 600,
78 .italic = false,
79 .margin_top = 0.50f,
80 .margin_bottom = 0.25f},
81 MdHeaderStyle{.size_factor = 1.10f,
82 .weight = 600,
83 .italic = false,
84 .margin_top = 0.50f,
85 .margin_bottom = 0.25f},
86 MdHeaderStyle{.size_factor = 1.00f,
87 .weight = 600,
88 .italic = false,
89 .margin_top = 0.50f,
90 .margin_bottom = 0.25f},
91 MdHeaderStyle{.size_factor = 1.00f,
92 .weight = 500,
93 .italic = false,
94 .margin_top = 0.50f,
95 .margin_bottom = 0.25f},
96};
97
98static MdBlockSpacing paragraph = {.margin_top = 0.25f, .margin_bottom = 0.50f};
99static MdBlockSpacing quote = {.margin_top = 0.50f, .margin_bottom = 0.75f};
100static float quote_bar_padding = 0.10f;
101static MdBlockSpacing code_block = {.margin_top = 0.50f, .margin_bottom = 0.75f};
102static float code_block_padding_x = 10.00f;
103static float code_block_padding_y = 8.00f;
104static float code_span_padding_x = 4.00f;
105static float code_span_padding_y = 2.00f;
106static MdBlockSpacing horizontal_rule = {.margin_top = 0.50f, .margin_bottom = 0.50f};
107
108static MdListSpacing list = {.margin_top = 0.50f,
109 .margin_bottom = 1.00f,
110 .item_spacing_loose = 0.50f,
111 .item_spacing_tight = 0.25f,
112 .nested_margin_top = 0.25f};
113
114static float list_indent_px = 18.00f;
115static float list_marker_padding_px = 4.00f;
116static float horizontal_rule_padding = 0.25f;
117
118}; // namespace md_style
119
121{
122 return button->type == ButtonType::Label &&
123 static_cast<const ButtonLabel *>(button)->label_type == ButtonLabelType::Markdown;
124}
125
126static void markdown_apply_font(const int fontid,
127 const float size_px,
128 const int weight,
129 const bool italic)
130{
131 BLF_disable(fontid, BLF_ASPECT);
132 BLF_size(fontid, size_px);
133 BLF_character_weight(fontid, weight);
134 if (italic) {
135 BLF_enable(fontid, BLF_ITALIC);
136 }
137 else {
138 BLF_disable(fontid, BLF_ITALIC);
139 }
140}
141
143{
144 markdown_apply_font(item.fontid, item.size_px, item.weight, item.italic);
145}
146
148{
150}
151
157 private:
158 MarkdownLayoutCache &cache_;
159
160 struct FontConfig {
161 int fontid;
162 float default_size;
163 int default_weight;
164 int bold_weight;
165 float default_line_height_px;
166 };
167
168 FontConfig main_font_;
169 FontConfig mono_font_;
170
172 float x_;
174 float y_;
175
177 float pending_spacing_ = 0.0f;
179 std::optional<float> flow_bottom_;
180
181 struct LineBox {
183 float top;
185 float height;
186 };
188 std::optional<LineBox> current_line_box_;
189
190 struct DocBlock {};
191
192 struct HeaderBlock {
194 int level = 1;
195 };
196
197 struct UnorderedListBlock {
198 bool is_tight = false;
200 bool has_item = false;
201 };
202
203 struct OrderedListBlock {
204 bool is_tight = false;
206 bool has_item = false;
207 int next_number = 1;
208 char mark_delimiter = '.';
209 };
210
211 struct ListItemBlock {
213 std::optional<int> number;
218 bool marker_pending = true;
219 };
220
221 struct ParagraphBlock {};
222
223 struct CodeBlock {
224 rctf bounds;
225 };
226
227 struct QuoteBlock {
228 float start_y = 0.0f;
229 float content_top = -FLT_MAX;
230 float content_bottom = FLT_MAX;
231 };
232
233 struct HorizontalRuleBlock {};
234
235 struct UnknownBlock {};
236
237 struct EmSpan {};
238 struct StrongSpan {};
239 struct LinkSpan {
240 StringRef url;
241 };
242 struct CodeSpan {
243 Vector<rctf, 2> line_bounds;
244 rctf current_bounds;
245 bool padding_left_applied = false;
246 };
247 struct UnknownSpan {};
248
249 using MdBlock = std::variant<DocBlock,
250 HeaderBlock,
251 UnorderedListBlock,
252 OrderedListBlock,
253 ListItemBlock,
254 ParagraphBlock,
255 CodeBlock,
256 QuoteBlock,
257 HorizontalRuleBlock,
258 UnknownBlock>;
259 using MdSpan = std::variant<EmSpan, StrongSpan, LinkSpan, CodeSpan, UnknownSpan>;
260
261 Vector<MdBlock, 16> block_stack_;
262 Vector<MdSpan, 16> span_stack_;
263
264 public:
265 MarkdownLayouter(MarkdownLayoutCache &cache_) : cache_(cache_)
266 {
267 const uiFontStyle &widget_style = style_get()->widget;
268 main_font_ = this->make_font_config(
269 widget_style.uifont_id, widget_style.points, widget_style.character_weight, 700);
270 mono_font_ = this->make_font_config(
271 blf_mono_font, widget_style.points, widget_style.character_weight, 700);
272 x_ = 0.0f;
273 y_ = 0.0f;
274 }
275
276 FontConfig make_font_config(const int fontid,
277 const float default_size,
278 const int default_weight,
279 const int bold_weight)
280 {
281 FontConfig config;
282 config.fontid = fontid;
283 config.default_size = default_size;
284 config.default_weight = default_weight;
285 config.bold_weight = bold_weight;
286 markdown_apply_font(fontid, default_size * cache_.key.pixels_per_point, default_weight, false);
287 config.default_line_height_px = BLF_height_max(fontid);
288 return config;
289 }
290
292 {
293 MD_PARSER md_parser{};
294 md_parser.enter_block = [](MD_BLOCKTYPE block_type, void *detail, void *userdata) {
295 static_cast<MarkdownLayouter *>(userdata)->md_enter_block(block_type, detail);
296 return 0;
297 };
298 md_parser.leave_block = [](MD_BLOCKTYPE block_type, void *detail, void *userdata) {
299 static_cast<MarkdownLayouter *>(userdata)->md_leave_block(block_type, detail);
300 return 0;
301 };
302 md_parser.enter_span = [](MD_SPANTYPE span_type, void *detail, void *userdata) {
303 static_cast<MarkdownLayouter *>(userdata)->md_enter_span(span_type, detail);
304 return 0;
305 };
306 md_parser.leave_span = [](MD_SPANTYPE span_type, void *detail, void *userdata) {
307 static_cast<MarkdownLayouter *>(userdata)->md_leave_span(span_type, detail);
308 return 0;
309 };
310 md_parser.text = [](MD_TEXTTYPE text_type, const char *text, uint32_t length, void *userdata) {
311 static_cast<MarkdownLayouter *>(userdata)->md_text(text_type, StringRef(text, length));
312 return 0;
313 };
314
315 const StringRef text = cache_.key.text;
316 md_parse(text.data(), text.size(), &md_parser, this);
318 }
319
320 void add_pending_spacing(const float spacing)
321 {
322 pending_spacing_ = std::max(pending_spacing_, this->spacing_px(spacing));
323 }
324
326 {
327 if (!current_line_box_) {
328 return;
329 }
330 flow_bottom_ = current_line_box_->top - current_line_box_->height;
331 current_line_box_.reset();
332 }
333
335 {
336 if (current_line_box_) {
337 this->line_box_end();
338 return;
339 }
340 const float top = flow_bottom_.value_or(0.0f) - pending_spacing_;
341 flow_bottom_ = top - main_font_.default_line_height_px;
342 pending_spacing_ = 0.0f;
343 }
344
345 void md_enter_block(const MD_BLOCKTYPE block_type, void *detail)
346 {
347 switch (block_type) {
348 case MD_BLOCK_QUOTE: {
349 block_stack_.append(QuoteBlock{});
350 break;
351 }
352 case MD_BLOCK_UL: {
353 const auto *ul_detail = static_cast<const MD_BLOCK_UL_DETAIL *>(detail);
354 block_stack_.append(UnorderedListBlock{bool(ul_detail->is_tight)});
355 break;
356 }
357 case MD_BLOCK_OL: {
358 const auto *ol_detail = static_cast<const MD_BLOCK_OL_DETAIL *>(detail);
359 block_stack_.append(OrderedListBlock{bool(ol_detail->is_tight),
360 false,
361 int(ol_detail->start),
362 char(ol_detail->mark_delimiter)});
363 break;
364 }
365 case MD_BLOCK_LI: {
366 ListItemBlock list_item;
367 if (!block_stack_.is_empty()) {
368 if (auto *ol = std::get_if<OrderedListBlock>(&block_stack_.last())) {
369 list_item.number = ol->next_number++;
370 if (ol->has_item) {
371 this->add_pending_spacing(ol->is_tight ? md_style::list.item_spacing_tight :
372 md_style::list.item_spacing_loose);
373 }
374 ol->has_item = true;
375 }
376 else if (auto *ul = std::get_if<UnorderedListBlock>(&block_stack_.last())) {
377 if (ul->has_item) {
378 this->add_pending_spacing(ul->is_tight ? md_style::list.item_spacing_tight :
379 md_style::list.item_spacing_loose);
380 }
381 ul->has_item = true;
382 }
383 }
384 block_stack_.append(list_item);
385 break;
386 }
387 case MD_BLOCK_H: {
388 const auto *h_detail = static_cast<const MD_BLOCK_H_DETAIL *>(detail);
389 block_stack_.append(HeaderBlock{std::clamp<int>(h_detail->level, 1, 6)});
390 break;
391 }
392 case MD_BLOCK_CODE: {
393 CodeBlock code_block;
394 BLI_rctf_init_minmax(&code_block.bounds);
395 block_stack_.append(code_block);
396 break;
397 }
398 case MD_BLOCK_P: {
399 block_stack_.append(ParagraphBlock{});
400 break;
401 }
402 case MD_BLOCK_DOC: {
403 block_stack_.append(DocBlock{});
404 break;
405 }
406 case MD_BLOCK_HR: {
407 block_stack_.append(HorizontalRuleBlock{});
408 break;
409 }
410 case MD_BLOCK_HTML:
411 case MD_BLOCK_TABLE:
412 case MD_BLOCK_THEAD:
413 case MD_BLOCK_TBODY:
414 case MD_BLOCK_TR:
415 case MD_BLOCK_TH:
416 case MD_BLOCK_TD: {
417 /* Not implemented. */
418 block_stack_.append(UnknownBlock{});
419 break;
420 }
421 }
422
423 if (!std::holds_alternative<DocBlock>(block_stack_.last())) {
424 this->line_box_end();
425 }
426
427 if (flow_bottom_) {
428 this->add_pending_spacing(this->block_margin_top(block_stack_.last()));
429 }
430 if (std::holds_alternative<CodeBlock>(block_stack_.last())) {
431 pending_spacing_ += this->code_block_padding_y_px();
432 }
433 if (is_list_container_block(block_stack_.last()) && this->is_direct_child_of_list_item()) {
434 this->add_pending_spacing(md_style::list.nested_margin_top);
435 }
436 x_ = this->context_block_start_x();
437
438 switch (block_type) {
439 case MD_BLOCK_HR: {
441 break;
442 }
443 case MD_BLOCK_QUOTE: {
444 std::get<QuoteBlock>(block_stack_.last()).start_y = flow_bottom_.value_or(0.0f) -
445 pending_spacing_;
446 break;
447 }
448 default: {
449 break;
450 }
451 }
452 }
453
454 float list_indent_px() const
455 {
456 return md_style::list_indent_px * cache_.key.pixels_per_point;
457 }
458
460 {
461 return md_style::code_block_padding_x * cache_.key.pixels_per_point;
462 }
463
465 {
466 return md_style::code_block_padding_y * cache_.key.pixels_per_point;
467 }
468
470 {
471 return md_style::code_span_padding_x * cache_.key.pixels_per_point;
472 }
473
475 {
476 return md_style::code_span_padding_y * cache_.key.pixels_per_point;
477 }
478
480 {
481 for (const int i : span_stack_.index_range()) {
482 MdSpan &md_span = span_stack_[span_stack_.size() - 1 - i];
483 if (auto *code_span = std::get_if<CodeSpan>(&md_span)) {
484 return code_span;
485 }
486 }
487 return nullptr;
488 }
489
491 {
492 float indentation = 0.0f;
493 const float indent = this->list_indent_px();
494 for (const auto &md_block : block_stack_) {
495 if (std::holds_alternative<QuoteBlock>(md_block)) {
496 indentation += indent;
497 }
498 if (std::holds_alternative<ListItemBlock>(md_block)) {
499 indentation += indent;
500 }
501 }
502 return indentation;
503 }
504
506 {
507 float x = this->context_block_start_x();
508 if (this->is_in_fenced_code_block()) {
509 x += this->code_block_padding_x_px();
510 }
511 return x;
512 }
513
515 {
516 float x = float(cache_.key.wrap_width_px);
517 if (this->is_in_fenced_code_block()) {
518 x -= this->code_block_padding_x_px();
519 }
520 return x;
521 }
522
523 static StringRef unordered_bullet_for_level(const int level)
524 {
525 switch (level % 3) {
526 case 1:
527 return "â—¦";
528 case 2:
529 return "â–ª";
530 default:
531 return "•";
532 }
533 }
534
536 {
537 for (const int64_t list_item_index : block_stack_.index_range()) {
538 auto *list_item = std::get_if<ListItemBlock>(&block_stack_[list_item_index]);
539 if (!list_item || !list_item->marker_pending) {
540 continue;
541 }
542 list_item->marker_pending = false;
543
544 MarkdownItemText item;
545 item.size_px = main_font_.default_size * cache_.key.pixels_per_point;
546 item.fontid = main_font_.fontid;
547 item.weight = main_font_.default_weight;
548 item.italic = false;
549 item.is_in_quote = this->is_in_quote();
550 item.y = y_;
551
552 int unordered_list_level = -1;
553 char ordered_delimiter = '.';
554 float content_x = 0.0f;
555 for (const int64_t ancestor_index : IndexRange(list_item_index + 1)) {
556 const MdBlock &ancestor = block_stack_[ancestor_index];
557 if (std::holds_alternative<QuoteBlock>(ancestor) ||
558 std::holds_alternative<ListItemBlock>(ancestor))
559 {
560 content_x += this->list_indent_px();
561 }
562 if (std::holds_alternative<UnorderedListBlock>(ancestor)) {
563 unordered_list_level++;
564 }
565 if (const auto *ordered_list = std::get_if<OrderedListBlock>(&ancestor)) {
566 ordered_delimiter = ordered_list->mark_delimiter;
567 }
568 }
569
570 if (list_item->number) {
571 item.text = cache_.scope.allocator().copy_string(
572 fmt::format("{}{}", *list_item->number, ordered_delimiter));
573 }
574 else {
575 item.text = unordered_bullet_for_level(std::max(unordered_list_level, 0));
576 }
577
579 const float marker_width = BLF_width(item.fontid, item.text.data(), item.text.size());
581
582 if (list_item->number) {
583 /* Right-align the number towards the content. */
584 item.x = content_x - marker_width -
585 md_style::list_marker_padding_px * cache_.key.pixels_per_point;
586 }
587 else {
588 /* Center the bullet in the list-item indent gutter. */
589 item.x = content_x - this->list_indent_px() * 0.5f - marker_width * 0.5f;
590 }
591 cache_.md_layout.items.append(item);
592 this->track_quote_text_bounds(item);
593 }
594 }
595
597 {
599 const float rule_top = flow_bottom_.value_or(0.0f) - pending_spacing_ - padding;
600 constexpr float rule_height = 1.0f;
601 cache_.md_layout.items.append(MarkdownItemHorizontalRule{rule_top - rule_height * 0.5f});
602 flow_bottom_ = rule_top - rule_height - padding;
603 pending_spacing_ = 0.0f;
604 }
605
607 {
608 if (!this->is_in_quote()) {
609 return;
610 }
611
613 const float top = item.y + BLF_ascender(item.fontid);
614 const float bottom = item.y + BLF_descender(item.fontid);
616
617 for (MdBlock &md_block : block_stack_) {
618 if (auto *quote = std::get_if<QuoteBlock>(&md_block)) {
619 quote->content_top = std::max(quote->content_top, top);
620 quote->content_bottom = std::min(quote->content_bottom, bottom);
621 }
622 }
623 }
624
626 {
628 const float top = item.y + BLF_ascender(item.fontid);
629 const float bottom = item.y + BLF_descender(item.fontid);
630 const float right = item.x + BLF_width(item.fontid, item.text.data(), item.text.size());
632
633 const rctf part{.xmin = item.x, .xmax = right, .ymin = bottom, .ymax = top};
634
635 if (this->is_in_fenced_code_block()) {
636 for (MdBlock &md_block : block_stack_) {
637 if (auto *code_block = std::get_if<CodeBlock>(&md_block)) {
638 BLI_rctf_union(&code_block->bounds, &part);
639 }
640 }
641 }
642
644 if (CodeSpan *code_span = this->mutable_current_code_span()) {
645 BLI_rctf_union(&code_span->current_bounds, &part);
646 }
647 }
648 }
649
651 {
652 CodeSpan *code_span = this->mutable_current_code_span();
653 if (!code_span || code_span->padding_left_applied) {
654 return;
655 }
656 x_ += this->code_span_padding_x_px();
657 code_span->padding_left_applied = true;
658 }
659
661 {
662 CodeSpan *code_span = this->mutable_current_code_span();
663 if (!code_span || BLI_rctf_is_empty(&code_span->current_bounds)) {
664 return;
665 }
666 code_span->line_bounds.append(code_span->current_bounds);
667 BLI_rctf_init_minmax(&code_span->current_bounds);
668 }
669
670 void append_code_span_boxes(const CodeSpan &code_span)
671 {
672 const float padding_x = this->code_span_padding_x_px();
673 const float padding_y = this->code_span_padding_y_px();
674
675 for (const rctf &bounds : code_span.line_bounds) {
677 continue;
678 }
679
682 box.rect.xmin = bounds.xmin - padding_x;
683 box.rect.xmax = bounds.xmax + padding_x;
684 box.rect.ymax = bounds.ymax + padding_y;
685 box.rect.ymin = bounds.ymin - padding_y;
686 cache_.md_layout.items.append(box);
687 }
688 }
689
690 void extend_flow_bottom_for_code_block(const CodeBlock &code_block)
691 {
692 if (BLI_rctf_is_empty(&code_block.bounds)) {
693 return;
694 }
695
696 const float box_bottom = code_block.bounds.ymin - this->code_block_padding_y_px();
697 if (!flow_bottom_) {
698 flow_bottom_ = box_bottom;
699 return;
700 }
701 flow_bottom_ = std::min(*flow_bottom_, box_bottom);
702 }
703
705 {
706 const auto *code_block = std::get_if<CodeBlock>(&block_stack_.last());
707 if (!code_block || BLI_rctf_is_empty(&code_block->bounds)) {
708 return;
709 }
710
711 const float padding_y = this->code_block_padding_y_px();
712
715 box.rect.xmin = this->context_block_start_x();
716 box.rect.xmax = float(cache_.key.wrap_width_px);
717 box.rect.ymax = code_block->bounds.ymax + padding_y;
718 box.rect.ymin = code_block->bounds.ymin - padding_y;
719 cache_.md_layout.items.append(box);
720 }
721
723 {
724 const auto *quote = std::get_if<QuoteBlock>(&block_stack_.last());
725 BLI_assert(quote);
726 if (!quote) {
727 return;
728 }
729
730 float top;
731 float bottom;
732 if (quote->content_top != -FLT_MAX) {
733 const float padding = md_style::quote_bar_padding * main_font_.default_line_height_px;
734 top = quote->content_top + padding;
735 bottom = quote->content_bottom - padding;
736 }
737 else {
738 top = quote->start_y;
739 bottom = y_;
740 }
741
742 const float height = top - bottom;
743 if (height <= 0.0f) {
744 return;
745 }
747 line.x = this->context_block_start_x() - this->list_indent_px() * 0.5f;
748 line.y = top;
749 line.height = height;
750 cache_.md_layout.items.append(line);
751 }
752
753 bool is_in_quote() const
754 {
755 for (const auto &md_block : block_stack_) {
756 if (std::holds_alternative<QuoteBlock>(md_block)) {
757 return true;
758 }
759 }
760 return false;
761 }
762
764 {
765 for (const MdBlock &md_block : block_stack_) {
766 if (std::holds_alternative<CodeBlock>(md_block)) {
767 return true;
768 }
769 }
770 return false;
771 }
772
773 bool has_code_span() const
774 {
775 for (const MdSpan &md_span : span_stack_) {
776 if (std::holds_alternative<CodeSpan>(md_span)) {
777 return true;
778 }
779 }
780 return false;
781 }
782
783 bool is_code() const
784 {
785 return this->is_in_fenced_code_block() || this->has_code_span();
786 }
787
788 static bool is_list_container_block(const MdBlock &block)
789 {
790 return std::holds_alternative<UnorderedListBlock>(block) ||
791 std::holds_alternative<OrderedListBlock>(block);
792 }
793
795 {
796 if (block_stack_.size() < 2) {
797 return false;
798 }
799 return std::holds_alternative<ListItemBlock>(block_stack_[block_stack_.size() - 2]);
800 }
801
802 float spacing_px(const float multiplier) const
803 {
804 return main_font_.default_line_height_px * multiplier;
805 }
806
807 float block_margin_top(const MdBlock &block) const
808 {
809 if (const auto *header = std::get_if<HeaderBlock>(&block)) {
810 return md_style::headers[header->level - 1].margin_top;
811 }
812 if (std::holds_alternative<ParagraphBlock>(block)) {
813 return md_style::paragraph.margin_top;
814 }
815 if (std::holds_alternative<QuoteBlock>(block)) {
816 return md_style::quote.margin_top;
817 }
818 if (std::holds_alternative<CodeBlock>(block)) {
819 return md_style::code_block.margin_top;
820 }
821 if (std::holds_alternative<HorizontalRuleBlock>(block)) {
822 return md_style::horizontal_rule.margin_top;
823 }
824 if (std::holds_alternative<UnorderedListBlock>(block) ||
825 std::holds_alternative<OrderedListBlock>(block))
826 {
827 return md_style::list.margin_top;
828 }
829 return 0.0f;
830 }
831
832 float block_margin_bottom(const MdBlock &block) const
833 {
834 if (const auto *header = std::get_if<HeaderBlock>(&block)) {
835 return md_style::headers[header->level - 1].margin_bottom;
836 }
837 if (std::holds_alternative<ParagraphBlock>(block)) {
838 return md_style::paragraph.margin_bottom;
839 }
840 if (std::holds_alternative<QuoteBlock>(block)) {
841 return md_style::quote.margin_bottom;
842 }
843 if (std::holds_alternative<CodeBlock>(block)) {
844 return md_style::code_block.margin_bottom;
845 }
846 if (std::holds_alternative<HorizontalRuleBlock>(block)) {
847 return md_style::horizontal_rule.margin_bottom;
848 }
849 if (std::holds_alternative<UnorderedListBlock>(block) ||
850 std::holds_alternative<OrderedListBlock>(block))
851 {
852 return md_style::list.margin_bottom;
853 }
854 return 0.0f;
855 }
856
857 void md_leave_block(const MD_BLOCKTYPE block_type, void * /*detail*/)
858 {
859 const MdBlock &md_block = block_stack_.last();
860 if (const auto *list_item = std::get_if<ListItemBlock>(&md_block);
861 list_item && list_item->marker_pending)
862 {
863 markdown_apply_font(main_font_.fontid,
864 main_font_.default_size * cache_.key.pixels_per_point,
865 main_font_.default_weight,
866 false);
867 this->ensure_line_box(main_font_.fontid);
868 }
869 if (std::holds_alternative<HeaderBlock>(md_block) ||
870 std::holds_alternative<ListItemBlock>(md_block) ||
871 std::holds_alternative<ParagraphBlock>(md_block) ||
872 std::holds_alternative<CodeBlock>(md_block))
873 {
874 this->line_box_end();
875 }
876 switch (block_type) {
877 case MD_BLOCK_QUOTE: {
878 BLI_assert(std::holds_alternative<QuoteBlock>(md_block));
879 this->append_quote_line();
880 break;
881 }
882 case MD_BLOCK_UL: {
883 BLI_assert(std::holds_alternative<UnorderedListBlock>(md_block));
884 break;
885 }
886 case MD_BLOCK_OL: {
887 BLI_assert(std::holds_alternative<OrderedListBlock>(md_block));
888 break;
889 }
890 case MD_BLOCK_LI: {
891 BLI_assert(std::holds_alternative<ListItemBlock>(md_block));
892 break;
893 }
894 case MD_BLOCK_H: {
895 BLI_assert(std::holds_alternative<HeaderBlock>(md_block));
896 break;
897 }
898 case MD_BLOCK_CODE: {
899 BLI_assert(std::holds_alternative<CodeBlock>(md_block));
900 this->extend_flow_bottom_for_code_block(std::get<CodeBlock>(md_block));
901 this->append_code_block_box();
902 break;
903 }
904 case MD_BLOCK_P: {
905 BLI_assert(std::holds_alternative<ParagraphBlock>(md_block));
906 break;
907 }
908 case MD_BLOCK_DOC: {
909 BLI_assert(std::holds_alternative<DocBlock>(md_block));
910 break;
911 }
912 case MD_BLOCK_HR: {
913 BLI_assert(std::holds_alternative<HorizontalRuleBlock>(md_block));
914 break;
915 }
916 case MD_BLOCK_HTML:
917 case MD_BLOCK_TABLE:
918 case MD_BLOCK_THEAD:
919 case MD_BLOCK_TBODY:
920 case MD_BLOCK_TR:
921 case MD_BLOCK_TH:
922 case MD_BLOCK_TD: {
923 BLI_assert(std::holds_alternative<UnknownBlock>(md_block));
924 break;
925 }
926 }
927 this->add_pending_spacing(this->block_margin_bottom(md_block));
928 block_stack_.pop_last();
929 }
930
931 void md_enter_span(const MD_SPANTYPE span_type, void *detail)
932 {
933 switch (span_type) {
934 case MD_SPAN_EM: {
935 span_stack_.append(EmSpan{});
936 break;
937 }
938 case MD_SPAN_STRONG: {
939 span_stack_.append(StrongSpan{});
940 break;
941 }
942 case MD_SPAN_A: {
943 const auto *a_detail = static_cast<const MD_SPAN_A_DETAIL *>(detail);
944 span_stack_.append(LinkSpan{cache_.scope.allocator().copy_string(
945 StringRef(a_detail->href.text, a_detail->href.size))});
946 break;
947 }
948 case MD_SPAN_CODE: {
949 CodeSpan code_span;
950 BLI_rctf_init_minmax(&code_span.current_bounds);
951 span_stack_.append(code_span);
952 break;
953 }
954 case MD_SPAN_IMG:
955 case MD_SPAN_DEL:
956 case MD_SPAN_LATEXMATH:
957 case MD_SPAN_LATEXMATH_DISPLAY:
958 case MD_SPAN_WIKILINK:
959 case MD_SPAN_U: {
960 /* Not implemented. */
961 span_stack_.append(UnknownSpan{});
962 break;
963 }
964 }
965 }
966
967 void md_leave_span(const MD_SPANTYPE span_type, void * /*detail*/)
968 {
969 const MdSpan &md_span = span_stack_.last();
970 switch (span_type) {
971 case MD_SPAN_EM: {
972 BLI_assert(std::holds_alternative<EmSpan>(md_span));
973 break;
974 }
975 case MD_SPAN_STRONG: {
976 BLI_assert(std::holds_alternative<StrongSpan>(md_span));
977 break;
978 }
979 case MD_SPAN_A: {
980 BLI_assert(std::holds_alternative<LinkSpan>(md_span));
981 break;
982 }
983 case MD_SPAN_CODE: {
984 BLI_assert(std::holds_alternative<CodeSpan>(md_span));
986 this->append_code_span_boxes(std::get<CodeSpan>(md_span));
987 x_ += this->code_span_padding_x_px();
988 break;
989 }
990 case MD_SPAN_IMG:
991 case MD_SPAN_DEL:
992 case MD_SPAN_LATEXMATH:
993 case MD_SPAN_LATEXMATH_DISPLAY:
994 case MD_SPAN_WIKILINK:
995 case MD_SPAN_U: {
996 BLI_assert(std::holds_alternative<UnknownSpan>(md_span));
997 break;
998 }
999 }
1000 span_stack_.pop_last();
1001 }
1002
1003 void md_text(const MD_TEXTTYPE text_type, const StringRef text)
1004 {
1005 switch (text_type) {
1006 case MD_TEXT_NORMAL: {
1007 this->md_text_normal(text);
1008 break;
1009 }
1010 case MD_TEXT_CODE: {
1011 this->md_text_code(text);
1012 break;
1013 }
1014 case MD_TEXT_BR:
1015 case MD_TEXT_SOFTBR: {
1016 this->add_line_break();
1017 x_ = this->context_content_start_x();
1018 break;
1019 }
1020 case MD_TEXT_NULLCHAR:
1021 case MD_TEXT_ENTITY:
1022 case MD_TEXT_HTML:
1023 case MD_TEXT_LATEXMATH: {
1024 /* Not implemented. */
1025 break;
1026 }
1027 }
1028 }
1029
1030 void md_text_normal(const StringRef text)
1031 {
1032 const ContextFontSettings settings = this->get_context_font_settings();
1033 const float start_x = this->context_content_start_x();
1034 this->output_wrapped_text(text,
1035 settings.size,
1036 settings.fontid,
1037 settings.weight,
1038 settings.italic,
1039 settings.url,
1040 start_x);
1041 }
1042
1044 {
1045 const ContextFontSettings settings = this->get_context_font_settings();
1046 const float start_x = this->context_content_start_x();
1047 markdown_apply_font(settings.fontid,
1048 settings.size * cache_.key.pixels_per_point,
1049 settings.weight,
1050 settings.italic);
1051 while (!text.is_empty()) {
1052 /* Literal newlines should be taken into account in code. */
1053 if (text[0] == '\n') {
1054 text = text.drop_prefix(1);
1055 this->add_line_break();
1056 x_ = start_x;
1057 continue;
1058 }
1059 const int64_t newline = text.find_first_of('\n');
1060 if (newline == StringRef::not_found) {
1061 this->output_wrapped_text(text,
1062 settings.size,
1063 settings.fontid,
1064 settings.weight,
1065 settings.italic,
1066 settings.url,
1067 start_x);
1068 break;
1069 }
1070 this->output_wrapped_text(text.substr(0, newline),
1071 settings.size,
1072 settings.fontid,
1073 settings.weight,
1074 settings.italic,
1075 settings.url,
1076 start_x);
1077 text = text.drop_prefix(newline);
1078 }
1079 }
1080
1085 float size;
1086 std::optional<StringRef> url;
1087 };
1088
1089 void ensure_line_box(const int fontid)
1090 {
1091 const float padding_y = this->has_code_span() ? this->code_span_padding_y_px() : 0.0f;
1092 const float line_height = BLF_height_max(fontid) + 2.0f * padding_y;
1093 if (current_line_box_) {
1094 current_line_box_->height = std::max(current_line_box_->height, line_height);
1095 return;
1096 }
1097
1098 current_line_box_ = LineBox{flow_bottom_.value_or(0.0f) - pending_spacing_, line_height};
1099 y_ = current_line_box_->top - BLF_ascender(fontid) - padding_y;
1100 pending_spacing_ = 0.0f;
1101 x_ = this->context_content_start_x();
1103 }
1104
1106 {
1107 ContextFontSettings settings;
1108 settings.fontid = main_font_.fontid;
1109 settings.weight = main_font_.default_weight;
1110 settings.size = main_font_.default_size;
1111 settings.italic = false;
1112
1113 if (this->is_in_fenced_code_block()) {
1114 settings.fontid = mono_font_.fontid;
1115 settings.size = mono_font_.default_size;
1116 settings.weight = mono_font_.default_weight;
1117 settings.italic = false;
1118 return settings;
1119 }
1120
1121 for (const auto &md_block : block_stack_) {
1122 if (const auto *header_block = std::get_if<HeaderBlock>(&md_block)) {
1123 const MdHeaderStyle &style = md_style::headers[header_block->level - 1];
1124 settings.fontid = main_font_.fontid;
1125 settings.size = main_font_.default_size * style.size_factor;
1126 settings.weight = style.weight;
1127 settings.italic = style.italic;
1128 }
1129 }
1130 for (const auto &md_span : span_stack_) {
1131 if (std::holds_alternative<CodeSpan>(md_span)) {
1132 settings.fontid = mono_font_.fontid;
1133 settings.weight = mono_font_.default_weight;
1134 settings.italic = false;
1135 }
1136 if (std::holds_alternative<StrongSpan>(md_span)) {
1137 settings.weight = main_font_.bold_weight;
1138 }
1139 if (std::holds_alternative<EmSpan>(md_span)) {
1140 settings.italic = true;
1141 }
1142 if (const auto *link_span = std::get_if<LinkSpan>(&md_span)) {
1143 settings.url = link_span->url;
1144 }
1145 }
1146 return settings;
1147 }
1148
1150 const float size,
1151 const int fontid,
1152 const int weight,
1153 const bool italic,
1154 const std::optional<StringRef> &url,
1155 const float start_x)
1156 {
1157 MarkdownItemText item_template;
1158 item_template.size_px = size * cache_.key.pixels_per_point;
1159 item_template.fontid = fontid;
1160 item_template.weight = weight;
1161 item_template.italic = italic;
1162 item_template.is_in_quote = this->is_in_quote();
1163 item_template.code_context = this->is_in_fenced_code_block() ?
1165 (this->has_code_span() ?
1168 item_template.url = url;
1169
1170 markdown_apply_item_font(item_template);
1171 BLI_SCOPED_DEFER([&]() { markdown_disable_item_font(item_template); });
1172
1173 while (!text.is_empty()) {
1174 this->ensure_line_box(fontid);
1177 }
1178 /* A list marker uses the body font and may have changed the active font settings. */
1179 markdown_apply_item_font(item_template);
1180 const float remaining_width = this->context_content_end_x() - x_;
1181 float needed_width = 0.0f;
1182 const int64_t last_fit_char_i = int64_t(BLF_width_to_strlen(
1183 fontid, text.data(), size_t(text.size()), remaining_width, &needed_width));
1184
1185 /* Number of bytes that should be drawn in the current line. */
1186 int64_t draw_bytes = last_fit_char_i;
1187 /* Number of bytes that should be skipped (this skips e.g. white-space at the line end). */
1188 int64_t drop_bytes = last_fit_char_i;
1189 const bool wrap_to_next_line = last_fit_char_i < text.size();
1190
1191 if (wrap_to_next_line) {
1192 const int64_t last_space = (last_fit_char_i > 0) ?
1193 text.find_last_of(' ', int64_t(last_fit_char_i) - 1) :
1195 if (last_space != StringRef::not_found) {
1196 draw_bytes = last_space;
1197 /* Skip the space. */
1198 drop_bytes = last_space + 1;
1199 needed_width = BLF_width(fontid, text.data(), draw_bytes);
1200 }
1201 else if (x_ > start_x) {
1202 /* Line has already started and the current word does not fit on it; retry on the next
1203 * line. */
1204 this->line_box_end();
1205 x_ = start_x;
1206 continue;
1207 }
1208 else if (last_fit_char_i == 0) {
1209 /* Nothing fits on an empty line; advance one character to avoid an infinite loop. */
1210 draw_bytes = BLI_str_utf8_size_safe(text.data());
1211 drop_bytes = draw_bytes;
1212 needed_width = BLF_width(fontid, text.data(), draw_bytes);
1213 }
1214 }
1215
1216 const StringRef fitting_text = text.substr(0, draw_bytes);
1217 text = text.drop_prefix(drop_bytes);
1218
1219 if (draw_bytes > 0) {
1220 item_template.text = fitting_text;
1221 item_template.x = x_;
1222 item_template.y = y_;
1223 cache_.md_layout.items.append(item_template);
1224 this->track_quote_text_bounds(item_template);
1225 this->track_code_text_bounds(item_template);
1226 }
1227 if (wrap_to_next_line) {
1230 }
1231 this->line_box_end();
1232 x_ = start_x;
1233 }
1234 else {
1235 x_ += needed_width;
1236 }
1237 }
1238 }
1239
1241 {
1242 this->line_box_end();
1243 if (!flow_bottom_) {
1244 cache_.md_layout.content_height = main_font_.default_line_height_px;
1245 return;
1246 }
1247
1248 float bottom_y = *flow_bottom_;
1249 for (const MarkdownItem &item : cache_.md_layout.items) {
1250 if (const auto *quote_line = std::get_if<MarkdownItemQuoteLine>(&item)) {
1251 bottom_y = std::min(bottom_y, quote_line->y - quote_line->height);
1252 }
1253 if (const auto *code_box = std::get_if<MarkdownItemCodeBox>(&item)) {
1254 bottom_y = std::min(bottom_y, code_box->rect.ymin);
1255 }
1256 }
1257 cache_.md_layout.content_height = -bottom_y;
1258 }
1259};
1260
1262{
1263 if (!button->markdown_cache) {
1264 return;
1265 }
1266 const MarkdownLayoutCache &cache = *button->markdown_cache;
1267 if (cache.md_layout.items.is_empty()) {
1268 return;
1269 }
1270
1271 Block *block = button->block;
1272 const float aspect = block->aspect;
1273 wmOperatorType *ot = WM_operatortype_find("WM_OT_url_open", false);
1274 if (!ot) {
1275 return;
1276 }
1277
1278 for (const MarkdownItem &item : cache.md_layout.items) {
1279 const auto *text_item_ptr = std::get_if<MarkdownItemText>(&item);
1280 if (!text_item_ptr || !text_item_ptr->url) {
1281 continue;
1282 }
1283 const MarkdownItemText &text_item = *text_item_ptr;
1284
1285 markdown_apply_item_font(text_item);
1286
1287 const StringRef text = text_item.text;
1288 const float descender_px = BLF_descender(text_item.fontid);
1289 const float ascender_px = BLF_ascender(text_item.fontid);
1290 const float font_height = (ascender_px - descender_px) * aspect;
1291 const float width = BLF_width(text_item.fontid, text.data(), text.size()) * aspect;
1292
1293 const float x = button->rect.xmin + text_item.x * aspect;
1294 const float y = button->rect.ymax + (text_item.y + descender_px) * aspect;
1295
1296 const EmbossType previous_emboss = block_emboss_get(block);
1298 Button *but = uiDefIconBut(block,
1300 ICON_NONE,
1301 x,
1302 y,
1303 width,
1304 font_height,
1305 nullptr,
1306 0.0,
1307 0.0,
1308 std::nullopt);
1309 block_emboss_set(block, previous_emboss);
1310
1311 static_cast<ButtonPush *>(but)->draw_as_link = true;
1312
1314 RNA_string_set(&props, "url", std::string(*text_item.url).c_str());
1316
1317 /* Invisible hit-target; markdown draw paints the link text. Show URL on hover. */
1319 but,
1320 [](bContext & /*C*/, TooltipData &data, Button *tip_but, void * /*argN*/) {
1322 RNA_string_get(tip_but->opptr, "url"),
1323 {},
1326 false);
1327 },
1328 nullptr,
1329 nullptr);
1330
1331 markdown_disable_item_font(text_item);
1332 }
1333}
1334
1336{
1337 Vector<ButtonLabel *> markdown_labels;
1338 for (Button &but : block->buttons()) {
1339 if (button_label_is_markdown(&but)) {
1340 markdown_labels.append(static_cast<ButtonLabel *>(&but));
1341 }
1342 }
1343 for (ButtonLabel *label : markdown_labels) {
1345 }
1346}
1347
1349{
1350 const float aspect = button.block->aspect;
1352 key.text = button.str;
1353 key.wrap_width_px = std::max<int>(std::ceil(BLI_rctf_size_x(&button.rect) / aspect), 0);
1354 key.pixels_per_point = UI_SCALE_FAC / aspect;
1356 return key;
1357}
1358
1360{
1361 button.rect.ymin = button.rect.ymax -
1362 button.markdown_cache->md_layout.content_height * button.block->aspect;
1363}
1364
1366{
1367 const MarkdownLayoutCacheKey cache_lookup_key = markdown_layout_key_for_button(*button);
1368 {
1369 /* Try to reuse an already attached cache. */
1370 if (button->markdown_cache) {
1371 const MarkdownLayoutCache &cache = *button->markdown_cache;
1372 if (cache.key != cache_lookup_key) {
1373 button->markdown_cache.reset();
1374 }
1375 }
1376 /* Try to take a matching cache from the previous block. */
1377 if (!button->markdown_cache && button->block->oldblock) {
1378 int i = 0;
1379 for (std::shared_ptr<MarkdownLayoutCache> &cache_ptr :
1381 {
1382 MarkdownLayoutCache &cache = *cache_ptr;
1383 if (cache.key == cache_lookup_key) {
1384 button->markdown_cache = cache_ptr;
1385 break;
1386 }
1387 i++;
1388 }
1389 if (button->markdown_cache) {
1390 button->block->oldblock->markdown_layout_cache.remove(i);
1391 }
1392 }
1393 if (button->markdown_cache) {
1394 button->block->markdown_layout_cache.append(button->markdown_cache);
1396 return;
1397 }
1398 }
1399
1400 button->markdown_cache = std::make_shared<MarkdownLayoutCache>();
1401 MarkdownLayoutCache &cache = *button->markdown_cache;
1402 cache.key = cache_lookup_key;
1403 /* Copy the string to the cache so that references into it can be preserved. */
1404 cache.key.text = cache.scope.allocator().copy_string(cache.key.text);
1405 button->block->markdown_layout_cache.append(button->markdown_cache);
1406
1407 MarkdownLayouter layouter(cache);
1408 layouter.compute_layout();
1409
1411}
1412
1426
1428{
1429 MarkdownDrawColors colors;
1430
1432 colors.link.a = color[3];
1433
1434 /* Blend toward the panel background so quote text is muted consistently across themes. */
1435 ColorTheme4b back_color;
1437 constexpr float quote_dimmed_blend = 0.3f;
1438 constexpr float code_span_fill_blend = 0.20f;
1439
1440 const bTheme *btheme = theme::theme_get();
1441 const uchar *code_box_fill_color = btheme->tui.wcol_box.inner;
1442 const uchar *code_box_border_color = btheme->tui.wcol_box.outline;
1443 const uchar *code_box_text_color = btheme->tui.wcol_box.text;
1444
1445 theme::get_color_blend_shade_3ubv(color, back_color, quote_dimmed_blend, 0, colors.quote_dimmed);
1446 colors.quote_dimmed.a = color[3];
1447
1448 colors.code_span_text = ColorTheme4b(code_box_text_color);
1449 colors.code_box_text = ColorTheme4b(code_box_text_color);
1450
1452 colors.link, back_color, quote_dimmed_blend, 0, colors.quote_dimmed_link);
1453 colors.quote_dimmed_link.a = colors.link.a;
1454
1456 colors.link, code_box_fill_color, 0.1f, 0, colors.code_span_link);
1457 colors.code_span_link.a = colors.link.a;
1458
1459 ColorTheme4b code_span_fill_color;
1461 back_color, code_box_fill_color, code_span_fill_blend, 0, code_span_fill_color);
1462 code_span_fill_color.a = 255;
1463
1464 colors.code_box_fill = color::to_float(ColorTheme4b(code_box_fill_color));
1465 colors.code_box_border = color::to_float(ColorTheme4b(code_box_border_color));
1466 colors.code_span_fill = color::to_float(code_span_fill_color);
1467
1468 colors.horizontal_rule = ColorTheme4b(color[0], color[1], color[2], 30);
1469 colors.quote_line = ColorTheme4b(color[0], color[1], color[2], 80);
1470
1471 return colors;
1472}
1473
1474void label_markdown_draw(const ButtonLabel *button, const uchar color[4], const rcti *rect)
1475{
1476 if (!button->markdown_cache || button->markdown_cache->md_layout.items.is_empty()) {
1477 return;
1478 }
1479
1480 const MarkdownLayoutCache &cache = *button->markdown_cache;
1482
1483 const bTheme *btheme = theme::theme_get();
1484 const float corner_radius = btheme->tui.wcol_box.roundness * U.widget_unit *
1485 cache.key.pixels_per_point;
1486
1487 for (const MarkdownItem &item : cache.md_layout.items) {
1488 const auto *code_box = std::get_if<MarkdownItemCodeBox>(&item);
1489 if (!code_box) {
1490 continue;
1491 }
1492
1493 rctf box_rect = code_box->rect;
1494 box_rect.xmin += rect->xmin;
1495 box_rect.xmax += rect->xmin;
1496 box_rect.ymax += rect->ymax;
1497 box_rect.ymin += rect->ymax;
1498
1500 if (code_box->kind == MarkdownItemCodeBox::Kind::Block) {
1501 draw_roundbox_4fv_ex(&box_rect,
1502 colors.code_box_fill,
1503 nullptr,
1504 1.0f,
1505 colors.code_box_border,
1506 U.pixelsize,
1507 corner_radius);
1508 }
1509 else {
1511 &box_rect, colors.code_span_fill, nullptr, 1.0f, nullptr, 0.0f, corner_radius);
1512 }
1513 }
1514
1515 for (const MarkdownItem &item : cache.md_layout.items) {
1516 if (const auto *text_item = std::get_if<MarkdownItemText>(&item)) {
1517 markdown_apply_item_font(*text_item);
1518 if (text_item->url) {
1519 if (text_item->is_in_quote) {
1520 BLF_color4ubv(text_item->fontid, colors.quote_dimmed_link);
1521 }
1522 else if (text_item->code_context == MarkdownItemText::CodeContext::CodeSpan) {
1523 BLF_color4ubv(text_item->fontid, colors.code_span_link);
1524 }
1525 else {
1526 BLF_color4ubv(text_item->fontid, colors.link);
1527 }
1528 }
1529 else {
1530 if (text_item->is_in_quote) {
1531 BLF_color4ubv(text_item->fontid, colors.quote_dimmed);
1532 }
1533 else if (text_item->code_context == MarkdownItemText::CodeContext::CodeBlock) {
1534 BLF_color4ubv(text_item->fontid, colors.code_box_text);
1535 }
1536 else if (text_item->code_context == MarkdownItemText::CodeContext::CodeSpan) {
1537 BLF_color4ubv(text_item->fontid, colors.code_span_text);
1538 }
1539 else {
1540 BLF_color4ubv(text_item->fontid, color);
1541 }
1542 }
1543 const float x = rect->xmin + text_item->x;
1544 const float y = rect->ymax + text_item->y;
1545 BLF_position(text_item->fontid, x, y, 0.0f);
1546 BLF_draw(text_item->fontid, text_item->text.data(), text_item->text.size());
1547 markdown_disable_item_font(*text_item);
1548 }
1549 else if (const auto *rule_item = std::get_if<MarkdownItemHorizontalRule>(&item)) {
1550 const float y = rect->ymax + rule_item->y;
1551
1552 const uint pos = GPU_vertformat_attr_add(
1553 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
1557 GPU_line_width(1.0f);
1559 immVertex2f(pos, rect->xmin, y);
1560 immVertex2f(pos, rect->xmax, y);
1561 immEnd();
1564 }
1565 else if (const auto *quote_line = std::get_if<MarkdownItemQuoteLine>(&item)) {
1566 const float x = rect->xmin + quote_line->x;
1567 const float y_top = rect->ymax + quote_line->y;
1568 const float y_bottom = y_top - quote_line->height;
1569
1570 const uint pos = GPU_vertformat_attr_add(
1571 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
1575 GPU_line_width(2.0f);
1577 immVertex2f(pos, x, y_top);
1578 immVertex2f(pos, x, y_bottom);
1579 immEnd();
1582 }
1583 }
1584}
1585
1591
1593{
1594 fmt::memory_buffer buf;
1595 fmt::appender dst{buf};
1596
1597 fmt::format_to(dst, "namespace md_style {{\n\n");
1598 fmt::format_to(dst, "static std::array<MdHeaderStyle, 6> headers = {{\n");
1599 for (const int level : IndexRange(md_style::headers.size())) {
1600 const MdHeaderStyle &style = md_style::headers[level];
1601 fmt::format_to(dst,
1602 " MdHeaderStyle{{.size_factor = {:.2f}f, .weight = {}, .italic = {}, "
1603 ".margin_top = {:.2f}f, .margin_bottom = {:.2f}f}},\n",
1604 style.size_factor,
1605 style.weight,
1606 style.italic ? "true" : "false",
1607 style.margin_top,
1608 style.margin_bottom);
1609 }
1610 fmt::format_to(dst, "}};\n\n");
1611
1612 auto append_block_spacing = [&](const char *name, const MdBlockSpacing &spacing) {
1613 fmt::format_to(
1614 dst,
1615 "static MdBlockSpacing {} = {{.margin_top = {:.2f}f, .margin_bottom = {:.2f}f}};\n",
1616 name,
1617 spacing.margin_top,
1618 spacing.margin_bottom);
1619 };
1620 append_block_spacing("paragraph", md_style::paragraph);
1621 append_block_spacing("quote", md_style::quote);
1622 fmt::format_to(dst, "static float quote_bar_padding = {:.2f}f;\n", md_style::quote_bar_padding);
1623 append_block_spacing("code_block", md_style::code_block);
1624 fmt::format_to(
1625 dst, "static float code_block_padding_x = {:.2f}f;\n", md_style::code_block_padding_x);
1626 fmt::format_to(
1627 dst, "static float code_block_padding_y = {:.2f}f;\n", md_style::code_block_padding_y);
1628 fmt::format_to(
1629 dst, "static float code_span_padding_x = {:.2f}f;\n", md_style::code_span_padding_x);
1630 fmt::format_to(
1631 dst, "static float code_span_padding_y = {:.2f}f;\n", md_style::code_span_padding_y);
1632 append_block_spacing("horizontal_rule", md_style::horizontal_rule);
1633 fmt::format_to(dst, "\n");
1634
1635 auto append_list_spacing = [&](const char *name, const MdListSpacing &spacing) {
1636 fmt::format_to(dst,
1637 "static MdListSpacing {} = {{.margin_top = {:.2f}f, .margin_bottom = {:.2f}f, "
1638 ".item_spacing_loose = {:.2f}f, .item_spacing_tight = {:.2f}f, "
1639 ".nested_margin_top = {:.2f}f}};\n",
1640 name,
1641 spacing.margin_top,
1642 spacing.margin_bottom,
1643 spacing.item_spacing_loose,
1644 spacing.item_spacing_tight,
1645 spacing.nested_margin_top);
1646 };
1647 append_list_spacing("list", md_style::list);
1648 fmt::format_to(dst, "\n");
1649
1650 fmt::format_to(dst, "static float list_indent_px = {:.2f}f;\n", md_style::list_indent_px);
1651 fmt::format_to(
1652 dst, "static float list_marker_padding_px = {:.2f}f;\n", md_style::list_marker_padding_px);
1653 fmt::format_to(
1654 dst, "static float horizontal_rule_padding = {:.2f}f;\n", md_style::horizontal_rule_padding);
1655 fmt::format_to(dst, "\n}};\n");
1656 return fmt::to_string(buf);
1657}
1658
1660{
1661 const std::string text = markdown_md_style_to_source();
1662 WM_clipboard_text_set(text.c_str(), false);
1663}
1664
1666{
1667 return short(2.0f * UI_UNIT_X);
1668}
1669
1671{
1672 return short(7.0f * UI_UNIT_X);
1673}
1674
1676{
1677 return short(3.5f * UI_UNIT_X);
1678}
1679
1681{
1682 return short(5.0f * UI_UNIT_X);
1683}
1684
1686 Layout &col,
1687 const StringRef label,
1688 const short width)
1689{
1690 block_layout_set_current(block, &col);
1691 uiDefBut(
1692 block, ButtonType::Label, label, 0, 0, width, UI_UNIT_Y, nullptr, 0.0f, 0.0f, std::nullopt);
1693}
1694
1696 Layout &col,
1697 float *value,
1698 const float min,
1699 const float max,
1700 const float step,
1701 const int precision,
1702 const StringRef tip)
1703{
1704 block_layout_set_current(block, &col);
1705 Button *but = uiDefButV(block,
1707 "",
1708 0,
1709 0,
1711 UI_UNIT_Y,
1712 value,
1713 min,
1714 max,
1715 tip);
1717 button_number_precision_set(but, precision);
1719}
1720
1722 Layout &col,
1723 int *value,
1724 const float min,
1725 const float max,
1726 const float step,
1727 const int precision,
1728 const StringRef tip)
1729{
1730 block_layout_set_current(block, &col);
1731 Button *but = uiDefButV(block,
1733 "",
1734 0,
1735 0,
1737 UI_UNIT_Y,
1738 value,
1739 min,
1740 max,
1741 tip);
1743 button_number_precision_set(but, precision);
1745}
1746
1748 Layout &col,
1749 bool *value,
1750 const StringRef tip)
1751{
1752 block_layout_set_current(block, &col);
1753 Button *but = uiDefButV(
1754 block, ButtonType::Checkbox, "", 0, 0, UI_UNIT_X, UI_UNIT_Y, value, 0, 0, tip);
1756}
1757
1759{
1760 Layout &table = panel_col.row(false);
1762
1763 Layout &col_h = table.column(true);
1764 Layout &col_size = table.column(true);
1765 Layout &col_weight = table.column(true);
1766 Layout &col_it = table.column(true);
1767 Layout &col_top = table.column(true);
1768 Layout &col_bottom = table.column(true);
1769
1770 const short num_w = md_dev_config_num_width();
1772 label_markdown_dev_config_col_label(block, col_size, IFACE_("Size"), num_w);
1773 label_markdown_dev_config_col_label(block, col_weight, IFACE_("Weight"), num_w);
1775 label_markdown_dev_config_col_label(block, col_top, IFACE_("Top"), num_w);
1776 label_markdown_dev_config_col_label(block, col_bottom, IFACE_("Bottom"), num_w);
1777
1778 for (const int level : IndexRange(md_style::headers.size())) {
1779 MdHeaderStyle &style = md_style::headers[level];
1780 const std::string h_label = fmt::format("H{}", level + 1);
1783 col_size,
1784 &style.size_factor,
1785 0.25f,
1786 4.0f,
1787 0.05f,
1788 2,
1789 IFACE_("Size factor relative to body text"));
1791 block, col_weight, &style.weight, 100, 900, 100, -1, IFACE_("Font weight"));
1792 label_markdown_dev_config_checkbox(block, col_it, &style.italic, IFACE_("Use italic style"));
1794 col_top,
1795 &style.margin_top,
1796 0.0f,
1797 4.0f,
1798 0.05f,
1799 2,
1800 IFACE_("Top margin as a multiple of the default line height"));
1802 block,
1803 col_bottom,
1804 &style.margin_bottom,
1805 0.0f,
1806 4.0f,
1807 0.05f,
1808 2,
1809 IFACE_("Bottom margin as a multiple of the default line height"));
1810 }
1811}
1812
1814{
1815 Layout &table = panel_col.row(false);
1817
1818 Layout &col_name = table.column(true);
1819 Layout &col_top = table.column(true);
1820 Layout &col_bottom = table.column(true);
1821
1822 const short num_w = md_dev_config_num_width();
1823 const short name_w = md_dev_config_name_col_width();
1824 label_markdown_dev_config_col_label(block, col_name, "", name_w);
1825 label_markdown_dev_config_col_label(block, col_top, IFACE_("Top"), num_w);
1826 label_markdown_dev_config_col_label(block, col_bottom, IFACE_("Bottom"), num_w);
1827
1828 struct BlockMarginRow {
1829 const char *label;
1830 float &margin_top;
1831 float &margin_bottom;
1832 };
1833
1834 const BlockMarginRow rows[] = {
1835 {IFACE_("Paragraph"), md_style::paragraph.margin_top, md_style::paragraph.margin_bottom},
1836 {IFACE_("Quote"), md_style::quote.margin_top, md_style::quote.margin_bottom},
1837 {IFACE_("Code Block"), md_style::code_block.margin_top, md_style::code_block.margin_bottom},
1838 {IFACE_("Horizontal Rule"),
1839 md_style::horizontal_rule.margin_top,
1840 md_style::horizontal_rule.margin_bottom},
1841 {IFACE_("List"), md_style::list.margin_top, md_style::list.margin_bottom},
1842 };
1843
1844 for (const BlockMarginRow &row : rows) {
1845 label_markdown_dev_config_col_label(block, col_name, row.label, name_w);
1847 col_top,
1848 &row.margin_top,
1849 0.0f,
1850 4.0f,
1851 0.05f,
1852 2,
1853 IFACE_("Top margin as a multiple of the default line height"));
1855 block,
1856 col_bottom,
1857 &row.margin_bottom,
1858 0.0f,
1859 4.0f,
1860 0.05f,
1861 2,
1862 IFACE_("Bottom margin as a multiple of the default line height"));
1863 }
1864}
1865
1867{
1868 Layout &table = panel_col.row(false);
1870
1871 Layout &col_name = table.column(true);
1872 Layout &col_loose = table.column(true);
1873 Layout &col_tight = table.column(true);
1874 Layout &col_nested = table.column(true);
1875
1876 const short num_w = md_dev_config_num_width();
1878 label_markdown_dev_config_col_label(block, col_loose, IFACE_("Loose"), num_w);
1879 label_markdown_dev_config_col_label(block, col_tight, IFACE_("Tight"), num_w);
1880 label_markdown_dev_config_col_label(block, col_nested, IFACE_("Nested"), num_w);
1881
1883 block, col_name, IFACE_("Items"), md_dev_config_h_col_width());
1885 col_loose,
1886 &md_style::list.item_spacing_loose,
1887 0.0f,
1888 4.0f,
1889 0.05f,
1890 2,
1891 IFACE_("Spacing between items in loose lists"));
1893 col_tight,
1894 &md_style::list.item_spacing_tight,
1895 0.0f,
1896 4.0f,
1897 0.05f,
1898 2,
1899 IFACE_("Spacing between items in tight lists"));
1901 col_nested,
1902 &md_style::list.nested_margin_top,
1903 0.0f,
1904 4.0f,
1905 0.05f,
1906 2,
1907 IFACE_("Margin above the first item in a nested list"));
1908}
1909
1911 const char *label;
1912 float *value;
1913 float min;
1914 float max;
1915 float step;
1917 const char *tip;
1918};
1919
1921 Block *block, Layout &panel_col, const Span<MarkdownDevConfigDetailColumn> columns)
1922{
1923 Layout &table = panel_col.row(false);
1925
1926 for (const MarkdownDevConfigDetailColumn &column : columns) {
1927 Layout &col = table.column(true);
1929 block, col, column.label, md_dev_config_detail_label_width());
1931 col,
1932 column.value,
1933 column.min,
1934 column.max,
1935 column.step,
1936 column.precision,
1937 column.tip);
1938 }
1939}
1940
1942{
1943 const MarkdownDevConfigDetailColumn general_columns[] = {
1944 {IFACE_("Quote Bar"),
1946 0.0f,
1947 1.0f,
1948 0.025f,
1949 3,
1950 IFACE_("Vertical padding around quote text for the quote bar")},
1951 {IFACE_("HR Pad"),
1953 0.0f,
1954 4.0f,
1955 0.05f,
1956 2,
1957 IFACE_("Additional vertical padding around the horizontal rule line")},
1958 {IFACE_("Indent"),
1960 4.0f,
1961 40.0f,
1962 1.0f,
1963 1,
1964 IFACE_("Horizontal indent per list level in pixels at 1x scale")},
1965 {IFACE_("Marker"),
1967 0.0f,
1968 20.0f,
1969 0.5f,
1970 1,
1971 IFACE_("Padding between ordered list markers and item text in pixels at 1x scale")},
1972 };
1973
1974 const MarkdownDevConfigDetailColumn code_block_columns[] = {
1975 {IFACE_("Code Block X"),
1977 0.0f,
1978 20.0f,
1979 0.5f,
1980 1,
1981 IFACE_("Horizontal padding around fenced code blocks in pixels at 1x scale")},
1982 {IFACE_("Code Block Y"),
1984 0.0f,
1985 20.0f,
1986 0.5f,
1987 1,
1988 IFACE_("Vertical padding around fenced code blocks in pixels at 1x scale")},
1989 };
1990
1991 const MarkdownDevConfigDetailColumn code_span_columns[] = {
1992 {IFACE_("Code Span X"),
1994 0.0f,
1995 20.0f,
1996 0.5f,
1997 1,
1998 IFACE_("Horizontal padding around inline code spans in pixels at 1x scale")},
1999 {IFACE_("Code Span Y"),
2001 0.0f,
2002 20.0f,
2003 0.5f,
2004 1,
2005 IFACE_("Vertical padding around inline code spans in pixels at 1x scale")},
2006 };
2007
2009 block, panel_col, Span(general_columns, std::size(general_columns)));
2011 block, panel_col, Span(code_block_columns, std::size(code_block_columns)));
2013 block, panel_col, Span(code_span_columns, std::size(code_span_columns)));
2014}
2015
2017{
2018 Block *block = layout.block();
2019 bContext *C = static_cast<bContext *>(block->evil_C);
2020 if (!C) {
2021 return;
2022 }
2023
2024 layout.use_property_split_set(false);
2025 Layout &col = layout.column(false);
2026
2027 if (Layout *panel = layout.panel(C, "md_style_headers", false, IFACE_("Headers"))) {
2028 label_markdown_dev_config_headers_table(block, panel->column(false));
2029 }
2030
2031 if (Layout *panel = layout.panel(C, "md_style_block_margins", false, IFACE_("Block Margins"))) {
2032 label_markdown_dev_config_block_margins_table(block, panel->column(false));
2033 }
2034
2035 if (Layout *panel = layout.panel(C, "md_style_list_spacing", false, IFACE_("List Spacing"))) {
2036 label_markdown_dev_config_list_spacing_table(block, panel->column(false));
2037 }
2038
2039 if (Layout *panel = layout.panel(C, "md_style_details", true, IFACE_("Details"))) {
2040 label_markdown_dev_config_details_table(block, panel->column(false));
2041 }
2042
2043 col.separator();
2044 Layout &copy_row = col.row(false);
2045 block_layout_set_current(block, &copy_row);
2046 Button *copy_but = uiDefBut(block,
2048 IFACE_("Copy Style to Clipboard"),
2049 0,
2050 0,
2051 short(15 * UI_UNIT_X),
2052 UI_UNIT_Y,
2053 nullptr,
2054 0,
2055 0,
2056 IFACE_("Copy md_style namespace source to the clipboard"));
2058}
2059
2060} // namespace blender::ui
#define BLI_SCOPED_DEFER(function_to_defer)
#define IFACE_(msgid)
#define UI_SCALE_FAC
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_UNIT_X
#define NC_WINDOW
Definition WM_types.hh:388
btScalar max
ChannelStorageType a
constexpr IndexRange()=default
StringRefNull copy_string(StringRef str)
LinearAllocator & allocator()
constexpr Span()=default
constexpr StringRef drop_prefix(int64_t n) const
constexpr StringRef()
constexpr int64_t find_first_of(StringRef chars, int64_t pos=0) const
static constexpr int64_t not_found
constexpr bool is_empty() const
constexpr int64_t size() const
constexpr StringRef substr(int64_t start, int64_t size) const
constexpr const char * data() const
constexpr int64_t find_last_of(StringRef chars, int64_t pos=INT64_MAX) const
void append(const T &value)
void md_text_normal(const StringRef text)
float spacing_px(const float multiplier) const
void md_leave_span(const MD_SPANTYPE span_type, void *)
void track_code_text_bounds(const MarkdownItemText &item)
ContextFontSettings get_context_font_settings() const
void append_code_span_boxes(const CodeSpan &code_span)
void md_enter_block(const MD_BLOCKTYPE block_type, void *detail)
void add_pending_spacing(const float spacing)
void md_leave_block(const MD_BLOCKTYPE block_type, void *)
void md_text(const MD_TEXTTYPE text_type, const StringRef text)
MarkdownLayouter(MarkdownLayoutCache &cache_)
static bool is_list_container_block(const MdBlock &block)
static StringRef unordered_bullet_for_level(const int level)
FontConfig make_font_config(const int fontid, const float default_size, const int default_weight, const int bold_weight)
float block_margin_top(const MdBlock &block) const
void track_quote_text_bounds(const MarkdownItemText &item)
void md_enter_span(const MD_SPANTYPE span_type, void *detail)
void output_wrapped_text(StringRef text, const float size, const int fontid, const int weight, const bool italic, const std::optional< StringRef > &url, const float start_x)
void extend_flow_bottom_for_code_block(const CodeBlock &code_block)
float block_margin_bottom(const MdBlock &block) const
#define FLT_MAX
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float length(VecOp< float, D >) RET
BLI_INLINE ColorTheme4f to_float(const ColorTheme4b &theme4b)
Definition BLI_color.hh:64
static std::array< MdHeaderStyle, 6 > headers
static MdBlockSpacing paragraph
static MdBlockSpacing code_block
static MdBlockSpacing horizontal_rule
void get_color_4ubv(int colorid, unsigned char col[4])
void get_color_blend_shade_3ubv(int colorid1, int colorid2, float fac, int offset, unsigned char col[3])
const bTheme * theme_get()
void get_color_3ubv(int colorid, unsigned char col[3])
static void markdown_disable_item_font(const MarkdownItemText &item)
static void label_markdown_dev_config_col_label(Block *block, Layout &col, const StringRef label, const short width)
void label_markdown_create_link_buttons(Block *block)
static void label_markdown_dev_config_int(Block *block, Layout &col, int *value, const float min, const float max, const float step, const int precision, const StringRef tip)
static short md_dev_config_num_width()
void button_func_set(Button *but, std::function< void(bContext &)> func)
static void label_markdown_dev_config_block_margins_table(Block *block, Layout &panel_col)
bool button_label_is_markdown(const Button *button)
const uiStyle * style_get()
void label_markdown_dev_config(Layout &layout)
static void label_markdown_dev_config_checkbox(Block *block, Layout &col, bool *value, const StringRef tip)
void label_markdown_resolve(ButtonLabel *button)
static MarkdownDrawColors markdown_draw_colors_init(const uchar color[4])
static short md_dev_config_name_col_width()
static short md_dev_config_detail_label_width()
void button_number_step_size_set(Button *but, float step_size)
static void label_markdown_dev_config_details_table(Block *block, Layout &panel_col)
void button_func_tooltip_custom_set(Button *but, ButtonToolTipCustomFunc func, void *arg, FreeArgFunc free_arg)
EmbossType block_emboss_get(Block *block)
static MarkdownLayoutCacheKey markdown_layout_key_for_button(const ButtonLabel &button)
void button_number_precision_set(Button *but, float precision)
static void markdown_apply_font(const int fontid, const float size_px, const int weight, const bool italic)
static int markdown_layout_generation
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)
void draw_roundbox_corner_set(int type)
static short md_dev_config_h_col_width()
std::variant< MarkdownItemText, MarkdownItemHorizontalRule, MarkdownItemQuoteLine, MarkdownItemCodeBox > MarkdownItem
void tooltip_text_field_add(TooltipData &data, std::string text, std::string suffix, const TooltipStyle style, const TooltipColorID color_id, const bool is_pad=false)
void block_emboss_set(Block *block, EmbossType emboss)
void label_markdown_draw(const ButtonLabel *button, const uchar color[4], const rcti *rect)
void draw_roundbox_4fv_ex(const rctf *rect, const float inner1[4], const float inner2[4], float shade_dir, const float outline[4], float outline_width, float rad)
static void label_markdown_copy_style_to_clipboard(bContext &)
static std::string markdown_md_style_to_source()
void button_operator_set(Button *but, wmOperatorType *optype, wm::OpCallContext opcontext, const PointerRNA *opptr=nullptr)
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 void markdown_apply_item_font(const MarkdownItemText &item)
static void markdown_apply_button_height(ButtonLabel &button)
static void create_link_buttons_for_label(ButtonLabel *button)
static void label_markdown_dev_config_update(bContext &)
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)
static void label_markdown_dev_config_list_spacing_table(Block *block, Layout &panel_col)
void block_layout_set_current(Block *block, Layout *layout)
static void label_markdown_dev_config_headers_table(Block *block, Layout &panel_col)
static void label_markdown_dev_config_details_row(Block *block, Layout &panel_col, const Span< MarkdownDevConfigDetailColumn > columns)
static void label_markdown_dev_config_num(Block *block, Layout &col, float *value, const float min, const float max, const float step, const int precision, const StringRef tip)
void WM_main_add_notifier(uint type, void *reference)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
ColorTheme4< uint8_t > ColorTheme4b
__int64 int64_t
Definition BKE_text.h:90
uint padding(uint offset, uint alignment)
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:390
void immEnd()
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
unsigned int uint
Definition BKE_text.h:55
size_t BLF_width_to_strlen(int fontid, const char *str, size_t str_len, float width, float *r_width) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:761
GPUVertFormat * immVertexFormat()
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
void immBegin(GPUPrimType, uint vertex_len)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
void BLF_character_weight(int fontid, int weight)
Definition blf.cc:349
void BLF_disable(int fontid, FontFlags flag)
Definition blf.cc:331
void immUnbindProgram()
void GPU_line_width(float width)
Definition gpu_state.cc:151
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
unsigned int uint32_t
Definition BKE_text.h:81
void BLF_size(int fontid, float size)
Definition blf.cc:445
bool BLI_rctf_is_empty(const struct rctf *rect)
void immVertex2f(uint attr_id, float x, float y)
unsigned char uchar
Definition BKE_text.h:58
BMesh const char void * data
void BLI_rctf_init_minmax(struct rctf *rect)
Definition rct.cc:494
int BLI_str_utf8_size_safe(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:587
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
int BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:916
void BLF_color4ubv(int fontid, const unsigned char rgba[4])
Definition blf.cc:454
void BLI_rctf_union(struct rctf *rct_a, const struct rctf *rct_b)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:883
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
void WM_clipboard_text_set(const char *buf, bool selection)
int BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT
Definition blf.cc:905
int blf_mono_font
Definition blf.cc:50
ColorTheme4< float > ColorTheme4f
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
std::string RNA_string_get(PointerRNA *ptr, const char *name)
void immUniformColor4ubv(const unsigned char rgba[4])
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:322
@ BLF_ASPECT
Definition BLF_enums.hh:41
@ BLF_ITALIC
Definition BLF_enums.hh:49
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
uiWidgetColors wcol_box
ThemeUI tui
Vector< std::shared_ptr< MarkdownLayoutCache > > markdown_layout_cache
std::ranges::transform_view< std::ranges::ref_view< const Vector< std::unique_ptr< Button > > >, Button &(*)(const std::unique_ptr< Button > &)> buttons() const
std::shared_ptr< MarkdownLayoutCache > markdown_cache
void alignment_set(LayoutAlign alignment)
void use_property_split_set(bool is_sep)
void label(StringRef name, int icon)
PanelLayout panel(const bContext *C, StringRef idname, bool default_closed)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
Layout & row(bool align)
uiFontStyle widget
unsigned char inner[4]
unsigned char outline[4]
unsigned char text[4]