Merge branch 'master' into viewport

# Conflicts:
#	imgui.cpp
This commit is contained in:
omar 2018-10-25 23:41:13 +02:00
commit 50f6e12d31
9 changed files with 2128 additions and 2059 deletions

View File

@ -50,6 +50,7 @@ Other Changes:
erroneously wrapped the value to one of the min/max edge. (#2024, #708, #320, #2075). erroneously wrapped the value to one of the min/max edge. (#2024, #708, #320, #2075).
- DragFloat: Disabled using power curve when one edge is FLT_MAX (broken in 1.61). (#2024) - DragFloat: Disabled using power curve when one edge is FLT_MAX (broken in 1.61). (#2024)
- DragFloat: Disabled setting a default drag speed when one edge is FLT_MAX. (#2024) - DragFloat: Disabled setting a default drag speed when one edge is FLT_MAX. (#2024)
- SliderAngle: Added optional format argument to alter precision or localize the string. (#2150) [@podsvirov]
- Window: Resizing from edges (with io.ConfigResizeWindowsFromEdges Beta flag) extends the hit region - Window: Resizing from edges (with io.ConfigResizeWindowsFromEdges Beta flag) extends the hit region
of root floating windows outside the window, making it easier to resize windows. Resize grips are also of root floating windows outside the window, making it easier to resize windows. Resize grips are also
extended accordingly so there are no discontinuity when hovering between borders and corners. (#1495, #822) extended accordingly so there are no discontinuity when hovering between borders and corners. (#1495, #822)
@ -68,6 +69,7 @@ Other Changes:
- RenderText(): Some optimization for very large text buffers, useful for non-optimized builds. - RenderText(): Some optimization for very large text buffers, useful for non-optimized builds.
- BeginMenu(): Fixed menu popup horizontal offset being off the item in the menu bar when WindowPadding=0.0f. - BeginMenu(): Fixed menu popup horizontal offset being off the item in the menu bar when WindowPadding=0.0f.
- ArrowButton(): Fixed arrow shape being horizontally misaligned by (FramePadding.y-FramePadding.x) if they are different. - ArrowButton(): Fixed arrow shape being horizontally misaligned by (FramePadding.y-FramePadding.x) if they are different.
- Demo: Split the contents of ShowDemoWindow() into smaller functions as it appears to speed up link time with VS. (#2152)
- Drag and Drop: Added GetDragDropPayload() to peek directly into the payload (if any) from anywhere. (#143) - Drag and Drop: Added GetDragDropPayload() to peek directly into the payload (if any) from anywhere. (#143)
- ImGuiTextBuffer: Avoid heap allocation when empty. - ImGuiTextBuffer: Avoid heap allocation when empty.
- ImDrawList: Fixed AddConvexPolyFilled() undefined behavior when passing points_count smaller than 3, - ImDrawList: Fixed AddConvexPolyFilled() undefined behavior when passing points_count smaller than 3,

View File

@ -85,9 +85,9 @@ Result:
### How it works ### How it works
Check out the References section if you want to understand the core principles behind the IMGUI paradigm. An IMGUI tries to minimize state duplication, state synchronization and state storage from the user's point of view. It is less error prone (less code and less bugs) than traditional retained-mode interfaces, and lends itself to create dynamic user interfaces. Check out the References section if you want to understand the core principles behind the IMGUI paradigm. An IMGUI tries to minimize superfluous state duplication, state synchronization and state retention from the user's point of view. It is less error prone (less code and less bugs) than traditional retained-mode interfaces, and lends itself to create dynamic user interfaces.
Dear ImGui outputs vertex buffers and command lists that you can easily render in your application. The number of draw calls and state changes is typically very small. Because it doesn't know or touch graphics state directly, you can call ImGui commands anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate dear imgui with your existing codebase. Dear ImGui outputs vertex buffers and command lists that you can easily render in your application. The number of draw calls and state changes required to render them is fairly small. Because Dear ImGui doesn't know or touch graphics state directly, you can call its functions anywhere in your code (e.g. in the middle of a running algorithm, or in the middle of your own rendering process). Refer to the sample applications in the examples/ folder for instructions on how to integrate dear imgui with your existing codebase.
_A common misunderstanding is to mistake immediate mode gui for immediate mode rendering, which usually implies hammering your driver/GPU with a bunch of inefficient draw calls and state changes as the gui functions are called. This is NOT what Dear ImGui does. Dear ImGui outputs vertex buffers and a small list of draw calls batches. It never touches your GPU directly. The draw call batches are decently optimal and you can render them later, in your app or even remotely._ _A common misunderstanding is to mistake immediate mode gui for immediate mode rendering, which usually implies hammering your driver/GPU with a bunch of inefficient draw calls and state changes as the gui functions are called. This is NOT what Dear ImGui does. Dear ImGui outputs vertex buffers and a small list of draw calls batches. It never touches your GPU directly. The draw call batches are decently optimal and you can render them later, in your app or even remotely._
@ -99,12 +99,12 @@ Demo Binaries
You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here: You should be able to build the examples from sources (tested on Windows/Mac/Linux). If you don't, let me know! If you want to have a quick look at some Dear ImGui features, you can download Windows binaries of the demo app here:
- [imgui-demo-binaries-20181008.zip](http://www.miracleworld.net/imgui/binaries/imgui-demo-binaries-20181008.zip) (Windows binaries, Dear ImGui 1.66 WIP built 2018/10/08, master branch, 5 executables) - [imgui-demo-binaries-20181008.zip](http://www.miracleworld.net/imgui/binaries/imgui-demo-binaries-20181008.zip) (Windows binaries, Dear ImGui 1.66 WIP built 2018/10/08, master branch, 5 executables)
The demo applications are unfortunately not yet DPI aware so expect some blurriness on a 4K screen. For DPI awareness you can load/reload your font at different scale, and scale your Style with `style.ScaleAllSizes()`. The demo applications are unfortunately not yet DPI aware so expect some blurriness on a 4K screen. For DPI awareness in your application, you can load/reload your font at different scale, and scale your Style with `style.ScaleAllSizes()`.
Bindings Bindings
-------- --------
Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer and at ease with those concepts, it should take you less than an hour to integrate Dear ImGui in your custom engine, but make sure to spend time reading the FAQ, the comments and other documentation! Integrating Dear ImGui within your custom engine is a matter of 1) wiring mouse/keyboard/gamepad inputs 2) uploading one texture to your GPU/render engine 3) providing a render function that can bind textures and render textured triangles. The [examples/](https://github.com/ocornut/imgui/tree/master/examples) folder is populated with applications doing just that. If you are an experienced programmer at ease with those concepts, it should take you about an hour to integrate Dear ImGui in your custom engine. Make sure to spend time reading the FAQ, the comments and other documentation!
_NB: those third-party bindings may be more or less maintained, more or less close to the original API (as people who create language bindings sometimes haven't used the C++ API themselves.. for the good reason that they aren't C++ users). Dear ImGui was designed with C++ in mind and some of the subtleties may be lost in translation with other languages. If your language supports it, I would suggest replicating the function overloading and default parameters used in the original, else the API may be harder to use. In doubt, please check the original C++ version first!_ _NB: those third-party bindings may be more or less maintained, more or less close to the original API (as people who create language bindings sometimes haven't used the C++ API themselves.. for the good reason that they aren't C++ users). Dear ImGui was designed with C++ in mind and some of the subtleties may be lost in translation with other languages. If your language supports it, I would suggest replicating the function overloading and default parameters used in the original, else the API may be harder to use. In doubt, please check the original C++ version first!_
@ -153,9 +153,9 @@ For other bindings: see [Bindings](https://github.com/ocornut/imgui/wiki/Binding
Roadmap Roadmap
------- -------
Some of the goals for 2018-2019 are: Some of the goals for 2018-2019 are:
- Finish work on gamepad/keyboard controls. (see [#787](https://github.com/ocornut/imgui/issues/787))
- Finish work on docking, tabs. (see [#2109](https://github.com/ocornut/imgui/issues/2109)) - Finish work on docking, tabs. (see [#2109](https://github.com/ocornut/imgui/issues/2109))
- Finish work on viewports and multiple OS windows management. (see [#1542](https://github.com/ocornut/imgui/issues/1542)) - Finish work on viewports and multiple OS windows management. (see [#1542](https://github.com/ocornut/imgui/issues/1542))
- Finish work on gamepad/keyboard controls. (see [#787](https://github.com/ocornut/imgui/issues/787))
- Make Columns better. (they are currently pretty terrible!) - Make Columns better. (they are currently pretty terrible!)
- Make the examples look better, improve styles, improve font support, make the examples hi-DPI aware. - Make the examples look better, improve styles, improve font support, make the examples hi-DPI aware.
@ -215,7 +215,7 @@ See the [Wiki](https://github.com/ocornut/imgui/wiki) for more references and [B
Support Forums Support Forums
-------------- --------------
If you have issues with: compiling, linking, adding fonts, running or displaying Dear ImGui, or wiring inputs: please post on the Discourse forum: https://discourse.dearimgui.org/c/getting-started. If you have issues with: compiling, linking, adding fonts, running or displaying Dear ImGui, or wiring inputs: please post on the Discourse forum: https://discourse.dearimgui.org.
For any other questions, bug reports, requests, feedback, you may post on https://github.com/ocornut/imgui/issues. For any other questions, bug reports, requests, feedback, you may post on https://github.com/ocornut/imgui/issues.
@ -305,7 +305,7 @@ If your company uses dear imgui, please consider financial support (e.g. sponsor
- Blizzard Entertainment. - Blizzard Entertainment.
**Double-chocolate sponsors** **Double-chocolate sponsors**
- Media Molecule, Mobigame, Insomniac Games, Aras Pranckevičius, Lizardcube, Greggman, DotEmu, Nadeo, Supercell, Runner, Friendly Shade. - Media Molecule, Mobigame, Insomniac Games, Aras Pranckevičius, Lizardcube, Greggman, DotEmu, Nadeo, Supercell, Runner.
**Salty caramel supporters** **Salty caramel supporters**
- Jetha Chan, Wild Sheep Studio, Pastagames, Mārtiņš Možeiko, Daniel Collin, Recognition Robotics, Chris Genova, ikrima, Glenn Fiedler, Geoffrey Evans, Dakko Dakko, Mercury Labs, Singularity Demo Group, Mischa Alff, Sebastien Ronsse, Lionel Landwerlin, Nikolay Ivanov, Ron Gilbert, Brandon Townsend, Nikhil Deshpande, Cort Stratton, drudru, Harfang 3D, Jeff Roberts. - Jetha Chan, Wild Sheep Studio, Pastagames, Mārtiņš Možeiko, Daniel Collin, Recognition Robotics, Chris Genova, ikrima, Glenn Fiedler, Geoffrey Evans, Dakko Dakko, Mercury Labs, Singularity Demo Group, Mischa Alff, Sebastien Ronsse, Lionel Landwerlin, Nikolay Ivanov, Ron Gilbert, Brandon Townsend, Nikhil Deshpande, Cort Stratton, drudru, Harfang 3D, Jeff Roberts.

View File

@ -320,7 +320,7 @@ void ImGui_ImplOpenGL3_DestroyFontsTexture()
} }
} }
// If you get an error please report on github. You may try different GL context version or GLSL version. // If you get an error please report on github. You may try different GL context version or GLSL version. See GL<>GLSL version table at the top of this file.
static bool CheckShader(GLuint handle, const char* desc) static bool CheckShader(GLuint handle, const char* desc)
{ {
GLint status = 0, log_length = 0; GLint status = 0, log_length = 0;
@ -338,14 +338,14 @@ static bool CheckShader(GLuint handle, const char* desc)
return (GLboolean)status == GL_TRUE; return (GLboolean)status == GL_TRUE;
} }
// If you get an error please report on github. You may try different GL context version or GLSL version. // If you get an error please report on GitHub. You may try different GL context version or GLSL version.
static bool CheckProgram(GLuint handle, const char* desc) static bool CheckProgram(GLuint handle, const char* desc)
{ {
GLint status = 0, log_length = 0; GLint status = 0, log_length = 0;
glGetProgramiv(handle, GL_LINK_STATUS, &status); glGetProgramiv(handle, GL_LINK_STATUS, &status);
glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length); glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length);
if ((GLboolean)status == GL_FALSE) if ((GLboolean)status == GL_FALSE)
fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s!\n", desc); fprintf(stderr, "ERROR: ImGui_ImplOpenGL3_CreateDeviceObjects: failed to link %s! (with GLSL '%s')\n", desc, g_GlslVersionString);
if (log_length > 0) if (log_length > 0)
{ {
ImVector<char> buf; ImVector<char> buf;

View File

@ -130,13 +130,15 @@ CODE
- Read the FAQ below this section! - Read the FAQ below this section!
- Your code creates the UI, if your code doesn't run the UI is gone! The UI can be highly dynamic, there are no construction - Your code creates the UI, if your code doesn't run the UI is gone! The UI can be highly dynamic, there are no construction
or destruction steps, less data retention on your side, less state duplication, less state synchronization, less bugs. or destruction steps, less superfluous data retention on your side, less state duplication, less state synchronization, less bugs.
- Call and read ImGui::ShowDemoWindow() for demo code demonstrating most features. - Call and read ImGui::ShowDemoWindow() for demo code demonstrating most features.
- You can learn about immediate-mode gui principles at http://www.johno.se/book/imgui.html or watch http://mollyrocket.com/861 - You can learn about immediate-mode GUI principles at http://www.johno.se/book/imgui.html or watch http://mollyrocket.com/861
See README.md for more links describing the IMGUI paradigm. Dear ImGui is an implementation of the IMGUI paradigm.
HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI HOW TO UPDATE TO A NEWER VERSION OF DEAR IMGUI
- Overwrite all the sources files except for imconfig.h (if you have made modification to your copy of imconfig.h) - Overwrite all the sources files except for imconfig.h (if you have made modification to your copy of imconfig.h)
- Or maintain your own branch where you have imconfig.h modified.
- Read the "API BREAKING CHANGES" section (below). This is where we list occasional API breaking changes. - Read the "API BREAKING CHANGES" section (below). This is where we list occasional API breaking changes.
If a function/type has been renamed / or marked obsolete, try to fix the name in your code before it is permanently removed If a function/type has been renamed / or marked obsolete, try to fix the name in your code before it is permanently removed
from the public API. If you have a problem with a missing function/symbols, search for its name in the code, there will from the public API. If you have a problem with a missing function/symbols, search for its name in the code, there will
@ -145,24 +147,24 @@ CODE
GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE GETTING STARTED WITH INTEGRATING DEAR IMGUI IN YOUR CODE/ENGINE
- Run and study the examples and demo to get acquainted with the library. - Run and study the examples and demo in imgui_demo.cpp to get acquainted with the library.
- Add the Dear ImGui source files to your projects or using your preferred build system. - Add the Dear ImGui source files to your projects or using your preferred build system.
It is recommended you build the .cpp files as part of your project and not as a library. It is recommended you build and statically link the .cpp files as part of your project and not as shared library (DLL).
- You can later customize the imconfig.h file to tweak some compilation time behavior, such as integrating imgui types with your own maths types. - You can later customize the imconfig.h file to tweak some compile-time behavior, such as integrating imgui types with your own maths types.
- You may be able to grab and copy a ready made imgui_impl_*** file from the examples/ folder.
- When using Dear ImGui, your programming IDE is your friend: follow the declaration of variables, functions and types to find comments about them. - When using Dear ImGui, your programming IDE is your friend: follow the declaration of variables, functions and types to find comments about them.
- Dear ImGui never touches or knows about your GPU state. The only function that knows about GPU is the draw function that you provide. - Dear ImGui never touches or knows about your GPU state. The only function that knows about GPU is the draw function that you provide.
Effectively it means you can create widgets at any time in your code, regardless of considerations of being in "update" vs "render" Effectively it means you can create widgets at any time in your code, regardless of considerations of being in "update" vs "render"
phases of your own application. All rendering informatioe are stored into command-lists that you will retrieve after calling ImGui::Render(). phases of your own application. All rendering informatioe are stored into command-lists that you will retrieve after calling ImGui::Render().
- Refer to the bindings and demo applications in the examples/ folder for instruction on how to setup your code. - Refer to the bindings and demo applications in the examples/ folder for instruction on how to setup your code.
- If you are running over a standard OS with a common graphics API, you should be able to use unmodified imgui_impl_*** files from the examples/ folder.
THIS IS HOW A SIMPLE APPLICATION MAY LOOK LIKE HOW A SIMPLE APPLICATION MAY LOOK LIKE
EXHIBIT 1: USING THE EXAMPLE BINDINGS (imgui_impl_XXX.cpp files from the examples/ folder) EXHIBIT 1: USING THE EXAMPLE BINDINGS (imgui_impl_XXX.cpp files from the examples/ folder)
// Application init: create a dear imgui context, setup some options, load fonts // Application init: create a dear imgui context, setup some options, load fonts
ImGui::CreateContext(); ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
// TODO: Set optional io.ConfigFlags values, e.g. 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard' to enable keyboard controls // TODO: Set optional io.ConfigFlags values, e.g. 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard' to enable keyboard controls.
// TODO: Fill optional fields of the io structure later. // TODO: Fill optional fields of the io structure later.
// TODO: Load TTF/OTF fonts if you don't want to use the default font. // TODO: Load TTF/OTF fonts if you don't want to use the default font.
@ -192,13 +194,13 @@ CODE
ImGui_ImplWin32_Shutdown(); ImGui_ImplWin32_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();
THIS IS HOW A SIMPLE APPLICATION MAY LOOK LIKE HOW A SIMPLE APPLICATION MAY LOOK LIKE
EXHIBIT 2: IMPLEMENTING CUSTOM BINDING / CUSTOM ENGINE EXHIBIT 2: IMPLEMENTING CUSTOM BINDING / CUSTOM ENGINE
// Application init: create a dear imgui context, setup some options, load fonts // Application init: create a dear imgui context, setup some options, load fonts
ImGui::CreateContext(); ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
// TODO: Set optional io.ConfigFlags values, e.g. 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard' to enable keyboard controls // TODO: Set optional io.ConfigFlags values, e.g. 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard' to enable keyboard controls.
// TODO: Fill optional fields of the io structure later. // TODO: Fill optional fields of the io structure later.
// TODO: Load TTF/OTF fonts if you don't want to use the default font. // TODO: Load TTF/OTF fonts if you don't want to use the default font.
@ -247,7 +249,7 @@ CODE
// Shutdown // Shutdown
ImGui::DestroyContext(); ImGui::DestroyContext();
THIS HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE HOW A SIMPLE RENDERING FUNCTION MAY LOOK LIKE
void void MyImGuiRenderFunction(ImDrawData* draw_data) void void MyImGuiRenderFunction(ImDrawData* draw_data)
{ {
@ -269,22 +271,22 @@ CODE
else else
{ {
// The texture for the draw call is specified by pcmd->TextureId. // The texture for the draw call is specified by pcmd->TextureId.
// The vast majority of draw calls with use the imgui texture atlas, which value you have set yourself during initialization. // The vast majority of draw calls will use the imgui texture atlas, which value you have set yourself during initialization.
MyEngineBindTexture(pcmd->TextureId); MyEngineBindTexture((MyTexture*)pcmd->TextureId);
// We are using scissoring to clip some objects. All low-level graphics API should supports it. // We are using scissoring to clip some objects. All low-level graphics API should supports it.
// - If your engine doesn't support scissoring yet, you may ignore this at first. You will get some small glitches // - If your engine doesn't support scissoring yet, you may ignore this at first. You will get some small glitches
// (some elements visible outside their bounds) but you can fix that once everywhere else works! // (some elements visible outside their bounds) but you can fix that once everything else works!
// - Clipping coordinates are provided in imgui coordinates space (from draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize) // - Clipping coordinates are provided in imgui coordinates space (from draw_data->DisplayPos to draw_data->DisplayPos + draw_data->DisplaySize)
// In a single viewport application, draw_data->DisplayPos will always be (0,0) and draw_data->DisplaySize will always be == io.DisplaySize. // In a single viewport application, draw_data->DisplayPos will always be (0,0) and draw_data->DisplaySize will always be == io.DisplaySize.
// However, in the interest of supporting multi-viewport applications in the future, always subtract draw_data->DisplayPos from // However, in the interest of supporting multi-viewport applications in the future (see 'viewport' branch on github),
// clipping bounds to convert them to your viewport space. // always subtract draw_data->DisplayPos from clipping bounds to convert them to your viewport space.
// - Note that pcmd->ClipRect contains Min+Max bounds. Some graphics API may use Min+Max, other may use Min+Size (size being Max-Min) // - Note that pcmd->ClipRect contains Min+Max bounds. Some graphics API may use Min+Max, other may use Min+Size (size being Max-Min)
ImVec2 pos = draw_data->DisplayPos; ImVec2 pos = draw_data->DisplayPos;
MyEngineScissor((int)(pcmd->ClipRect.x - pos.x), (int)(pcmd->ClipRect.y - pos.y), (int)(pcmd->ClipRect.z - pos.x), (int)(pcmd->ClipRect.w - pos.y)); MyEngineScissor((int)(pcmd->ClipRect.x - pos.x), (int)(pcmd->ClipRect.y - pos.y), (int)(pcmd->ClipRect.z - pos.x), (int)(pcmd->ClipRect.w - pos.y));
// Render 'pcmd->ElemCount/3' indexed triangles. // Render 'pcmd->ElemCount/3' indexed triangles.
// By default the indices ImDrawIdx are 16-bits, you can change them to 32-bits if your engine doesn't support 16-bits indices. // By default the indices ImDrawIdx are 16-bits, you can change them to 32-bits in imconfig.h if your engine doesn't support 16-bits indices.
MyEngineDrawIndexedTriangles(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer, vtx_buffer); MyEngineDrawIndexedTriangles(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer, vtx_buffer);
} }
idx_buffer += pcmd->ElemCount; idx_buffer += pcmd->ElemCount;
@ -292,15 +294,16 @@ CODE
} }
} }
- The examples/ folders contains many functional implementation of the pseudo-code above. - The examples/ folders contains many actual implementation of the pseudo-codes above.
- When calling NewFrame(), the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags are updated. - When calling NewFrame(), the 'io.WantCaptureMouse', 'io.WantCaptureKeyboard' and 'io.WantTextInput' flags are updated.
They tell you if ImGui intends to use your inputs. When a flag is set you want to hide the corresponding inputs from the rest of your application. They tell you if Dear ImGui intends to use your inputs. When a flag is set you want to hide the corresponding inputs
In both cases you need to pass on the inputs to imgui. Read the FAQ below for more information about those flags. from the rest of your application. In every cases you need to pass on the inputs to imgui. Refer to the FAQ for more information.
- Please read the FAQ above. Amusingly, it is called a FAQ because people frequently have the same issues! - Please read the FAQ below!. Amusingly, it is called a FAQ because people frequently run into the same issues!
USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS USING GAMEPAD/KEYBOARD NAVIGATION CONTROLS
- The gamepad/keyboard navigation is fairly functional and keeps being improved. - The gamepad/keyboard navigation is fairly functional and keeps being improved.
- Gamepad support is particularly useful to use dear imgui on a console system (e.g. PS4, Switch, XB1) without a mouse!
- You can ask questions and report issues at https://github.com/ocornut/imgui/issues/787 - You can ask questions and report issues at https://github.com/ocornut/imgui/issues/787
- The initial focus was to support game controllers, but keyboard is becoming increasingly and decently usable. - The initial focus was to support game controllers, but keyboard is becoming increasingly and decently usable.
- Gamepad: - Gamepad:
@ -536,7 +539,7 @@ CODE
- When 'io.WantCaptureKeyboard' is set, imgui wants to use your keyboard state, and you may want to discard/hide the inputs from the rest of your application. - When 'io.WantCaptureKeyboard' is set, imgui wants to use your keyboard state, and you may want to discard/hide the inputs from the rest of your application.
- When 'io.WantTextInput' is set to may want to notify your OS to popup an on-screen keyboard, if available (e.g. on a mobile phone, or console OS). - When 'io.WantTextInput' is set to may want to notify your OS to popup an on-screen keyboard, if available (e.g. on a mobile phone, or console OS).
Note: you should always pass your mouse/keyboard inputs to imgui, even when the io.WantCaptureXXX flag are set false. Note: you should always pass your mouse/keyboard inputs to imgui, even when the io.WantCaptureXXX flag are set false.
This is because imgui needs to detect that you clicked in the void to unfocus its windows. This is because imgui needs to detect that you clicked in the void to unfocus its own windows.
Note: The 'io.WantCaptureMouse' is more accurate that any attempt to "check if the mouse is hovering a window" (don't do that!). Note: The 'io.WantCaptureMouse' is more accurate that any attempt to "check if the mouse is hovering a window" (don't do that!).
It handle mouse dragging correctly (both dragging that started over your application or over an imgui window) and handle e.g. modal windows blocking inputs. It handle mouse dragging correctly (both dragging that started over your application or over an imgui window) and handle e.g. modal windows blocking inputs.
Those flags are updated by ImGui::NewFrame(). Preferably read the flags after calling NewFrame() if you can afford it, but reading them before is also Those flags are updated by ImGui::NewFrame(). Preferably read the flags after calling NewFrame() if you can afford it, but reading them before is also
@ -548,7 +551,7 @@ CODE
Q: How can I display an image? What is ImTextureID, how does it works? Q: How can I display an image? What is ImTextureID, how does it works?
A: Short explanation: A: Short explanation:
- You may use functions such as ImGui::Image(), ImGui::ImageButton() or lower-level ImDrawList::AddImage() to emit draw calls that will use your own textures. - You may use functions such as ImGui::Image(), ImGui::ImageButton() or lower-level ImDrawList::AddImage() to emit draw calls that will use your own textures.
- Actual textures are identified in a way that is up to the user/engine. - Actual textures are identified in a way that is up to the user/engine. Those identifiers are stored and passed as ImTextureID (void*) value.
- Loading image files from the disk and turning them into a texture is not within the scope of Dear ImGui (for a good reason). - Loading image files from the disk and turning them into a texture is not within the scope of Dear ImGui (for a good reason).
Please read documentations or tutorials on your graphics API to understand how to display textures on the screen before moving onward. Please read documentations or tutorials on your graphics API to understand how to display textures on the screen before moving onward.
@ -607,6 +610,8 @@ CODE
GLuint my_opengl_texture; GLuint my_opengl_texture;
glGenTextures(1, &my_opengl_texture); glGenTextures(1, &my_opengl_texture);
glBindTexture(GL_TEXTURE_2D, my_opengl_texture); glBindTexture(GL_TEXTURE_2D, my_opengl_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width, image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image_width, image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);
@ -673,7 +678,7 @@ CODE
- If you want to completely hide the label, but still need an ID: - If you want to completely hide the label, but still need an ID:
Checkbox("##On", &b); // Label = "", ID = hash of (..., "##On") // No visible label! Checkbox("##On", &b); // Label = "", ID = hash of (..., "##On") // No visible label, just a checkbox!
- Occasionally/rarely you might want change a label while preserving a constant ID. This allows - Occasionally/rarely you might want change a label while preserving a constant ID. This allows
you to animate labels. For example you may want to include varying information in a window title bar, you to animate labels. For example you may want to include varying information in a window title bar,
@ -683,7 +688,7 @@ CODE
Button("World###ID"; // Label = "World", ID = hash of (..., "ID") // Same as above, even though the label looks different Button("World###ID"; // Label = "World", ID = hash of (..., "ID") // Same as above, even though the label looks different
sprintf(buf, "My game (%f FPS)###MyGame", fps); sprintf(buf, "My game (%f FPS)###MyGame", fps);
Begin(buf); // Variable label, ID = hash of "MyGame" Begin(buf); // Variable title, ID = hash of "MyGame"
- Solving ID conflict in a more general manner: - Solving ID conflict in a more general manner:
Use PushID() / PopID() to create scopes and manipulate the ID stack, as to avoid ID conflicts Use PushID() / PopID() to create scopes and manipulate the ID stack, as to avoid ID conflicts
@ -750,7 +755,8 @@ CODE
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels); io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8() io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
(default is ProggyClean.ttf, rendered at size 13, embedded in dear imgui's source code) Default is ProggyClean.ttf, rendered at size 13, embedded in dear imgui's source code.
(Read the 'misc/fonts/README.txt' file for more details about font loading.)
New programmers: remember that in C/C++ and most programming languages if you want to use a New programmers: remember that in C/C++ and most programming languages if you want to use a
backslash \ within a string literal, you need to write it double backslash "\\": backslash \ within a string literal, you need to write it double backslash "\\":
@ -760,12 +766,12 @@ CODE
Q: How can I easily use icons in my application? Q: How can I easily use icons in my application?
A: The most convenient and practical way is to merge an icon font such as FontAwesome inside you A: The most convenient and practical way is to merge an icon font such as FontAwesome inside you
main font. Then you can refer to icons within your strings. Read 'How can I load multiple fonts?' main font. Then you can refer to icons within your strings.
and the file 'misc/fonts/README.txt' for instructions and useful header files. (Read the 'misc/fonts/README.txt' file for more details about icons font loading.)
Q: How can I load multiple fonts? Q: How can I load multiple fonts?
A: Use the font atlas to pack them into a single texture: A: Use the font atlas to pack them into a single texture:
(Read misc/fonts/README.txt and the code in ImFontAtlas for more details.) (Read the 'misc/fonts/README.txt' file and the code in ImFontAtlas for more details.)
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
ImFont* font0 = io.Fonts->AddFontDefault(); ImFont* font0 = io.Fonts->AddFontDefault();
@ -784,7 +790,7 @@ CODE
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, &config); io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, &config);
// Combine multiple fonts into one (e.g. for icon fonts) // Combine multiple fonts into one (e.g. for icon fonts)
ImWchar ranges[] = { 0xf000, 0xf3ff, 0 }; static ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
ImFontConfig config; ImFontConfig config;
config.MergeMode = true; config.MergeMode = true;
io.Fonts->AddFontDefault(); io.Fonts->AddFontDefault();
@ -819,10 +825,12 @@ CODE
the default implementation of io.ImeSetInputScreenPosFn() to set your Microsoft IME position correctly. the default implementation of io.ImeSetInputScreenPosFn() to set your Microsoft IME position correctly.
Q: How can I use the drawing facilities without an ImGui window? (using ImDrawList API) Q: How can I use the drawing facilities without an ImGui window? (using ImDrawList API)
A: - You can create a dummy window. Call SetNextWindowBgAlpha(0.0f), call Begin() with NoTitleBar|NoResize|NoMove|NoScrollbar|NoSavedSettings|NoInputs flags. A: - You can create a dummy window. Call Begin() with the NoBackground | NoDecoration | NoSavedSettings | NoInputs flags.
(The ImGuiWindowFlags_NoDecoration flag itself is a shortcut for NoTitleBar | NoResize | NoScrollbar | NoCollapse)
Then you can retrieve the ImDrawList* via GetWindowDrawList() and draw to it in any way you like. Then you can retrieve the ImDrawList* via GetWindowDrawList() and draw to it in any way you like.
- You can call ImGui::GetOverlayDrawList() and use this draw list to display contents over every other imgui windows (1 overlay per viewport). - You can call ImGui::GetOverlayDrawList() and use this draw list to display contents over every other imgui windows (1 overlay per viewport).
- You can create your own ImDrawList instance. You'll need to initialize them ImGui::GetDrawListSharedData(), or create your own ImDrawListSharedData. - You can create your own ImDrawList instance. You'll need to initialize them ImGui::GetDrawListSharedData(), or create your own ImDrawListSharedData,
and then call your rendered code with your own ImDrawList or ImDrawData data.
Q: I integrated Dear ImGui in my engine and the text or lines are blurry.. Q: I integrated Dear ImGui in my engine and the text or lines are blurry..
A: In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f). A: In your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f).
@ -834,7 +842,7 @@ CODE
Q: How can I help? Q: How can I help?
A: - If you are experienced with Dear ImGui and C++, look at the github issues, or docs/TODO.txt and see how you want/can help! A: - If you are experienced with Dear ImGui and C++, look at the github issues, or docs/TODO.txt and see how you want/can help!
- Convince your company to fund development time! Individual users: you can also become a Patron (patreon.com/imgui) or donate on PayPal! See README. - Convince your company to sponsor/fund development! Individual users: you can also become a Patron (patreon.com/imgui) or donate on PayPal! See README.
- Disclose your usage of dear imgui via a dev blog post, a tweet, a screenshot, a mention somewhere etc. - Disclose your usage of dear imgui via a dev blog post, a tweet, a screenshot, a mention somewhere etc.
You may post screenshot or links in the gallery threads (github.com/ocornut/imgui/issues/1269). Visuals are ideal as they inspire other programmers. You may post screenshot or links in the gallery threads (github.com/ocornut/imgui/issues/1269). Visuals are ideal as they inspire other programmers.
But even without visuals, disclosing your use of dear imgui help the library grow credibility, and help other teams and programmers with taking decisions. But even without visuals, disclosing your use of dear imgui help the library grow credibility, and help other teams and programmers with taking decisions.
@ -981,7 +989,7 @@ extern void ImGuiTestEngineHook_ItemAdd(const ImRect& bb, ImGuiID id
// [SECTION] CONTEXT AND MEMORY ALLOCATORS // [SECTION] CONTEXT AND MEMORY ALLOCATORS
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Current context pointer. Implicitly used by all ImGui functions. Always assumed to be != NULL. // Current context pointer. Implicitly used by all Dear ImGui functions. Always assumed to be != NULL.
// CreateContext() will automatically set this pointer if it is NULL. Change to a different context by calling ImGui::SetCurrentContext(). // CreateContext() will automatically set this pointer if it is NULL. Change to a different context by calling ImGui::SetCurrentContext().
// If you use DLL hotreloading you might need to call SetCurrentContext() after reloading code from this file. // If you use DLL hotreloading you might need to call SetCurrentContext() after reloading code from this file.
// ImGui functions are not thread-safe because of this pointer. If you want thread-safety to allow N threads to access N different contexts, you can: // ImGui functions are not thread-safe because of this pointer. If you want thread-safety to allow N threads to access N different contexts, you can:
@ -2534,7 +2542,7 @@ void ImGui::SetHoveredID(ImGuiID id)
g.HoveredId = id; g.HoveredId = id;
g.HoveredIdAllowOverlap = false; g.HoveredIdAllowOverlap = false;
if (id != 0 && g.HoveredIdPreviousFrame != id) if (id != 0 && g.HoveredIdPreviousFrame != id)
g.HoveredIdTimer = 0.0f; g.HoveredIdTimer = g.HoveredIdNotActiveTimer = 0.0f;
} }
ImGuiID ImGui::GetHoveredID() ImGuiID ImGui::GetHoveredID()
@ -3324,8 +3332,12 @@ void ImGui::NewFrame()
// Clear reference to active widget if the widget isn't alive anymore // Clear reference to active widget if the widget isn't alive anymore
if (!g.HoveredIdPreviousFrame) if (!g.HoveredIdPreviousFrame)
g.HoveredIdTimer = 0.0f; g.HoveredIdTimer = 0.0f;
if (!g.HoveredIdPreviousFrame || (g.HoveredId && g.ActiveId == g.HoveredId))
g.HoveredIdNotActiveTimer = 0.0f;
if (g.HoveredId) if (g.HoveredId)
g.HoveredIdTimer += g.IO.DeltaTime; g.HoveredIdTimer += g.IO.DeltaTime;
if (g.HoveredId && g.ActiveId != g.HoveredId)
g.HoveredIdNotActiveTimer += g.IO.DeltaTime;
g.HoveredIdPreviousFrame = g.HoveredId; g.HoveredIdPreviousFrame = g.HoveredId;
g.HoveredId = 0; g.HoveredId = 0;
g.HoveredIdAllowOverlap = false; g.HoveredIdAllowOverlap = false;

View File

@ -389,7 +389,7 @@ namespace ImGui
IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* format = "%.3f", float power = 1.0f); IMGUI_API bool SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* format = "%.3f", float power = 1.0f); IMGUI_API bool SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* format = "%.3f", float power = 1.0f); IMGUI_API bool SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* format = "%.3f", float power = 1.0f);
IMGUI_API bool SliderAngle(const char* label, float* v_rad, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f); IMGUI_API bool SliderAngle(const char* label, float* v_rad, float v_degrees_min = -360.0f, float v_degrees_max = +360.0f, const char* format = "%.0f deg");
IMGUI_API bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* format = "%d"); IMGUI_API bool SliderInt(const char* label, int* v, int v_min, int v_max, const char* format = "%d");
IMGUI_API bool SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* format = "%d"); IMGUI_API bool SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* format = "%d");
IMGUI_API bool SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* format = "%d"); IMGUI_API bool SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* format = "%d");
@ -498,7 +498,7 @@ namespace ImGui
IMGUI_API void CloseCurrentPopup(); // close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup. IMGUI_API void CloseCurrentPopup(); // close the popup we have begin-ed into. clicking on a MenuItem or Selectable automatically close the current popup.
// Columns // Columns
// You can also use SameLine(pos_x) for simplified columns. The columns API is still work-in-progress and rather lacking. // You can also use SameLine(pos_x) for simplified columns. The columns API is work-in-progress and rather lacking (columns are arguably the worst part of dear imgui at the moment!)
IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true); IMGUI_API void Columns(int count = 1, const char* id = NULL, bool border = true);
IMGUI_API void NextColumn(); // next column, defaults to current row or next row if the current row is finished IMGUI_API void NextColumn(); // next column, defaults to current row or next row if the current row is finished
IMGUI_API int GetColumnIndex(); // get current column index IMGUI_API int GetColumnIndex(); // get current column index

