libwtk-sdl2  0.0.1
box.hpp
1 #ifndef LIBWTK_SDL2_BOX_HPP
2 #define LIBWTK_SDL2_BOX_HPP
3 
4 #include <vector>
5 
6 #include "container.hpp"
7 
11 struct box : container
12 {
13  struct child
14  {
21  bool expand;
22  widget_ptr wptr;
23  };
24 
25  typedef std::vector<child> children_type;
26 
27  enum class orientation { VERTICAL, HORIZONTAL };
28 
29  box(orientation o, children_type children);
30  box(orientation o, children_type children, int children_spacing);
31  box(orientation o, children_type children, bool children_homogeneous);
32  box(orientation o, children_type children, int children_spacing, bool children_homogeneous);
33 
34  void on_box_allocated() override;
35 
36  widget * find_selectable(navigation_type nt, point center) override;
37 
38  static bool is_orthogonal(navigation_type nt, orientation o);
39  static bool is_forward(navigation_type nt);
40 
41  widget * navigate_selectable_from_children(navigation_type nt, widget * w, point center) override;
42 
43  size_hint get_size_hint(int width, int height) const override;
44 
45  ~box() override;
46 
47 
48  std::vector<widget *> get_children() override;
49  std::vector<widget const *> get_children() const override;
50 
58  private:
59 
60  // Finds the relevant distance based on the containers orientation.
61  int relevant_distance(point old_center, point new_center) const;
62 
63  // Check for orthogonality to container orientation.
64  bool is_orthogonal(navigation_type nt) const;
65 
66 
67  children_type _children;
68  int _children_spacing;
69  bool _children_homogeneous;
70 
71  orientation _o;
72 
73 };
74 
75 widget_ptr hbox(box::children_type children);
76 widget_ptr vbox(box::children_type children);
77 
78 widget_ptr hbox(box::children_type children, int children_spacing);
79 widget_ptr vbox(box::children_type children, int children_spacing);
80 
81 widget_ptr hbox(box::children_type children, bool children_homogeneous);
82 widget_ptr vbox(box::children_type children, bool children_homogeneous);
83 
84 widget_ptr hbox(box::children_type children, int children_spacing, bool children_homogeneous);
85 widget_ptr vbox(box::children_type children, int children_spacing, bool children_homogeneous);
86 
87 #endif
size_hint get_size_hint(int width, int height) const override
std::vector< widget * > get_children() override
bool expand
Definition: box.hpp:21
void on_box_allocated() override
Definition: container.hpp:10
widget * navigate_selectable_from_children(navigation_type nt, widget *w, point center) override
Definition: geometry.hpp:6
Definition: box.hpp:13
Definition: widget.hpp:52
Definition: widget.hpp:35
widget * find_selectable(navigation_type nt, point center) override
Definition: box.hpp:11