如何在IMGUI中创建垂直的按钮?

发布于 2025-02-12 14:44:13 字数 1538 浏览 1 评论 0原文

我有此IMGUI菜单:

”在此处输入图像描述”

我想将“ del”按钮移至上一个红色选定区域 图像。

这是菜单片段的那部分:

class Waypoint {
public:
    int x, y, z;
    std::string action;
    std::string display;
    Waypoint(std::string action, int x, int y, int z) {
        this->action = action;
        this->x = x;
        this->y = y;
        this->z = z;
        this->display = action + " " + std::to_string(x) + " " + std::to_string(y) + " " + std::to_string(z);
    }
};

static int listbox_item_current = 0;
Waypoint wp1("ROPE", 100, 100, 7);
Waypoint wp2("WALK", 100, 100, 6);
Waypoint wp3("WALK", 110, 131, 6);
std::vector<Waypoint> listbox_items{ wp1, wp2, wp3 };

if (ImGui::CollapsingHeader("Cavebot")) {
    ImGui::ListBox(
    "##listbox::Cavebot",
    &listbox_item_current,
    waypoint_getter,
    listbox_items.data(),
    listbox_items.size()
);

ImGui::SameLine();

if (ImGui::Button("Clean"))
    listbox_items.clear();

ImGui::SameLine();

if (ImGui::Button("Del"))
    listbox_items.erase(listbox_items.begin() + listbox_item_current);

如何将“ DEL”按钮移至“清洁”按钮下方?

编辑:

测试删除imgui :: sameline();在两个按钮之间:

“

I have this ImGui menu:

enter image description here

I want to move the "Del" button to the red selected area in the previous image.

This is that part of the menu snippet:

class Waypoint {
public:
    int x, y, z;
    std::string action;
    std::string display;
    Waypoint(std::string action, int x, int y, int z) {
        this->action = action;
        this->x = x;
        this->y = y;
        this->z = z;
        this->display = action + " " + std::to_string(x) + " " + std::to_string(y) + " " + std::to_string(z);
    }
};

static int listbox_item_current = 0;
Waypoint wp1("ROPE", 100, 100, 7);
Waypoint wp2("WALK", 100, 100, 6);
Waypoint wp3("WALK", 110, 131, 6);
std::vector<Waypoint> listbox_items{ wp1, wp2, wp3 };

if (ImGui::CollapsingHeader("Cavebot")) {
    ImGui::ListBox(
    "##listbox::Cavebot",
    &listbox_item_current,
    waypoint_getter,
    listbox_items.data(),
    listbox_items.size()
);

ImGui::SameLine();

if (ImGui::Button("Clean"))
    listbox_items.clear();

ImGui::SameLine();

if (ImGui::Button("Del"))
    listbox_items.erase(listbox_items.begin() + listbox_item_current);

How can I move the "Del" button to be below the "Clean" button?

EDIT:

Testing removing ImGui::SameLine(); between both buttons:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

铁轨上的流浪者 2025-02-19 14:44:13

我通常使用imgui :: setCursorPos(),如@thedemons所建议。但是还有imgui :: begingroup();

删除最后的imgui :: sameline();,然后将两个按钮包装在begin/endgroup中。这是一个简化的示例:

ImGui::Begin("Window");
ImGui::Button("x", ImVec2(200,100));
ImGui::SameLine();
ImGui::BeginGroup();
ImGui::Button("Alpha");
ImGui::Button("Beta");
ImGui::EndGroup();
ImGui::End();

“在此处输入图像描述”

I normally use ImGui::SetCursorPos() for this, as suggested by @thedemons. But there is also ImGui::BeginGroup();.

Remove the last ImGui::SameLine(); and wrap the two buttons in Begin/EndGroup. Here's a simplified example:

ImGui::Begin("Window");
ImGui::Button("x", ImVec2(200,100));
ImGui::SameLine();
ImGui::BeginGroup();
ImGui::Button("Alpha");
ImGui::Button("Beta");
ImGui::EndGroup();
ImGui::End();

enter image description here

笑梦风尘 2025-02-19 14:44:13

您可以使用imgui :: SetCursorPos将项目位置设置为您的需求。

ImVec2 currentCurPos = ImGui::GetCursorPos();

if (ImGui::Button("Clean"))
    listbox_items.clear();

ImVec2 DelButtonPos(currentCurPos.x, currentCurPos.y + 25);
ImGui::SetCursorPos(DelButtonPos);

if (ImGui::Button("Del"))
    listbox_items.erase(listbox_items.begin() + listbox_item_current);

You can use ImGui::SetCursorPos to set the item position to your desire.

ImVec2 currentCurPos = ImGui::GetCursorPos();

if (ImGui::Button("Clean"))
    listbox_items.clear();

ImVec2 DelButtonPos(currentCurPos.x, currentCurPos.y + 25);
ImGui::SetCursorPos(DelButtonPos);

if (ImGui::Button("Del"))
    listbox_items.erase(listbox_items.begin() + listbox_item_current);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文