neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
anchorable.hpp
Go to the documentation of this file.
1// anchorable.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2018, 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>
24
25namespace neogfx
26{
27 template <typename Base>
28 class anchorable : public Base
29 {
30 typedef anchorable<Base> self_type;
31 typedef Base base_type;
32 // types
33 public:
34 using typename base_type::abstract_type;
36 // operations
37 public:
39 {
40 }
41 public:
42 using base_type::anchor_to;
43 i_anchor& anchor_to(i_anchorable& aRhs, const i_string& aLhsAnchor, anchor_constraint_function aLhsFunction, const i_string& aRhsAnchor, anchor_constraint_function aRhsFunction) override
44 {
45 auto lhsAnchor = anchors().find(aLhsAnchor);
46 auto rhsAnchor = aRhs.anchors().find(aRhsAnchor);
47 if (lhsAnchor == anchors().end())
48 throw anchor_not_found(aLhsAnchor);
49 if (rhsAnchor == aRhs.anchors().end())
50 throw anchor_not_found(aRhsAnchor);
51 rhsAnchor->second()->constrain(*lhsAnchor->second(), aLhsFunction, aRhsFunction);
52 return *lhsAnchor->second();
53 }
54 // state
55 public:
56 const anchor_map_type& anchors() const override
57 {
58 return iAnchors;
59 }
61 {
62 return iAnchors;
63 }
64 // state
65 private:
66 anchor_map_type iAnchors;
67 };
68}
anchor_map_type & anchors() override
const anchor_map_type & anchors() const override
neolib::map< string, i_anchor * > anchor_map_type
i_anchor & anchor_to(i_anchorable &aRhs, const i_string &aLhsAnchor, anchor_constraint_function aLhsFunction, const i_string &aRhsAnchor, anchor_constraint_function aRhsFunction) override
virtual const anchor_map_type & anchors() const =0
anchor_constraint_function
Definition i_anchor.hpp:31