ui: add typed editor field foundations
This commit is contained in:
35
new_editor/include/XCEditor/Widgets/UIEditorTextLayout.h
Normal file
35
new_editor/include/XCEditor/Widgets/UIEditorTextLayout.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace XCEngine::UI::Editor::Widgets {
|
||||
|
||||
inline float MeasureUIEditorTextLayoutHeight(float fontSize) {
|
||||
return (std::max)(0.0f, fontSize * 1.35f);
|
||||
}
|
||||
|
||||
inline float ResolveUIEditorTextTop(
|
||||
const ::XCEngine::UI::UIRect& rect,
|
||||
float fontSize,
|
||||
float offsetY = 0.0f) {
|
||||
const float textHeight = MeasureUIEditorTextLayoutHeight(fontSize);
|
||||
const float centeredTop =
|
||||
rect.y + (std::max)(0.0f, std::floor((rect.height - textHeight) * 0.5f));
|
||||
return centeredTop - 1.0f + offsetY;
|
||||
}
|
||||
|
||||
inline ::XCEngine::UI::UIRect ResolveUIEditorTextClipRect(
|
||||
const ::XCEngine::UI::UIRect& rect,
|
||||
float fontSize) {
|
||||
const float extraPadding = (std::max)(2.0f, std::ceil(fontSize * 0.35f));
|
||||
return ::XCEngine::UI::UIRect(
|
||||
rect.x,
|
||||
rect.y - 1.0f,
|
||||
rect.width,
|
||||
rect.height + extraPadding + 1.0f);
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::Widgets
|
||||
Reference in New Issue
Block a user