104 template <
typename T>
105 class anchor_constraint :
public std::function<T(const T&, const T&)>
107 typedef std::function<T(
const T&,
const T&)> base_type;
109 typedef T value_type;
111 using base_type::base_type;
113 static anchor_constraint<T> identity;
114 static anchor_constraint<T> identity_x;
115 static anchor_constraint<T> identity_y;
116 static anchor_constraint<T> equal;
117 static anchor_constraint<T> equal_x;
118 static anchor_constraint<T> equal_y;
119 static anchor_constraint<T> min;
120 static anchor_constraint<T> min_x;
121 static anchor_constraint<T> min_y;
122 static anchor_constraint<T> max;
123 static anchor_constraint<T> max_x;
124 static anchor_constraint<T> max_y;
127 template <
typename T>
128 inline T constraint_x(
const T& value)
133 template <
typename T>
134 inline T constraint_y(
const T& value)
139 template <
typename T>
140 inline T constraint_x(
const basic_point<T>& value)
145 template <
typename T>
146 inline T constraint_y(
const basic_point<T>& value)
151 template <
typename T>
152 inline T constraint_x(
const basic_size<T>& value)
157 template <
typename T>
158 inline T constraint_y(
const basic_size<T>& value)
163 template <
typename T>
164 inline T constraint_x(
const basic_box_areas<T>& value)
166 return value.size().cx;
169 template <
typename T>
170 inline T constraint_y(
const basic_box_areas<T>& value)
172 return value.size().cy;
175 template <
typename T>
176 anchor_constraint<T> anchor_constraint<T>::identity = [](
const T& lhs,
const T&) -> T
180 template <
typename T>
181 anchor_constraint<T> anchor_constraint<T>::identity_x = [](
const T& lhs,
const T& rhs) -> T
183 return T{ constraint_x(lhs), constraint_y(rhs) };
185 template <
typename T>
186 anchor_constraint<T> anchor_constraint<T>::identity_y = [](
const T& lhs,
const T& rhs) -> T
188 return T{ constraint_x(rhs), constraint_y(lhs) };
191 template <
typename T>
192 anchor_constraint<T> anchor_constraint<T>::equal = [](
const T&,
const T& rhs) -> T
196 template <
typename T>
197 anchor_constraint<T> anchor_constraint<T>::equal_x = [](
const T& lhs,
const T& rhs) -> T
199 return T{ constraint_x(rhs), constraint_y(lhs) };
201 template <
typename T>
202 anchor_constraint<T> anchor_constraint<T>::equal_y = [](
const T& lhs,
const T& rhs) -> T
204 return T{ constraint_x(lhs), constraint_y(rhs) };
207 template <
typename T>
208 anchor_constraint<T> anchor_constraint<T>::min = [](
const T& lhs,
const T& rhs) -> T
210 return std::min(lhs, rhs);
212 template <
typename T>
213 anchor_constraint<T> anchor_constraint<T>::min_x = [](
const T& lhs,
const T& rhs) -> T
215 return T{ std::min(constraint_x(lhs), constraint_x(rhs)), constraint_y(lhs) };
217 template <
typename T>
218 anchor_constraint<T> anchor_constraint<T>::min_y = [](
const T& lhs,
const T& rhs) -> T
220 return T{ constraint_x(lhs), std::min(constraint_y(lhs), constraint_y(rhs)) };
223 template <
typename T>
224 anchor_constraint<T> anchor_constraint<T>::max = [](
const T& lhs,
const T& rhs) -> T
226 return std::max(lhs, rhs);
228 template <
typename T>
229 anchor_constraint<T> anchor_constraint<T>::max_x = [](
const T& lhs,
const T& rhs) -> T
231 return T{ std::max(constraint_x(lhs), constraint_x(rhs)), constraint_y(lhs) };
233 template <
typename T>
234 anchor_constraint<T> anchor_constraint<T>::max_y = [](
const T& lhs,
const T& rhs) -> T
236 return T{ constraint_x(lhs), std::max(constraint_y(lhs), constraint_y(rhs)) };
239 struct anchor_property_has_no_value : std::logic_error { anchor_property_has_no_value() :
std::logic_error{
"neogfx::anchor_property_has_no_value" } {} };
247 virtual ~i_anchor() =
default;
250 virtual i_anchorable& owner()
const = 0;
251 virtual const i_string& name()
const = 0;
252 virtual const i_property& property()
const = 0;
253 virtual i_property& property() = 0;
254 virtual bool active() const noexcept = 0;
255 virtual
bool calculator_overriden() const noexcept = 0;
256 virtual
bool calculating() const noexcept = 0;
259 virtual
void constrain(i_anchor& aRhs, anchor_constraint_function aLhsFunction, anchor_constraint_function aRhsFunction) = 0;
260 virtual
void constrain(i_anchor& aOther, anchor_constraint_function aOtherFunction) = 0;
263 template <typename T, typename PVT, typename... CalculatorArgs>
264 class i_calculating_anchor : public i_anchor
266 typedef i_calculating_anchor<T, PVT, CalculatorArgs...> self_type;
268 typedef self_type abstract_type;
269 typedef T value_type;
270 typedef PVT property_value_type;
271 typedef anchor_constraint<value_type> constraint;
273 virtual bool property_set()
const = 0;
274 virtual value_type
const& property_value()
const = 0;
275 virtual value_type& property_value() = 0;
276 virtual void add_constraint(
const constraint& aConstraint, abstract_type& aOtherAnchor) = 0;
277 virtual void add_constraint(
const constraint& aConstraint, std::shared_ptr<abstract_type> aOtherAnchor) = 0;
279 virtual value_type evaluate_constraints(
const CalculatorArgs&... aArgs)
const = 0;
280 virtual value_type calculate(
const CalculatorArgs&... aArgs)
const = 0;
285 template <
template<
typename,
typename,
typename...>
class Anchor,
typename PVT,
typename Callable>
286 struct abstract_anchor_callable_function_cracker;
287 template <
template<
typename,
typename,
typename...>
class Anchor,
typename PVT,
typename R,
typename C,
typename... Args>
288 struct abstract_anchor_callable_function_cracker<Anchor, PVT, R(
C::*)(Args...) const>
290 typedef Anchor<R, PVT, Args...> type;
291 typedef R(C::* callable_type)(Args...) const;
292 typedef PVT property_value_type;
293 typedef R value_type;
294 typedef C class_type;
296 template <
template<
typename,
typename,
typename...>
class Anchor,
typename PVT,
typename R,
typename C,
typename... Args>
297 struct abstract_anchor_callable_function_cracker<Anchor, PVT, R(
C::*)(Args...)>
299 typedef Anchor<R, PVT, Args...> type;
300 typedef R(C::* callable_type)(Args...);
301 typedef PVT property_value_type;
302 typedef R value_type;
303 typedef C class_type;
307 template <
typename Property>
308 using i_anchor_t =
typename detail::abstract_anchor_callable_function_cracker<i_calculating_anchor, typename Property::value_type, typename Property::calculator_function_type>::type;
#define end_declare_enum(enumName)
#define declare_enum_string(enumName, enumEnumerator)
#define begin_declare_enum(enumName)
constexpr style_aspect operator&(style_aspect aLhs, style_aspect aRhs)
anchor_constraint_function
audio_channel operator~(audio_channel lhs)
constexpr style_aspect operator|(style_aspect aLhs, style_aspect aRhs)