mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-12 02:00:58 +01:00
Remove IO.FontHeight, cached automatically. Added assertions.
This commit is contained in:
parent
dd5d251273
commit
8fc50f5ed3
11
imgui.cpp
11
imgui.cpp
@ -104,8 +104,8 @@
|
||||
e.g. "##Foobar" display an empty label and uses "##Foobar" as ID
|
||||
|
||||
- if you want to use a different font than the default
|
||||
- create bitmap font data using BMFont. allocate ImGui::GetIO().Font and use ->LoadFromFile()/LoadFromMemory(), set ImGui::GetIO().FontHeight
|
||||
- load your texture yourself. texture *MUST* have white pixel at UV coordinate Imgui::GetIO().FontTexUvForWhite. This is used to draw all solid shapes.
|
||||
- create bitmap font data using BMFont. allocate ImGui::GetIO().Font and use ->LoadFromFile()/LoadFromMemory().
|
||||
- load your texture yourself. texture *MUST* have white pixel at UV coordinate ImGui::GetIO().FontTexUvForWhite. This is used to draw all solid shapes.
|
||||
|
||||
- tip: the construct 'if (IMGUI_ONCE_UPON_A_FRAME)' will evaluate to true only once a frame, you can use it to add custom UI in the middle of a deep nested inner loop in your code.
|
||||
- tip: you can call Render() multiple times (e.g for VR renders), up to you to communicate the extra state to your RenderDrawListFn function.
|
||||
@ -604,6 +604,8 @@ struct ImGuiState
|
||||
bool Initialized;
|
||||
ImGuiIO IO;
|
||||
ImGuiStyle Style;
|
||||
float FontSize; // == IO.Font->GetFontSize(). Vertical distance between two lines of text, aka == CalcTextSize(" ").y
|
||||
|
||||
float Time;
|
||||
int FrameCount;
|
||||
int FrameCountRendered;
|
||||
@ -709,7 +711,7 @@ public:
|
||||
|
||||
ImGuiAabb Aabb() const { return ImGuiAabb(Pos, Pos+Size); }
|
||||
ImFont Font() const { return GImGui.IO.Font; }
|
||||
float FontSize() const { return GImGui.IO.FontHeight * FontScale; }
|
||||
float FontSize() const { return GImGui.FontSize * FontScale; }
|
||||
ImVec2 CursorPos() const { return DC.CursorPos; }
|
||||
float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui.Style.FramePadding.y * 2.0f; }
|
||||
ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
|
||||
@ -1197,14 +1199,15 @@ void NewFrame()
|
||||
ImGui::GetDefaultFontData(&fnt_data, &fnt_size, NULL, NULL);
|
||||
g.IO.Font = new ImBitmapFont();
|
||||
g.IO.Font->LoadFromMemory(fnt_data, fnt_size);
|
||||
g.IO.FontHeight = g.IO.Font->GetFontSize();
|
||||
}
|
||||
g.Initialized = true;
|
||||
}
|
||||
IM_ASSERT(g.IO.Font && g.IO.Font->IsLoaded()); // Font not loaded
|
||||
|
||||
g.Time += g.IO.DeltaTime;
|
||||
g.FrameCount += 1;
|
||||
g.Tooltip[0] = '\0';
|
||||
g.FontSize = g.IO.Font->GetFontSize();
|
||||
|
||||
// Update inputs state
|
||||
if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
|
||||
|
2
imgui.h
2
imgui.h
@ -391,7 +391,6 @@ struct ImGuiIO
|
||||
float MouseDoubleClickMaxDist; // = 6.0f // Distance threshold to stay in to validate a double-click, in pixels.
|
||||
int KeyMap[ImGuiKey_COUNT]; // <unset> // Map of indices into the KeysDown[512] entries array
|
||||
ImFont Font; // <auto> // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font).
|
||||
float FontHeight; // <auto> // Default font height, must be the vertical distance between two lines of text, aka == CalcTextSize(" ").y
|
||||
ImVec2 FontTexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture.
|
||||
bool FontAllowScaling; // = false // Set to allow scaling text with CTRL+Wheel.
|
||||
float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry
|
||||
@ -642,6 +641,7 @@ struct ImBitmapFont
|
||||
void BuildLookupTable();
|
||||
const FntGlyph * FindGlyph(unsigned short c) const;
|
||||
float GetFontSize() const { return (float)Info->FontSize; }
|
||||
bool IsLoaded() const { return Info != NULL && Common != NULL && Glyphs != NULL; }
|
||||
|
||||
ImVec2 CalcTextSize(float size, float max_width, const char* text_begin, const char* text_end, const char** remaining = NULL) const;
|
||||
void RenderText(float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, ImDrawVert*& out_vertices) const;
|
||||
|
Loading…
Reference in New Issue
Block a user