/* * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #include #include #include #include #include #include #include #include namespace GUI { class Application::TooltipWindow final : public Window { C_OBJECT(TooltipWindow); public: void set_tooltip(const String& tooltip) { m_label->set_text(Gfx::parse_ampersand_string(tooltip)); int tooltip_width = m_label->min_width() + 10; int line_count = m_label->text().count("\n"); int glyph_height = m_label->font().glyph_height(); int tooltip_height = glyph_height * (1 + line_count) + ((glyph_height + 1) / 2) * line_count + 8; Gfx::IntRect desktop_rect = Desktop::the().rect(); if (tooltip_width > desktop_rect.width()) tooltip_width = desktop_rect.width(); set_rect(rect().x(), rect().y(), tooltip_width, tooltip_height); } private: TooltipWindow() { set_window_type(WindowType::Tooltip); m_label = set_main_widget