1/*
2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors.
3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com>
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#pragma once
10
11#include <libg/Color.h>
12#include <libg/Context.h>
13#include <string>
14
15namespace WinServer {
16
17class Button {
18public:
19 Button() = default;
20 ~Button() = default;
21
22 void display();
23 void set_title(const std::string& title) { m_title = title, recalc_dims(); }
24 void set_title(std::string&& title) { m_title = std::move(title), recalc_dims(); }
25 const std::string& title() const { return m_title; }
26
27 void set_font(const LG::Font& font) { m_font = font, recalc_dims(); }
28 void set_icon(const LG::GlyphBitmap& icon) { m_is_icon_set = true, m_icon = icon, recalc_dims(); }
29
30 void set_title_color(const LG::Color& color) { m_title_color = color; }
31 const LG::Color& title_color() const { return m_title_color; }
32
33 inline const LG::Font& font() const { return m_font; }
34
35 inline LG::Rect& bounds() { return m_bounds; }
36 inline const LG::Rect& bounds() const { return m_bounds; }
37
38 void display(LG::Context& ctx, LG::Point<int> pt);
39
40private:
41 void recalc_dims();
42 size_t text_width();
43 inline size_t text_height() const { return font().glyph_height(); }
44
45 LG::Rect m_bounds {};
46 std::string m_title {};
47 LG::Font m_font { LG::Font::system_font() };
48 LG::Color m_title_color;
49 LG::GlyphBitmap m_icon;
50
51 bool m_is_icon_set { false };
52};
53
54} // namespace WinServer