view_tree.h Source File - ClanLib SDK
Description: view_tree.h Source File

view_tree.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 The ClanLib Team
4**
5** This software is provided 'as-is', without any express or implied
6** warranty. In no event will the authors be held liable for any damages
7** arising from the use of this software.
8**
9** Permission is granted to anyone to use this software for any purpose,
10** including commercial applications, and to alter it and redistribute it
11** freely, subject to the following restrictions:
12**
13** 1. The origin of this software must not be misrepresented; you must not
14** claim that you wrote the original software. If you use this software
15** in a product, an acknowledgment in the product documentation would be
16** appreciated but is not required.
17** 2. Altered source versions must be plainly marked as such, and must not be
18** misrepresented as being the original software.
19** 3. This notice may not be removed or altered from any source distribution.
20**
21** Note: Some of the libraries ClanLib may link to may have additional
22** requirements or restrictions.
23**
24** File Author(s):
25**
26** Magnus Norddahl
27*/
28
29#pragma once
30
31#include "../View/view.h"
32#include "../Events/activation_change_event.h"
33
34namespace clan
35{
36 class DisplayWindow;
37 class Canvas;
38 class ViewTreeImpl;
39
41 class ViewTree
42 {
43 public:
44 ViewTree();
45 virtual ~ViewTree();
46
48 View *focus_view() const;
49
53 virtual DisplayWindow display_window() = 0;
54
56 virtual Canvas canvas() const = 0;
57
59 const std::shared_ptr<View> &root_view() const;
60
62 void set_root_view(std::shared_ptr<View> root_view);
63
65 void add_child(const std::shared_ptr<View> &view)
66 {
67 root_view()->add_child(view);
68 }
69
70 template<typename T, typename... Types>
71 std::shared_ptr<T> add_child(Types &&... args)
72 {
73 auto child = std::make_shared<T>(std::forward<Types>(args)...);
74 add_child(child);
75 return child;
76 }
77
78 std::shared_ptr<View> add_child()
79 {
80 return add_child<View>();
81 }
82
83 protected:
85 void set_focus_view(View *view);
86
88 void render(Canvas &canvas, const Rectf &margin_box);
89
91 void dispatch_activation_change(ActivationChangeType type);
92
94 virtual void set_needs_render() = 0;
95
97 virtual Pointf client_to_screen_pos(const Pointf &pos) = 0;
98
100 virtual Pointf screen_to_client_pos(const Pointf &pos) = 0;
101
102 private:
103 ViewTree(const ViewTree &) = delete;
104 ViewTree &operator=(const ViewTree &) = delete;
105
106 std::unique_ptr<ViewTreeImpl> impl;
107
108 friend class View;
109 friend class ViewImpl;
110 friend class ViewController;
111 friend class PositionedLayout;
112 };
113}
clan::Canvas
2D Graphics Canvas
Definition canvas.h:72
clan::DisplayWindow
Top-level window class.
Definition display_window.h:101
clan::Pointf
2D (x,y) point structure - Float
Definition point.h:72
clan::Rectf
2D (left,top,right,bottom) rectangle structure - Float
Definition rect.h:503
clan::ViewTree
Base class for managing a tree of views.
Definition view_tree.h:42
clan::ViewTree::dispatch_activation_change
void dispatch_activation_change(ActivationChangeType type)
Dispatch activation change event to all views.
clan::ViewTree::PositionedLayout
friend class PositionedLayout
Definition view_tree.h:111
clan::ViewTree::set_needs_render
virtual void set_needs_render()=0
Signals that the root view needs to be rendered again.
clan::ViewTree::display_window
virtual DisplayWindow display_window()=0
clan::ViewTree::canvas
virtual Canvas canvas() const =0
Gets the current canvas used to render.
clan::ViewTree::add_child
std::shared_ptr< T > add_child(Types &&... args)
Definition view_tree.h:71
clan::ViewTree::ViewTree
ViewTree()
clan::ViewTree::ViewImpl
friend class ViewImpl
Definition view_tree.h:109
clan::ViewTree::add_child
std::shared_ptr< View > add_child()
Definition view_tree.h:78
clan::ViewTree::ViewController
friend class ViewController
Definition view_tree.h:110
clan::ViewTree::add_child
void add_child(const std::shared_ptr< View > &view)
Add a child view.
Definition view_tree.h:65
clan::ViewTree::set_root_view
void set_root_view(std::shared_ptr< View > root_view)
Sets a new root view controller for the view tree.
clan::ViewTree::~ViewTree
virtual ~ViewTree()
clan::ViewTree::root_view
const std::shared_ptr< View > & root_view() const
Retrieves the root of the view tree.
clan::ViewTree::screen_to_client_pos
virtual Pointf screen_to_client_pos(const Pointf &pos)=0
Map from screen to client coordinates.
clan::ViewTree::client_to_screen_pos
virtual Pointf client_to_screen_pos(const Pointf &pos)=0
Map from client to screen coordinates.
clan::ViewTree::focus_view
View * focus_view() const
The view receiving keyboard events or nullptr if no view has the focus.
clan::ViewTree::set_focus_view
void set_focus_view(View *view)
Set or clears the focus.
clan::ViewTree::render
void render(Canvas &canvas, const Rectf &margin_box)
Renders view into the specified canvas.
clan::View
View for an area of the user interface.
Definition view.h:66
clan
Definition clanapp.h:36
clan::ActivationChangeType
ActivationChangeType
Window activation change.
Definition activation_change_event.h:37