Add default image provider

This commit is contained in:
Nikita Lisitsa 2022-12-19 09:52:02 +03:00
parent 852a170c97
commit c1699fe882
3 changed files with 31 additions and 1 deletions

View file

@ -0,0 +1,30 @@
#pragma once
#include <psemek/ui/image_provider.hpp>
#include <psemek/util/hstring.hpp>
#include <unordered_map>
namespace psemek::ui
{
struct default_image_provider
: image_provider
{
void put(std::string id, gfx::texture_view_2d view)
{
images_[std::move(id)] = view;
}
gfx::texture_view_2d get(std::string_view const & id) const override
{
if (auto it = images_.find(id); it != images_.end())
return it->second;
return {};
}
private:
std::unordered_map<util::hstring, gfx::texture_view_2d> images_;
};
}

View file

@ -9,7 +9,7 @@ namespace psemek::ui
struct image_provider
{
virtual gfx::texture_view_2d get(std::string_view const & id) = 0;
virtual gfx::texture_view_2d get(std::string_view const & id) const = 0;
virtual ~ image_provider() {}
};