#include "ui/Icons.hpp" #include #include "core/Assets.hpp" #include "core/Log.hpp" namespace dp::ui { std::string Icons::resolve(const std::string& symbol) { static const std::map kMap = { {"checkmark", "check"}, {"chevron.up.chevron.down", "chevrons-up-down"}, {"xmark", "x"}, {"trash", "trash"}, {"bubble.left.and.bubble.right", "messages-square"}, {"arrow.clockwise", "rotate-cw"}, {"text.bubble", "message-square-text"}, {"plus", "plus"}, {"pencil", "pencil"}, {"paperplane.fill", "send"}, {"paperclip", "paperclip"}, {"flag", "flag"}, {"chart.bar.yaxis", "chart-bar"}, {"bell.slash", "bell-off"}, {"arrowshape.turn.up.left", "reply"}, {"text.quote", "text-quote"}, {"selection.pin.in.out", "map-pin"}, {"plus.circle.fill", "circle-plus"}, {"plus.circle", "circle-plus"}, {"play.circle.fill", "circle-play"}, {"photo", "image"}, {"person", "user"}, {"minus.circle.fill", "circle-minus"}, {"minus.circle", "circle-minus"}, {"list.bullet.rectangle", "list"}, {"iphone.and.arrow.right.outward", "smartphone"}, {"gear", "settings"}, {"face.smiling", "face-slightly-smiling"}, {"exclamationmark.triangle", "triangle-exclamation-point"}, {"document.on.clipboard", "clipboard-copy"}, {"circle.lefthalf.filled", "contrast"}, {"chevron.down", "chevron-down"}, {"chevron.up", "chevron-up"}, {"chevron.right", "chevron-right"}, {"chevron.left", "chevron-left"}, {"bubble.left", "message-square"}, {"bell", "bell"}, {"arrow.up", "arrow-up"}, {"arrow.down", "arrow-down"}, {"magnifyingglass", "search"}, {"ellipsis", "ellipsis"}, {"square.and.arrow.up", "share"}, {"doc.on.doc", "copy"}, {"link", "link"}, {"eye", "eye"}, {"eye.slash", "eye-off"}, {"lock", "lock"}, {"heart", "heart"}, {"bookmark", "bookmark"}, {"checkmark.circle", "circle-check"}, {"xmark.circle", "circle-x"}, {"info.circle", "info"}, {"textformat.characters.arrow.left.and.right", "square-dashed"}, {"hand.raised", "hand"}, {"leaf", "leaf"}, {"fork.knife", "utensils"}, {"figure.run", "activity"}, {"airplane", "plane"}, {"lightbulb", "lightbulb"}, {"number", "hash"}, {"film", "film"}, {"doc", "file"}, {"hand.thumbsup", "thumbs-up"}, {"hand.thumbsdown", "thumbs-down"}, }; auto it = kMap.find(symbol); return it == kMap.end() ? symbol : it->second; } BitmapPtr Icons::get(const std::string& name, int px) { const std::string file = resolve(name); const std::string key = file + "@" + std::to_string(px); auto it = cache_.find(key); if (it != cache_.end()) return it->second; std::string svg; BitmapPtr bmp; if (Assets::readFile(Assets::path("icons/" + file + ".svg"), svg, 64 * 1024)) { for (std::size_t pos = svg.find("currentColor"); pos != std::string::npos; pos = svg.find("currentColor", pos)) { svg.replace(pos, 12, "#000000"); } bmp = Bitmap::decode(svg, px); } else { Log::warn("icon missing: " + file); } if (cache_.size() > 2000) cache_.clear(); cache_[key] = bmp; return bmp; } } // namespace dp::ui