40 lines
1019 B
C++
40 lines
1019 B
C++
#pragma once
|
|
|
|
#include <XCEditor/Foundation/UIEditorTextMeasurement.h>
|
|
|
|
#include <algorithm>
|
|
#include <string_view>
|
|
|
|
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<float>(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
|