libwtk-sdl2  0.0.1
list_view.hpp
1 #ifndef LIBWTK_SDL2_LIST_VIEW_HPP
2 #define LIBWTK_SDL2_LIST_VIEW_HPP
3 
4 #include <vector>
5 #include <functional>
6 #include <optional>
7 
8 #include "selectable.hpp"
9 
10 // TODO change to vector_view ?
12 {
13  list_view(std::vector<std::string> const & values, std::size_t position, std::function<void(std::size_t)> activate_callback);
14  ~list_view() override;
15 
16  void on_draw(draw_context & dc, selection_context const & sc) const override;
17  void on_mouse_up_event(mouse_up_event const & e) override;
18  void on_mouse_down_event(mouse_down_event const & e) override;
19  void on_key_event(key_event const & e) override;
20  void on_activate() override;
21 
22  void on_box_allocated() override;
23 
24  size_hint get_size_hint(int width, int height) const override;
25 
31  // Set the position of the first entry to be shown.
32  void set_position(std::size_t position);
33  void set_selected_position(std::size_t position);
34  void set_highlight_position(std::size_t position);
35  void set_list(std::vector<std::string> const & values, std::size_t position = 0);
36 
37  std::size_t get_visible_entries() const;
38 
39  void scroll_up(std::size_t amount);
40  void scroll_down(std::size_t amount);
41  void scroll_up();
42  void scroll_down();
43 
46  private:
47 
48  int hit_entry(int y) const;
49 
50  std::optional<point> _opt_pressed_point;
51 
52  std::size_t _position;
53 
54  std::size_t _selected_position;
55 
56  std::size_t _highlight_position;
57 
58  std::size_t _x_shift;
59 
60  // TODO more columns and other types
61  std::reference_wrapper<std::vector<std::string> const> _values;
62 
63  std::function<void(std::size_t)> _activate_callback;
64 
65  int _row_height;
66  int _visible_entries;
67 };
68 
69 #endif
70 
Definition: mouse_event.hpp:19
Definition: mouse_event.hpp:8
Definition: selectable.hpp:6
Definition: draw_context.hpp:126
void on_draw(draw_context &dc, selection_context const &sc) const override
Definition: key_event.hpp:4
void on_box_allocated() override
Definition: list_view.hpp:11
Definition: selection_context.hpp:18
size_hint get_size_hint(int width, int height) const override
void on_activate() override
Definition: widget.hpp:35