Skip to content

Commit 2796140

Browse files
committed
Cleanup (#219)
1 parent 88a00f7 commit 2796140

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

imgui.cpp

+43-43
Original file line numberDiff line numberDiff line change
@@ -328,41 +328,43 @@
328328
Q: How can I load a different font than the default? (default is an embedded version of ProggyClean.ttf, rendered at size 13)
329329
A: Use the font atlas to load the TTF file you want:
330330
331-
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
332-
io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
331+
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
332+
io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
333333
334334
Q: How can I load multiple fonts?
335335
A: Use the font atlas to pack them into a single texture:
336336
337-
ImFont* font0 = io.Fonts->AddFontDefault();
338-
ImFont* font1 = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
339-
ImFont* font2 = io.Fonts->AddFontFromFileTTF("myfontfile2.ttf", size_in_pixels);
340-
io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
341-
// the first loaded font gets used by default
342-
// use ImGui::PushFont()/ImGui::PopFont() to change the font at runtime
343-
344-
// Options
345-
ImFontConfig config;
346-
config.OversampleH = 3;
347-
config.OversampleV = 3;
348-
config.GlyphExtraSpacing.x = 1.0f;
349-
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, &config);
350-
351-
// Merging input from different fonts into one
352-
ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
353-
ImFontConfig config;
354-
config.MergeMode = true;
355-
io.Fonts->AddFontDefault();
356-
io.Fonts->LoadFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges);
357-
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, NULL, &config, io.Fonts->GetGlyphRangesJapanese());
337+
ImFont* font0 = io.Fonts->AddFontDefault();
338+
ImFont* font1 = io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels);
339+
ImFont* font2 = io.Fonts->AddFontFromFileTTF("myfontfile2.ttf", size_in_pixels);
340+
io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
341+
// the first loaded font gets used by default
342+
// use ImGui::PushFont()/ImGui::PopFont() to change the font at runtime
343+
344+
// Options
345+
ImFontConfig config;
346+
config.OversampleH = 3;
347+
config.OversampleV = 3;
348+
config.GlyphExtraSpacing.x = 1.0f;
349+
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, &config);
350+
351+
// Combine multiple fonts into one
352+
ImWchar ranges[] = { 0xf000, 0xf3ff, 0 };
353+
ImFontConfig config;
354+
config.MergeMode = true;
355+
io.Fonts->AddFontDefault();
356+
io.Fonts->LoadFromFileTTF("fontawesome-webfont.ttf", 16.0f, &config, ranges);
357+
io.Fonts->LoadFromFileTTF("myfontfile.ttf", size_pixels, NULL, &config, io.Fonts->GetGlyphRangesJapanese());
358+
359+
Read extra_fonts/README.txt or ImFontAtlas class for more details.
358360
359361
Q: How can I display and input non-latin characters such as Chinese, Japanese, Korean, Cyrillic?
360362
A: When loading a font, pass custom Unicode ranges to specify the glyphs to load. ImGui will support UTF-8 encoding across the board.
361363
Character input depends on you passing the right character code to io.AddInputCharacter(). The example applications do that.
362364
363-
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, NULL, io.Fonts->GetGlyphRangesJapanese()); // Load Japanese characters
364-
io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
365-
io.ImeWindowHandle = MY_HWND; // To input using Microsoft IME, give ImGui the hwnd of your application
365+
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, NULL, io.Fonts->GetGlyphRangesJapanese()); // Load Japanese characters
366+
io.Fonts->GetTexDataAsRGBA32() or GetTexDataAsAlpha8()
367+
io.ImeWindowHandle = MY_HWND; // To input using Microsoft IME, give ImGui the hwnd of your application
366368
367369
- tip: the construct 'IMGUI_ONCE_UPON_A_FRAME { ... }' will run the block of code only once a frame. You can use it to quickly add custom UI in the middle of a deep nested inner loop in your code.
368370
- tip: you can create widgets without a Begin()/End() block, they will go in an implicit window called "Debug"
@@ -374,8 +376,8 @@
374376
ISSUES & TODO-LIST
375377
==================
376378
Issue numbers (#) refer to github issues.
379+
The list below consist mostly of notes of things to do before they are requested/discussed by users (at that point it usually happens on the github)
377380
378-
- misc: merge or clarify ImVec4 vs ImRect?
379381
- window: autofit feedback loop when user relies on any dynamic layout (window width multiplier, column). maybe just clearly drop manual autofit?
380382
- window: add a way for very transient windows (non-saved, temporary overlay over hundreds of objects) to "clean" up from the global window list.
381383
- window: allow resizing of child windows (possibly given min/max for each axis?)
@@ -430,7 +432,8 @@
430432
- slider: initial absolute click is imprecise. change to relative movement slider (same as scrollbar).
431433
- slider: add dragging-based widgets to edit values with mouse (on 2 axises), saving screen real-estate.
432434
- slider: tint background based on value (e.g. v_min -> v_max, or use 0.0f either side of the sign)
433-
- dragfloat: up/down axis
435+
- slider & drag: int data passing through a float
436+
- drag float: up/down axis
434437
- text edit: clean up the mess caused by converting UTF-8 <> wchar. the code is rather inefficient right now.
435438
- text edit: centered text for slider as input text so it matches typical positioning.
436439
- text edit: flag to disable live update of the user buffer.
@@ -454,7 +457,6 @@
454457
- focus: SetKeyboardFocusHere() on with >= 0 offset could be done on same frame (else latch and modulate on beginning of next frame)
455458
- input: rework IO to be able to pass actual events to fix temporal aliasing issues.
456459
- input: support track pad style scrolling & slider edit.
457-
- portability: big-endian test/support (#81)
458460
- memory: add a way to discard allocs of unused/transient windows. with the current architecture new windows (including popup, opened combos, listbox) perform at least 3 allocs.
459461
- misc: mark printf compiler attributes on relevant functions
460462
- misc: provide a way to compile out the entire implementation while providing a dummy API (e.g. #define IMGUI_DUMMY_IMPL)
@@ -558,10 +560,14 @@ static ImGuiWindow* GetFrontMostModalRootWindow();
558560
static ImVec2 FindBestPopupWindowPos(const ImVec2& base_pos, const ImVec2& size, ImGuiWindowFlags flags, int* last_dir, const ImRect& r_inner);
559561

560562
static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback, void* user_data);
561-
static void InputTextApplyArithmeticOp(const char* buf, const char* initial_value_buf, float *v);
562563
static int InputTextCalcTextLenAndLineCount(const char* text_begin, const char** out_text_end);
563564
static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL, ImVec2* out_offset = NULL, bool stop_on_new_line = false);
564565

566+
static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr, const char* display_format, char* buf, int buf_size);
567+
static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr, int decimal_precision, char* buf, int buf_size);
568+
static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* value1, const void* value2);
569+
static void DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* data_ptr, const char* scalar_format);
570+
565571
//-----------------------------------------------------------------------------
566572
// Platform dependent default implementations
567573
//-----------------------------------------------------------------------------
@@ -5545,12 +5551,6 @@ ImGuiID ImGui::GetID(const void* ptr_id)
55455551
return GImGui->CurrentWindow->GetID(ptr_id);
55465552
}
55475553

