Added PushFont/PopFont API

docking
ocornut 10 years ago
parent ab8d2782c6
commit 7ebd7ef9ac

@ -323,6 +323,7 @@ static void RenderText(ImVec2 pos, const char* text, const char* text_en
static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); static void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false); static void RenderCollapseTriangle(ImVec2 p_min, bool opened, float scale = 1.0f, bool shadow = false);
static void SetFont(ImFont* font);
static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL); static void ItemSize(ImVec2 size, ImVec2* adjust_start_offset = NULL);
static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL); static void ItemSize(const ImGuiAabb& aabb, ImVec2* adjust_start_offset = NULL);
static void PushColumnClipRect(int column_index = -1); static void PushColumnClipRect(int column_index = -1);
@ -345,9 +346,10 @@ static const char* ImStristr(const char* haystack, const char* needle, const ch
static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...); static size_t ImFormatString(char* buf, size_t buf_size, const char* fmt, ...);
static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args); static size_t ImFormatStringV(char* buf, size_t buf_size, const char* fmt, va_list args);
// Helpers: Data // Helpers: Misc
static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed); static ImU32 ImCrc32(const void* data, size_t data_size, ImU32 seed);
static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes = 0); static bool ImLoadFileToMemory(const char* filename, const char* file_open_mode, void** out_file_data, size_t* out_file_size, size_t padding_bytes = 0);
static int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
// Helpers: Color Conversion // Helpers: Color Conversion
static ImU32 ImConvertColorFloat4ToU32(const ImVec4& in); static ImU32 ImConvertColorFloat4ToU32(const ImVec4& in);
@ -873,8 +875,9 @@ struct ImGuiState
bool Initialized; bool Initialized;
ImGuiIO IO; ImGuiIO IO;
ImGuiStyle Style; ImGuiStyle Style;
float FontSize; // == IO.FontGlobalScale * IO.Font->Scale * IO.Font->Info->FontSize. Vertical distance between two lines of text, aka == CalcTextSize(" ").y ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
ImVec2 FontTexUvWhitePixel; // == IO.Font->TexUvForWhite (cached copy) float FontSize; // (Shortcut) == IO.FontGlobalScale * (Font->Scale * Font->FontSize). Vertical distance between two lines of text, aka == CalcTextSize(" ").y
ImVec2 FontTexUvWhitePixel; // (Shortcut) == Font->TexUvForWhite
float Time; float Time;
int FrameCount; int FrameCount;
@ -893,6 +896,7 @@ struct ImGuiState
ImVector<ImGuiIniData*> Settings; ImVector<ImGuiIniData*> Settings;
ImVector<ImGuiColMod> ColorModifiers; ImVector<ImGuiColMod> ColorModifiers;
ImVector<ImGuiStyleMod> StyleModifiers; ImVector<ImGuiStyleMod> StyleModifiers;
ImVector<ImFont*> FontStack;
ImVec2 SetNextWindowPosVal; ImVec2 SetNextWindowPosVal;
ImGuiSetCondition SetNextWindowPosCond; ImGuiSetCondition SetNextWindowPosCond;
ImVec2 SetNextWindowSizeVal; ImVec2 SetNextWindowSizeVal;
@ -1003,7 +1007,7 @@ public:
void FocusItemUnregister(); void FocusItemUnregister();
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.Font; }
float FontSize() const { return GImGui.FontSize * FontWindowScale; } 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; }
@ -1537,11 +1541,7 @@ void ImGui::NewFrame()
g.Initialized = true; g.Initialized = true;
} }
IM_ASSERT(g.IO.Font->Scale > 0.0f); SetFont(g.IO.Font);
g.FontSize = g.IO.FontGlobalScale * g.IO.Font->FontSize * g.IO.Font->Scale;
g.FontTexUvWhitePixel = g.IO.Font->TexUvWhitePixel;
g.IO.Font->FallbackGlyph = NULL;
g.IO.Font->FallbackGlyph = g.IO.Font->FindGlyph(g.IO.Font->FallbackChar);
g.Time += g.IO.DeltaTime; g.Time += g.IO.DeltaTime;
g.FrameCount += 1; g.FrameCount += 1;
@ -2795,6 +2795,34 @@ float ImGui::GetItemWidth()
return window->DC.ItemWidth.back(); return window->DC.ItemWidth.back();
} }
static void SetFont(ImFont* font)
{
ImGuiState& g = GImGui;
IM_ASSERT(font->Scale > 0.0f);
g.Font = font;
g.FontSize = g.IO.FontGlobalScale * g.Font->FontSize * g.Font->Scale;
g.FontTexUvWhitePixel = g.Font->TexUvWhitePixel;
g.Font->FallbackGlyph = NULL;
g.Font->FallbackGlyph = g.Font->FindGlyph(g.Font->FallbackChar);
}
void ImGui::PushFont(ImFont* font)
{
ImGuiState& g = GImGui;
g.FontStack.push_back(font);
SetFont(font);
}
void ImGui::PopFont()
{
ImGuiState& g = GImGui;
g.FontStack.pop_back();
SetFont(g.FontStack.empty() ? g.IO.Font : g.FontStack.back());
}
void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus) void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus)
{ {
ImGuiWindow* window = GetCurrentWindow(); ImGuiWindow* window = GetCurrentWindow();
@ -6432,8 +6460,6 @@ bool ImFont::LoadFromFileTTF(const char* filename, float size_pixels, const I
return ret; return ret;
} }
static int ImUpperPowerOfTwo(int v) { v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v++; return v; }
bool ImFont::LoadFromMemoryTTF(const void* data, size_t data_size, float size_pixels, const ImWchar* glyph_ranges, int font_no) bool ImFont::LoadFromMemoryTTF(const void* data, size_t data_size, float size_pixels, const ImWchar* glyph_ranges, int font_no)
{ {
Clear(); Clear();
@ -6841,7 +6867,7 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c
ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) const ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) const
{ {
if (!text_end) if (!text_end)
text_end = text_begin + strlen(text_begin); // FIXME-OPT text_end = text_begin + strlen(text_begin); // FIXME-OPT: Need to avoid this.
const float scale = size / FontSize; const float scale = size / FontSize;
const float line_height = FontSize * scale; const float line_height = FontSize * scale;
@ -6890,8 +6916,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
if (c == '\n') if (c == '\n')
{ {
if (text_size.x < line_width) text_size.x = ImMax(text_size.x, line_width);
text_size.x = line_width;
text_size.y += line_height; text_size.y += line_height;
line_width = 0.0f; line_width = 0.0f;
continue; continue;
@ -6946,8 +6971,7 @@ ImVec2 ImFont::CalcTextSizeW(float size, float max_width, const ImWchar* text_be
if (c == '\n') if (c == '\n')
{ {
if (text_size.x < line_width) text_size.x = ImMax(text_size.x, line_width);
text_size.x = line_width;
text_size.y += line_height; text_size.y += line_height;
line_width = 0.0f; line_width = 0.0f;
continue; continue;

@ -178,6 +178,8 @@ namespace ImGui
IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case. default to ~2/3 of windows width. IMGUI_API void PushItemWidth(float item_width); // width of items for the common item+label case. default to ~2/3 of windows width.
IMGUI_API void PopItemWidth(); IMGUI_API void PopItemWidth();
IMGUI_API float GetItemWidth(); IMGUI_API float GetItemWidth();
IMGUI_API void PushFont(ImFont* font);
IMGUI_API void PopFont();
IMGUI_API void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets. IMGUI_API void PushAllowKeyboardFocus(bool v); // allow focusing using TAB/Shift-TAB, enabled by default but you can disable it for certain widgets.
IMGUI_API void PopAllowKeyboardFocus(); IMGUI_API void PopAllowKeyboardFocus();
IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4& col); IMGUI_API void PushStyleColor(ImGuiCol idx, const ImVec4& col);

Loading…
Cancel
Save