This commit is contained in:
Rowland 2026-01-08 17:43:43 +08:00
parent 3f6ae9185e
commit 6a7b6b6959
2 changed files with 69 additions and 64 deletions

109
demo.py
View File

@ -341,9 +341,8 @@ class MyWorld(CoreWorld):
font_path = "/System/Library/Fonts/PingFang.ttc"
if font_path and Path(font_path).exists():
# 添加中文字体,明确指定中文字符集
# 添加中文字体,包含中文字符集
try:
# 获取中文字符集
chinese_ranges = imgui.get_io().fonts.get_glyph_ranges_chinese_full()
self.imgui.io.fonts.add_font_from_file_ttf(font_path, 14.0, None, chinese_ranges)
print("✓ 第一帧重新设置中文字体(包含中文字符集)")
@ -354,33 +353,21 @@ class MyWorld(CoreWorld):
except Exception as e:
print(f"⚠ 第一帧设置中文字体失败: {e}")
# 获取窗口尺寸
display_size = imgui.get_io().display_size
window_width = display_size.x
window_height = display_size.y
# 绘制菜单栏
self._draw_menu_bar()
# 绘制工具栏
if self.showToolbar:
self._draw_toolbar()
# 绘制场景树面板
if self.showSceneTree:
self._draw_scene_tree()
# 绘制属性面板
if self.showPropertyPanel:
self._draw_property_panel()
# 绘制控制台面板
if self.showConsole:
self._draw_console()
# 绘制脚本面板
if self.showScriptPanel:
self._draw_script_panel()
# 绘制停靠布局
self._draw_docked_layout(window_width, window_height)
# 绘制纹理测试窗口
if self.testTexture:
with self.style_manager.begin_styled_window("Texture Test", True,
imgui.WINDOW_ALWAYS_AUTO_RESIZE) as (_, windowOpen):
imgui.WindowFlags_.always_auto_resize) as (_, windowOpen):
if not windowOpen:
self.imgui.removeTexture(self.testTexture)
self.testTexture = None
@ -391,6 +378,49 @@ class MyWorld(CoreWorld):
if self.showDemoWindow:
imgui.show_demo_window()
def _draw_docked_layout(self, window_width, window_height):
"""绘制停靠布局(模拟)"""
# 布局参数
left_panel_width = 250
right_panel_width = 300
top_toolbar_height = 40
bottom_console_height = 150
menu_bar_height = 20
# 左侧场景树面板
if self.showSceneTree:
imgui.set_next_window_pos((0, menu_bar_height), imgui.Cond_.always.value)
imgui.set_next_window_size((left_panel_width, window_height - menu_bar_height - bottom_console_height), imgui.Cond_.always.value)
self._draw_scene_tree()
# 右侧面板区域
right_panel_y = menu_bar_height
right_panel_height = (window_height - menu_bar_height - bottom_console_height) // 2
# 属性面板
if self.showPropertyPanel:
imgui.set_next_window_pos((window_width - right_panel_width, right_panel_y), imgui.Cond_.always.value)
imgui.set_next_window_size((right_panel_width, right_panel_height), imgui.Cond_.always.value)
self._draw_property_panel()
# 脚本面板
if self.showScriptPanel:
imgui.set_next_window_pos((window_width - right_panel_width, right_panel_y + right_panel_height), imgui.Cond_.always.value)
imgui.set_next_window_size((right_panel_width, right_panel_height), imgui.Cond_.always.value)
self._draw_script_panel()
# 底部控制台
if self.showConsole:
imgui.set_next_window_pos((0, window_height - bottom_console_height), imgui.Cond_.always.value)
imgui.set_next_window_size((window_width, bottom_console_height), imgui.Cond_.always.value)
self._draw_console()
# 顶部工具栏
if self.showToolbar:
imgui.set_next_window_pos((left_panel_width, menu_bar_height), imgui.Cond_.always.value)
imgui.set_next_window_size((window_width - left_panel_width - right_panel_width, top_toolbar_height), imgui.Cond_.always.value)
self._draw_toolbar()
def _draw_menu_bar(self):
@ -456,12 +486,7 @@ class MyWorld(CoreWorld):
def _draw_toolbar(self):
"""绘制工具栏"""
# 设置工具栏位置
imgui.set_next_window_pos((10, 30), imgui.Cond_.first_use_ever.value)
imgui.set_next_window_size((300, 40), imgui.Cond_.first_use_ever.value)
with self.style_manager.begin_styled_window("工具栏", self.showToolbar,
self.style_manager.get_window_flags("toolbar")):
with self.style_manager.begin_styled_window("工具栏", self.showToolbar):
self.showToolbar = True # 确保窗口保持打开
# 工具按钮组
@ -523,12 +548,7 @@ class MyWorld(CoreWorld):
def _draw_scene_tree(self):
"""绘制场景树面板"""
# 设置场景树位置
imgui.set_next_window_pos((10, 80), imgui.Cond_.first_use_ever.value)
imgui.set_next_window_size((250, 300), imgui.Cond_.first_use_ever.value)
with self.style_manager.begin_styled_window("场景树", self.showSceneTree,
self.style_manager.get_window_flags("panel")):
with self.style_manager.begin_styled_window("场景树", self.showSceneTree):
self.showSceneTree = True # 确保窗口保持打开
imgui.text("场景层级")
@ -557,12 +577,7 @@ class MyWorld(CoreWorld):
def _draw_property_panel(self):
"""绘制属性面板"""
# 设置属性面板位置
imgui.set_next_window_pos((270, 80), imgui.Cond_.first_use_ever.value)
imgui.set_next_window_size((250, 300), imgui.Cond_.first_use_ever.value)
with self.style_manager.begin_styled_window("属性面板", self.showPropertyPanel,
self.style_manager.get_window_flags("panel")):
with self.style_manager.begin_styled_window("属性面板", self.showPropertyPanel):
self.showPropertyPanel = True # 确保窗口保持打开
imgui.text("对象属性")
@ -590,12 +605,7 @@ class MyWorld(CoreWorld):
def _draw_console(self):
"""绘制控制台面板"""
# 设置控制台位置
imgui.set_next_window_pos((10, 390), imgui.Cond_.first_use_ever.value)
imgui.set_next_window_size((770, 150), imgui.Cond_.first_use_ever.value)
with self.style_manager.begin_styled_window("控制台", self.showConsole,
self.style_manager.get_window_flags("panel")):
with self.style_manager.begin_styled_window("控制台", self.showConsole):
self.showConsole = True # 确保窗口保持打开
imgui.text("控制台输出")
@ -635,12 +645,7 @@ class MyWorld(CoreWorld):
def _draw_script_panel(self):
"""绘制脚本管理面板"""
# 设置脚本面板位置
imgui.set_next_window_pos((530, 80), imgui.Cond_.first_use_ever.value)
imgui.set_next_window_size((250, 300), imgui.Cond_.first_use_ever.value)
with self.style_manager.begin_styled_window("脚本管理", self.showScriptPanel,
self.style_manager.get_window_flags("panel")):
with self.style_manager.begin_styled_window("脚本管理", self.showScriptPanel):
self.showScriptPanel = True # 确保窗口保持打开
imgui.text("脚本列表")

View File

@ -19,33 +19,33 @@ Size=745,76
Collapsed=0
[Window][Dear ImGui Demo]
Pos=989,19
Pos=948,19
Size=550,680
Collapsed=1
[Window][工具栏]
Pos=10,30
Size=300,40
Pos=250,20
Size=1300,40
Collapsed=0
[Window][场景树]
Pos=-3,66
Size=270,497
Pos=0,20
Size=250,846
Collapsed=0
[Window][属性面板]
Pos=1132,337
Size=252,416
Collapsed=0
Pos=1550,20
Size=300,423
Collapsed=1
[Window][控制台]
Pos=0,562
Size=1132,191
Pos=0,866
Size=1850,150
Collapsed=0
[Window][脚本管理]
Pos=1132,39
Size=250,300
Pos=1550,443
Size=300,423
Collapsed=0
[Window][中文显示测试]