View File

@ -1,22 +1,25 @@
// dear imgui, v1.66 WIP // dear imgui, v1.66 WIP
// (demo code) // (demo code)
// Message to the person tempted to delete this file when integrating ImGui into their code base: // Message to the person tempted to delete this file when integrating Dear ImGui into their code base:
// Don't do it! Do NOT remove this file from your project! It is useful reference code that you and other users will want to refer to. // Do NOT remove this file from your project! Think again! It is the most useful reference code that you and other coders
// will want to refer to and call. Have the ImGui::ShowDemoWindow() function wired in an always-available debug menu of
// your game/app! Removing this file from your project is hindering access to documentation for everyone in your team,
// likely leading you to poorer usage of the library.
// Everything in this file will be stripped out by the linker if you don't call ImGui::ShowDemoWindow(). // Everything in this file will be stripped out by the linker if you don't call ImGui::ShowDemoWindow().
// During development, you can call ImGui::ShowDemoWindow() in your code to learn about various features of ImGui. Have it wired in a debug menu! // If you want to link core Dear ImGui in your shipped builds but want an easy guarantee that the demo will not be linked,
// Removing this file from your project is hindering access to documentation for everyone in your team, likely leading you to poorer usage of the library. // you can setup your imconfig.h with #define IMGUI_DISABLE_DEMO_WINDOWS and those functions will be empty.
// Note that you can #define IMGUI_DISABLE_DEMO_WINDOWS in imconfig.h for the same effect. // In other situation, whenever you have Dear ImGui available you probably want this to be available for reference.
// If you want to link core ImGui in your final builds but not those demo windows, #define IMGUI_DISABLE_DEMO_WINDOWS in imconfig.h and those functions will be empty.
// In other situation, when you have ImGui available you probably want this to be available for reference and execution.
// Thank you, // Thank you,
// -Your beloved friend, imgui_demo.cpp (that you won't delete) // -Your beloved friend, imgui_demo.cpp (that you won't delete)
// Message to beginner C/C++ programmers about the meaning of the 'static' keyword: in this demo code, we frequently we use 'static' variables inside functions. // Message to beginner C/C++ programmers about the meaning of the 'static' keyword:
// A static variable persist across calls, so it is essentially like a global variable but declared inside the scope of the function. // In this demo code, we frequently we use 'static' variables inside functions. A static variable persist across calls, so it is
// We do this as a way to gather code and data in the same place, just to make the demo code faster to read, faster to write, and use less code. // essentially like a global variable but declared inside the scope of the function. We do this as a way to gather code and data
// It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be reentrant or used in threads. // in the same place, to make the demo source code faster to read, faster to write, and smaller in size.
// This might be a pattern you occasionally want to use in your code, but most of the real data you would be editing is likely to be stored outside your functions. // It also happens to be a convenient way of storing simple UI related information as long as your function doesn't need to be reentrant
// or used in threads. This might be a pattern you will want to use in your code, but most of the real data you would be editing is
// likely going to be stored outside your functions.
/* /*
@ -152,6 +155,13 @@ void ImGui::ShowUserGuide()
// [SECTION] Demo Window / ShowDemoWindow() // [SECTION] Demo Window / ShowDemoWindow()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// We split the contents of the big ShowDemoWindow() function into smaller functions (because the link time of very large functions grow non-linearly)
static void ShowDemoWindowWidgets();
static void ShowDemoWindowLayout();
static void ShowDemoWindowPopups();
static void ShowDemoWindowColumns();
static void ShowDemoWindowMisc();
// Demonstrate most Dear ImGui features (this is big function!) // Demonstrate most Dear ImGui features (this is big function!)
// You may execute this function to experiment with the UI and understand what it does. You may then search for keywords in the code when you are interested by a specific feature. // You may execute this function to experiment with the UI and understand what it does. You may then search for keywords in the code when you are interested by a specific feature.
void ImGui::ShowDemoWindow(bool* p_open) void ImGui::ShowDemoWindow(bool* p_open)
@ -380,8 +390,22 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::Checkbox("No bring to front", &no_bring_to_front); ImGui::Checkbox("No bring to front", &no_bring_to_front);
} }
if (ImGui::CollapsingHeader("Widgets")) // All demo contents
{ ShowDemoWindowWidgets();
ShowDemoWindowLayout();
ShowDemoWindowPopups();
ShowDemoWindowColumns();
ShowDemoWindowMisc();
// End of ShowDemoWindow()
ImGui::End();
}
static void ShowDemoWindowWidgets()
{
if (!ImGui::CollapsingHeader("Widgets"))
return;
if (ImGui::TreeNode("Basic")) if (ImGui::TreeNode("Basic"))
{ {
static int clicked = 0; static int clicked = 0;
@ -610,13 +634,13 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::Checkbox("Enable extra group", &closable_group); ImGui::Checkbox("Enable extra group", &closable_group);
if (ImGui::CollapsingHeader("Header")) if (ImGui::CollapsingHeader("Header"))
{ {
ImGui::Text("IsItemHovered: %d", IsItemHovered()); ImGui::Text("IsItemHovered: %d", ImGui::IsItemHovered());
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
ImGui::Text("Some content %d", i); ImGui::Text("Some content %d", i);
} }
if (ImGui::CollapsingHeader("Header with a close button", &closable_group)) if (ImGui::CollapsingHeader("Header with a close button", &closable_group))
{ {
ImGui::Text("IsItemHovered: %d", IsItemHovered()); ImGui::Text("IsItemHovered: %d", ImGui::IsItemHovered());
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
ImGui::Text("More content %d", i); ImGui::Text("More content %d", i);
} }
@ -1058,11 +1082,11 @@ void ImGui::ShowDemoWindow(bool* p_open)
if (ImGui::BeginDragDropTarget()) if (ImGui::BeginDragDropTarget())
{ {
if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F)) if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_3F))
memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 3); memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 3);
if (const ImGuiPayload* payload = AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F)) if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload(IMGUI_PAYLOAD_TYPE_COLOR_4F))
memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 4); memcpy((float*)&saved_palette[n], payload->Data, sizeof(float) * 4);
EndDragDropTarget(); ImGui::EndDragDropTarget();
} }
ImGui::PopID(); ImGui::PopID();
@ -1478,7 +1502,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::Text("This is another child window for testing with the _ChildWindows flag."); ImGui::Text("This is another child window for testing with the _ChildWindows flag.");
ImGui::EndChild(); ImGui::EndChild();
if (embed_all_inside_a_child_window) if (embed_all_inside_a_child_window)
EndChild(); ImGui::EndChild();
// Calling IsItemHovered() after begin returns the hovered status of the title bar. // Calling IsItemHovered() after begin returns the hovered status of the title bar.
// This is useful in particular if you want to create a context menu (with BeginPopupContextItem) associated to the title bar of a window. // This is useful in particular if you want to create a context menu (with BeginPopupContextItem) associated to the title bar of a window.
@ -1501,10 +1525,13 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::TreePop(); ImGui::TreePop();
} }
} }
static void ShowDemoWindowLayout()
{
if (!ImGui::CollapsingHeader("Layout"))
return;
if (ImGui::CollapsingHeader("Layout"))
{
if (ImGui::TreeNode("Child regions")) if (ImGui::TreeNode("Child regions"))
{ {
static bool disable_mouse_wheel = false; static bool disable_mouse_wheel = false;
@ -1538,7 +1565,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
// Child 2: rounded border // Child 2: rounded border
{ {
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f); ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 5.0f);
ImGui::BeginChild("Child2", ImVec2(0,300), true, (disable_mouse_wheel ? ImGuiWindowFlags_NoScrollWithMouse : 0) | (disable_menu ? 0 : ImGuiWindowFlags_MenuBar)); ImGui::BeginChild("Child2", ImVec2(0, 300), true, (disable_mouse_wheel ? ImGuiWindowFlags_NoScrollWithMouse : 0) | (disable_menu ? 0 : ImGuiWindowFlags_MenuBar));
if (!disable_menu && ImGui::BeginMenuBar()) if (!disable_menu && ImGui::BeginMenuBar())
{ {
if (ImGui::BeginMenu("Menu")) if (ImGui::BeginMenu("Menu"))
@ -1632,21 +1659,21 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::SameLine(300); ImGui::SmallButton("x=300"); ImGui::SameLine(300); ImGui::SmallButton("x=300");
// Checkbox // Checkbox
static bool c1=false,c2=false,c3=false,c4=false; static bool c1 = false, c2 = false, c3 = false, c4 = false;
ImGui::Checkbox("My", &c1); ImGui::SameLine(); ImGui::Checkbox("My", &c1); ImGui::SameLine();
ImGui::Checkbox("Tailor", &c2); ImGui::SameLine(); ImGui::Checkbox("Tailor", &c2); ImGui::SameLine();
ImGui::Checkbox("Is", &c3); ImGui::SameLine(); ImGui::Checkbox("Is", &c3); ImGui::SameLine();
ImGui::Checkbox("Rich", &c4); ImGui::Checkbox("Rich", &c4);
// Various // Various
static float f0=1.0f, f1=2.0f, f2=3.0f; static float f0 = 1.0f, f1 = 2.0f, f2 = 3.0f;
ImGui::PushItemWidth(80); ImGui::PushItemWidth(80);
const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD" }; const char* items[] = { "AAAA", "BBBB", "CCCC", "DDDD" };
static int item = -1; static int item = -1;
ImGui::Combo("Combo", &item, items, IM_ARRAYSIZE(items)); ImGui::SameLine(); ImGui::Combo("Combo", &item, items, IM_ARRAYSIZE(items)); ImGui::SameLine();
ImGui::SliderFloat("X", &f0, 0.0f,5.0f); ImGui::SameLine(); ImGui::SliderFloat("X", &f0, 0.0f, 5.0f); ImGui::SameLine();
ImGui::SliderFloat("Y", &f1, 0.0f,5.0f); ImGui::SameLine(); ImGui::SliderFloat("Y", &f1, 0.0f, 5.0f); ImGui::SameLine();
ImGui::SliderFloat("Z", &f2, 0.0f,5.0f); ImGui::SliderFloat("Z", &f2, 0.0f, 5.0f);
ImGui::PopItemWidth(); ImGui::PopItemWidth();
ImGui::PushItemWidth(80); ImGui::PushItemWidth(80);
@ -1663,7 +1690,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::PopItemWidth(); ImGui::PopItemWidth();
// Dummy // Dummy
ImVec2 button_sz(40,40); ImVec2 button_sz(40, 40);
ImGui::Button("A", button_sz); ImGui::SameLine(); ImGui::Button("A", button_sz); ImGui::SameLine();
ImGui::Dummy(button_sz); ImGui::SameLine(); ImGui::Dummy(button_sz); ImGui::SameLine();
ImGui::Button("B", button_sz); ImGui::Button("B", button_sz);
@ -1712,9 +1739,9 @@ void ImGui::ShowDemoWindow(bool* p_open)
const float values[5] = { 0.5f, 0.20f, 0.80f, 0.60f, 0.25f }; const float values[5] = { 0.5f, 0.20f, 0.80f, 0.60f, 0.25f };
ImGui::PlotHistogram("##values", values, IM_ARRAYSIZE(values), 0, NULL, 0.0f, 1.0f, size); ImGui::PlotHistogram("##values", values, IM_ARRAYSIZE(values), 0, NULL, 0.0f, 1.0f, size);
ImGui::Button("ACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y)); ImGui::Button("ACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f, size.y));
ImGui::SameLine(); ImGui::SameLine();
ImGui::Button("REACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f,size.y)); ImGui::Button("REACTION", ImVec2((size.x - ImGui::GetStyle().ItemSpacing.x)*0.5f, size.y));
ImGui::EndGroup(); ImGui::EndGroup();
ImGui::SameLine(); ImGui::SameLine();
@ -1811,7 +1838,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
{ {
if (track && line == track_line) if (track && line == track_line)
{ {
ImGui::TextColored(ImColor(255,255,0), "Line %d", line); ImGui::TextColored(ImVec4(1,1,0,1), "Line %d", line);
ImGui::SetScrollHereY(i * 0.25f); // 0.0f:top, 0.5f:center, 1.0f:bottom ImGui::SetScrollHereY(i * 0.25f); // 0.0f:top, 0.5f:center, 1.0f:bottom
} }
else else
@ -1835,7 +1862,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::SliderInt("Lines", &lines, 1, 15); ImGui::SliderInt("Lines", &lines, 1, 15);
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f); ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2.0f, 1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(2.0f, 1.0f));
ImGui::BeginChild("scrolling", ImVec2(0, ImGui::GetFrameHeightWithSpacing()*7 + 30), true, ImGuiWindowFlags_HorizontalScrollbar); ImGui::BeginChild("scrolling", ImVec2(0, ImGui::GetFrameHeightWithSpacing() * 7 + 30), true, ImGuiWindowFlags_HorizontalScrollbar);
for (int line = 0; line < lines; line++) for (int line = 0; line < lines; line++)
{ {
// Display random stuff (for the sake of this trivial demo we are using basic Button+SameLine. If you want to create your own time line for a real application you may be better off // Display random stuff (for the sake of this trivial demo we are using basic Button+SameLine. If you want to create your own time line for a real application you may be better off
@ -1881,17 +1908,20 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::DragFloat2("size", (float*)&size, 0.5f, 0.0f, 200.0f, "%.0f"); ImGui::DragFloat2("size", (float*)&size, 0.5f, 0.0f, 200.0f, "%.0f");
ImGui::TextWrapped("(Click and drag)"); ImGui::TextWrapped("(Click and drag)");
ImVec2 pos = ImGui::GetCursorScreenPos(); ImVec2 pos = ImGui::GetCursorScreenPos();
ImVec4 clip_rect(pos.x, pos.y, pos.x+size.x, pos.y+size.y); ImVec4 clip_rect(pos.x, pos.y, pos.x + size.x, pos.y + size.y);
ImGui::InvisibleButton("##dummy", size); ImGui::InvisibleButton("##dummy", size);
if (ImGui::IsItemActive() && ImGui::IsMouseDragging()) { offset.x += ImGui::GetIO().MouseDelta.x; offset.y += ImGui::GetIO().MouseDelta.y; } if (ImGui::IsItemActive() && ImGui::IsMouseDragging()) { offset.x += ImGui::GetIO().MouseDelta.x; offset.y += ImGui::GetIO().MouseDelta.y; }
ImGui::GetWindowDrawList()->AddRectFilled(pos, ImVec2(pos.x+size.x,pos.y+size.y), IM_COL32(90,90,120,255)); ImGui::GetWindowDrawList()->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(90, 90, 120, 255));
ImGui::GetWindowDrawList()->AddText(ImGui::GetFont(), ImGui::GetFontSize()*2.0f, ImVec2(pos.x+offset.x,pos.y+offset.y), IM_COL32(255,255,255,255), "Line 1 hello\nLine 2 clip me!", NULL, 0.0f, &clip_rect); ImGui::GetWindowDrawList()->AddText(ImGui::GetFont(), ImGui::GetFontSize()*2.0f, ImVec2(pos.x + offset.x, pos.y + offset.y), IM_COL32(255, 255, 255, 255), "Line 1 hello\nLine 2 clip me!", NULL, 0.0f, &clip_rect);
ImGui::TreePop(); ImGui::TreePop();
} }
} }
static void ShowDemoWindowPopups()
{
if (!ImGui::CollapsingHeader("Popups & Modal windows"))
return;
if (ImGui::CollapsingHeader("Popups & Modal windows"))
{
// Popups are windows with a few special properties: // Popups are windows with a few special properties:
// - They block normal mouse hovering detection outside them. (*) // - They block normal mouse hovering detection outside them. (*)
// - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE. // - Unless modal, they can be closed by clicking anywhere outside them, or by pressing ESCAPE.
@ -2035,14 +2065,14 @@ void ImGui::ShowDemoWindow(bool* p_open)
//ImGui::Combo("Combo", &dummy_i, "Delete\0Delete harder\0"); //ImGui::Combo("Combo", &dummy_i, "Delete\0Delete harder\0");
static bool dont_ask_me_next_time = false; static bool dont_ask_me_next_time = false;
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::Checkbox("Don't ask me next time", &dont_ask_me_next_time); ImGui::Checkbox("Don't ask me next time", &dont_ask_me_next_time);
ImGui::PopStyleVar(); ImGui::PopStyleVar();
if (ImGui::Button("OK", ImVec2(120,0))) { ImGui::CloseCurrentPopup(); } if (ImGui::Button("OK", ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); }
ImGui::SetItemDefaultFocus(); ImGui::SetItemDefaultFocus();
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Cancel", ImVec2(120,0))) { ImGui::CloseCurrentPopup(); } if (ImGui::Button("Cancel", ImVec2(120, 0))) { ImGui::CloseCurrentPopup(); }
ImGui::EndPopup(); ImGui::EndPopup();
} }
@ -2092,10 +2122,13 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::Separator(); ImGui::Separator();
ImGui::TreePop(); ImGui::TreePop();
} }
} }
static void ShowDemoWindowColumns()
{
if (!ImGui::CollapsingHeader("Columns"))
return;
if (ImGui::CollapsingHeader("Columns"))
{
ImGui::PushID("Columns"); ImGui::PushID("Columns");
// Basic columns // Basic columns
@ -2272,8 +2305,10 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::TreePop(); ImGui::TreePop();
} }
ImGui::PopID(); ImGui::PopID();
} }
static void ShowDemoWindowMisc()
{
if (ImGui::CollapsingHeader("Filtering")) if (ImGui::CollapsingHeader("Filtering"))
{ {
static ImGuiTextFilter filter; static ImGuiTextFilter filter;
@ -2431,9 +2466,6 @@ void ImGui::ShowDemoWindow(bool* p_open)
ImGui::TreePop(); ImGui::TreePop();
} }
} }
// End of ShowDemoWindow()
ImGui::End();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -701,7 +701,8 @@ struct ImGuiContext
ImGuiID HoveredId; // Hovered widget ImGuiID HoveredId; // Hovered widget
bool HoveredIdAllowOverlap; bool HoveredIdAllowOverlap;
ImGuiID HoveredIdPreviousFrame; ImGuiID HoveredIdPreviousFrame;
float HoveredIdTimer; float HoveredIdTimer; // Measure contiguous hovering time
float HoveredIdNotActiveTimer; // Measure contiguous hovering time where the item has not been active
ImGuiID ActiveId; // Active widget ImGuiID ActiveId; // Active widget
ImGuiID ActiveIdPreviousFrame; ImGuiID ActiveIdPreviousFrame;
ImGuiID ActiveIdIsAlive; // Active widget has been seen this frame (we can't use a bool as the ActiveId may change within the frame) ImGuiID ActiveIdIsAlive; // Active widget has been seen this frame (we can't use a bool as the ActiveId may change within the frame)
@ -856,7 +857,7 @@ struct ImGuiContext
HoveredId = 0; HoveredId = 0;
HoveredIdAllowOverlap = false; HoveredIdAllowOverlap = false;
HoveredIdPreviousFrame = 0; HoveredIdPreviousFrame = 0;
HoveredIdTimer = 0.0f; HoveredIdTimer = HoveredIdNotActiveTimer = 0.0f;
ActiveId = 0; ActiveId = 0;
ActiveIdPreviousFrame = 0; ActiveIdPreviousFrame = 0;
ActiveIdIsAlive = 0; ActiveIdIsAlive = 0;

View File

@ -2390,10 +2390,12 @@ bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max
return SliderScalarN(label, ImGuiDataType_Float, v, 4, &v_min, &v_max, format, power); return SliderScalarN(label, ImGuiDataType_Float, v, 4, &v_min, &v_max, format, power);
} }
bool ImGui::SliderAngle(const char* label, float* v_rad, float v_degrees_min, float v_degrees_max) bool ImGui::SliderAngle(const char* label, float* v_rad, float v_degrees_min, float v_degrees_max, const char* format)
{ {
if (format == NULL)
format = "%.0f deg";
float v_deg = (*v_rad) * 360.0f / (2*IM_PI); float v_deg = (*v_rad) * 360.0f / (2*IM_PI);
bool value_changed = SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, "%.0f deg", 1.0f); bool value_changed = SliderFloat(label, &v_deg, v_degrees_min, v_degrees_max, format, 1.0f);
*v_rad = v_deg * (2*IM_PI) / 360.0f; *v_rad = v_deg * (2*IM_PI) / 360.0f;
return value_changed; return value_changed;
} }

View File

@ -32,32 +32,33 @@ If you have other loading/merging/adding fonts, you can post on the Dear ImGui "
README FIRST / FAQ README FIRST / FAQ
--------------------------------------- ---------------------------------------
- You can use the style editor ImGui::ShowStyleEditor() to browse your fonts and understand what's going on if you have an issue. - You can use the style editor ImGui::ShowStyleEditor() to browse your fonts and understand what's going on if you have an issue.
- Make sure your font ranges data are persistent (available during the call to GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build(). - Make sure your font ranges data are persistent (available during the call to GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build().
- Use C++11 u8"my text" syntax to encode literal strings as UTF-8. e.g.: - Use C++11 u8"my text" syntax to encode literal strings as UTF-8. e.g.:
u8"hello" u8"hello"
u8"こんにちは" // this will be encoded as UTF-8 u8"こんにちは" // this will be encoded as UTF-8
- If you want to include a backslash \ character in your string literal, you need to double them e.g. "folder\\filename". - If you want to include a backslash \ character in your string literal, you need to double them e.g. "folder\\filename".
- Please use the Discourse forum (https://discourse.dearimgui.org) and not the Github issue tracker for basic font loading questions. - Please use the Discourse forum (https://discourse.dearimgui.org) and not the Github issue tracker for basic font loading questions.
--------------------------------------- ---------------------------------------
USING ICONS USING ICONS
--------------------------------------- ---------------------------------------
Using an icon font (such as FontAwesome: http://fontawesome.io) is an easy and practical way to use icons in your ImGui application. Using an icon font (such as FontAwesome: http://fontawesome.io or OpenFontIcons. https://github.com/traverseda/OpenFontIcons)
A common pattern is to merge the icon font within your main font, so you can embed icons directly from your strings without is an easy and practical way to use icons in your Dear ImGui application.
having to change fonts back and forth. A common pattern is to merge the icon font within your main font, so you can embed icons directly from your strings without
having to change fonts back and forth.
To refer to the icon UTF-8 codepoints from your C++ code, you may use those headers files created by Juliette Foucaut: To refer to the icon UTF-8 codepoints from your C++ code, you may use those headers files created by Juliette Foucaut:
https://github.com/juliettef/IconFontCppHeaders https://github.com/juliettef/IconFontCppHeaders
The C++11 version of those files uses the u8"" utf-8 encoding syntax + \u The C++11 version of those files uses the u8"" utf-8 encoding syntax + \u
#define ICON_FA_SEARCH u8"\uf002" #define ICON_FA_SEARCH u8"\uf002"
The pre-C++11 version has the values directly encoded as utf-8: The pre-C++11 version has the values directly encoded as utf-8:
#define ICON_FA_SEARCH "\xEF\x80\x82" #define ICON_FA_SEARCH "\xEF\x80\x82"
Example: Example Setup:
// Merge icons into default tool font // Merge icons into default tool font
#include "IconsFontAwesome.h" #include "IconsFontAwesome.h"
@ -70,27 +71,27 @@ If you have other loading/merging/adding fonts, you can post on the Dear ImGui "
static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
io.Fonts->AddFontFromFileTTF("fonts/fontawesome-webfont.ttf", 13.0f, &config, icon_ranges); io.Fonts->AddFontFromFileTTF("fonts/fontawesome-webfont.ttf", 13.0f, &config, icon_ranges);
Example Usage:
// Usage, e.g. // Usage, e.g.
ImGui::Text("%s among %d items", ICON_FA_SEARCH, count);
ImGui::Button(ICON_FA_SEARCH " Search"); ImGui::Button(ICON_FA_SEARCH " Search");
// C string _literals_ can be concatenated at compilation time, e.g. "hello" " world" // C string _literals_ can be concatenated at compilation time, e.g. "hello" " world"
// ICON_FA_SEARCH is defined as a string literal so this is the same as "A" "B" becoming "AB" // ICON_FA_SEARCH is defined as a string literal so this is the same as "A" "B" becoming "AB"
// Usage, e.g. See Links below for other icons fonts and related tools.
ImGui::Text("%s among %d items", ICON_FA_SEARCH, count);
See Links below for other icons fonts and related tools.
--------------------------------------- ---------------------------------------
FONTS LOADING INSTRUCTIONS FONTS LOADING INSTRUCTIONS
--------------------------------------- ---------------------------------------
Load default font: Load default font:
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontDefault(); io.Fonts->AddFontDefault();
Load .TTF/.OTF file with: Load .TTF/.OTF file with:
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
ImFont* font1 = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels); ImFont* font1 = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels);
@ -102,7 +103,7 @@ If you have other loading/merging/adding fonts, you can post on the Dear ImGui "
ImGui::Text("Hello with another font"); ImGui::Text("Hello with another font");
ImGui::PopFont(); ImGui::PopFont();
For advanced options create a ImFontConfig structure and pass it to the AddFont function (it will be copied internally): For advanced options create a ImFontConfig structure and pass it to the AddFont function (it will be copied internally):
ImFontConfig config; ImFontConfig config;
config.OversampleH = 3; config.OversampleH = 3;
@ -110,13 +111,13 @@ If you have other loading/merging/adding fonts, you can post on the Dear ImGui "
config.GlyphExtraSpacing.x = 1.0f; config.GlyphExtraSpacing.x = 1.0f;
ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config); ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config);
If you have very large number of glyphs or multiple fonts, the texture may become too big for your graphics API. If you have very large number of glyphs or multiple fonts, the texture may become too big for your graphics API.
The typical result of failing to upload a texture is if every glyphs appears as white rectangles. The typical result of failing to upload a texture is if every glyphs appears as white rectangles.
In particular, using a large range such as GetGlyphRangesChineseSimplifiedCommon() is not recommended unless you In particular, using a large range such as GetGlyphRangesChineseSimplifiedCommon() is not recommended unless you
set OversampleH/OversampleV to 1 and use a small font size. set OversampleH/OversampleV to 1 and use a small font size.
Mind the fact that some graphics drivers have texture size limitation. Mind the fact that some graphics drivers have texture size limitation.
If you are building a PC application, mind the fact that your users may use hardware with lower limitations than yours. If you are building a PC application, mind the fact that your users may use hardware with lower limitations than yours.
Some solutions: Some solutions:
- 1) Reduce glyphs ranges by calculating them from source localization data. You can use ImFont::GlyphRangesBuilder for this purpose, - 1) Reduce glyphs ranges by calculating them from source localization data. You can use ImFont::GlyphRangesBuilder for this purpose,
this will be the biggest win. this will be the biggest win.
@ -124,7 +125,7 @@ If you have other loading/merging/adding fonts, you can post on the Dear ImGui "
- 3) Set io.Fonts.TexDesiredWidth to specify a texture width to minimize texture height (see comment in ImFontAtlas::Build function). - 3) Set io.Fonts.TexDesiredWidth to specify a texture width to minimize texture height (see comment in ImFontAtlas::Build function).
- 4) Set io.Fonts.Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight; to disable rounding the texture height to the next power of two. - 4) Set io.Fonts.Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight; to disable rounding the texture height to the next power of two.
Combine two fonts into one: Combine two fonts into one:
// Load a first font // Load a first font
ImFont* font = io.Fonts->AddFontDefault(); ImFont* font = io.Fonts->AddFontDefault();
@ -139,7 +140,7 @@ If you have other loading/merging/adding fonts, you can post on the Dear ImGui "
io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 18.0f, &config, icons_ranges); io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 18.0f, &config, icons_ranges);
io.Fonts->Build(); io.Fonts->Build();
Add a fourth parameter to bake specific font ranges only: Add a fourth parameter to bake specific font ranges only:
// Basic Latin, Extended Latin // Basic Latin, Extended Latin
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesDefault()); io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesDefault());
@ -150,8 +151,8 @@ If you have other loading/merging/adding fonts, you can post on the Dear ImGui "
// Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesJapanese()); io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, NULL, io.Fonts->GetGlyphRangesJapanese());
See "BUILDING CUSTOM GLYPH RANGES" section to create your own ranges. See "BUILDING CUSTOM GLYPH RANGES" section to create your own ranges.
Offset font vertically by altering the io.Font->DisplayOffset value: Offset font vertically by altering the io.Font->DisplayOffset value:
ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels); ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels);
font->DisplayOffset.y = 1; // Render 1 pixel down font->DisplayOffset.y = 1; // Render 1 pixel down
@ -161,23 +162,23 @@ If you have other loading/merging/adding fonts, you can post on the Dear ImGui "
FREETYPE RASTERIZER, SMALL FONT SIZES FREETYPE RASTERIZER, SMALL FONT SIZES
--------------------------------------- ---------------------------------------
Dear ImGui uses imstb_truetype.h to rasterize fonts (with optional oversampling). Dear ImGui uses imstb_truetype.h to rasterize fonts (with optional oversampling).
This technique and its implementation are not ideal for fonts rendered at _small sizes_, which may appear a This technique and its implementation are not ideal for fonts rendered at _small sizes_, which may appear a
little blurry or hard to read. little blurry or hard to read.
There is an implementation of the ImFontAtlas builder using FreeType that you can use in the misc/freetype/ folder. There is an implementation of the ImFontAtlas builder using FreeType that you can use in the misc/freetype/ folder.
FreeType supports auto-hinting which tends to improve the readability of small fonts. FreeType supports auto-hinting which tends to improve the readability of small fonts.
Note that this code currently creates textures that are unoptimally too large (could be fixed with some work). Note that this code currently creates textures that are unoptimally too large (could be fixed with some work).
Also note that correct sRGB space blending will have an important effect on your font rendering quality. Also note that correct sRGB space blending will have an important effect on your font rendering quality.
--------------------------------------- ---------------------------------------
BUILDING CUSTOM GLYPH RANGES BUILDING CUSTOM GLYPH RANGES
--------------------------------------- ---------------------------------------
You can use the ImFontAtlas::GlyphRangesBuilder helper to create glyph ranges based on text input. You can use the ImFontAtlas::GlyphRangesBuilder helper to create glyph ranges based on text input.
For example: for a game where your script is known, if you can feed your entire script to it and only build the characters the game needs. For example: for a game where your script is known, if you can feed your entire script to it and only build the characters the game needs.
ImVector<ImWchar> ranges; ImVector<ImWchar> ranges;
ImFontAtlas::GlyphRangesBuilder builder; ImFontAtlas::GlyphRangesBuilder builder;
@ -194,14 +195,14 @@ If you have other loading/merging/adding fonts, you can post on the Dear ImGui "
EMBEDDING FONTS IN SOURCE CODE EMBEDDING FONTS IN SOURCE CODE
--------------------------------------- ---------------------------------------
Compile and use 'binary_to_compressed_c.cpp' to create a compressed C style array that you can embed in source code. Compile and use 'binary_to_compressed_c.cpp' to create a compressed C style array that you can embed in source code.
See the documentation in binary_to_compressed_c.cpp for instruction on how to use the tool. See the documentation in binary_to_compressed_c.cpp for instruction on how to use the tool.
You may find a precompiled version binary_to_compressed_c.exe for Windows instead of demo binaries package (see README). You may find a precompiled version binary_to_compressed_c.exe for Windows instead of demo binaries package (see README).
The tool optionally used Base85 encoding to reduce the size of _source code_ but the read-only arrays will be about 20% bigger. The tool optionally used Base85 encoding to reduce the size of _source code_ but the read-only arrays will be about 20% bigger.
Then load the font with: Then load the font with:
ImFont* font = io.Fonts->AddFontFromMemoryCompressedTTF(compressed_data, compressed_data_size, size_pixels, ...); ImFont* font = io.Fonts->AddFontFromMemoryCompressedTTF(compressed_data, compressed_data_size, size_pixels, ...);
or: or:
ImFont* font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(compressed_data_base85, size_pixels, ...); ImFont* font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(compressed_data_base85, size_pixels, ...);
@ -209,82 +210,101 @@ If you have other loading/merging/adding fonts, you can post on the Dear ImGui "
CREDITS/LICENSES FOR FONTS INCLUDED IN THIS FOLDER CREDITS/LICENSES FOR FONTS INCLUDED IN THIS FOLDER
--------------------------------------- ---------------------------------------
Roboto-Medium.ttf Roboto-Medium.ttf
Apache License 2.0 Apache License 2.0
by Christian Robertson by Christian Robertson
https://fonts.google.com/specimen/Roboto https://fonts.google.com/specimen/Roboto
Cousine-Regular.ttf Cousine-Regular.ttf
by Steve Matteson by Steve Matteson
Digitized data copyright (c) 2010 Google Corporation. Digitized data copyright (c) 2010 Google Corporation.
Licensed under the SIL Open Font License, Version 1.1 Licensed under the SIL Open Font License, Version 1.1
https://fonts.google.com/specimen/Cousine https://fonts.google.com/specimen/Cousine
DroidSans.ttf DroidSans.ttf
Copyright (c) Steve Matteson Copyright (c) Steve Matteson
Apache License, version 2.0 Apache License, version 2.0
https://www.fontsquirrel.com/fonts/droid-sans https://www.fontsquirrel.com/fonts/droid-sans
ProggyClean.ttf ProggyClean.ttf
Copyright (c) 2004, 2005 Tristan Grimmer Copyright (c) 2004, 2005 Tristan Grimmer
MIT License MIT License
recommended loading setting in ImGui: Size = 13.0, DisplayOffset.Y = +1 recommended loading setting in ImGui: Size = 13.0, DisplayOffset.Y = +1
http://www.proggyfonts.net/ http://www.proggyfonts.net/
ProggyTiny.ttf ProggyTiny.ttf
Copyright (c) 2004, 2005 Tristan Grimmer Copyright (c) 2004, 2005 Tristan Grimmer
MIT License MIT License
recommended loading setting in ImGui: Size = 10.0, DisplayOffset.Y = +1 recommended loading setting in ImGui: Size = 10.0, DisplayOffset.Y = +1
http://www.proggyfonts.net/ http://www.proggyfonts.net/
Karla-Regular.ttf Karla-Regular.ttf
Copyright (c) 2012, Jonathan Pinhorn Copyright (c) 2012, Jonathan Pinhorn
SIL OPEN FONT LICENSE Version 1.1 SIL OPEN FONT LICENSE Version 1.1
--------------------------------------- ---------------------------------------
LINKS, OTHER FONTS FONTS LINKS
--------------------------------------- ---------------------------------------
(Icons) Icon fonts ICON FONTS
https://fortawesome.github.io/Font-Awesome/
https://github.com/SamBrishes/kenney-icon-font
https://design.google.com/icons/
You can use https://github.com/juliettef/IconFontCppHeaders for C/C++ header files with name #define to access icon codepoint in source code.
(Icons) IcoMoon - Custom Icon font builder C/C++ header for icon fonts (#define with code points to use in source code string literals)
https://github.com/juliettef/IconFontCppHeaders
FontAwesome
https://fortawesome.github.io/Font-Awesome
OpenFontIcons
https://github.com/traverseda/OpenFontIcons
Google Icon Fonts
https://design.google.com/icons/
Kenney Icon Font (Game Controller Icons)
https://github.com/nicodinh/kenney-icon-font
IcoMoon - Custom Icon font builder
https://icomoon.io/app https://icomoon.io/app
(Pixel perfect) Sweet16, Sweet16 Mono, by Martin Sedlak (Latin + Supplemental + Extended A) REGULAR FONTS
Google Noto Fonts (worldwide languages)
https://www.google.com/get/noto/
Open Sans Fonts
https://fonts.google.com/specimen/Open+Sans
(Japanese) M+ fonts by Coji Morishita are free
http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html
MONOSPACE FONTS
(Pixel Perfect) Proggy Fonts, by Tristan Grimmer
http://www.proggyfonts.net or http://upperbounds.net
(Pixel Perfect) Sweet16, Sweet16 Mono, by Martin Sedlak (Latin + Supplemental + Extended A)
https://github.com/kmar/Sweet16Font https://github.com/kmar/Sweet16Font
Also include .inl file to use directly in dear imgui. Also include .inl file to use directly in dear imgui.
(Regular) Open Sans Fonts Typefaces for source code beautification
https://fonts.google.com/specimen/Open+Sans
(Regular) Google Noto Fonts (worldwide languages)
https://www.google.com/get/noto/
(Monospace) Typefaces for source code beautification
https://github.com/chrissimpkins/codeface https://github.com/chrissimpkins/codeface
(Monospace) Programmation fonts Programmation fonts
http://s9w.github.io/font_compare/ http://s9w.github.io/font_compare/
(Monospace) Proggy Programming Fonts Inconsolata
http://upperbounds.net
(Monospace) Inconsolata
http://www.levien.com/type/myfonts/inconsolata.html http://www.levien.com/type/myfonts/inconsolata.html
(Monospace) Adobe Source Code Pro: Monospaced font family for user interface and coding environments Adobe Source Code Pro: Monospaced font family for user interface and coding environments
https://github.com/adobe-fonts/source-code-pro https://github.com/adobe-fonts/source-code-pro
(Monospace) Monospace/Fixed Width Programmer's Fonts Monospace/Fixed Width Programmer's Fonts
http://www.lowing.org/fonts/ http://www.lowing.org/fonts/
(Japanese) M+ fonts by Coji Morishita are free and include most useful Kanjis you would need.
http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html
Or use Arial Unicode or other Unicode fonts provided with Windows for full characters coverage (not sure of their licensing). Or use Arial Unicode or other Unicode fonts provided with Windows for full characters coverage (not sure of their licensing).