28
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ImGuiのWidgets

Posted at

imgui_demo.cppのImGui::ShowTestWindowを読んでピックアップしてみた。

Window

ImGui::Begin("About ImGui"
, &show_app_about // bool 表示するか否か。ウインドウ右肩のxボタン
, ImGuiWindowFlags_AlwaysAutoResize // 位置決めのflag
);

// 中身

ImGui::End();

デフォルトでドラッグ可能なタイトル付きのウィンドウになる。
一つしか使わないときはBegin~Endを省略することもできる。
ウインドウの位置とサイズはアプリケーションの終了時に自動で保存されて、次回実行時に値が復帰される。
いろいろとフラグを指定してカスタマイズできる。

   // Demonstrate the various window flags. Typically you would just use the default.
    ImGuiWindowFlags window_flags = 0;
    if (no_titlebar)  window_flags |= ImGuiWindowFlags_NoTitleBar;
    if (!no_border)   window_flags |= ImGuiWindowFlags_ShowBorders;
    if (no_resize)    window_flags |= ImGuiWindowFlags_NoResize;
    if (no_move)      window_flags |= ImGuiWindowFlags_NoMove;
    if (no_scrollbar) window_flags |= ImGuiWindowFlags_NoScrollbar;
    if (no_collapse)  window_flags |= ImGuiWindowFlags_NoCollapse;
    if (!no_menu)     window_flags |= ImGuiWindowFlags_MenuBar;
    ImGui::SetNextWindowSize(ImVec2(550,680), ImGuiSetCond_FirstUseEver);
    if (!ImGui::Begin("ImGui Demo", p_open, window_flags))
    {
        // Early out if the window is collapsed, as an optimization.
        ImGui::End();
        return;
    }

Overlay

タイトルバーなし、リサイズなし、移動なしの例。

static void ShowExampleAppFixedOverlay(bool* p_open)
{
    ImGui::SetNextWindowPos(ImVec2(10,10));
    if (!ImGui::Begin("Example: Fixed Overlay", p_open, ImVec2(0,0), 0.3f, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoSavedSettings))
    {
        ImGui::End();
        return;
    }
    ImGui::Text("Simple overlay\non the top-left side of the screen.");
    ImGui::Separator();
    ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
    ImGui::End();
}

文字列

Text

ImGui::Text("Camera");

Bullet

list表示。

ImGui::BulletText("Bullet point 1");
ImGui::BulletText("Bullet point 2\nOn multiple lines");
ImGui::Bullet(); ImGui::Text("Bullet point 3 (two calls)");
ImGui::Bullet(); ImGui::SmallButton("Button");

ColoredText

ImGui::TextColored(ImVec4(1.0f,0.0f,1.0f,1.0f), "Pink");

Button

if(ImGui::Button("Open")){
  // on click
}

InputText

static char str0[128] = "Hello, world!";
ImGui::InputText("input text", str0, IM_ARRAYSIZE(str0));

ブーリアン・選択

CheckBox

ImGui::Checkbox("No titlebar", &no_titlebar);

Selectables

static bool selected[4] = { false, true, false, false };
ImGui::Selectable("1. I am selectable", &selected[0]);
ImGui::Selectable("2. I am selectable", &selected[1]);
ImGui::Text("3. I am not selectable");
ImGui::Selectable("4. I am selectable", &selected[2]);
if (ImGui::Selectable("5. I am double clickable", selected[3], ImGuiSelectableFlags_AllowDoubleClick))
    if (ImGui::IsMouseDoubleClicked(0))
        selected[3] = !selected[3];

RadioButton

static int e = 0;
ImGui::RadioButton("radio a", &e, 0); ImGui::SameLine();
ImGui::RadioButton("radio b", &e, 1); ImGui::SameLine();
ImGui::RadioButton("radio c", &e, 2);

ComboBox

static int item = 1;
ImGui::Combo("combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0");   // Combo using values packed in a single constant string (for really quick combo)

