mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Added IO.FontBaseScale for global rescale. Renamed SetFontScale to SetWindowFontScale
This commit is contained in:
parent
da2ccf0a78
commit
05a42ba3a6
30
imgui.cpp
30
imgui.cpp
@ -1,4 +1,4 @@
|
|||||||
// ImGui library v1.11
|
// ImGui library v1.11+
|
||||||
// See ImGui::ShowTestWindow() for sample code.
|
// See ImGui::ShowTestWindow() for sample code.
|
||||||
// Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
|
// Read 'Programmer guide' below for notes on how to setup ImGui in your codebase.
|
||||||
// Get latest version at https://github.com/ocornut/imgui
|
// Get latest version at https://github.com/ocornut/imgui
|
||||||
@ -301,7 +301,8 @@ ImGuiIO::ImGuiIO()
|
|||||||
Font = NULL;
|
Font = NULL;
|
||||||
FontYOffset = 0.0f;
|
FontYOffset = 0.0f;
|
||||||
FontTexUvForWhite = ImVec2(0.0f,0.0f);
|
FontTexUvForWhite = ImVec2(0.0f,0.0f);
|
||||||
FontAllowScaling = false;
|
FontBaseScale = 1.0f;
|
||||||
|
FontAllowUserScaling = false;
|
||||||
PixelCenterOffset = 0.0f;
|
PixelCenterOffset = 0.0f;
|
||||||
MousePos = ImVec2(-1,-1);
|
MousePos = ImVec2(-1,-1);
|
||||||
MousePosPrev = ImVec2(-1,-1);
|
MousePosPrev = ImVec2(-1,-1);
|
||||||
@ -633,7 +634,7 @@ struct ImGuiState
|
|||||||
bool Initialized;
|
bool Initialized;
|
||||||
ImGuiIO IO;
|
ImGuiIO IO;
|
||||||
ImGuiStyle Style;
|
ImGuiStyle Style;
|
||||||
float FontSize; // == IO.Font->GetFontSize(). Vertical distance between two lines of text, aka == CalcTextSize(" ").y
|
float FontSize; // == IO.FontBaseScale * IO.Font->GetFontSize(). Vertical distance between two lines of text, aka == CalcTextSize(" ").y
|
||||||
|
|
||||||
float Time;
|
float Time;
|
||||||
int FrameCount;
|
int FrameCount;
|
||||||
@ -720,7 +721,7 @@ struct ImGuiWindow
|
|||||||
int LastFrameDrawn;
|
int LastFrameDrawn;
|
||||||
float ItemWidthDefault;
|
float ItemWidthDefault;
|
||||||
ImGuiStorage StateStorage;
|
ImGuiStorage StateStorage;
|
||||||
float FontScale;
|
float FontWindowScale; // Scale multipler per-window
|
||||||
|
|
||||||
int FocusIdxCounter; // Start at -1 and increase as assigned via FocusItemRegister()
|
int FocusIdxCounter; // Start at -1 and increase as assigned via FocusItemRegister()
|
||||||
int FocusIdxRequestCurrent; // Item being requested for focus, rely on layout to be stable between the frame pressing TAB and the next frame
|
int FocusIdxRequestCurrent; // Item being requested for focus, rely on layout to be stable between the frame pressing TAB and the next frame
|
||||||
@ -741,7 +742,7 @@ public:
|
|||||||
|
|
||||||
ImGuiAabb Aabb() const { return ImGuiAabb(Pos, Pos+Size); }
|
ImGuiAabb Aabb() const { return ImGuiAabb(Pos, Pos+Size); }
|
||||||
ImFont Font() const { return GImGui.IO.Font; }
|
ImFont Font() const { return GImGui.IO.Font; }
|
||||||
float FontSize() const { return GImGui.FontSize * FontScale; }
|
float FontSize() const { return GImGui.FontSize * FontWindowScale; }
|
||||||
ImVec2 CursorPos() const { return DC.CursorPos; }
|
ImVec2 CursorPos() const { return DC.CursorPos; }
|
||||||
float TitleBarHeight() const { return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0 : FontSize() + GImGui.Style.FramePadding.y * 2.0f; }
|
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())); }
|
ImGuiAabb TitleBarAabb() const { return ImGuiAabb(Pos, Pos + ImVec2(SizeFull.x, TitleBarHeight())); }
|
||||||
@ -973,7 +974,7 @@ ImGuiWindow::ImGuiWindow(const char* name, ImVec2 default_pos, ImVec2 default_si
|
|||||||
AutoFitFrames = -1;
|
AutoFitFrames = -1;
|
||||||
LastFrameDrawn = -1;
|
LastFrameDrawn = -1;
|
||||||
ItemWidthDefault = 0.0f;
|
ItemWidthDefault = 0.0f;
|
||||||
FontScale = 1.0f;
|
FontWindowScale = 1.0f;
|
||||||
|
|
||||||
if (ImLength(Size) < 0.001f)
|
if (ImLength(Size) < 0.001f)
|
||||||
AutoFitFrames = 3;
|
AutoFitFrames = 3;
|
||||||
@ -1218,6 +1219,7 @@ void NewFrame()
|
|||||||
IM_ASSERT(g.IO.DeltaTime > 0.0f);
|
IM_ASSERT(g.IO.DeltaTime > 0.0f);
|
||||||
IM_ASSERT(g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f);
|
IM_ASSERT(g.IO.DisplaySize.x > 0.0f && g.IO.DisplaySize.y > 0.0f);
|
||||||
IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented
|
IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented
|
||||||
|
IM_ASSERT(g.IO.FontBaseScale > 0.0f);
|
||||||
|
|
||||||
if (!g.Initialized)
|
if (!g.Initialized)
|
||||||
{
|
{
|
||||||
@ -1245,7 +1247,7 @@ void NewFrame()
|
|||||||
g.Time += g.IO.DeltaTime;
|
g.Time += g.IO.DeltaTime;
|
||||||
g.FrameCount += 1;
|
g.FrameCount += 1;
|
||||||
g.Tooltip[0] = '\0';
|
g.Tooltip[0] = '\0';
|
||||||
g.FontSize = g.IO.Font->GetFontSize();
|
g.FontSize = g.IO.FontBaseScale * g.IO.Font->GetFontSize();
|
||||||
|
|
||||||
// Update inputs state
|
// Update inputs state
|
||||||
if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
|
if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
|
||||||
@ -1306,12 +1308,12 @@ void NewFrame()
|
|||||||
ImGuiWindow* window = g.HoveredWindow;
|
ImGuiWindow* window = g.HoveredWindow;
|
||||||
if (g.IO.KeyCtrl)
|
if (g.IO.KeyCtrl)
|
||||||
{
|
{
|
||||||
if (g.IO.FontAllowScaling)
|
if (g.IO.FontAllowUserScaling)
|
||||||
{
|
{
|
||||||
// Zoom / Scale window
|
// Zoom / Scale window
|
||||||
float new_font_scale = ImClamp(window->FontScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
|
float new_font_scale = ImClamp(window->FontWindowScale + g.IO.MouseWheel * 0.10f, 0.50f, 2.50f);
|
||||||
float scale = new_font_scale / window->FontScale;
|
float scale = new_font_scale / window->FontWindowScale;
|
||||||
window->FontScale = new_font_scale;
|
window->FontWindowScale = new_font_scale;
|
||||||
|
|
||||||
const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
|
const ImVec2 offset = window->Size * (1.0f - scale) * (g.IO.MousePos - window->Pos) / window->Size;
|
||||||
window->Pos += offset;
|
window->Pos += offset;
|
||||||
@ -2507,10 +2509,10 @@ ImDrawList* GetWindowDrawList()
|
|||||||
return window->DrawList;
|
return window->DrawList;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFontScale(float scale)
|
void SetWindowFontScale(float scale)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = GetCurrentWindow();
|
ImGuiWindow* window = GetCurrentWindow();
|
||||||
window->FontScale = scale;
|
window->FontWindowScale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImVec2 GetCursorPos()
|
ImVec2 GetCursorPos()
|
||||||
@ -5533,7 +5535,7 @@ void ShowUserGuide()
|
|||||||
ImGui::BulletText("Click and drag on lower right corner to resize window.");
|
ImGui::BulletText("Click and drag on lower right corner to resize window.");
|
||||||
ImGui::BulletText("Click and drag on any empty space to move window.");
|
ImGui::BulletText("Click and drag on any empty space to move window.");
|
||||||
ImGui::BulletText("Mouse Wheel to scroll.");
|
ImGui::BulletText("Mouse Wheel to scroll.");
|
||||||
if (g.IO.FontAllowScaling)
|
if (g.IO.FontAllowUserScaling)
|
||||||
ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
|
ImGui::BulletText("CTRL+Mouse Wheel to zoom window contents.");
|
||||||
ImGui::BulletText("TAB/SHIFT+TAB to cycle thru keyboard editable fields.");
|
ImGui::BulletText("TAB/SHIFT+TAB to cycle thru keyboard editable fields.");
|
||||||
ImGui::BulletText("CTRL+Click on a slider to input text.");
|
ImGui::BulletText("CTRL+Click on a slider to input text.");
|
||||||
|
5
imgui.h
5
imgui.h
@ -152,7 +152,7 @@ namespace ImGui
|
|||||||
ImVec2 GetWindowContentRegionMin();
|
ImVec2 GetWindowContentRegionMin();
|
||||||
ImVec2 GetWindowContentRegionMax();
|
ImVec2 GetWindowContentRegionMax();
|
||||||
ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives.
|
ImDrawList* GetWindowDrawList(); // get rendering command-list if you want to append your own draw primitives.
|
||||||
void SetFontScale(float scale);
|
void SetWindowFontScale(float scale); // per-window font scale. Adjust IO.FontBaseScale if you want to scale all windows together.
|
||||||
void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position.
|
void SetScrollPosHere(); // adjust scrolling position to center into the current cursor position.
|
||||||
void SetTreeStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
|
void SetTreeStateStorage(ImGuiStorage* tree); // replace tree state storage with our own (if you want to manipulate it yourself, typically clear subsection of it).
|
||||||
ImGuiStorage* GetTreeStateStorage();
|
ImGuiStorage* GetTreeStateStorage();
|
||||||
@ -406,7 +406,8 @@ struct ImGuiIO
|
|||||||
ImFont Font; // <auto> // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font).
|
ImFont Font; // <auto> // Gets passed to text functions. Typedef ImFont to the type you want (ImBitmapFont* or your own font).
|
||||||
float FontYOffset; // = 0.0f // Offset font rendering by xx pixels in Y axis.
|
float FontYOffset; // = 0.0f // Offset font rendering by xx pixels in Y axis.
|
||||||
ImVec2 FontTexUvForWhite; // = (0.0f,0.0f) // Font texture must have a white pixel at this UV coordinate. Adjust if you are using custom texture.
|
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 FontBaseScale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
|
||||||
|
bool FontAllowUserScaling; // = 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
|
float PixelCenterOffset; // = 0.0f // Try to set to 0.5f or 0.375f if rendering is blurry
|
||||||
|
|
||||||
// Settings - Rendering function (REQUIRED)
|
// Settings - Rendering function (REQUIRED)
|
||||||
|
Loading…
Reference in New Issue
Block a user