neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_anchorable.hpp
Go to the documentation of this file.
1// i_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>
23#include <neolib/core/map.hpp>
26
27namespace neogfx
28{
29 class i_object;
30
31 struct anchor_not_found : std::runtime_error { anchor_not_found(std::string const& aAnchor) : std::runtime_error{ "neoGFX: Anchor '" + aAnchor + "' not found." } {} };
32
34 {
35 // types
36 public:
39 // meta
40 public:
41 virtual i_object& as_object() = 0;
42 // operations
43 public:
44 virtual i_anchor& anchor_to(i_anchorable& aRhs, const i_string& aLhsAnchor, anchor_constraint_function aLhsFunction, const i_string& aRhsAnchor, anchor_constraint_function aRhsFunction) = 0;
45 // state
46 public:
47 virtual const anchor_map_type& anchors() const = 0;
48 virtual anchor_map_type& anchors() = 0;
49 // helpers
50 public:
51 i_anchor& anchor_to(i_anchorable& aRhs, std::string const& aLhsAnchor, anchor_constraint_function aLhsFunction, std::string const& aRhsAnchor, anchor_constraint_function aRhsFunction)
52 {
53 return anchor_to(aRhs, string{ aLhsAnchor }, aLhsFunction, string{ aRhsAnchor }, aRhsFunction);
54 }
55 };
56
57 inline void layout_as_same_size(i_anchorable& aFirst, i_anchorable& aSecond)
58 {
59 aFirst.anchor_to(aSecond, string{ "MinimumSize" }, anchor_constraint_function::Max, string{ "MinimumSize" }, anchor_constraint_function::Max);
60 }
61
62 inline void layout_as_same_width(i_anchorable& aFirst, i_anchorable& aSecond)
63 {
64 aFirst.anchor_to(aSecond, string{ "MinimumSize" }, anchor_constraint_function::MaxX, string{ "MinimumSize" }, anchor_constraint_function::MaxX);
65 }
66
67 inline void layout_as_same_height(i_anchorable& aFirst, i_anchorable& aSecond)
68 {
69 aFirst.anchor_to(aSecond, string{ "MinimumSize" }, anchor_constraint_function::MaxY, string{ "MinimumSize" }, anchor_constraint_function::MaxY);
70 }
71
73 {
74 aFirst.anchor_to(aSecond, string{ "MinimumSize" }, anchor_constraint_function::Min, string{ "MinimumSize" }, anchor_constraint_function::Max);
75 }
76
78 {
79 aFirst.anchor_to(aSecond, string{ "MinimumSize" }, anchor_constraint_function::MinX, string{ "MinimumSize" }, anchor_constraint_function::MaxX);
80 }
81
83 {
84 aFirst.anchor_to(aSecond, string{ "MinimumSize" }, anchor_constraint_function::MinY, string{ "MinimumSize" }, anchor_constraint_function::MaxY);
85 }
86}
i_anchorable abstract_type
neolib::i_map< i_string, i_anchor * > anchor_map_type
virtual anchor_map_type & anchors()=0
virtual const anchor_map_type & anchors() const =0
virtual i_object & as_object()=0
virtual i_anchor & anchor_to(i_anchorable &aRhs, const i_string &aLhsAnchor, anchor_constraint_function aLhsFunction, const i_string &aRhsAnchor, anchor_constraint_function aRhsFunction)=0
i_anchor & anchor_to(i_anchorable &aRhs, std::string const &aLhsAnchor, anchor_constraint_function aLhsFunction, std::string const &aRhsAnchor, anchor_constraint_function aRhsFunction)
anchor_constraint_function
Definition i_anchor.hpp:31
void layout_as_same_width_min_max(i_anchorable &aFirst, i_anchorable &aSecond)
void layout_as_same_height_min_max(i_anchorable &aFirst, i_anchorable &aSecond)
void layout_as_same_size(i_anchorable &aFirst, i_anchorable &aSecond)
void layout_as_same_height(i_anchorable &aFirst, i_anchorable &aSecond)
void layout_as_same_width(i_anchorable &aFirst, i_anchorable &aSecond)
void layout_as_same_size_min_max(i_anchorable &aFirst, i_anchorable &aSecond)
anchor_not_found(std::string const &aAnchor)