From 1433240ae6bba17c8b955a43bc7da10f216cda08 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 2 Sep 2025 16:00:14 +0500 Subject: [PATCH] Fix text edit popup UI going out of sync with general text editing UI (a98cddf) --- .../bonsai/bim/module/drawing/operator.py | 42 +------ src/bonsai/bonsai/bim/module/drawing/ui.py | 105 ++++++++++-------- 2 files changed, 62 insertions(+), 85 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index 15c3a962b7..7a841e1fdd 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -2971,47 +2971,9 @@ class EditTextPopup(bpy.types.Operator): first_run: bpy.props.BoolProperty(default=True) def draw(self, context): - # shares most of the code with BIM_PT_text.draw() - # need to keep them in sync or move to some common function - # NOTE: that `popup_active_attribute` is used here when it's not used in `BIM_PT_text.draw()` + from bonsai.bim.module.drawing.ui import BIM_PT_text - assert self.layout - obj = context.active_object - assert obj - props = tool.Drawing.get_text_props(obj) - - row = self.layout.row(align=True) - row.operator("bim.add_text_literal", icon="ADD", text="Add Literal") - - row = self.layout.row(align=True) - row.prop(props, "font_size") - - for i, literal_props in enumerate(props.literals): - box = self.layout.box() - row = self.layout.row(align=True) - - row = box.row(align=True) - row.label(text=f"Literal[{i}]:") - row.operator("bim.remove_text_literal", icon="X", text="").literal_prop_id = i - - # skip BoxAlignment since we're going to format it ourselves - attributes = [a for a in literal_props.attributes if a.name != "BoxAlignment"] - bonsai.bim.helper.draw_attributes(attributes, box, popup_active_attribute=attributes[0]) - - row = box.row(align=True) - cols = [row.column(align=True) for i in range(3)] - for i in range(9): - cols[i % 3].prop( - literal_props, - "box_alignment", - text="", - index=i, - icon="RADIOBUT_ON" if literal_props.box_alignment[i] else "RADIOBUT_OFF", - ) - - col = row.column(align=True) - col.label(text=" Text box alignment:") - col.label(text=f' {literal_props.attributes["BoxAlignment"].string_value}') + BIM_PT_text.draw_text_editing_ui(self, context, popup_mode=True) def cancel(self, context): # disable editing when dialog is closed diff --git a/src/bonsai/bonsai/bim/module/drawing/ui.py b/src/bonsai/bonsai/bim/module/drawing/ui.py index e35b9195c1..02a2bc589b 100644 --- a/src/bonsai/bonsai/bim/module/drawing/ui.py +++ b/src/bonsai/bonsai/bim/module/drawing/ui.py @@ -29,7 +29,7 @@ from bonsai.bim.module.drawing.data import ( ElementFiltersData, DecoratorData, ) -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Union if TYPE_CHECKING: from bonsai.bim.module.drawing.prop import DocProperties, Drawing, Sheet @@ -565,56 +565,71 @@ class BIM_PT_text(Panel): return return tool.Drawing.is_annotation_object_type(element, ["TEXT", "TEXT_LEADER"]) + def draw_text_editing_ui( + self: Union[bpy.types.Panel, bpy.types.Operator], + context: bpy.types.Context, + *, + popup_mode: bool = False, + ) -> None: + # The method is also used in EditTextPopup.draw(). + assert self.layout + obj = context.active_object + assert obj + props = tool.Drawing.get_text_props(obj) + + row = self.layout.row(align=True) + + if popup_mode: + row.operator("bim.add_text_literal", icon="ADD", text="Add Literal") + else: + row.operator("bim.edit_text", icon="CHECKMARK") + row.operator("bim.add_text_literal", icon="ADD", text="") + row.operator("bim.disable_editing_text", icon="CANCEL", text="") + + row = self.layout.row(align=True) + row.prop(props, "font_size") + row = self.layout.row(align=True) + row.prop(props, "newline_at") + + for i, literal_props in enumerate(props.literals): + box = self.layout.box() + row = self.layout.row(align=True) + + row = box.row(align=True) + row.label(text=f"Literal[{i}]:") + if i > 0: + row.operator("bim.order_text_literal_up", icon="TRIA_UP", text="").literal_prop_id = i + if i < len(props.literals) - 1: + row.operator("bim.order_text_literal_down", icon="TRIA_DOWN", text="").literal_prop_id = i + row.operator("bim.remove_text_literal", icon="X", text="").literal_prop_id = i + + # skip BoxAlignment since we're going to format it ourselves + attributes = [a for a in literal_props.attributes if a.name != "BoxAlignment"] + popup_active_attribute = attributes[0] if popup_mode else None + bonsai.bim.helper.draw_attributes(attributes, box, popup_active_attribute=popup_active_attribute) + + row = box.row(align=True) + cols = [row.column(align=True) for i in range(3)] + for i in range(9): + cols[i % 3].prop( + literal_props, + "box_alignment", + text="", + index=i, + icon="RADIOBUT_ON" if literal_props.box_alignment[i] else "RADIOBUT_OFF", + ) + + col = row.column(align=True) + col.label(text=" Text box alignment:") + col.label(text=f' {literal_props.attributes["BoxAlignment"].string_value}') + def draw(self, context): obj = context.active_object assert obj props = tool.Drawing.get_text_props(obj) if props.is_editing: - # shares most of the code with EditTextPopup.draw() - # need to keep them in sync or move to some common function - - row = self.layout.row(align=True) - row.operator("bim.edit_text", icon="CHECKMARK") - row.operator("bim.add_text_literal", icon="ADD", text="") - row.operator("bim.disable_editing_text", icon="CANCEL", text="") - - row = self.layout.row(align=True) - row.prop(props, "font_size") - row = self.layout.row(align=True) - row.prop(props, "newline_at") - - for i, literal_props in enumerate(props.literals): - box = self.layout.box() - row = self.layout.row(align=True) - - row = box.row(align=True) - row.label(text=f"Literal[{i}]:") - if i > 0: - row.operator("bim.order_text_literal_up", icon="TRIA_UP", text="").literal_prop_id = i - if i < len(props.literals) - 1: - row.operator("bim.order_text_literal_down", icon="TRIA_DOWN", text="").literal_prop_id = i - row.operator("bim.remove_text_literal", icon="X", text="").literal_prop_id = i - - # skip BoxAlignment since we're going to format it ourselves - attributes = [a for a in literal_props.attributes if a.name != "BoxAlignment"] - bonsai.bim.helper.draw_attributes(attributes, box) - - row = box.row(align=True) - cols = [row.column(align=True) for i in range(3)] - for i in range(9): - cols[i % 3].prop( - literal_props, - "box_alignment", - text="", - index=i, - icon="RADIOBUT_ON" if literal_props.box_alignment[i] else "RADIOBUT_OFF", - ) - - col = row.column(align=True) - col.label(text=" Text box alignment:") - col.label(text=f' {literal_props.attributes["BoxAlignment"].string_value}') - + self.draw_text_editing_ui(context) else: text_data = DecoratorData.get_text_data(obj)