ui替换
This commit is contained in:
parent
403c4d34f8
commit
e42d3cfa30
67
demo.py
67
demo.py
@ -961,48 +961,81 @@ class MyWorld(CoreWorld):
|
||||
with self.style_manager.begin_styled_window("工具栏", self.showToolbar, flags):
|
||||
self.showToolbar = True # 确保窗口保持打开
|
||||
|
||||
# 工具按钮组
|
||||
# 选择工具按钮
|
||||
select_active = self.tool_manager.isSelectionTool()
|
||||
if self.icons.get('select'):
|
||||
if self.style_manager.image_button(self.icons['select'], (24, 24)):
|
||||
print("选择工具")
|
||||
tint_col = (1.0, 1.0, 0.0, 1.0) if select_active else (1.0, 1.0, 1.0, 1.0)
|
||||
if self.style_manager.image_button(self.icons['select'], (24, 24), tint_col=tint_col):
|
||||
self.tool_manager.setCurrentTool("选择")
|
||||
if imgui.is_item_hovered():
|
||||
imgui.set_tooltip("选择工具 (Q)")
|
||||
imgui.same_line()
|
||||
else:
|
||||
if imgui.button("选择"):
|
||||
print("选择工具")
|
||||
if imgui.button("选择##select_tool"):
|
||||
self.tool_manager.setCurrentTool("选择")
|
||||
if select_active:
|
||||
draw_list = imgui.get_window_draw_list()
|
||||
button_min = imgui.get_item_rect_min()
|
||||
button_max = imgui.get_item_rect_max()
|
||||
draw_list.add_rect_filled(button_min, button_max, imgui.get_color_u32((0.3, 0.6, 1.0, 0.3)))
|
||||
imgui.same_line()
|
||||
|
||||
# 移动工具按钮
|
||||
move_active = self.tool_manager.isMoveTool()
|
||||
if self.icons.get('move'):
|
||||
if self.style_manager.image_button(self.icons['move'], (24, 24)):
|
||||
print("移动工具")
|
||||
# 使用不同颜色表示活动状态
|
||||
tint_col = (1.0, 1.0, 0.0, 1.0) if move_active else (1.0, 1.0, 1.0, 1.0) # 活动时显示黄色
|
||||
if self.style_manager.image_button(self.icons['move'], (24, 24), tint_col=tint_col):
|
||||
self.tool_manager.setCurrentTool("移动")
|
||||
if imgui.is_item_hovered():
|
||||
imgui.set_tooltip("移动工具 (W)")
|
||||
imgui.same_line()
|
||||
else:
|
||||
if imgui.button("移动"):
|
||||
print("移动工具")
|
||||
if imgui.button("移动##move_tool"):
|
||||
self.tool_manager.setCurrentTool("移动")
|
||||
if move_active:
|
||||
# 为活动按钮添加背景色
|
||||
draw_list = imgui.get_window_draw_list()
|
||||
button_min = imgui.get_item_rect_min()
|
||||
button_max = imgui.get_item_rect_max()
|
||||
draw_list.add_rect_filled(button_min, button_max, imgui.get_color_u32((0.3, 0.6, 1.0, 0.3)))
|
||||
imgui.same_line()
|
||||
|
||||
# 旋转工具按钮
|
||||
rotate_active = self.tool_manager.isRotateTool()
|
||||
if self.icons.get('rotate'):
|
||||
if self.style_manager.image_button(self.icons['rotate'], (24, 24)):
|
||||
print("旋转工具")
|
||||
tint_col = (1.0, 1.0, 0.0, 1.0) if rotate_active else (1.0, 1.0, 1.0, 1.0)
|
||||
if self.style_manager.image_button(self.icons['rotate'], (24, 24), tint_col=tint_col):
|
||||
self.tool_manager.setCurrentTool("旋转")
|
||||
if imgui.is_item_hovered():
|
||||
imgui.set_tooltip("旋转工具 (E)")
|
||||
imgui.same_line()
|
||||
else:
|
||||
if imgui.button("旋转"):
|
||||
print("旋转工具")
|
||||
if imgui.button("旋转##rotate_tool"):
|
||||
self.tool_manager.setCurrentTool("旋转")
|
||||
if rotate_active:
|
||||
draw_list = imgui.get_window_draw_list()
|
||||
button_min = imgui.get_item_rect_min()
|
||||
button_max = imgui.get_item_rect_max()
|
||||
draw_list.add_rect_filled(button_min, button_max, imgui.get_color_u32((0.3, 0.6, 1.0, 0.3)))
|
||||
imgui.same_line()
|
||||
|
||||
# 缩放工具按钮
|
||||
scale_active = self.tool_manager.isScaleTool()
|
||||
if self.icons.get('scale'):
|
||||
if self.style_manager.image_button(self.icons['scale'], (24, 24)):
|
||||
print("缩放工具")
|
||||
tint_col = (1.0, 1.0, 0.0, 1.0) if scale_active else (1.0, 1.0, 1.0, 1.0)
|
||||
if self.style_manager.image_button(self.icons['scale'], (24, 24), tint_col=tint_col):
|
||||
self.tool_manager.setCurrentTool("缩放")
|
||||
if imgui.is_item_hovered():
|
||||
imgui.set_tooltip("缩放工具 (R)")
|
||||
else:
|
||||
if imgui.button("缩放"):
|
||||
print("缩放工具")
|
||||
if imgui.button("缩放##scale_tool"):
|
||||
self.tool_manager.setCurrentTool("缩放")
|
||||
if scale_active:
|
||||
draw_list = imgui.get_window_draw_list()
|
||||
button_min = imgui.get_item_rect_min()
|
||||
button_max = imgui.get_item_rect_max()
|
||||
draw_list.add_rect_filled(button_min, button_max, imgui.get_color_u32((0.3, 0.6, 1.0, 0.3)))
|
||||
|
||||
imgui.same_line()
|
||||
imgui.separator()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user