5548-
enum ImGuiDataTypeOp
5549-
{
5550-
ImGuiDataTypeOp_Add,
5551-
ImGuiDataTypeOp_Sub
5552-
};
5553-
55545554
static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr, const char* display_format, char* buf, int buf_size)
55555555
{
55565556
if (data_type == ImGuiDataType_Int)
@@ -5577,20 +5577,20 @@ static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr,
55775577
}
55785578
}
55795579

5580-
static void DataTypeApplyOp(ImGuiDataType data_type, ImGuiDataTypeOp op, void* value1, const void* value2)// Store into value1
5580+
static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* value1, const void* value2)// Store into value1
55815581
{
55825582
if (data_type == ImGuiDataType_Int)
55835583
{
5584-
if (op == ImGuiDataTypeOp_Add)
5584+
if (op == '+')
55855585
*(int*)value1 = *(int*)value1 + *(const int*)value2;
5586-
else if (op == ImGuiDataTypeOp_Sub)
5586+
else if (op == '-')
55875587
*(int*)value1 = *(int*)value1 - *(const int*)value2;
55885588
}
55895589
else if (data_type == ImGuiDataType_Float)
55905590
{
5591-
if (op == ImGuiDataTypeOp_Add)
5591+
if (op == '+')
55925592
*(float*)value1 = *(float*)value1 + *(const float*)value2;
5593-
else if (op == ImGuiDataTypeOp_Sub)
5593+
else if (op == '-')
55945594
*(float*)value1 = *(float*)value1 - *(const float*)value2;
55955595
}
55965596
}
@@ -7412,13 +7412,13 @@ bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data
74127412
ImGui::SameLine(0, style.ItemInnerSpacing.x);
74137413
if (ButtonEx("-", button_sz, ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups))
74147414
{
7415-
DataTypeApplyOp(data_type, ImGuiDataTypeOp_Sub, data_ptr, g.IO.KeyCtrl && step_fast_ptr ? step_fast_ptr : step_ptr);
7415+
DataTypeApplyOp(data_type, '-', data_ptr, g.IO.KeyCtrl && step_fast_ptr ? step_fast_ptr : step_ptr);
74167416
value_changed = true;
74177417
}
74187418
ImGui::SameLine(0, style.ItemInnerSpacing.x);
74197419
if (ButtonEx("+", button_sz, ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups))
74207420
{
7421-
DataTypeApplyOp(data_type, ImGuiDataTypeOp_Add, data_ptr, g.IO.KeyCtrl && step_fast_ptr ? step_fast_ptr : step_ptr);
7421+
DataTypeApplyOp(data_type, '+', data_ptr, g.IO.KeyCtrl && step_fast_ptr ? step_fast_ptr : step_ptr);
74227422
value_changed = true;
74237423
}
74247424
}

0 commit comments

Comments
 (0)