diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-11-28 22:48:30 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-11-28 22:48:30 -0500 |
commit | e1703aea3fd597b23bde90e6c505278c517be611 (patch) | |
tree | 37d98fc90c9cd0844388bfb79beda2204f44af92 /src/components/completer.hpp | |
parent | fd53a76bf6f53a095a639765923a30f2206b2cd6 (diff) | |
parent | e02107feea8214a045e6faa969f00dcbc0d2b072 (diff) | |
download | abaddon-portaudio-e1703aea3fd597b23bde90e6c505278c517be611.tar.gz abaddon-portaudio-e1703aea3fd597b23bde90e6c505278c517be611.zip |
merge master
Diffstat (limited to 'src/components/completer.hpp')
-rw-r--r-- | src/components/completer.hpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/components/completer.hpp b/src/components/completer.hpp new file mode 100644 index 0000000..6bd8be9 --- /dev/null +++ b/src/components/completer.hpp @@ -0,0 +1,68 @@ +#pragma once +#include <gtkmm.h> +#include <functional> +#include "lazyimage.hpp" +#include "discord/snowflake.hpp" + +constexpr static int CompleterImageSize = 24; + +class CompleterEntry : public Gtk::ListBoxRow { +public: + CompleterEntry(const Glib::ustring &completion, int index); + void SetTextColor(int color); // SetText will reset + void SetText(const Glib::ustring &text); + void SetImage(const Glib::RefPtr<Gdk::Pixbuf> &pb); + void SetImage(const std::string &url); + void SetAnimation(const std::string &url); + + int GetIndex() const; + Glib::ustring GetCompletion() const; + +private: + void CheckImage(); + + Glib::ustring m_completion; + int m_index; + Gtk::Box m_box; + Gtk::Label *m_text = nullptr; + LazyImage *m_img = nullptr; +}; + +class Completer : public Gtk::Revealer { +public: + Completer(); + Completer(const Glib::RefPtr<Gtk::TextBuffer> &buf); + + void SetBuffer(const Glib::RefPtr<Gtk::TextBuffer> &buf); + bool ProcessKeyPress(GdkEventKey *e); + + using get_recent_authors_cb = std::function<std::vector<Snowflake>()>; + void SetGetRecentAuthors(get_recent_authors_cb cb); // maybe a better way idk + using get_channel_id_cb = std::function<Snowflake()>; + void SetGetChannelID(get_channel_id_cb cb); + + bool IsShown() const; + +private: + CompleterEntry *CreateEntry(const Glib::ustring &completion); + void CompleteMentions(const Glib::ustring &term); + void CompleteEmojis(const Glib::ustring &term); + void CompleteChannels(const Glib::ustring &term); + void DoCompletion(Gtk::ListBoxRow *row); + + std::vector<CompleterEntry *> m_entries; + + void OnRowActivate(Gtk::ListBoxRow *row); + void OnTextBufferChanged(); + Glib::ustring GetTerm(); + + Gtk::TextBuffer::iterator m_start; + Gtk::TextBuffer::iterator m_end; + + Gtk::ScrolledWindow m_scroll; + Gtk::ListBox m_list; + Glib::RefPtr<Gtk::TextBuffer> m_buf; + + get_recent_authors_cb m_recent_authors_cb; + get_channel_id_cb m_channel_id_cb; +}; |