Toast Engine
Loading...
Searching...
No Matches
color_scheme.hpp
Go to the documentation of this file.
1
8
9#pragma once
10#include <glm/glm.hpp>
11#include <optional>
12#include <string>
13#include <toast/assets/data.hpp>
14#include <toast/export.hpp>
15#include <unordered_map>
16
17namespace assets {
18
19class TOAST_API ColorScheme : public Data {
20public:
21 explicit ColorScheme(const toml::table& table, Handle<Schema> schema = {}) : Data(table, std::move(schema)) { }
22
23 [[nodiscard]]
24 auto type() const -> std::string_view override {
25 return "color_scheme";
26 }
27
28 void reload(const toml::table& table) override;
29
31 [[nodiscard]]
32 auto color(std::string_view name) const -> std::optional<glm::vec4>;
33
35 [[nodiscard]]
36 auto hex(std::string_view name) const -> std::optional<std::string>;
37
39 [[nodiscard]]
40 static auto toHex(glm::vec4 color) -> std::string;
41
42private:
43 void buildLookup() const;
44
45 mutable bool m_built = false;
46 mutable std::unordered_map<std::string, glm::vec4> m_lookup;
47};
48
49}
void reload(const toml::table &table) override
Re-parses the asset contents in place.
Definition color_scheme.cpp:10
static auto toHex(glm::vec4 color) -> std::string
Formats a color as RRGGBBAA.
Definition color_scheme.cpp:59
auto color(std::string_view name) const -> std::optional< glm::vec4 >
Looks a color up by name.
Definition color_scheme.cpp:42
auto hex(std::string_view name) const -> std::optional< std::string >
Same lookup returning a RRGGBBAA string.
Definition color_scheme.cpp:51
Type-safe smart pointer for assets.
Definition core_types.hpp:149
Typed data asset backed by schema-driven TOML.