int

InputInt

static int i0=123;
ImGui::InputInt("input int", &i0);

DragInt

static int i1=50, i2=42;
ImGui::DragInt("drag int", &i1, 1);

ImGui::DragInt("drag int 0..100", &i2, 1, 0, 100, "%.0f%%");

DragIntRange2

static int begin_i = 100, end_i = 1000;
ImGui::DragIntRange2("range int (no bounds)", &begin_i, &end_i, 5, 0, 0, "Min: %.0f units", "Max: %.0f units");

float

InputFloat

static float f0=0.001f;
ImGui::InputFloat("input float", &f0, 0.01f, 1.0f);

InputFloat4

static float vec4a[4] = { 0.10f, 0.20f, 0.30f, 0.44f };
ImGui::InputFloat3("input float3", vec4a);

DragFloat

static float f1=1.00f, f2=0.0067f;
ImGui::DragFloat("drag float", &f1, 0.005f);

SliderAngle

static float angle = 0.0f;
ImGui::SliderAngle("slider angle", &angle);

DragFloatRange2

static float begin = 10, end = 90;
ImGui::DragFloatRange2("range", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%");

VSliderFloat

ImGui::VSliderFloat("##v", ImVec2(18,160), &values[i], 0.0f, 1.0f, "");

Input, Drag, Slider

各種。

ImGui::InputFloat2("input float2", vec4f);
ImGui::DragFloat2("drag float2", vec4f, 0.01f, 0.0f, 1.0f);
ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f);
ImGui::DragInt2("drag int2", vec4i, 1, 0, 255);
ImGui::InputInt2("input int2", vec4i);
ImGui::SliderInt2("slider int2", vec4i, 0, 255);

ImGui::InputFloat3("input float3", vec4f);
ImGui::DragFloat3("drag float3", vec4f, 0.01f, 0.0f, 1.0f);
ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f);
ImGui::DragInt3("drag int3", vec4i, 1, 0, 255);
ImGui::InputInt3("input int3", vec4i);
ImGui::SliderInt3("slider int3", vec4i, 0, 255);

ImGui::InputFloat4("input float4", vec4f);
ImGui::DragFloat4("drag float4", vec4f, 0.01f, 0.0f, 1.0f);
ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f);
ImGui::InputInt4("input int4", vec4i);
ImGui::DragInt4("drag int4", vec4i, 1, 0, 255);
ImGui::SliderInt4("slider int4", vec4i, 0, 255);

Color

ColorEdit3

static float col1[3] = { 1.0f,0.0f,0.2f };
ImGui::ColorEdit3("color 1", col1);
ImGui::SameLine(); ShowHelpMarker("Click on the colored square to change edit mode.\nCTRL+click on individual component to input value.\n");

ColorEdit4

static float col2[4] = { 0.4f,0.7f,0.0f,0.5f };
ImGui::ColorEdit4("color 2", col2);

Texture/画像

TexturedButton

コンテナ・レイアウト

隙間

ImGui::Space();
ImGui::Separator();

Header

折り畳みヘッダ。

if (ImGui::CollapsingHeader("Help"))
{
}

Group

ImGui::BeginGroup();
// 中身
ImGui::EndGroup();

TreeNode

改行をキャンセル

ImGui::SameLine();

ImGui::SameLine(300);

Columns

ImGui::Columns(3, NULL, false);

ListBox

const char* listbox_items[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pineapple", "Strawberry", "Watermelon" };
static int listbox_item_current = 1;
ImGui::ListBox("listbox\n(single select)", &listbox_item_current, listbox_items, IM_ARRAYSIZE(listbox_items), 4);

Help

ShowHelpMarker

static int i1=0;
ImGui::SliderInt("slider int", &i1, -1, 3);
ImGui::SameLine(); ShowHelpMarker("CTRL+click to input value.");

Tooltip

 if (ImGui::IsItemHovered())
    ImGui::SetTooltip("Group hovered");
28
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?