#pragma once #include #include #include namespace XCEngine::UI::Editor { inline float ClampUIEditorNonNegative(float value) { return (std::max)(value, 0.0f); } inline float EstimateUIEditorSimpleTextWidth( std::string_view text, float estimatedGlyphWidth) { return static_cast(text.size()) * ClampUIEditorNonNegative(estimatedGlyphWidth); } inline float ResolveUIEditorMeasuredTextWidth( std::string_view text, float measuredWidth, float fontSize, float estimatedGlyphWidth, const UIEditorTextMeasurer* textMeasurer = nullptr) { if (measuredWidth > 0.0f) { return measuredWidth; } if (textMeasurer != nullptr && !text.empty() && fontSize > 0.0f) { return textMeasurer->MeasureTextWidth(UIEditorTextMeasureRequest { text, fontSize }); } return EstimateUIEditorSimpleTextWidth(text, estimatedGlyphWidth); } } // namespace XCEngine::UI::Editor