1
0
mirror of https://github.com/ocornut/imgui.git synced 2024-11-14 11:07:48 +01:00

Examples: Clarified comments. Removed font merging example from comments.

This commit is contained in:
ocornut 2015-11-29 11:11:03 +00:00
parent d673db3092
commit 5c52e9ec0d
10 changed files with 14 additions and 60 deletions

View File

@ -25,7 +25,7 @@ int main(int, char**)
ImGui_ImplA5_Init(display); ImGui_ImplA5_Init(display);
// Load Fonts // Load Fonts
// (see extra_fonts/README.txt for more details) // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
//ImGuiIO& io = ImGui::GetIO(); //ImGuiIO& io = ImGui::GetIO();
//io.Fonts->AddFontDefault(); //io.Fonts->AddFontDefault();
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
@ -34,12 +34,6 @@ int main(int, char**)
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
//static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
bool show_test_window = true; bool show_test_window = true;
bool show_another_window = false; bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154); ImVec4 clear_color = ImColor(114, 144, 154);

View File

@ -152,7 +152,7 @@ int main(int, char**)
ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext); ImGui_ImplDX11_Init(hwnd, g_pd3dDevice, g_pd3dDeviceContext);
// Load Fonts // Load Fonts
// (see extra_fonts/README.txt for more details) // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
//ImGuiIO& io = ImGui::GetIO(); //ImGuiIO& io = ImGui::GetIO();
//io.Fonts->AddFontDefault(); //io.Fonts->AddFontDefault();
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
@ -161,12 +161,6 @@ int main(int, char**)
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
//static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
bool show_test_window = true; bool show_test_window = true;
bool show_another_window = false; bool show_another_window = false;
ImVec4 clear_col = ImColor(114, 144, 154); ImVec4 clear_col = ImColor(114, 144, 154);

View File

@ -76,7 +76,7 @@ int main(int, char**)
ImGui_ImplDX9_Init(hwnd, g_pd3dDevice); ImGui_ImplDX9_Init(hwnd, g_pd3dDevice);
// Load Fonts // Load Fonts
// (see extra_fonts/README.txt for more details) // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
//ImGuiIO& io = ImGui::GetIO(); //ImGuiIO& io = ImGui::GetIO();
//io.Fonts->AddFontDefault(); //io.Fonts->AddFontDefault();
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
@ -85,12 +85,6 @@ int main(int, char**)
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
//static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
bool show_test_window = true; bool show_test_window = true;
bool show_another_window = false; bool show_another_window = false;
ImVec4 clear_col = ImColor(114, 144, 154); ImVec4 clear_col = ImColor(114, 144, 154);

View File

@ -17,7 +17,7 @@ int main(int, char**)
ImGui_Marmalade_Init(true); ImGui_Marmalade_Init(true);
// Load Fonts // Load Fonts
// (see extra_fonts/README.txt for more details) // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
//ImGuiIO& io = ImGui::GetIO(); //ImGuiIO& io = ImGui::GetIO();
//io.Fonts->AddFontDefault(); //io.Fonts->AddFontDefault();
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
@ -26,12 +26,6 @@ int main(int, char**)
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
//static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
bool show_test_window = true; bool show_test_window = true;
bool show_another_window = false; bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154); ImVec4 clear_color = ImColor(114, 144, 154);

View File

@ -31,7 +31,7 @@ int main(int, char**)
ImGui_ImplGlfwGL3_Init(window, true); ImGui_ImplGlfwGL3_Init(window, true);
// Load Fonts // Load Fonts
// (see extra_fonts/README.txt for more details) // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
//ImGuiIO& io = ImGui::GetIO(); //ImGuiIO& io = ImGui::GetIO();
//io.Fonts->AddFontDefault(); //io.Fonts->AddFontDefault();
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
@ -40,12 +40,6 @@ int main(int, char**)
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
//static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
bool show_test_window = true; bool show_test_window = true;
bool show_another_window = false; bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154); ImVec4 clear_color = ImColor(114, 144, 154);

View File

@ -23,7 +23,7 @@ int main(int, char**)
ImGui_ImplGlfw_Init(window, true); ImGui_ImplGlfw_Init(window, true);
// Load Fonts // Load Fonts
// (see extra_fonts/README.txt for more details) // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
//ImGuiIO& io = ImGui::GetIO(); //ImGuiIO& io = ImGui::GetIO();
//io.Fonts->AddFontDefault(); //io.Fonts->AddFontDefault();
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
@ -32,12 +32,6 @@ int main(int, char**)
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
//static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
bool show_test_window = true; bool show_test_window = true;
bool show_another_window = false; bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154); ImVec4 clear_color = ImColor(114, 144, 154);

