mirror of https://gitlab.com/cppit/jucipp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.5 KiB
77 lines
2.5 KiB
|
8 years ago
|
#pragma once
|
||
|
8 years ago
|
#include <functional>
|
||
|
6 years ago
|
#include <gtkmm.h>
|
||
|
8 years ago
|
#include <list>
|
||
|
8 years ago
|
#include <set>
|
||
|
8 years ago
|
#include <string>
|
||
|
6 years ago
|
#include <unordered_map>
|
||
|
11 years ago
|
|
||
|
11 years ago
|
class Tooltip {
|
||
|
11 years ago
|
public:
|
||
|
6 years ago
|
Tooltip(Gtk::TextView *text_view, Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark_, Glib::RefPtr<Gtk::TextBuffer::Mark> end_mark_, std::function<void(Tooltip &)> set_buffer_);
|
||
|
|
Tooltip(std::function<void(Tooltip &tooltip)> set_buffer_) : Tooltip(nullptr, Glib::RefPtr<Gtk::TextBuffer::Mark>(), Glib::RefPtr<Gtk::TextBuffer::Mark>(), std::move(set_buffer_)) {}
|
||
|
11 years ago
|
~Tooltip();
|
||
|
8 years ago
|
|
||
|
11 years ago
|
void update();
|
||
|
8 years ago
|
void show(bool disregard_drawn = false, const std::function<void()> &on_motion = nullptr);
|
||
|
8 years ago
|
void hide(const std::pair<int, int> &last_mouse_pos = {-1, -1}, const std::pair<int, int> &mouse_pos = {-1, -1});
|
||
|
8 years ago
|
|
||
|
11 years ago
|
Gdk::Rectangle activation_rectangle;
|
||
|
10 years ago
|
Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark;
|
||
|
|
Glib::RefPtr<Gtk::TextBuffer::Mark> end_mark;
|
||
|
8 years ago
|
|
||
|
6 years ago
|
Glib::RefPtr<Gtk::TextBuffer> buffer;
|
||
|
|
|
||
|
|
void insert_with_links_tagged(const std::string &text);
|
||
|
6 years ago
|
void insert_markdown(const std::string &text);
|
||
|
|
// Remove empty lines at end of buffer
|
||
|
|
void remove_trailing_newlines();
|
||
|
8 years ago
|
|
||
|
11 years ago
|
private:
|
||
|
10 years ago
|
std::unique_ptr<Gtk::Window> window;
|
||
|
8 years ago
|
void wrap_lines();
|
||
|
8 years ago
|
|
||
|
9 years ago
|
Gtk::TextView *text_view;
|
||
|
6 years ago
|
std::function<void(Tooltip &)> set_buffer;
|
||
|
10 years ago
|
std::pair<int, int> size;
|
||
|
8 years ago
|
Gdk::Rectangle rectangle;
|
||
|
8 years ago
|
|
||
|
|
bool shown = false;
|
||
|
7 years ago
|
|
||
|
|
Glib::RefPtr<Gtk::TextTag> link_tag;
|
||
|
6 years ago
|
Glib::RefPtr<Gtk::TextTag> h1_tag;
|
||
|
|
Glib::RefPtr<Gtk::TextTag> h2_tag;
|
||
|
|
Glib::RefPtr<Gtk::TextTag> h3_tag;
|
||
|
|
Glib::RefPtr<Gtk::TextTag> code_tag;
|
||
|
|
Glib::RefPtr<Gtk::TextTag> code_block_tag;
|
||
|
|
Glib::RefPtr<Gtk::TextTag> bold_tag;
|
||
|
|
Glib::RefPtr<Gtk::TextTag> italic_tag;
|
||
|
|
Glib::RefPtr<Gtk::TextTag> strikethrough_tag;
|
||
|
|
|
||
|
|
std::map<Glib::RefPtr<Gtk::TextTag>, std::string> links;
|
||
|
|
std::map<Glib::RefPtr<Gtk::TextTag>, std::string> reference_links;
|
||
|
|
std::unordered_map<std::string, std::string> references;
|
||
|
11 years ago
|
};
|
||
|
|
|
||
|
10 years ago
|
class Tooltips {
|
||
|
11 years ago
|
public:
|
||
|
8 years ago
|
static std::set<Tooltip *> shown_tooltips;
|
||
|
8 years ago
|
static Gdk::Rectangle drawn_tooltips_rectangle;
|
||
|
8 years ago
|
static void init() { drawn_tooltips_rectangle = Gdk::Rectangle(); }
|
||
|
|
|
||
|
|
void show(const Gdk::Rectangle &rectangle, bool disregard_drawn = false);
|
||
|
|
void show(bool disregard_drawn = false);
|
||
|
8 years ago
|
void hide(const std::pair<int, int> &last_mouse_pos = {-1, -1}, const std::pair<int, int> &mouse_pos = {-1, -1});
|
||
|
8 years ago
|
void clear() { tooltip_list.clear(); };
|
||
|
|
|
||
|
|
template <typename... Ts>
|
||
|
|
void emplace_back(Ts &&... params) {
|
||
|
10 years ago
|
tooltip_list.emplace_back(std::forward<Ts>(params)...);
|
||
|
10 years ago
|
}
|
||
|
8 years ago
|
|
||
|
8 years ago
|
std::function<void()> on_motion;
|
||
|
8 years ago
|
|
||
|
10 years ago
|
private:
|
||
|
10 years ago
|
std::list<Tooltip> tooltip_list;
|
||
|
11 years ago
|
};
|