aboutsummaryrefslogtreecommitdiff
path: root/include/Tabs.hpp
blob: b7d8de602caa30b1f3781ac1d4302be6c93be90f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#include "RoundedRectangle.hpp"
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/Text.hpp>
#include <vector>
#include <functional>

namespace sf {
    class Event;
    class RenderWindow;
    class Shader;
}

namespace QuickMedia {
    class Body;

    class Tabs {
    public:
        Tabs(sf::Shader *rounded_rectangle_shader);
        Tabs(sf::Shader *rounded_rectangle_shader, sf::Color shade_color);

        static float get_height();
        static float get_shade_height();

        // Returns the id (index) of the tab. The ids start from 0
        int add_tab(const std::string &title, Body *body);
        void on_event(sf::Event &event);
        void draw(sf::RenderWindow &window, sf::Vector2f pos, float width);

        void set_text(int index, const std::string &text);

        void set_selected(int index);
        int get_selected() const;

        std::function<void(int)> on_change_tab = nullptr;
    private:
        void move_selected_tab(int new_tab);
        float tab_index_to_x_offset(int index);
    private:
        struct Tab {
            sf::Text text;
            std::string label_utf8; // TODO: Remove
            Body *body;
        };
        std::vector<Tab> tabs;
        RoundedRectangle background;
        sf::RectangleShape shade;
        int selected_tab = 0;
        float scroll = 0.0f;
        float width_per_tab = 0.0f;
        float tab_background_width = 0.0f;
        float container_width = 0.0f;
        int tab_offset = 0;
        sf::Color shade_color;
    };
}