【Blender开发】UI:多行显示参考

https://b3d.interplanety.org/en/multiline-text-in-blender-interface-panels

Blender目前没有多行编辑器,本例使用切割文字,再分别用layout.label展示

代码

from bpy.types import Panel
from bpy.utils import register_class
import textwrap

def _label_multiline(context, text, layout):
    chars = int(context.region.width / 7)   # 7pix/字符

    wrapper = textwrap.TextWrapper(width=chars)

    text_lines = wrapper.wrap(text=text)
    # 遍历分割的字符,然后用label显示
    for text_line in text_lines:
        layout.label(text=text_line)

# N面板
class TEST_PT_private(Panel):
    bl_idname = 'TEST_PT_test'
    bl_label = 'MULTILINE TEXT'
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = 'TEST'

    def draw(self, context):
        layout = self.layout
        text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut laborein voui officia deserunt mollit anim id est laborum.'

        _label_multiline(
            context=context,
            text=text,
            layout=layout
        )

register_class(TEST_PT_private)

 

给TA充电
共{{data.count}}人
人已充电
BlenderBlender开发

【Blender开发】UI:带有自定义过滤的UIList

2022-1-17 10:08:37

BlenderBlender插件

【Blender插件】Blender 中文输入文字

2022-1-17 18:09:54

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
今日签到
搜索