建立視窗 Window
1 | ImGui::Begin("Window Title"); |

顯示文字 Text
Prototype
1
void Text(const char* fmt, ...)
fmt- 格式字串
1 | ImGui::Text("This is a text"); |

所有的 TextXXX() 系列的 function 皆有 va_list 版本 TextXXXV()
有顏色的字 TextColored
1 | ImGui::TextColored(ImVec4(255, 0, 0, 255), "red"); |

TextDisabled
1 | ImGui::Text("Enabled text"); |

縮放文字 TextWrapped
TextWrapped 會跟隨著視窗的縮放
1 | ImGui::Text("Normal texts"); |

標籤文字 LabelText
1 | ImGui::LabelText("t1", "texts in label1"); |

Pic

項目符號文字 BulletText
1 | ImGui::BulletText("texts in label1"); |

工具提示 Tooltip
將滑鼠擺在該元素上,顯示工具提示
1 | ImGui::Text("Hover over me"); |

截圖沒辦法擷取滑鼠,但此圖滑鼠確實擺在文字上方
- tooltip 裏頭想裝其他 widget?
- 用
BeginTooltip()/EndTooltip()
- 用
1 | ImGui::Text("Hover over me"); |

例子:HelpMarker
將滑鼠放在 (?) 文字上方可以顯示提示(Tooltip)
1 | void HelpMarker(const char *desc) |

按鈕 Buttons
- Prototype
1
bool Button(const char* label, const ImVec2& size = ImVec2(0,0));
1 | if(ImGui::Button("Button")) |

e.g. 1
1
2
3
4
5
6
7
8static int clicked = 0;
if(ImGui::Button("Press me"))
clicked++;
if(clicked)
{
ImGui::SameLine();
ImGui::Text("You pressed for %d times\n", clicked);
}
按鈕可以設定大小(第二個參數)
1 | ImGui::Button("tets", ImVec2(100, 100)); |

換顏色
Button 可以用 PushStyleColor 換顏色
1 | ImGui::Begin("Sample Window"); |

小按鈕 SmallButton
沒有 FramePadding 的按鈕
1 | ImGui::Button("A normal btn"); |

InvisibleButton
隱形的按鈕,一個按鈕該有的行為它都有,通常會搭配 IsItemActive() 或 IsItemHover() 等 Query Status 的函式
參考 Demo Window 的 Widgets->Querying Status
1 | if(ImGui::InvisibleButton("1", ImVec2(100, 100))) |

箭頭按鈕 ArrowButton

正方形的按鈕,上頭的圖案是箭頭,通常用在要切換的地方
1 | ImGui::ArrowButton("##Left", ImGuiDir_Left); |
- e.g.
1 | static int counter = 0; |

文字與按鈕對齊
直接使用 SameLine() 文字與元件之間仍然會有高度差,而 AlignTextToFramePadding() 則可以解決這件事情
1 | ImGui::Text("text 1"); ImGui::SameLine(); |

如果你覺得這篇文章很棒,請你不吝點讚 (゚∀゚)