Remove redundant lambda, use initializer, add nodiscard
This commit is contained in:
@@ -42,27 +42,23 @@ namespace OpenVulkano::Scene
|
||||
Shader TextDrawable::DEFAULT_SHADER_SDF = MakeDefaultShader("sdfText", "sdfText");
|
||||
Shader TextDrawable::DEFAULT_SHADER_MSDF = MakeDefaultShader("sdfText", "msdfText");
|
||||
|
||||
TextDrawable::TextDrawable(const TextConfig& config)
|
||||
TextDrawable::TextDrawable(const TextConfig& config) : m_cfg(config)
|
||||
{
|
||||
m_cfg = config;
|
||||
m_uniBuffer.Init(sizeof(TextConfig), &m_cfg, 3);
|
||||
m_uniBuffer.binding.stageFlags = ShaderProgramType::FRAGMENT;
|
||||
}
|
||||
|
||||
TextDrawable::TextDrawable(const Array<char>& atlasMetadata, const TextConfig& config)
|
||||
: TextDrawable(atlasMetadata, nullptr, config)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
TextDrawable::TextDrawable(const std::string& atlasMetadataFile, const TextConfig& config)
|
||||
: TextDrawable(Utils::ReadFile(atlasMetadataFile), nullptr, config)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
TextDrawable::TextDrawable(const std::string& atlasMetadataFile, Texture* atlasTex, const TextConfig& config)
|
||||
: TextDrawable(Utils::ReadFile(atlasMetadataFile), atlasTex, config)
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
TextDrawable::TextDrawable(const Array<char>& atlasMetadata, Texture* atlasTex, const TextConfig& config)
|
||||
{
|
||||
@@ -130,27 +126,11 @@ namespace OpenVulkano::Scene
|
||||
|
||||
void TextDrawable::GenerateText(const std::string& text, const Math::Vector3f& pos)
|
||||
{
|
||||
if (text.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (text.empty()) return;
|
||||
|
||||
m_text = text;
|
||||
auto GetActualLength = [&]()
|
||||
{
|
||||
auto begin = text.begin();
|
||||
auto end = text.end();
|
||||
size_t len = 0;
|
||||
while (begin != end)
|
||||
{
|
||||
uint32_t c = utf8::next(begin, end);
|
||||
if (c == '\n') continue;
|
||||
++len;
|
||||
}
|
||||
return len;
|
||||
};
|
||||
|
||||
size_t len = GetActualLength();
|
||||
size_t len = utf8::distance(text.begin(), text.end());
|
||||
m_geometry.Close();
|
||||
m_geometry.Init(len * 4, len * 6);
|
||||
AtlasMetadata* meta;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
|
||||
class IFontAtlasGenerator;
|
||||
|
||||
struct TextConfig
|
||||
@@ -48,10 +47,11 @@ namespace OpenVulkano::Scene
|
||||
void GenerateText(const std::string& text, const Math::Vector3f& pos = Math::Vector3f(0.f));
|
||||
void SetConfig(const TextConfig& cfg) { m_cfg = cfg; }
|
||||
void SetAtlasData(const std::shared_ptr<AtlasData>& atlasData);
|
||||
Math::AABB& GetBoundingBox() { return m_bbox; }
|
||||
TextConfig& GetConfig() { return m_cfg; }
|
||||
[[nodiscard]] Math::AABB& GetBoundingBox() { return m_bbox; }
|
||||
[[nodiscard]] TextConfig& GetConfig() { return m_cfg; }
|
||||
[[nodiscard]] const std::string& GetText() const { return m_text; }
|
||||
std::shared_ptr<AtlasData> GetAtlasData() { return m_atlasData; }
|
||||
[[nodiscard]] const std::shared_ptr<AtlasData> GetAtlasData() { return m_atlasData; }
|
||||
|
||||
private:
|
||||
Geometry m_geometry;
|
||||
Material m_material;
|
||||
|
||||
Reference in New Issue
Block a user