Changing how string format for imgui float widgets work, suppressing stbi warnings
This commit is contained in:
		
							
								
								
									
										40
									
								
								src/COMMON.h
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								src/COMMON.h
									
									
									
									
									
								
							@@ -128,6 +128,46 @@ static inline std::string string_quote(const std::string& string)
 | 
				
			|||||||
    return "\"" + string + "\"";
 | 
					    return "\"" + string + "\"";
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define FLOAT_FORMAT_MAX_DECIMALS 2
 | 
				
			||||||
 | 
					#define FLOAT_FORMAT_EPSILON 1e-6f
 | 
				
			||||||
 | 
					static constexpr f32 FLOAT_FORMAT_POW10[] = {1.f, 10.f, 100.f};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline s32 f32_decimals_needed(f32 value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    f32 integerPart = 0.f;
 | 
				
			||||||
 | 
					    f32 fractionalPart = modff(value, &integerPart);
 | 
				
			||||||
 | 
					    fractionalPart = fabsf(fractionalPart);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (fractionalPart < FLOAT_FORMAT_EPSILON)
 | 
				
			||||||
 | 
					        return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (s32 decimalCount = 1; decimalCount <= FLOAT_FORMAT_MAX_DECIMALS; ++decimalCount)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        f32 scaledFraction = fractionalPart * FLOAT_FORMAT_POW10[decimalCount];
 | 
				
			||||||
 | 
					        if (fabsf(scaledFraction - roundf(scaledFraction)) < FLOAT_FORMAT_EPSILON * FLOAT_FORMAT_POW10[decimalCount])
 | 
				
			||||||
 | 
					            return decimalCount;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return FLOAT_FORMAT_MAX_DECIMALS;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline const char* f32_format_get(f32 value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    static std::string formatString;
 | 
				
			||||||
 | 
					    const s32 decimalCount = f32_decimals_needed(value);
 | 
				
			||||||
 | 
					    formatString = (decimalCount == 0) ? "%.0f" : ("%." + std::to_string(decimalCount) + "f");
 | 
				
			||||||
 | 
					    return formatString.c_str();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline const char* vec2_format_get(const vec2& value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    static std::string formatString;
 | 
				
			||||||
 | 
					    const s32 decimalCountX = f32_decimals_needed(value.x);
 | 
				
			||||||
 | 
					    const s32 decimalCountY = f32_decimals_needed(value.y);
 | 
				
			||||||
 | 
					    const s32 decimalCount = (decimalCountX > decimalCountY) ? decimalCountX : decimalCountY;
 | 
				
			||||||
 | 
					    formatString = (decimalCount == 0) ? "%.0f" : ("%." + std::to_string(decimalCount) + "f");
 | 
				
			||||||
 | 
					    return formatString.c_str();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline std::string path_canonical_resolve
 | 
					static inline std::string path_canonical_resolve
 | 
				
			||||||
(
 | 
					(
 | 
				
			||||||
    const std::string& inputPath,
 | 
					    const std::string& inputPath,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -389,12 +389,12 @@ IMGUI_ITEM_FUNCTION(_imgui_selectable, IMGUI_SELECTABLE, ImGui::Selectable(self.
 | 
				
			|||||||
IMGUI_ITEM_VALUE_FUNCTION(_imgui_radio_button, IMGUI_RADIO_BUTTON, s32, ImGui::RadioButton(self.label_get(), &value, self.value));
 | 
					IMGUI_ITEM_VALUE_FUNCTION(_imgui_radio_button, IMGUI_RADIO_BUTTON, s32, ImGui::RadioButton(self.label_get(), &value, self.value));
 | 
				
			||||||
IMGUI_ITEM_VALUE_FUNCTION(_imgui_color_button, IMGUI_COLOR_BUTTON, vec4, ImGui::ColorButton(self.label_get(), ImVec4(value), self.flags));
 | 
					IMGUI_ITEM_VALUE_FUNCTION(_imgui_color_button, IMGUI_COLOR_BUTTON, vec4, ImGui::ColorButton(self.label_get(), ImVec4(value), self.flags));
 | 
				
			||||||
IMGUI_ITEM_VALUE_FUNCTION(_imgui_checkbox, IMGUI_CHECKBOX, bool, ImGui::Checkbox(self.label_get(), &value));
 | 
					IMGUI_ITEM_VALUE_FUNCTION(_imgui_checkbox, IMGUI_CHECKBOX, bool, ImGui::Checkbox(self.label_get(), &value));
 | 
				
			||||||
IMGUI_ITEM_VALUE_CLAMP_FUNCTION(_imgui_input_int, IMGUI_INPUT_INT, s32, ImGui::InputInt(self.label.c_str(), &value, self.step, self.stepFast, self.flags));
 | 
					IMGUI_ITEM_VALUE_CLAMP_FUNCTION(_imgui_input_int, IMGUI_INPUT_INT, s32, ImGui::InputInt(self.label_get(), &value, self.step, self.stepFast, self.flags));
 | 
				
			||||||
IMGUI_ITEM_VALUE_CLAMP_FUNCTION(_imgui_input_int2, IMGUI_INPUT_INT, ivec2, ImGui::InputInt2(self.label.c_str(), value_ptr(value), self.flags));
 | 
					IMGUI_ITEM_VALUE_CLAMP_FUNCTION(_imgui_input_int2, IMGUI_INPUT_INT, ivec2, ImGui::InputInt2(self.label_get(), value_ptr(value), self.flags));
 | 
				
			||||||
IMGUI_ITEM_VALUE_CLAMP_FUNCTION(_imgui_input_float, IMGUI_INPUT_FLOAT, f32, ImGui::InputFloat(self.label.c_str(), &value, self.step, self.stepFast, self.format_get(), self.flags));
 | 
					IMGUI_ITEM_VALUE_CLAMP_FUNCTION(_imgui_input_float, IMGUI_INPUT_FLOAT, f32, ImGui::InputFloat(self.label_get(), &value, self.step, self.stepFast, f32_format_get(value), self.flags));
 | 
				
			||||||
IMGUI_ITEM_VALUE_FUNCTION(_imgui_slider_float, IMGUI_SLIDER_FLOAT, f32, ImGui::SliderFloat(self.label_get(), &value, self.min, self.max, self.format_get(), self.flags));
 | 
					IMGUI_ITEM_VALUE_FUNCTION(_imgui_slider_float, IMGUI_SLIDER_FLOAT, f32, ImGui::SliderFloat(self.label_get(), &value, self.min, self.max, f32_format_get(value), self.flags));
 | 
				
			||||||
IMGUI_ITEM_VALUE_FUNCTION(_imgui_drag_float, IMGUI_DRAG_FLOAT, f32, ImGui::DragFloat(self.label_get(), &value, self.speed, self.min, self.max, self.format_get()));
 | 
					IMGUI_ITEM_VALUE_FUNCTION(_imgui_drag_float, IMGUI_DRAG_FLOAT, f32, ImGui::DragFloat(self.label_get(), &value, self.speed, self.min, self.max, f32_format_get(value)));
 | 
				
			||||||
IMGUI_ITEM_VALUE_FUNCTION(_imgui_drag_float2, IMGUI_DRAG_FLOAT, vec2, ImGui::DragFloat2(self.label_get(), value_ptr(value), self.speed, self.min, self.max, self.format_get()));
 | 
					IMGUI_ITEM_VALUE_FUNCTION(_imgui_drag_float2, IMGUI_DRAG_FLOAT, vec2, ImGui::DragFloat2(self.label_get(), value_ptr(value), self.speed, self.min, self.max, vec2_format_get(value)));
 | 
				
			||||||
IMGUI_ITEM_VALUE_FUNCTION(_imgui_color_edit3, IMGUI_COLOR_EDIT, vec3, ImGui::ColorEdit3(self.label_get(), value_ptr(value), self.flags));
 | 
					IMGUI_ITEM_VALUE_FUNCTION(_imgui_color_edit3, IMGUI_COLOR_EDIT, vec3, ImGui::ColorEdit3(self.label_get(), value_ptr(value), self.flags));
 | 
				
			||||||
IMGUI_ITEM_VALUE_FUNCTION(_imgui_color_edit4, IMGUI_COLOR_EDIT, vec4, ImGui::ColorEdit4(self.label_get(), value_ptr(value), self.flags));
 | 
					IMGUI_ITEM_VALUE_FUNCTION(_imgui_color_edit4, IMGUI_COLOR_EDIT, vec4, ImGui::ColorEdit4(self.label_get(), value_ptr(value), self.flags));
 | 
				
			||||||
IMGUI_ITEM_CHECKBOX_FUNCTION(_imgui_checkbox_selectable, _imgui_selectable(self, imgui));
 | 
					IMGUI_ITEM_CHECKBOX_FUNCTION(_imgui_checkbox_selectable, _imgui_selectable(self, imgui));
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										27
									
								
								src/imgui.h
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/imgui.h
									
									
									
									
									
								
							@@ -466,7 +466,6 @@ struct ImguiItem
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    std::string label{};
 | 
					    std::string label{};
 | 
				
			||||||
    std::string tooltip{};
 | 
					    std::string tooltip{};
 | 
				
			||||||
    std::string format{};
 | 
					 | 
				
			||||||
    std::string& text = tooltip;
 | 
					    std::string& text = tooltip;
 | 
				
			||||||
    std::string undoAction{};
 | 
					    std::string undoAction{};
 | 
				
			||||||
    std::string popup{};
 | 
					    std::string popup{};
 | 
				
			||||||
@@ -548,11 +547,7 @@ struct ImguiItem
 | 
				
			|||||||
    ImguiItem copy(const ImguiItemOverride& override) const
 | 
					    ImguiItem copy(const ImguiItemOverride& override) const
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ImguiItem out = *this;
 | 
					        ImguiItem out = *this;
 | 
				
			||||||
        if (override.isDisabled) 
 | 
					        if (override.isDisabled) out.isDisabled = override.isDisabled;
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            out.isDisabled = override.isDisabled;
 | 
					 | 
				
			||||||
            out.format.clear();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        if(override.isSelected) out.isSelected = override.isSelected;
 | 
					        if(override.isSelected) out.isSelected = override.isSelected;
 | 
				
			||||||
        if (is_popup() && imgui_is_popup_open(popup)) out.isSelected = true;
 | 
					        if (is_popup() && imgui_is_popup_open(popup)) out.isSelected = true;
 | 
				
			||||||
        if (id != ID_NONE) out.id = id + idOffset + override.id;
 | 
					        if (id != ID_NONE) out.id = id + idOffset + override.id;
 | 
				
			||||||
@@ -581,7 +576,6 @@ struct ImguiItem
 | 
				
			|||||||
    const char* drag_drop_get() const { return dragDrop.c_str(); }
 | 
					    const char* drag_drop_get() const { return dragDrop.c_str(); }
 | 
				
			||||||
    const char* tooltip_get() const { return tooltip.c_str(); }
 | 
					    const char* tooltip_get() const { return tooltip.c_str(); }
 | 
				
			||||||
    const char* text_get() const { return text.c_str(); }
 | 
					    const char* text_get() const { return text.c_str(); }
 | 
				
			||||||
    const char* format_get() const { return format.c_str(); }
 | 
					 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define IMGUI_ITEM(NAME, ...) const inline ImguiItem NAME = []{ ImguiItem self; __VA_ARGS__; self.construct(); return self; }()
 | 
					#define IMGUI_ITEM(NAME, ...) const inline ImguiItem NAME = []{ ImguiItem self; __VA_ARGS__; self.construct(); return self; }()
 | 
				
			||||||
@@ -888,7 +882,6 @@ IMGUI_ITEM(IMGUI_SCALE_ANM2_OPTIONS_CHILD,
 | 
				
			|||||||
IMGUI_ITEM(IMGUI_SCALE_ANM2_VALUE,
 | 
					IMGUI_ITEM(IMGUI_SCALE_ANM2_VALUE,
 | 
				
			||||||
    self.label = "Value",
 | 
					    self.label = "Value",
 | 
				
			||||||
    self.tooltip = "The size and position-related frame properties in the anm2 will be scaled by this value.",
 | 
					    self.tooltip = "The size and position-related frame properties in the anm2 will be scaled by this value.",
 | 
				
			||||||
    self.format = "%.2f",
 | 
					 | 
				
			||||||
    self.value = 1,
 | 
					    self.value = 1,
 | 
				
			||||||
    self.step = 0.25,
 | 
					    self.step = 0.25,
 | 
				
			||||||
    self.stepFast = 1
 | 
					    self.stepFast = 1
 | 
				
			||||||
@@ -1277,7 +1270,6 @@ IMGUI_ITEM(IMGUI_CANVAS_VIEW_CHILD,
 | 
				
			|||||||
IMGUI_ITEM(IMGUI_CANVAS_ZOOM, 
 | 
					IMGUI_ITEM(IMGUI_CANVAS_ZOOM, 
 | 
				
			||||||
    self.label = "Zoom",
 | 
					    self.label = "Zoom",
 | 
				
			||||||
    self.tooltip = "Change the zoom of the canvas.",
 | 
					    self.tooltip = "Change the zoom of the canvas.",
 | 
				
			||||||
    self.format = "%.0f",
 | 
					 | 
				
			||||||
    self.min = CANVAS_ZOOM_MIN,
 | 
					    self.min = CANVAS_ZOOM_MIN,
 | 
				
			||||||
    self.max = CANVAS_ZOOM_MAX,
 | 
					    self.max = CANVAS_ZOOM_MAX,
 | 
				
			||||||
    self.value = CANVAS_ZOOM_DEFAULT
 | 
					    self.value = CANVAS_ZOOM_DEFAULT
 | 
				
			||||||
@@ -1309,7 +1301,6 @@ IMGUI_ITEM(IMGUI_CANVAS_ANIMATION_OVERLAY,
 | 
				
			|||||||
IMGUI_ITEM(IMGUI_CANVAS_ANIMATION_OVERLAY_TRANSPARENCY,
 | 
					IMGUI_ITEM(IMGUI_CANVAS_ANIMATION_OVERLAY_TRANSPARENCY,
 | 
				
			||||||
    self.label = "Alpha",
 | 
					    self.label = "Alpha",
 | 
				
			||||||
    self.tooltip = "Set the transparency of the animation overlay.",
 | 
					    self.tooltip = "Set the transparency of the animation overlay.",
 | 
				
			||||||
    self.format = "%.0f",
 | 
					 | 
				
			||||||
    self.value = 255,
 | 
					    self.value = 255,
 | 
				
			||||||
    self.max = 255
 | 
					    self.max = 255
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
@@ -1374,39 +1365,34 @@ IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_POSITION,
 | 
				
			|||||||
    self.label = "Position",
 | 
					    self.label = "Position",
 | 
				
			||||||
    self.tooltip = "Change the position of the selected frame.",
 | 
					    self.tooltip = "Change the position of the selected frame.",
 | 
				
			||||||
    self.undoAction = "Frame Position",
 | 
					    self.undoAction = "Frame Position",
 | 
				
			||||||
    self.isUseItemActivated = true,
 | 
					    self.isUseItemActivated = true
 | 
				
			||||||
    self.format = "%.0f"
 | 
					 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_CROP,
 | 
					IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_CROP,
 | 
				
			||||||
    self.label = "Crop",
 | 
					    self.label = "Crop",
 | 
				
			||||||
    self.tooltip = "Change the crop position of the selected frame.",
 | 
					    self.tooltip = "Change the crop position of the selected frame.",
 | 
				
			||||||
    self.undoAction = "Frame Crop",
 | 
					    self.undoAction = "Frame Crop",
 | 
				
			||||||
    self.isUseItemActivated = true,
 | 
					    self.isUseItemActivated = true
 | 
				
			||||||
    self.format = "%.0f"
 | 
					 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_SIZE,
 | 
					IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_SIZE,
 | 
				
			||||||
    self.label = "Size",
 | 
					    self.label = "Size",
 | 
				
			||||||
    self.tooltip = "Change the size of the crop of the selected frame.",
 | 
					    self.tooltip = "Change the size of the crop of the selected frame.",
 | 
				
			||||||
    self.undoAction = "Frame Size",
 | 
					    self.undoAction = "Frame Size",
 | 
				
			||||||
    self.isUseItemActivated = true,
 | 
					    self.isUseItemActivated = true
 | 
				
			||||||
    self.format = "%.0f"
 | 
					 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_PIVOT,
 | 
					IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_PIVOT,
 | 
				
			||||||
    self.label = "Pivot",
 | 
					    self.label = "Pivot",
 | 
				
			||||||
    self.tooltip = "Change the pivot of the selected frame.",
 | 
					    self.tooltip = "Change the pivot of the selected frame.",
 | 
				
			||||||
    self.undoAction = "Frame Pivot",
 | 
					    self.undoAction = "Frame Pivot",
 | 
				
			||||||
    self.isUseItemActivated = true,
 | 
					    self.isUseItemActivated = true
 | 
				
			||||||
    self.format = "%.0f"
 | 
					 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_SCALE,
 | 
					IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_SCALE,
 | 
				
			||||||
    self.label = "Scale",
 | 
					    self.label = "Scale",
 | 
				
			||||||
    self.tooltip = "Change the scale of the selected frame.",
 | 
					    self.tooltip = "Change the scale of the selected frame.",
 | 
				
			||||||
    self.undoAction = "Frame Scale",
 | 
					    self.undoAction = "Frame Scale",
 | 
				
			||||||
    self.format = "%.0f",
 | 
					 | 
				
			||||||
    self.isUseItemActivated = true,
 | 
					    self.isUseItemActivated = true,
 | 
				
			||||||
    self.value = 100
 | 
					    self.value = 100
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
@@ -1415,8 +1401,7 @@ IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_ROTATION,
 | 
				
			|||||||
    self.label = "Rotation",
 | 
					    self.label = "Rotation",
 | 
				
			||||||
    self.tooltip = "Change the rotation of the selected frame.",
 | 
					    self.tooltip = "Change the rotation of the selected frame.",
 | 
				
			||||||
    self.undoAction = "Frame Rotation",
 | 
					    self.undoAction = "Frame Rotation",
 | 
				
			||||||
    self.isUseItemActivated = true,
 | 
					    self.isUseItemActivated = true
 | 
				
			||||||
    self.format = "%.0f"
 | 
					 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_DELAY,
 | 
					IMGUI_ITEM(IMGUI_FRAME_PROPERTIES_DELAY,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,10 @@
 | 
				
			|||||||
 | 
					#if defined(__clang__) || defined(__GNUC__)
 | 
				
			||||||
 | 
					  #pragma GCC diagnostic push
 | 
				
			||||||
 | 
					  #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
 | 
				
			||||||
 | 
					  #pragma GCC diagnostic ignored "-Wunused-function"
 | 
				
			||||||
 | 
					  #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "texture.h"
 | 
					#include "texture.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define STBI_ONLY_PNG  
 | 
					#define STBI_ONLY_PNG  
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user