| 1703 | } |
| 1704 | |
| 1705 | nb::object PyUILayout::operator_(const std::string& operator_id, const std::string& text, |
| 1706 | const std::string& icon) { |
| 1707 | const auto* desc = vis::op::operators().getDescriptor(operator_id); |
| 1708 | std::string label = text.empty() ? (desc ? desc->label : operator_id) : text; |
| 1709 | std::string btn_text = LOC(label.c_str()); |
| 1710 | |
| 1711 | const bool can_execute = vis::op::operators().poll(operator_id); |
| 1712 | |
| 1713 | if (collecting_ && collect_target_) { |
| 1714 | vis::gui::MenuItemDesc item; |
| 1715 | item.type = vis::gui::MenuItemDesc::Type::Operator; |
| 1716 | item.label = btn_text; |
| 1717 | item.operator_id = operator_id; |
| 1718 | item.enabled = can_execute; |
| 1719 | collect_target_->items.push_back(std::move(item)); |
| 1720 | return nb::cast(PyOperatorProperties(operator_id)); |
| 1721 | } |
| 1722 | |
| 1723 | bool clicked = false; |
| 1724 | if (menu_depth_ > 0) { |
| 1725 | clicked = ImGui::MenuItem(btn_text.c_str(), nullptr, false, can_execute); |
| 1726 | } else { |
| 1727 | if (!can_execute) { |
| 1728 | ImGui::BeginDisabled(); |
| 1729 | } |
| 1730 | |
| 1731 | if (!icon.empty()) { |
| 1732 | unsigned int tex_id = load_icon_texture(icon); |
| 1733 | if (tex_id) { |
| 1734 | float size = ImGui::GetTextLineHeight(); |
| 1735 | clicked = ImGui::ImageButton(operator_id.c_str(), static_cast<ImTextureID>(tex_id), |
| 1736 | ImVec2(size, size)); |
| 1737 | if (!btn_text.empty()) { |
| 1738 | ImGui::SameLine(); |
| 1739 | ImGui::TextUnformatted(btn_text.c_str()); |
| 1740 | } |
| 1741 | } else { |
| 1742 | clicked = ImGui::Button(btn_text.c_str()); |
| 1743 | } |
| 1744 | } else { |
| 1745 | clicked = ImGui::Button(btn_text.c_str()); |
| 1746 | } |
| 1747 | |
| 1748 | if (!can_execute) { |
| 1749 | ImGui::EndDisabled(); |
| 1750 | } |
| 1751 | } |
| 1752 | |
| 1753 | auto props = PyOperatorProperties(operator_id); |
| 1754 | |
| 1755 | if (clicked) { |
| 1756 | vis::op::operators().invoke(operator_id); |
| 1757 | } |
| 1758 | |
| 1759 | return nb::cast(props); |
| 1760 | } |
| 1761 | |
| 1762 | std::tuple<bool, int> PyUILayout::prop_search(nb::object /*data*/, const std::string& prop_id, |
nothing calls this directly
no test coverage detected