libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UIContainer.hpp
Go to the documentation of this file.
1 #ifndef UICONTAINER_HPP
2 #define UICONTAINER_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 #include "UIWidget.hpp"
22 
23 namespace AlgAudio{
24 
27 class UIContainerSingle : public UIWidget{
28 public:
29  virtual void Insert(std::shared_ptr<UIWidget>) {};
30  virtual Point2D GetChildPos() const = 0;
31  virtual void RemoveChild() {};
32  virtual std::shared_ptr<UIWidget> CustomFindChild(ID id) const override {return child?child->FindChild(id):nullptr;}
33  virtual void OnChildFocusRequested(std::shared_ptr<UIWidget>) override {
34  child->OnFocusChanged(true);
35  child_is_focused = true;
37  }
38  virtual void RequestFocus() override{
39  if(child) child->OnFocusChanged(false);
40  child_is_focused = false;
42  }
43  virtual bool OnChildFocusTested(std::shared_ptr<const UIWidget>) override {
44  return child_is_focused;
45  }
46  virtual void OnKeyboard(KeyData k) override {
47  if(child && child_is_focused) child->OnKeyboard(k);
48  }
49  virtual void OnFocusChanged(bool has_focus) override{
50  if(child) child->OnFocusChanged(has_focus && child_is_focused);
51  }
52 protected:
53  UIContainerSingle(std::weak_ptr<Window> parent_window) : UIWidget(parent_window) {}
54  std::shared_ptr<UIWidget> child;
55  bool child_is_focused = false;
56 };
57 
61 public:
62  // Not forcing on an Insert method, as some widgets may require extra arguments
63  // for insert
64  // virtual void Insert(std::shared_ptr<UIWidget>) = 0;
65  virtual Point2D GetChildPos(std::shared_ptr<UIWidget>) const = 0;
66  virtual void Clear() = 0;
67 
68  virtual void OnChildFocusRequested(std::shared_ptr<UIWidget> w) override {
69  auto old_focused_child = focused_child;
70 
71  if(w != focused_child){
72  focused_child = nullptr;
74  focused_child = w;
75  if(old_focused_child && old_focused_child != w) old_focused_child->OnFocusChanged(false);
76  focused_child->OnFocusChanged(true);
77  }else{
79  }
80  }
81  virtual void RequestFocus() override{
82  if(focused_child) focused_child->OnFocusChanged(false);
83  focused_child = nullptr;
85  }
86  virtual bool OnChildFocusTested(std::shared_ptr<const UIWidget> w) override {
87  return (w == focused_child) && IsFocused();
88  }
89  virtual void OnKeyboard(KeyData k) override{
90  if(focused_child) focused_child->OnKeyboard(k);
91  }
92  virtual void OnFocusChanged(bool has_focus) override{
93  if(focused_child) focused_child->OnFocusChanged(has_focus);
94  }
95 protected:
96  UIContainerMultiple(std::weak_ptr<Window> parent_window) : UIWidget(parent_window) {}
97  // Not forcing what the child list looks like, some widgets may wish to store
98  // some extra data wich each child.
99  //std::list<std::shared_ptr<UIWidget>> child;
100 
101  std::shared_ptr<UIWidget> focused_child = nullptr;
102 };
103 
104 } // namespace AlgAudio
105 
106 #endif // UICONTAINER_HPP
Definition: UIWidget.hpp:65
std::shared_ptr< UIWidget > focused_child
Definition: UIContainer.hpp:101
Definition: UIContainer.hpp:27
virtual Point2D GetChildPos() const =0
virtual void RequestFocus() override
bool child_is_focused
Definition: UIContainer.hpp:55
virtual void OnChildFocusRequested(std::shared_ptr< UIWidget > w) override
Definition: UIContainer.hpp:68
virtual void OnFocusChanged(bool has_focus) override
Definition: UIContainer.hpp:92
virtual void OnFocusChanged(bool has_focus) override
Definition: UIContainer.hpp:49
std::shared_ptr< UIWidget > child
Definition: UIContainer.hpp:54
virtual std::shared_ptr< UIWidget > CustomFindChild(ID id) const override
Definition: UIContainer.hpp:32
virtual bool OnChildFocusTested(std::shared_ptr< const UIWidget >) override
Definition: UIContainer.hpp:43
bool IsFocused() const
Definition: Utilities.hpp:34
virtual void Insert(std::shared_ptr< UIWidget >)
Definition: UIContainer.hpp:29
virtual void RequestFocus() override
Definition: UIContainer.hpp:81
UIContainerMultiple(std::weak_ptr< Window > parent_window)
Definition: UIContainer.hpp:96
Definition: UIContainer.hpp:60
virtual void OnKeyboard(KeyData k) override
Definition: UIContainer.hpp:46
Definition: Alertable.hpp:26
Definition: UIWidget.hpp:137
virtual void OnChildFocusRequested(std::shared_ptr< UIWidget >) override
Definition: UIContainer.hpp:33
virtual void OnKeyboard(KeyData k) override
Definition: UIContainer.hpp:89
virtual bool OnChildFocusTested(std::shared_ptr< const UIWidget > w) override
Definition: UIContainer.hpp:86
virtual Point2D GetChildPos(std::shared_ptr< UIWidget >) const =0
virtual void RequestFocus() override
Definition: UIContainer.hpp:38
virtual void RemoveChild()
Definition: UIContainer.hpp:31
UIContainerSingle(std::weak_ptr< Window > parent_window)
Definition: UIContainer.hpp:53
Definition: Utilities.hpp:157