put tooltips on reactions
This commit is contained in:
@@ -475,6 +475,10 @@ Gtk::Widget *ChatMessageItemContainer::CreateReactionsComponent(const Message &d
|
|||||||
|
|
||||||
// image
|
// image
|
||||||
if (is_stock) { // unicode/stock
|
if (is_stock) { // unicode/stock
|
||||||
|
const auto shortcode = emojis.GetShortCodeForPattern(reaction.Emoji.Name);
|
||||||
|
if (shortcode != "")
|
||||||
|
ev->set_tooltip_text(shortcode);
|
||||||
|
|
||||||
const auto &pb = emojis.GetPixBuf(reaction.Emoji.Name);
|
const auto &pb = emojis.GetPixBuf(reaction.Emoji.Name);
|
||||||
Gtk::Image *img;
|
Gtk::Image *img;
|
||||||
if (pb)
|
if (pb)
|
||||||
@@ -484,6 +488,8 @@ Gtk::Widget *ChatMessageItemContainer::CreateReactionsComponent(const Message &d
|
|||||||
img->set_can_focus(false);
|
img->set_can_focus(false);
|
||||||
box->add(*img);
|
box->add(*img);
|
||||||
} else { // custom
|
} else { // custom
|
||||||
|
ev->set_tooltip_text(reaction.Emoji.Name);
|
||||||
|
|
||||||
auto img = Gtk::manage(new LazyImage(reaction.Emoji.GetURL(), 16, 16));
|
auto img = Gtk::manage(new LazyImage(reaction.Emoji.GetURL(), 16, 16));
|
||||||
img->set_can_focus(false);
|
img->set_can_focus(false);
|
||||||
box->add(*img);
|
box->add(*img);
|
||||||
|
@@ -25,6 +25,7 @@ bool EmojiResource::Load() {
|
|||||||
if (shortcode_strlen > 0) {
|
if (shortcode_strlen > 0) {
|
||||||
std::fread(shortcode.data(), shortcode_strlen, 1, m_fp);
|
std::fread(shortcode.data(), shortcode_strlen, 1, m_fp);
|
||||||
m_shortcode_index[shortcode] = pattern_hex;
|
m_shortcode_index[shortcode] = pattern_hex;
|
||||||
|
m_pattern_shortcode_index[pattern_hex] = shortcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::fread(&len, 4, 1, m_fp);
|
std::fread(&len, 4, 1, m_fp);
|
||||||
@@ -120,6 +121,13 @@ void EmojiResource::ReplaceEmojis(Glib::RefPtr<Gtk::TextBuffer> buf, int size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string EmojiResource::GetShortCodeForPattern(const Glib::ustring &pattern) {
|
||||||
|
auto it = m_pattern_shortcode_index.find(pattern);
|
||||||
|
if (it != m_pattern_shortcode_index.end())
|
||||||
|
return it->second;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<Glib::ustring> &EmojiResource::GetPatterns() const {
|
const std::vector<Glib::ustring> &EmojiResource::GetPatterns() const {
|
||||||
return m_patterns;
|
return m_patterns;
|
||||||
}
|
}
|
||||||
|
@@ -17,8 +17,10 @@ public:
|
|||||||
const std::vector<Glib::ustring> &GetPatterns() const;
|
const std::vector<Glib::ustring> &GetPatterns() const;
|
||||||
const std::map<std::string, std::string> &GetShortCodes() const;
|
const std::map<std::string, std::string> &GetShortCodes() const;
|
||||||
void ReplaceEmojis(Glib::RefPtr<Gtk::TextBuffer> buf, int size = 24);
|
void ReplaceEmojis(Glib::RefPtr<Gtk::TextBuffer> buf, int size = 24);
|
||||||
|
std::string GetShortCodeForPattern(const Glib::ustring &pattern);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::unordered_map<std::string, std::string> m_pattern_shortcode_index;
|
||||||
std::map<std::string, std::string> m_shortcode_index; // shortcode -> pattern
|
std::map<std::string, std::string> m_shortcode_index; // shortcode -> pattern
|
||||||
std::unordered_map<std::string, std::pair<int, int>> m_index; // pattern -> [pos, len]
|
std::unordered_map<std::string, std::pair<int, int>> m_index; // pattern -> [pos, len]
|
||||||
FILE *m_fp = nullptr;
|
FILE *m_fp = nullptr;
|
||||||
|
Reference in New Issue
Block a user