如何在IMGUI中创建垂直的按钮?
我有此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:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常使用
imgui :: setCursorPos()
,如@thedemons所建议。但是还有imgui :: begingroup();
。删除最后的
imgui :: sameline();
,然后将两个按钮包装在begin/endgroup
中。这是一个简化的示例:I normally use
ImGui::SetCursorPos()
for this, as suggested by @thedemons. But there is alsoImGui::BeginGroup();
.Remove the last
ImGui::SameLine();
and wrap the two buttons inBegin/EndGroup
. Here's a simplified example:您可以使用
imgui :: SetCursorPos
将项目位置设置为您的需求。You can use
ImGui::SetCursorPos
to set the item position to your desire.