ImGuiのWidgets

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


# Window

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

// 中身

ImGui::End();
```

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

```c++
   // 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
タイトルバーなし、リサイズなし、移動なしの例。

```c++
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

```c++
ImGui::Text("Camera");
```
## Bullet
list表示。

```c++
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

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

## Button

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

## InputText

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

# ブーリアン・選択
## CheckBox

```C++
ImGui::Checkbox("No titlebar", &no_titlebar);
```
## Selectables

```C++
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

```C++
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

```C++
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

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

## DragInt

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

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

## DragIntRange2

```c++
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

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

## InputFloat4

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

## DragFloat

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

## SliderAngle

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

## DragFloatRange2

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

## VSliderFloat

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

# Input, Drag, Slider
各種。

```c++
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

```C++
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

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

# Texture/画像

## TexturedButton

# コンテナ・レイアウト
## 隙間

```C++
ImGui::Space();
ImGui::Separator();
```

## Header
折り畳みヘッダ。

```C++
if (ImGui::CollapsingHeader("Help"))
{
}
```

## Group

```C++
ImGui::BeginGroup();
// 中身
ImGui::EndGroup();
```

## TreeNode

## 改行をキャンセル

```C++
ImGui::SameLine();

ImGui::SameLine(300);
```

## Columns

```C++
ImGui::Columns(3, NULL, false);
```

## ListBox

```C++
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

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

## Tooltip

```C++
 if (ImGui::IsItemHovered())
    ImGui::SetTooltip("Group hovered");
```