Browse Source

Now draws markdown lines in tooltips

master
eidheim 1 month ago
parent
commit
c2eedbfce1
  1. 16
      src/tooltips.cpp
  2. 1
      src/tooltips.hpp

16
src/tooltips.cpp

@ -444,12 +444,17 @@ void Tooltip::create_tags() {
code_tag = buffer->create_tag(); code_tag = buffer->create_tag();
code_tag->property_family() = source_font_family; code_tag->property_family() = source_font_family;
auto background_rgba = Gdk::RGBA(); auto background_rgba = Gdk::RGBA();
auto line_rgba = Gdk::RGBA();
auto normal_color = window->get_style_context()->get_color(Gtk::StateFlags::STATE_FLAG_NORMAL); auto normal_color = window->get_style_context()->get_color(Gtk::StateFlags::STATE_FLAG_NORMAL);
auto light_theme = (normal_color.get_red() + normal_color.get_green() + normal_color.get_blue()) / 3 < 0.5; auto light_theme = (normal_color.get_red() + normal_color.get_green() + normal_color.get_blue()) / 3 < 0.5;
if(light_theme) if(light_theme) {
background_rgba.set_rgba(1.0, 1.0, 1.0, 0.4); background_rgba.set_rgba(1.0, 1.0, 1.0, 0.4);
else line_rgba.set_rgba(0.0, 0.0, 0.0, 0.25);
}
else {
background_rgba.set_rgba(0.0, 0.0, 0.0, 0.2); background_rgba.set_rgba(0.0, 0.0, 0.0, 0.2);
line_rgba.set_rgba(1.0, 1.0, 1.0, 0.25);
}
code_tag->property_background_rgba() = background_rgba; code_tag->property_background_rgba() = background_rgba;
code_block_tag = buffer->create_tag(); code_block_tag = buffer->create_tag();
@ -464,6 +469,11 @@ void Tooltip::create_tags() {
strikethrough_tag = buffer->create_tag(); strikethrough_tag = buffer->create_tag();
strikethrough_tag->property_strikethrough() = true; strikethrough_tag->property_strikethrough() = true;
line_tag = buffer->create_tag();
line_tag->property_paragraph_background_rgba() = line_rgba;
line_tag->property_foreground_rgba() = line_rgba;
line_tag->property_size() = 1;
} }
} }
@ -846,7 +856,7 @@ void Tooltip::insert_markdown(const std::string &input) {
if(i == input.size() || input[i] == '\n') { if(i == input.size() || input[i] == '\n') {
if(i < input.size()) if(i < input.size())
++i; ++i;
buffer->insert_at_cursor("---\n"); buffer->insert_with_tag(buffer->get_insert()->get_iter(), "---\n", line_tag);
if(is_empty_line()) if(is_empty_line())
buffer->insert_at_cursor("\n"); buffer->insert_at_cursor("\n");
return true; return true;

1
src/tooltips.hpp

@ -56,6 +56,7 @@ private:
Glib::RefPtr<Gtk::TextTag> bold_tag; Glib::RefPtr<Gtk::TextTag> bold_tag;
Glib::RefPtr<Gtk::TextTag> italic_tag; Glib::RefPtr<Gtk::TextTag> italic_tag;
Glib::RefPtr<Gtk::TextTag> strikethrough_tag; Glib::RefPtr<Gtk::TextTag> strikethrough_tag;
Glib::RefPtr<Gtk::TextTag> line_tag;
std::map<Glib::RefPtr<Gtk::TextTag>, std::string> links; std::map<Glib::RefPtr<Gtk::TextTag>, std::string> links;
std::map<Glib::RefPtr<Gtk::TextTag>, std::string> reference_links; std::map<Glib::RefPtr<Gtk::TextTag>, std::string> reference_links;

Loading…
Cancel
Save