View File

@ -31,7 +31,7 @@ int main(int, char**)
ImGui_ImplSdlGL3_Init(window); ImGui_ImplSdlGL3_Init(window);
// Load Fonts // Load Fonts
// (see extra_fonts/README.txt for more details) // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
//ImGuiIO& io = ImGui::GetIO(); //ImGuiIO& io = ImGui::GetIO();
//io.Fonts->AddFontDefault(); //io.Fonts->AddFontDefault();
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
@ -40,12 +40,6 @@ int main(int, char**)
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
//ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
bool show_test_window = true; bool show_test_window = true;
bool show_another_window = false; bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154); ImVec4 clear_color = ImColor(114, 144, 154);

View File

@ -30,7 +30,7 @@ int main(int, char**)
ImGui_ImplSdl_Init(window); ImGui_ImplSdl_Init(window);
// Load Fonts // Load Fonts
// (see extra_fonts/README.txt for more details) // (there is a default font, this is only if you want to change it. see extra_fonts/README.txt for more details)
//ImGuiIO& io = ImGui::GetIO(); //ImGuiIO& io = ImGui::GetIO();
//io.Fonts->AddFontDefault(); //io.Fonts->AddFontDefault();
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/Cousine-Regular.ttf", 15.0f);
@ -39,12 +39,6 @@ int main(int, char**)
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f); //io.Fonts->AddFontFromFileTTF("../../extra_fonts/ProggyTiny.ttf", 10.0f);
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
// Merge glyphs from multiple fonts into one (e.g. combine default font with another with Chinese glyphs, or add icons)
//static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
//ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/DroidSans.ttf", 18.0f);
//io.Fonts->AddFontFromFileTTF("../../extra_fonts/fontawesome-webfont.ttf", 18.0f, &icons_config, icons_ranges);
bool show_test_window = true; bool show_test_window = true;
bool show_another_window = false; bool show_another_window = false;
ImVec4 clear_color = ImColor(114, 144, 154); ImVec4 clear_color = ImColor(114, 144, 154);

View File

@ -32,11 +32,11 @@
// Add character ranges and merge into main font // Add character ranges and merge into main font
// The ranges array is not copied by the AddFont* functions and is used lazily // The ranges array is not copied by the AddFont* functions and is used lazily
// so ensure it is available for duration of font usage // so ensure it is available for duration of font usage
static const ImWchar ranges[] = { 0xf000, 0xf3ff, 0 }; static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // will not be copied by AddFont* so keep in scope.
ImFontConfig config; ImFontConfig config;
config.MergeMode = true; config.MergeMode = true;
io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges); io.Fonts->AddFontFromFileTTF("DroidSans.ttf", 18.0f, &config, io.Fonts->GetGlyphRangesJapanese());
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config, io.Fonts->GetGlyphRangesJapanese()); io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 18.0f, &config, icons_ranges);
Add a fourth parameter to bake specific font ranges only: Add a fourth parameter to bake specific font ranges only:

View File

@ -80,7 +80,8 @@
- customization: PushStyleColor()/PushStyleVar() or the style editor to tweak the look of the interface (e.g. if you want a more compact UI or a different color scheme). - customization: PushStyleColor()/PushStyleVar() or the style editor to tweak the look of the interface (e.g. if you want a more compact UI or a different color scheme).
- getting started: - getting started:
- initialisation: call ImGui::GetIO() to retrieve the ImGuiIO structure and fill the fields marked 'Settings'. - init: call ImGui::GetIO() to retrieve the ImGuiIO structure and fill the fields marked 'Settings'.
- init: call io.Fonts->GetTexDataAsRGBA32(...) and load the font texture pixels into graphics memory.
- every frame: - every frame:
1/ in your mainloop or right after you got your keyboard/mouse info, call ImGui::GetIO() and fill the fields marked 'Input' 1/ in your mainloop or right after you got your keyboard/mouse info, call ImGui::GetIO() and fill the fields marked 'Input'
2/ call ImGui::NewFrame(). 2/ call ImGui::NewFrame().
@ -101,6 +102,7 @@
// TODO: Fill others settings of the io structure // TODO: Fill others settings of the io structure
// Load texture atlas // Load texture atlas
// There is a default font so you don't need to care about choosing a font yet
unsigned char* pixels; unsigned char* pixels;
int width, height; int width, height;
io.Fonts->GetTexDataAsRGBA32(pixels, &width, &height); io.Fonts->GetTexDataAsRGBA32(pixels, &width, &height);