-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathxtoolbar.hpp
More file actions
157 lines (124 loc) · 4.35 KB
/
Copy pathxtoolbar.hpp
File metadata and controls
157 lines (124 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/***************************************************************************
* Copyright (c) 2017, Sylvain Corlay and Johan Mabille *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XPLOT_TOOLBAR_HPP
#define XPLOT_TOOLBAR_HPP
#include <utility>
#include "nlohmann/json.hpp"
#include "xtl/xoptional.hpp"
#include "xwidgets/xmaterialize.hpp"
#include "xwidgets/xmaker.hpp"
#include "xwidgets/xwidget.hpp"
#include "xfigure.hpp"
#include "xinteracts.hpp"
namespace nl = nlohmann;
namespace xpl
{
template <class D>
class xfigure;
/************************
* xtoolbar declaration *
************************/
template <class D>
class xtoolbar : public xw::xwidget<D>
{
public:
using base_type = xw::xwidget<D>;
using derived_type = D;
void serialize_state(nl::json&, xeus::buffer_sequence&) const;
void apply_patch(const nl::json&, const xeus::buffer_sequence&);
XPROPERTY(xw::xholder<xfigure>, derived_type, figure);
XPROPERTY(bool, derived_type, panning);
XPROPERTY(xtl::xoptional<xw::xmaterialize<xpan_zoom>>, derived_type, panzoom);
protected:
template <class S>
xtoolbar(const xfigure<S>&);
template <class S>
xtoolbar(xfigure<S>&&);
template <class S, class = enable_xfigure_t<S>>
xtoolbar(std::shared_ptr<S>);
using base_type::base_type;
private:
void set_defaults();
static int register_panzoom();
};
using toolbar = xw::xmaterialize<xtoolbar>;
/***************************
* xtoolbar implementation *
***************************/
template <class D>
inline void xtoolbar<D>::apply_patch(const nl::json& patch, const xeus::buffer_sequence& buffers)
{
using xw::set_property_from_patch;
base_type::apply_patch(patch, buffers);
set_property_from_patch(figure, patch, buffers);
set_property_from_patch(panning, patch, buffers);
set_property_from_patch(panzoom, patch, buffers);
}
template <class D>
inline void xtoolbar<D>::serialize_state(nl::json& state, xeus::buffer_sequence& buffers) const
{
using xw::xwidgets_serialize;
base_type::serialize_state(state, buffers);
xwidgets_serialize(figure, state["figure"], buffers);
xwidgets_serialize(panning, state["panning"], buffers);
xwidgets_serialize(panzoom, state["panzoom"], buffers);
}
template <class D>
template <class S>
inline xtoolbar<D>::xtoolbar(const xfigure<S>& fig)
: base_type()
{
static int init = register_panzoom();
set_defaults();
this->figure() = fig;
}
template <class D>
template <class S>
inline xtoolbar<D>::xtoolbar(xfigure<S>&& fig)
: base_type()
{
set_defaults();
this->figure() = std::move(fig);
}
template <class D>
template <class S, class>
inline xtoolbar<D>::xtoolbar(std::shared_ptr<S> fig)
: base_type()
{
set_defaults();
this->figure() = fig;
}
template <class D>
inline void xtoolbar<D>::set_defaults()
{
this->_view_name() = "Toolbar";
this->_model_module() = "bqplot";
this->_model_module_version() = bqplot_semver();
this->_model_name() = "ToolbarModel";
this->_view_module() = "bqplot";
this->_view_module_version() = bqplot_semver();
}
template <class D>
inline int xtoolbar<D>::register_panzoom()
{
xw::get_xfactory().register_maker("bqplot",
"PanZoomModel",
"bqplot",
"PanZoom",
xw::xmaker<xpan_zoom>);
return 0;
}
}
/*********************
* precompiled types *
*********************/
#ifndef _WIN32
extern template class xw::xmaterialize<xpl::xtoolbar>;
extern template class xw::xtransport<xw::xmaterialize<xpl::xtoolbar>>;
#endif
#endif