03 控件:按钮(Button)

03 控件:按钮(Button)

​ 控件要写在BeginEnd之间,才能被窗口正确接收使用。

基本案例

​ 按钮创建直接使用Button函数,注意按钮文本不能为空

{
using namespace ImGui;
static bool isOpen = true;
if (isOpen)
{
ImGui::Begin("Test", &isOpen, wflags);
auto b_h = Button("hello");
if(b_h) std::cout << b_h << std::endl;
ImGui::End();
}
}

按钮布局

换行布局

​ 一般来说,创建多个控件会以换行的形式布局,如下:

image-20231129210104951

同行布局

​ 使用ImGui::SameLine();设置下个控件同行布局。

image-20231129210250986