neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
item_editor.hpp
Go to the documentation of this file.
1// item_editor.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include "text_edit.hpp"
24#include "line_edit.hpp"
25#include "spin_box.hpp"
26
27namespace neogfx
28{
30 {
31 public:
32 virtual ~i_item_editor() = default;
33 public:
34 virtual const i_widget& as_widget() const = 0;
35 virtual i_widget& as_widget() = 0;
36 virtual bool has_text_edit() const = 0;
37 virtual text_edit& text_edit() const = 0;
38 };
39
40 class item_view;
41
42 template <typename EditorWidget>
44 {
45 public:
47 iEditorWidget{ std::make_shared<EditorWidget>(aParent) } { init(); }
48 item_editor(EditorWidget& aEditorWidget) :
49 iEditorWidget{ std::shared_ptr<i_widget>(std::shared_ptr<i_widget>(), &aEditorWidget) } { init(); }
50 item_editor(std::shared_ptr<EditorWidget> aEditorWidget) :
51 iEditorWidget{ std::shared_ptr<i_widget>(aEditorWidget) } { init(); }
52 public:
53 const i_widget& as_widget() const override
54 {
55 return *iEditorWidget;
56 }
57 i_widget& as_widget() override
58 {
59 return *iEditorWidget;
60 }
61 bool has_text_edit() const override;
62 neogfx::text_edit& text_edit() const override;
63 protected:
64 void init()
65 {
66 static_cast<framed_widget<>&>(as_widget()).set_frame_style(frame_style::SolidFrame);
67 }
68 private:
69 std::shared_ptr<i_widget> iEditorWidget;
70 };
71
72 template <>
74 {
75 return true;
76 }
77
78 template <>
79 inline text_edit& item_editor<text_edit>::text_edit() const
80 {
81 return static_cast<neogfx::text_edit&>(*iEditorWidget);
82 }
83
84 template <>
86 {
87 return true;
88 }
89
90 template <>
91 inline text_edit& item_editor<line_edit>::text_edit() const
92 {
93 return static_cast<neogfx::line_edit&>(*iEditorWidget);
94 }
95
96 template <>
97 inline bool item_editor<basic_spin_box<int32_t>>::has_text_edit() const
98 {
99 return true;
100 }
101
102 template <>
103 inline text_edit& item_editor<basic_spin_box<int32_t>>::text_edit() const
104 {
105 return static_cast<basic_spin_box<int32_t>&>(*iEditorWidget).text_box();
106 }
107
108 template <>
109 inline bool item_editor<basic_spin_box<uint32_t>>::has_text_edit() const
110 {
111 return true;
112 }
113
114 template <>
115 inline text_edit& item_editor<basic_spin_box<uint32_t>>::text_edit() const
116 {
117 return static_cast<basic_spin_box<uint32_t>&>(*iEditorWidget).text_box();
118 }
119
120 template <>
121 inline bool item_editor<basic_spin_box<int64_t>>::has_text_edit() const
122 {
123 return true;
124 }
125
126 template <>
127 inline text_edit& item_editor<basic_spin_box<int64_t>>::text_edit() const
128 {
129 return static_cast<basic_spin_box<int64_t>&>(*iEditorWidget).text_box();
130 }
131
132 template <>
133 inline bool item_editor<basic_spin_box<uint64_t>>::has_text_edit() const
134 {
135 return true;
136 }
137
138 template <>
139 inline text_edit& item_editor<basic_spin_box<uint64_t>>::text_edit() const
140 {
141 return static_cast<basic_spin_box<uint64_t>&>(*iEditorWidget).text_box();
142 }
143
144 template <>
145 inline bool item_editor<basic_spin_box<float>>::has_text_edit() const
146 {
147 return true;
148 }
149
150 template <>
151 inline text_edit& item_editor<basic_spin_box<float>>::text_edit() const
152 {
153 return static_cast<basic_spin_box<float>&>(*iEditorWidget).text_box();
154 }
155
156 template <>
157 inline bool item_editor<basic_spin_box<double>>::has_text_edit() const
158 {
159 return true;
160 }
161
162 template <>
163 inline text_edit& item_editor<basic_spin_box<double>>::text_edit() const
164 {
165 return static_cast<basic_spin_box<double>&>(*iEditorWidget).text_box();
166 }
167}
const line_edit & text_box() const
Definition spin_box.ipp:145
virtual bool has_text_edit() const =0
virtual const i_widget & as_widget() const =0
virtual ~i_item_editor()=default
virtual i_widget & as_widget()=0
virtual text_edit & text_edit() const =0
item_editor(EditorWidget &aEditorWidget)
neogfx::text_edit & text_edit() const override
bool has_text_edit() const override
i_widget & as_widget() override
item_editor(item_view &aParent)
const i_widget & as_widget() const override
item_editor(std::shared_ptr< EditorWidget > aEditorWidget)
Definition plf_hive.h:79