neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
dockable.hpp
Go to the documentation of this file.
1// dockable.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 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 <string>
24#include <neolib/task/timer.hpp>
29
30namespace neogfx
31{
32 class dockable : public decorated<framed_widget<>, reference_counted<i_dockable>>
33 {
35 public:
36 define_declared_event(Docked, docked, i_dock&)
37 define_declared_event(Undocked, undocked, i_dock&)
38 public:
40 public:
41 dockable(std::shared_ptr<i_widget> aDockableWidget, std::string const& aTitle = "", dock_area aAcceptableDocks = dock_area::Any);
42 public:
43 const neolib::string& title() const override;
44 public:
45 bool can_dock(const i_dock& aDock) const override;
46 bool is_docked() const override;
47 const i_dock& which_dock() const override;
48 i_dock& which_dock() override;
49 void dock(i_dock& aDock) override;
50 void undock() override;
51 public:
52 const i_widget& docked_widget() const override;
54 protected:
55 void focus_gained(focus_reason aFocusReason) override;
56 protected:
57 color frame_color() const override;
58 public:
59 template <typename WidgetType>
60 const WidgetType& docked_widget() const
61 {
62 return static_cast<const WidgetType&>(docked_widget());
63 }
64 template <typename WidgetType>
65 WidgetType& docked_widget()
66 {
67 return static_cast<WidgetType&>(docked_widget());
68 }
69 private:
70 neolib::string iTitle;
71 dock_area iAcceptableDocks;
72 std::shared_ptr<i_widget> iDockedWidget;
73 i_dock* iDock;
74 };
75
76 template <typename WidgetType, typename... Args>
77 inline dockable make_dockable(std::string const& aTitle = "", dock_area aAcceptableDocks = dock_area::Any, Args&&... aArgs)
78 {
79 return dockable{ std::make_shared<WidgetType>(std::forward<Args>(aArgs)...), aTitle, aAcceptableDocks };
80 }
81 template <typename WidgetType, typename... Args>
82 static std::shared_ptr<i_dockable> make_shared_dockable(std::string const& aTitle = "", dock_area aAcceptableDocks = dock_area::Any, Args&&... aArgs)
83 {
84 return std::make_shared<dockable>(std::make_shared<WidgetType>(std::forward<Args>(aArgs)...), aTitle, aAcceptableDocks);
85 }
86}
const i_dock & which_dock() const override
i_widget & docked_widget() override
i_dock & which_dock() override
bool is_docked() const override
color frame_color() const override
dockable(std::shared_ptr< i_widget > aDockableWidget, std::string const &aTitle="", dock_area aAcceptableDocks=dock_area::Any)
WidgetType & docked_widget()
Definition dockable.hpp:65
bool can_dock(const i_dock &aDock) const override
const WidgetType & docked_widget() const
Definition dockable.hpp:60
void undock() override
const i_widget & docked_widget() const override
const neolib::string & title() const override
void focus_gained(focus_reason aFocusReason) override
void dock(i_dock &aDock) override
i_widget abstract_type
Definition widget.hpp:69
dock_area
Definition i_dock.hpp:31
dockable make_dockable(std::string const &aTitle="", dock_area aAcceptableDocks=dock_area::Any, Args &&... aArgs)
Definition dockable.hpp:77
#define meta_object(...)
Definition i_object.hpp:28
#define define_declared_event(name, declName,...)
Definition event.hpp:195