libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UIBox.hpp
Go to the documentation of this file.
1 #ifndef UIVBOX_HPP
2 #define UIVBOX_HPP
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include <vector>
23 #include <functional>
24 #include "UI/UIContainer.hpp"
25 
26 namespace AlgAudio{
27 
28 class UIBox : public UIContainerMultiple{
29 public:
30  enum PackMode{
33  };
34  virtual void CustomDraw(DrawContext& c) override __attribute__((hot));
35  virtual void CustomResize(Size2D) override;
36  virtual void OnChildRequestedSizeChanged() override;
37  virtual void OnChildVisibilityChanged() override;
38  void Insert(std::shared_ptr<UIWidget> w, PackMode m);
39  virtual void Clear() override;
40  void SetPadding(unsigned int padding);
41  virtual bool CustomMousePress(bool down, MouseButton b,Point2D) override;
42  virtual void CustomMouseMotion(Point2D p1, Point2D p2) override;
43  virtual void CustomMouseEnter(Point2D) override;
44  virtual void CustomMouseLeave(Point2D) override;
45  virtual Point2D GetChildPos(std::shared_ptr<UIWidget>) const override;
46  virtual std::shared_ptr<UIWidget> CustomFindChild(ID id) const override;
47 private:
48  struct PackData{
49  std::shared_ptr<UIWidget> child;
50  PackMode mode;
51  int size;
52  };
53  std::vector<PackData> children;
54  unsigned int padding = 0;
55  Size2D GetChildSize(unsigned int n) const;
56  void TriggerChildResizes();
57  void RecalculateChildSizes(int available_space);
58  Point2D GetChildLocation(unsigned int n) const;
59  unsigned int GetTotalSize() const;
60  unsigned int GetChildMaxContra() const;
61  // For given coordinates, this function returns the child number inside which
62  // the point is, or -1 if none.
63  int InWhich(Point2D) const;
64 protected:
65  UIBox(std::weak_ptr<Window> parent_window);
66  // These functions provide access to width/height from Size2D in an abstract
67  // manner. In a vertical box, the DirectionalDimension will refer to height,
68  // and in a horizontal box it will refer to width. The
69  // ContradirectionalDimension must refer to the other dimension than
70  // directional_dimension.
71  virtual int DirectionalDimension(Size2D s) const = 0;
72  virtual int ContradirectionalDimension(Size2D s) const = 0;
73  virtual int DirectionalDimension(Point2D s) const = 0;
74  virtual int ContradirectionalDimension(Point2D s) const = 0;
75  virtual Size2D DirectionalSize2D(int direction, int contra) const = 0;
76  virtual Point2D DirectionalPoint2D(int direction, int contra) const = 0;
77 };
78 
79 class UIVBox : public UIBox{
80 public:
81  static std::shared_ptr<UIVBox> Create(std::weak_ptr<Window> parent_window);
82 protected:
83  UIVBox(std::weak_ptr<Window> parent_window);
84  // Specify what a vertical direction is
85  inline virtual int DirectionalDimension(Size2D s) const override {return s.height;}
86  inline virtual int ContradirectionalDimension(Size2D s) const override {return s.width;}
87  inline virtual int DirectionalDimension(Point2D s) const override {return s.y;}
88  inline virtual int ContradirectionalDimension(Point2D s) const override {return s.x;}
89  inline virtual Size2D DirectionalSize2D(int direction, int contra) const override {return Size2D(contra, direction);}
90  inline virtual Point2D DirectionalPoint2D(int direction, int contra) const override {return Point2D(contra, direction);}
91 };
92 class UIHBox : public UIBox{
93 public:
94  static std::shared_ptr<UIHBox> Create(std::weak_ptr<Window> parent_window);
95 protected:
96  UIHBox(std::weak_ptr<Window> parent_window);
97  // Specify what a horizontal direction is
98  inline virtual int DirectionalDimension(Size2D s) const override {return s.width;}
99  inline virtual int ContradirectionalDimension(Size2D s) const override {return s.height;}
100  inline virtual int DirectionalDimension(Point2D s) const override {return s.x;}
101  inline virtual int ContradirectionalDimension(Point2D s) const override {return s.y;}
102  inline virtual Size2D DirectionalSize2D(int direction, int contra) const override {return Size2D(direction,contra);}
103  inline virtual Point2D DirectionalPoint2D(int direction, int contra) const override {return Point2D(direction,contra);}
104 };
105 
106 } // namespace AlgAudio
107 
108 #endif // UIVBOX_HPP
virtual Size2D DirectionalSize2D(int direction, int contra) const =0
virtual Point2D DirectionalPoint2D(int direction, int contra) const =0
void SetPadding(unsigned int padding)
static std::shared_ptr< UIVBox > Create(std::weak_ptr< Window > parent_window)
virtual Size2D DirectionalSize2D(int direction, int contra) const override
Definition: UIBox.hpp:89
Definition: UIBox.hpp:79
Definition: UIBox.hpp:92
Definition: UIBox.hpp:31
UIVBox(std::weak_ptr< Window > parent_window)
virtual int ContradirectionalDimension(Size2D s) const override
Definition: UIBox.hpp:86
Definition: DrawContext.hpp:65
Point2D_< int > Point2D
Definition: Utilities.hpp:35
int height
Definition: Utilities.hpp:46
MouseButton
Definition: Utilities.hpp:190
virtual void CustomDraw(DrawContext &c) override __attribute__((hot))
virtual void CustomResize(Size2D) override
virtual int ContradirectionalDimension(Size2D s) const =0
virtual void Clear() override
virtual Point2D DirectionalPoint2D(int direction, int contra) const override
Definition: UIBox.hpp:90
virtual void OnChildVisibilityChanged() override
virtual int ContradirectionalDimension(Point2D s) const override
Definition: UIBox.hpp:88
virtual void CustomMouseEnter(Point2D) override
Definition: Utilities.hpp:34
virtual Point2D DirectionalPoint2D(int direction, int contra) const override
Definition: UIBox.hpp:103
int width
Definition: Utilities.hpp:46
Definition: UIBox.hpp:28
virtual void CustomMouseMotion(Point2D p1, Point2D p2) override
Definition: UIContainer.hpp:60
T x
Definition: Utilities.hpp:62
UIHBox(std::weak_ptr< Window > parent_window)
Definition: Alertable.hpp:26
virtual void CustomMouseLeave(Point2D) override
virtual Point2D GetChildPos(std::shared_ptr< UIWidget >) const override
virtual int DirectionalDimension(Size2D s) const =0
Definition: UIBox.hpp:32
virtual void OnChildRequestedSizeChanged() override
T y
Definition: Utilities.hpp:62
virtual Size2D DirectionalSize2D(int direction, int contra) const override
Definition: UIBox.hpp:102
virtual int DirectionalDimension(Size2D s) const override
Definition: UIBox.hpp:98
Subscription __attribute__((warn_unused_result)) Signal< Types...>
Definition: Signal.hpp:208
static std::shared_ptr< UIHBox > Create(std::weak_ptr< Window > parent_window)
virtual int DirectionalDimension(Size2D s) const override
Definition: UIBox.hpp:85
PackMode
Definition: UIBox.hpp:30
virtual int DirectionalDimension(Point2D s) const override
Definition: UIBox.hpp:87
virtual int DirectionalDimension(Point2D s) const override
Definition: UIBox.hpp:100
virtual std::shared_ptr< UIWidget > CustomFindChild(ID id) const override
UIBox(std::weak_ptr< Window > parent_window)
virtual bool CustomMousePress(bool down, MouseButton b, Point2D) override
Definition: Utilities.hpp:40
virtual int ContradirectionalDimension(Size2D s) const override
Definition: UIBox.hpp:99
void Insert(std::shared_ptr< UIWidget > w, PackMode m)
virtual int ContradirectionalDimension(Point2D s) const override
Definition: UIBox.hpp:101