Android-cuttlefish cvd tool
utils.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright 2019, The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef TEEUI_LIBTEEUI_UTILS_H_
19#define TEEUI_LIBTEEUI_UTILS_H_
20
21#include <math.h>
22#include <stddef.h>
23#include <stdint.h>
24#include <sys/types.h>
25
26#include <algorithm>
27#include <initializer_list>
28#include <optional>
29#include <tuple>
30#include <type_traits>
31
32#include <teeui/error.h>
33#include <teeui/log.h>
34
35namespace teeui {
36
37using std::optional;
38
39template <typename T, size_t elements> class Array {
40 using array_type = T[elements];
41
42 public:
43 constexpr Array() : data_{} {}
44 constexpr Array(const T (&data)[elements]) { std::copy(data, data + elements, data_); }
45 constexpr Array(const std::initializer_list<uint8_t>& li) {
46 size_t i = 0;
47 for (auto& item : li) {
48 data_[i] = item;
49 ++i;
50 if (i == elements) break;
51 }
52 for (; i < elements; ++i) {
53 data_[i] = {};
54 }
55 }
56
57 T* data() { return data_; }
58 const T* data() const { return data_; }
59 constexpr size_t size() const { return elements; }
60
61 T* begin() { return data_; }
62 T* end() { return data_ + elements; }
63 const T* begin() const { return data_; }
64 const T* end() const { return data_ + elements; }
65
66 static constexpr Array fill(const T& v) {
67 Array result;
68 for (size_t i = 0; i < elements; ++i) {
69 result.data_[i] = v;
70 }
71 return result;
72 }
73
74 private:
76};
77
78template <typename T> auto bytesCast(const T& v) -> const uint8_t (&)[sizeof(T)] {
79 return *reinterpret_cast<const uint8_t(*)[sizeof(T)]>(&v);
80}
81template <typename T> auto bytesCast(T& v) -> uint8_t (&)[sizeof(T)] {
82 return *reinterpret_cast<uint8_t(*)[sizeof(T)]>(&v);
83}
84
86 template <typename T> struct has_data {
87 template <typename U> static int f(const U*, const void*) { return 0; }
88 template <typename U> static int* f(const U* u, decltype(u->data())) { return nullptr; }
89 static constexpr bool value = std::is_pointer<decltype(f((T*)nullptr, ""))>::value;
90 };
91
92 public:
93 template <typename T>
94 ByteBufferProxy(const T& buffer, decltype(buffer.data()) = nullptr)
95 : data_(reinterpret_cast<const uint8_t*>(buffer.data())), size_(buffer.size()) {
96 static_assert(sizeof(decltype(*buffer.data())) == 1, "elements to large");
97 }
98
99 template <size_t size>
100 ByteBufferProxy(const char (&buffer)[size])
101 : data_(reinterpret_cast<const uint8_t*>(buffer)), size_(size - 1) {
102 static_assert(size > 0, "even an empty string must be 0-terminated");
103 }
104
105 template <size_t size>
106 ByteBufferProxy(const uint8_t (&buffer)[size]) : data_(buffer), size_(size) {}
107
108 ByteBufferProxy() : data_(nullptr), size_(0) {}
109
110 const uint8_t* data() const { return data_; }
111 size_t size() const { return size_; }
112
113 const uint8_t* begin() const { return data_; }
114 const uint8_t* end() const { return data_ + size_; }
115
116 private:
117 const uint8_t* data_;
118 size_t size_;
119};
120
121constexpr const uint8_t kAuthTokenKeySize = 32;
122constexpr const uint8_t kHmacKeySize = kAuthTokenKeySize;
125
131template <typename Impl> class HMac {
132 public:
133 template <typename... Data>
134 static optional<Hmac> hmac256(const AuthTokenKey& key, const Data&... data) {
135 return Impl::hmac256(key, {data...});
136 }
137};
138
139bool operator==(const ByteBufferProxy& lhs, const ByteBufferProxy& rhs);
140
141template <typename IntType, uint32_t byteOrder> struct choose_hton;
142
143template <typename IntType> struct choose_hton<IntType, __ORDER_LITTLE_ENDIAN__> {
144 inline static IntType hton(const IntType& value) {
145 IntType result = {};
146 const unsigned char* inbytes = reinterpret_cast<const unsigned char*>(&value);
147 unsigned char* outbytes = reinterpret_cast<unsigned char*>(&result);
148 for (int i = sizeof(IntType) - 1; i >= 0; --i) {
149 *(outbytes++) = inbytes[i];
150 }
151 return result;
152 }
153};
154
155template <typename IntType> struct choose_hton<IntType, __ORDER_BIG_ENDIAN__> {
156 inline static IntType hton(const IntType& value) { return value; }
157};
158
159template <typename IntType> inline IntType hton(const IntType& value) {
161}
162
163template <typename IntType> inline IntType ntoh(const IntType& value) {
164 // same operation as hton
166}
167
168enum class Unit : uint8_t {
169 PX,
170 DP,
171 MM,
172};
173
174template <Unit unit> struct UnitT { constexpr static const Unit value = unit; };
175
179
180template <typename Unit> inline constexpr const char* str = "N/A";
181
182template <> inline constexpr const char* str<px> = "px";
183template <> inline constexpr const char* str<dp> = "dp";
184template <> inline constexpr const char* str<mm> = "mm";
185
186using DefaultNumericType = float;
187
188namespace bits {
189
190inline long double abs(long double v) {
191 return ::fabsl(v);
192}
193inline double abs(double v) {
194 return ::fabs(v);
195}
196
197inline long double ceil(long double v) {
198 return ::ceill(v);
199}
200
201inline double ceil(double v) {
202 return ::ceil(v);
203}
204
205inline long double floor(long double v) {
206 return ::floorl(v);
207}
208
209inline double floor(double v) {
211}
212
213inline long double sqrt(long double v) {
214 return ::sqrtl(v);
215}
216
217inline double sqrt(double v) {
218 return ::sqrt(v);
219}
220
221inline float round(float v) {
222 return ::roundf(v);
223}
224
225inline long double round(long double v) {
226 return ::roundl(v);
227}
228
229inline double round(double v) {
231}
232
233} // namespace bits
234
235template <typename Unit, typename Numeric = DefaultNumericType> class Coordinate;
236
237template <typename Numeric> struct Add {
239 const Coordinate<px, Numeric>& v2) {
240 return v1 + v2;
241 }
242};
243template <typename Numeric> struct Sub {
245 const Coordinate<px, Numeric>& v2) {
246 return v1 - v2;
247 }
248};
249template <typename Numeric> struct Mul {
251 const Coordinate<px, Numeric>& v2) {
252 return v1 * v2;
253 }
254};
255template <typename Numeric> struct Div {
257 const Coordinate<px, Numeric>& v2) {
258 return v1 / v2;
259 }
260};
261
262template <typename T1, typename T2, typename Numeric, template <typename> class Op> struct BinOp;
263
264template <typename T1, typename T2, typename Numeric> using add = BinOp<T1, T2, Numeric, Add>;
265template <typename T1, typename T2, typename Numeric> using sub = BinOp<T1, T2, Numeric, Sub>;
266template <typename T1, typename T2, typename Numeric> using mul = BinOp<T1, T2, Numeric, Mul>;
267template <typename T1, typename T2, typename Numeric> using div = BinOp<T1, T2, Numeric, Div>;
268
269template <typename T1, typename T2, typename Numeric, template <typename> class Op> struct BinOp {
270 private:
271 T1 v1_;
272 T2 v2_;
273
274 public:
275 constexpr BinOp(const T1& v1, const T2& v2) : v1_(v1), v2_(v2) {}
276 BinOp(const BinOp&) = default;
277 BinOp(BinOp&&) = default;
278
279 template <typename Context> Coordinate<px, Numeric> eval(const Context& ctx) const {
280 Coordinate<px, Numeric> v1 = ctx = v1_;
281 Coordinate<px, Numeric> v2 = ctx = v2_;
282 return Op<Numeric>::eval(v1, v2);
283 }
284 template <typename T> constexpr add<BinOp, T, Numeric> operator+(const T& v) const {
285 return {*this, v};
286 }
287 template <typename T> constexpr sub<BinOp, T, Numeric> operator-(const T& v) const {
288 return {*this, v};
289 }
290 template <typename T> constexpr mul<BinOp, T, Numeric> operator*(const T& v) const {
291 return {*this, v};
292 }
293 template <typename T> constexpr div<BinOp, T, Numeric> operator/(const T& v) const {
294 return {*this, v};
295 }
296};
297
298template <typename Name, typename ParamType> struct MetaParam {};
299
300template <typename Name, typename Unit, typename Numeric>
301struct MetaParam<Name, Coordinate<Unit, Numeric>> {
302 template <typename T> constexpr add<MetaParam, T, Numeric> operator+(const T& v) const {
303 return {*this, v};
304 }
305 template <typename T> constexpr sub<MetaParam, T, Numeric> operator-(const T& v) const {
306 return {*this, v};
307 }
308 template <typename T> constexpr mul<MetaParam, T, Numeric> operator*(const T& v) const {
309 return {*this, v};
310 }
311 template <typename T> constexpr div<MetaParam, T, Numeric> operator/(const T& v) const {
312 return {*this, v};
313 }
314};
315
316template <typename Name, typename ParamType> class Param {
317 private:
318 ParamType param_;
319
320 public:
321 Param() : param_{} {}
322 Param(const Param&) = default;
323 Param(Param&&) = default;
324 Param& operator=(const Param&) = default;
325 Param& operator=(Param&&) = default;
326 inline const ParamType& operator*() const { return param_; }
327 inline ParamType& operator*() { return param_; }
328 inline const ParamType* operator->() const { return &param_; }
329 inline ParamType* operator->() { return &param_; }
330};
331
332template <typename Unit, typename Numeric> class Coordinate {
333 Numeric value_;
334
335 public:
336 using unit_t = Unit;
337 constexpr Coordinate() : value_{} {}
338 constexpr Coordinate(Numeric value) : value_(value) {}
339 Coordinate(const Coordinate&) = default;
340 Coordinate(Coordinate&&) = default;
341 template <typename N> Coordinate(const Coordinate<Unit, N>& other) {
342 if constexpr (std::is_floating_point<N>::value && std::is_integral<Numeric>::value) {
343 value_ = bits::round(other.count());
344 } else {
345 value_ = other.count();
346 }
347 }
348 Coordinate& operator=(const Coordinate& rhs) = default;
349 Coordinate& operator=(Coordinate&& rhs) = default;
350
351 constexpr Coordinate operator-(const Coordinate& v) const { return value_ - v.value_; }
352 constexpr Coordinate operator+(const Coordinate& v) const { return value_ + v.value_; }
353 constexpr Coordinate& operator-=(const Coordinate& v) {
354 value_ -= v.value_;
355 return *this;
356 }
357 constexpr Coordinate& operator+=(const Coordinate& v) {
358 value_ += v.value_;
359 return *this;
360 }
361 constexpr Coordinate operator*(const Coordinate& v) const { return value_ * v.value_; }
362 constexpr Coordinate& operator*=(const Coordinate& v) {
363 value_ *= v.value_;
364 return *this;
365 }
366 constexpr Coordinate operator/(const Coordinate& v) const { return value_ / v.value_; }
367 constexpr Coordinate& operator/=(const Coordinate& v) {
368 value_ /= v.value_;
369 return *this;
370 }
371 constexpr Coordinate operator-() const { return -value_; }
372
373 Coordinate abs() const { return bits::abs(value_); }
374 Coordinate ceil() const { return bits::ceil(value_); }
375 Coordinate floor() const { return bits::floor(value_); }
376 Coordinate sqrt() const { return bits::sqrt(value_); }
377
378 constexpr bool operator==(const Coordinate& v) const { return value_ == v.value_; }
379 constexpr bool operator!=(const Coordinate& v) const { return !(*this == v); }
380 constexpr bool operator<(const Coordinate& v) const { return value_ < v.value_; }
381 constexpr bool operator>(const Coordinate& v) const { return v < *this; }
382 constexpr bool operator<=(const Coordinate& v) const { return !(v < *this); }
383 constexpr bool operator>=(const Coordinate& v) const { return !(*this < v); }
384
385 template <typename T> constexpr add<Coordinate, T, Numeric> operator+(const T& v) const {
386 return {*this, v};
387 }
388 template <typename T> constexpr sub<Coordinate, T, Numeric> operator-(const T& v) const {
389 return {*this, v};
390 }
391 template <typename T> constexpr mul<Coordinate, T, Numeric> operator*(const T& v) const {
392 return {*this, v};
393 }
394 template <typename T> constexpr div<Coordinate, T, Numeric> operator/(const T& v) const {
395 return {*this, v};
396 }
397
398 Numeric count() const { return value_; }
399};
400
401template <typename... T> struct MetaList {};
402
403template <typename MetaParam> struct metaParam2Param;
404
405template <typename ParamName, typename ParamType>
406struct metaParam2Param<MetaParam<ParamName, ParamType>> {
408};
409
410template <typename MetaParam> struct metaParam2ParamType;
411
412template <typename ParamName, typename ParamType>
413struct metaParam2ParamType<MetaParam<ParamName, ParamType>> {
414 using type = ParamType;
415};
416
417template <typename T> struct isCoordinateType { constexpr static const bool value = false; };
418
419template <typename Unit, typename Numeric> struct isCoordinateType<Coordinate<Unit, Numeric>> {
420 constexpr static const bool value = true;
421};
422
423template <typename MetaParam> struct isCoordinateParam;
424
425template <typename ParamName, typename ParamType>
426struct isCoordinateParam<MetaParam<ParamName, ParamType>> {
427 constexpr static const bool value = isCoordinateType<ParamType>::value;
428};
429
430template <typename T> struct isMetaParam { constexpr static const bool value = false; };
431
432template <typename ParamName, typename ParamType>
433struct isMetaParam<MetaParam<ParamName, ParamType>> {
434 constexpr static const bool value = true;
435};
436
437template <typename Param, typename Numeric = DefaultNumericType> class context;
438
439template <typename... ParamsNames, typename... ParamTypes, typename Numeric>
440class context<MetaList<MetaParam<ParamsNames, ParamTypes>...>, Numeric> {
441 Numeric mm2px_;
442 Numeric dp2px_;
443 std::tuple<Param<ParamsNames, ParamTypes>...> params_;
444
445 class Proxy {
446 Numeric valuepx_;
447 Numeric mm2px_, dp2px_;
448
449 public:
450 Proxy(Numeric valuepx, Numeric mm2px, Numeric dp2px)
451 : valuepx_(valuepx), mm2px_(mm2px), dp2px_(dp2px) {}
452 Proxy(const Proxy&) = default;
453 Proxy(Proxy&&) = default;
454
455 operator Coordinate<px, Numeric>() const { return valuepx_; }
456 operator Coordinate<mm, Numeric>() const { return valuepx_ / mm2px_; }
457 operator Coordinate<dp, Numeric>() const { return valuepx_ / dp2px_; }
458 };
459
460 public:
461 explicit context(Numeric mm2px) {
462 mm2px_ = mm2px;
463 dp2px_ = (mm2px * 25.4) / 160.0; /* 1dp = 1/160th of an inch */
464 }
465
466 context(Numeric mm2px, Numeric dp2px) : mm2px_(mm2px), dp2px_(dp2px) {}
467
468 context(const context&) = default;
469 context(context&&) = default;
470 context& operator=(const context&) = default;
471 context& operator=(context&&) = default;
472
473 template <typename MetaParam> auto& getParam() {
475 }
476 template <typename MetaParam> const auto& getParam() const {
478 }
479
480 template <typename MetaParam, typename = std::enable_if_t<isCoordinateParam<MetaParam>::value>>
482 *getParam<MetaParam>() = v;
483 }
484
485 template <typename MetaParam, typename Unit, typename N,
486 typename = std::enable_if_t<isCoordinateParam<MetaParam>::value>>
488 *getParam<MetaParam>() = *this = v;
489 }
490
491 template <typename MetaParam>
493 const typename metaParam2ParamType<MetaParam>::type>& v) {
494 *getParam<MetaParam>() = v;
495 }
496
498 return {rhs.count(), mm2px_, dp2px_};
499 }
501 return {rhs.count() * mm2px_, mm2px_, dp2px_};
502 }
504 return {rhs.count() * dp2px_, mm2px_, dp2px_};
505 }
506 template <typename T1, typename T2, template <typename> class Op>
508 return {rhs.eval(*this).count(), mm2px_, dp2px_};
509 }
510 template <typename ParamName, typename ParamType>
511 std::enable_if_t<isCoordinateParam<MetaParam<ParamName, ParamType>>::value, Proxy>
513 return {getParam<MetaParam<ParamName, ParamType>>()->count(), mm2px_, dp2px_};
514 }
515 template <typename ParamName, typename ParamType>
516 std::enable_if_t<!isCoordinateParam<MetaParam<ParamName, ParamType>>::value, const ParamType&>
518 return *getParam<MetaParam<ParamName, ParamType>>();
519 }
520 template <typename T,
521 typename = std::enable_if_t<!(isMetaParam<T>::value || isCoordinateType<T>::value)>>
522 inline T&& operator=(T&& v) const {
523 return std::forward<T>(v);
524 }
525};
526
530
531template <typename Coord> class Vec2d {
532 Coord x_, y_;
533
534 public:
535 constexpr Vec2d() : x_{}, y_{} {}
536 constexpr Vec2d(Coord x, Coord y) : x_(x), y_(y) {}
537 Vec2d(const Vec2d&) = default;
538 Vec2d(Vec2d&&) = default;
539 template <typename N>
541 : x_(other.x()), y_(other.y()) {}
542
543 Vec2d& operator=(const Vec2d& rhs) = default;
544 Vec2d& operator=(Vec2d&& rhs) = default;
545
546 Vec2d operator-(const Vec2d& rhs) const { return Vec2d(*this) -= rhs; }
547 Vec2d operator+(const Vec2d& rhs) const { return Vec2d(*this) += rhs; }
548 Vec2d& operator-=(const Vec2d& rhs) {
549 x_ -= rhs.x_;
550 y_ -= rhs.y_;
551 return *this;
552 }
553 Vec2d& operator+=(const Vec2d& rhs) {
554 x_ += rhs.x_;
555 y_ += rhs.y_;
556 return *this;
557 }
558 Coord operator*(const Vec2d& rhs) const { return (x_ * rhs.x_ + y_ * rhs.y_).count(); }
559 Vec2d operator*(const Coord& f) const { return Vec2d(*this) *= f; }
560 Vec2d& operator*=(const Coord& f) {
561 x_ *= f;
562 y_ *= f;
563 return *this;
564 }
565 Vec2d operator/(const Coord& f) { return Vec2d(*this) /= f; }
566 Vec2d& operator/=(const Coord& f) {
567 x_ /= f;
568 y_ /= f;
569 return *this;
570 }
571 bool operator==(const Vec2d& rhs) const { return x_ == rhs.x() && y_ == rhs.y(); }
572 Coord length() const {
573 Coord factor = *this * *this;
574 return bits::sqrt(factor.count());
575 }
576 Vec2d unit() const { return Vec2d(*this) /= length(); }
577 Coord x() const { return x_; }
578 Coord y() const { return y_; }
579};
580
581#ifdef TEEUI_DO_LOG_DEBUG
582template <typename Unit, typename Numeric>
583std::ostream& operator<<(std::ostream& out, const Coordinate<Unit, Numeric>& p) {
584 out << std::setprecision(10) << p.count() << str<Unit>;
585 return out;
586}
587
588template <typename Coord> std::ostream& operator<<(std::ostream& out, const Vec2d<Coord>& p) {
589 out << "Vec2d(" << p.x() << ", " << p.y() << ")";
590 return out;
591}
592#endif
593
594using Color = uint32_t;
595
596template <typename Coord> using Point = Vec2d<Coord>;
597
599 pxs width = pxs(1.0));
600
601Color drawCirclePoint(Point<pxs> center, pxs r, Point<pxs> px_origin, Color c);
602
605
606/*
607 * Computes the intersection of the lines given by ax + b and cy + d.
608 * The result may be empty if there is no solution.
609 */
610optional<PxPoint> intersect(const PxVec& a, const PxPoint& b, const PxVec& c, const PxPoint& d);
611
612namespace bits {
613
614static constexpr const ssize_t kIntersectEmpty = -1;
618static constexpr const ssize_t kIntersectAllPositive = -2;
619
620ssize_t intersect(const PxPoint* oBegin, const PxPoint* oEnd, const PxPoint& lineA,
621 const PxPoint& lineB, PxPoint* nBegin, PxPoint* nEnd);
622
623pxs area(const PxPoint* begin, const PxPoint* end);
624
625} // namespace bits
626
635template <size_t capacity> class ConvexObject {
636 template <size_t other_cap> friend class ConvexObject;
637
638 protected:
640 size_t fill_;
641
642 public:
643 ConvexObject() : fill_(0) {}
644 explicit constexpr ConvexObject(std::initializer_list<PxPoint> l) : fill_(0) {
645 if (l.size() > capacity) return;
646 for (const auto& p : l) {
647 points_[fill_++] = p;
648 }
649 }
650 ConvexObject(const ConvexObject& other) = default;
651 ConvexObject(ConvexObject&& other) = default;
652 ConvexObject& operator=(const ConvexObject& other) = default;
654
655 constexpr size_t size() const { return fill_; }
656
657 constexpr const PxPoint* begin() const { return &points_[0]; }
658 constexpr const PxPoint* end() const { return &points_[fill_]; }
659
660 template <size_t result_cap>
661 optional<ConvexObject<result_cap>> intersect(const PxPoint& A, const PxPoint& B) const {
662 static_assert(result_cap >= capacity,
663 "resulting capacity must be at least as large as the original");
665 ssize_t vCount =
666 bits::intersect(begin(), end(), A, B, &result.points_[0], &result.points_[result_cap]);
667 if (vCount == bits::kIntersectEmpty) return {};
668 // -2 is returned if the object is in the positive half plane of the line (may be tangent)
669 if (vCount == bits::kIntersectAllPositive) {
670 std::copy(begin(), end(), &result.points_[0]);
671 vCount = fill_;
672 }
673 result.fill_ = vCount;
674 return result;
675 }
676
677 template <size_t result_cap, size_t arg_cap>
678 optional<ConvexObject<result_cap>> intersect(const ConvexObject<arg_cap>& other) const {
679 return intersect<result_cap>(other.begin(), other.end());
680 }
681
682 template <size_t result_cap>
683 optional<ConvexObject<result_cap>> intersect(const PxPoint* begin, const PxPoint* end) const {
684 if (end - begin < 3) return {};
685 auto b = begin;
686 auto a = end - 1;
687 auto result = intersect<result_cap>(*a, *b);
688 a = b++;
689 while (result && b != end) {
690 result = result->template intersect<result_cap>(*a, *b);
691 a = b++;
692 }
693 return result;
694 }
695
696 pxs area() const { return bits::area(begin(), end()); }
697
698 void push_back(const PxPoint& p) {
699 if (fill_ < capacity) {
700 points_[fill_++] = p;
701 }
702 }
703};
704
705#ifdef TEEUI_DO_LOG_DEBUG
706template <size_t capacity>
707std::ostream& operator<<(std::ostream& out, const ConvexObject<capacity>& o) {
708 out << "ConvexObject(";
709 bool first = true;
710 for (const auto& p : o) {
711 if (first)
712 first = false;
713 else
714 out << ", ";
715 out << p;
716 }
717 out << ")";
718 return out;
719}
720#endif
721
722template <typename Coord> class Box {
725
726 public:
727 Box() {}
728 template <typename N>
730 : topLeft_(other.topLeft()), extend_(other.extend()) {}
731 Box(const Coord& x, const Coord& y, const Coord& w, const Coord& h)
732 : topLeft_(x, y), extend_(w, h) {}
735 bool contains(Point<Coord> p) const {
736 p -= topLeft_;
737 return p.y().count() >= 0 && p.y().count() <= extend_.y().count() && p.x().count() >= 0 &&
738 p.x().count() <= extend_.x().count();
739 }
740 bool contains(const Box& other) const {
741 auto br = bottomRight();
742 auto obr = other.bottomRight();
743 return topLeft_.x() <= other.topLeft_.x() && br.x() >= obr.x() &&
744 topLeft_.y() <= other.topLeft_.y() && br.y() >= obr.y();
745 }
746 bool overlaps(const Box& other) const {
747 auto br = bottomRight();
748 auto obr = other.bottomRight();
749 return topLeft_.x() < obr.x() && other.topLeft_.x() < br.x() && topLeft_.y() < obr.y() &&
750 other.topLeft_.y() < obr.y();
751 }
752
757 bool fitsInside(const Box& other) const { return w() <= other.w() && h() <= other.w(); }
759 Point<Coord> topLeft() const { return topLeft_; }
760 Vec2d<Coord> extend() const { return extend_; }
761 Coord x() const { return topLeft_.x(); }
762 Coord y() const { return topLeft_.y(); }
763 Coord w() const { return extend_.x(); }
764 Coord h() const { return extend_.y(); }
765
766 Box merge(const Box& other) const {
767 Coord x = std::min(topLeft_.x(), other.topLeft_.x());
768 Coord y = std::min(topLeft_.y(), other.topLeft_.y());
769 auto br = bottomRight();
770 auto obr = other.bottomRight();
771 Coord w = std::max(br.x(), obr.x()) - x;
772 Coord h = std::max(br.y(), obr.y()) - y;
773 return {x, y, w, h};
774 }
775
779 Box merge(const Point<Coord>& p) const {
780 auto br = bottomRight();
781 TEEUI_LOG << "A tl: " << topLeft_ << " br: " << br << " new: " << p << ENDL;
782 Coord x = std::min(topLeft_.x(), p.x());
783 Coord y = std::min(topLeft_.y(), p.y());
784 Coord w = std::max(br.x(), p.x()) - x;
785 Coord h = std::max(br.y(), p.y()) - y;
786 TEEUI_LOG << "B x: " << x << " y: " << y << " w: " << w << " h: " << h << ENDL;
787 return {x, y, w, h};
788 }
789
793 Box merge(const Point<Coord>* begin, const Point<Coord>* end) const {
794 auto tl = topLeft();
795 auto br = bottomRight();
796 while (begin != end) {
797 TEEUI_LOG << "A tl: " << tl << " br: " << br << " new: " << *begin << ENDL;
798 tl = {std::min(tl.x(), begin->x()), std::min(tl.y(), begin->y())};
799 br = {std::max(br.x(), begin->x()), std::max(br.y(), begin->y())};
800 TEEUI_LOG << "B tl: " << tl << " br: " << br << " new: " << *begin << ENDL;
801 ++begin;
802 }
803 return {tl, br - tl};
804 }
805
809 static Box boundingBox(const Point<Coord>* begin, const Point<Coord>* end) {
810 if (begin == end) return {};
811 Box result(*begin, {0, 0});
812 result.merge(begin + 1, end);
813 return result;
814 }
815
816 /*
817 * Translates the Box by the given offset. And returns a reference to itself
818 */
820 topLeft_ += offset;
821 return *this;
822 }
823 /*
824 * Returns copy of this box translated by offset.
825 */
826 Box translate(const Point<Coord>& offset) const& {
827 Box result = *this;
828 result.topLeft_ += offset;
829 return result;
830 }
831 /*
832 * When called on a temporary just reuse this box.
833 */
834 Box translate(const Point<Coord>& offset) && {
835 topLeft_ += offset;
836 return *this;
837 }
838};
839
840#ifdef TEEUI_DO_LOG_DEBUG
841template <typename Coord> std::ostream& operator<<(std::ostream& out, const Box<Coord>& p) {
842 out << "Box(x: " << p.x().count() << " y: " << p.y().count() << " w: " << p.w().count()
843 << " h: " << p.h().count() << ")";
844 return out;
845}
846#endif
847
848enum class EventType : uint8_t {
849 KeyDown,
850 KeyUp,
851 KeyMoved,
852};
853
854struct Event {
855 uint32_t x_;
856 uint32_t y_;
858};
859
860template <typename Fn> struct Callback;
861
862template <typename Ret, typename... Args> struct Callback<Ret(Args...)> {
863 Ret (*callback_)(Args... args, void* priv_data);
865 Ret operator()(Args... args) const { return callback_(args..., priv_data_); }
866};
867
868template <typename Ret, typename... Args>
869Callback<Ret(Args...)> makeCallback(Ret (*fn)(Args..., void*), void* priv_data) {
870 return {fn, priv_data};
871}
872
873template <typename Fn, typename Ret, typename... Args> struct CallbackHelper {
874 Fn fn_;
875 operator Callback<Ret(Args...)>() {
876 return makeCallback<Ret, Args...>(
877 [](Args... args, void* priv_data) -> Ret {
878 return reinterpret_cast<CallbackHelper*>(priv_data)->fn_(args...);
879 },
880 this);
881 }
882};
883
885using PixelDrawer = Callback<Error(uint32_t, uint32_t, Color)>;
886
887template <typename Fn>
889
890template <typename Fn> PixelDrawerHelper<Fn> makePixelDrawer(Fn fn) {
891 return PixelDrawerHelper<Fn>{fn};
892}
893
894template <typename Derived> struct LayoutElement {
896 LayoutElement() = default;
897 template <typename Context>
898 LayoutElement(const Context& context)
899 : bounds_{context = Derived::pos_x, context = Derived::pos_y, context = Derived::dim_w,
900 context = Derived::dim_h} {}
901
902 Error draw(const PixelDrawer&) { return Error::OK; }
903 Error hit(const Event&) { return Error::OK; }
904};
905
906template <typename... Elements, typename Context>
907std::tuple<Elements...> instantiateLayout(MetaList<Elements...>, const Context& context) {
908 std::tuple<Elements...> result{Elements(context)...};
909 return result;
910}
911
912template <typename T> struct MetaList2Layout;
913
914template <typename... Elements> struct MetaList2Layout<MetaList<Elements...>> {
915 using type = std::tuple<Elements...>;
916};
917
918template <typename T> using layout_t = typename MetaList2Layout<T>::type;
919
920template <typename... Coords>
921constexpr inline std::tuple<Vec2d<Coords>...> makeConvexObject(const Vec2d<Coords>&... points) {
922 return {points...};
923}
924
925template <size_t capacity, typename Tuple, typename Context, size_t... I>
926constexpr inline ConvexObject<capacity>
927initConvexObject(const Context& context, const Tuple& outline, std::index_sequence<I...>) {
929 {PxVec(context = std::get<I>(outline).x(), context = std::get<I>(outline).y())...});
930}
931
932template <size_t capacity, typename... Points, typename Context>
933constexpr inline ConvexObject<capacity> initConvexObject(const Context& context,
934 const std::tuple<Points...>& outline) {
935 return initConvexObject<capacity>(context, outline, std::index_sequence_for<Points...>{});
936}
937
938template <size_t capacity, typename Tuple, typename Context, size_t... I, size_t size>
939constexpr inline void initConvexObjectArray(const Context& context,
940 ConvexObject<capacity> (&out)[size], const Tuple& t,
941 std::index_sequence<I...>) {
942 static_assert(sizeof...(I) <= size,
943 "Array to initialize must be big enough to hold all tuple elements");
944 [](auto...) {}((out[I] = initConvexObject<capacity>(context, std::get<I>(t)))...);
945}
946
947template <size_t capacity, typename... COs, typename Context, size_t size>
948constexpr inline void initConvexObjectArray(const Context& context,
950 const std::tuple<COs...>& t) {
951 initConvexObjectArray(context, out, t, std::index_sequence_for<COs...>());
952}
953
954template <typename Iterator> class Range {
957
958 public:
960 const Iterator begin() const { return begin_; }
961 const Iterator end() const { return end_; }
962};
963
964template <typename Iterator> Range<Iterator> makeRange(Iterator begin, Iterator end) {
965 return {begin, end};
966}
967
968} // namespace teeui
969
970#define Position(x, y) \
971 static const constexpr auto pos_x = x; \
972 static const constexpr auto pos_y = y
973
974#define Dimension(w, h) \
975 static const constexpr auto dim_w = w; \
976 static const constexpr auto dim_h = h
977
978#define BEGIN_ELEMENT(name, type, ...) \
979 struct name : public type<name, ##__VA_ARGS__> { \
980 name() = default; \
981 template <typename Context> \
982 name(const Context& context) : type<name, ##__VA_ARGS__>(context) {}
983
984#define END_ELEMENT() }
985
986#define DECLARE_TYPED_PARAMETER(name, type) \
987 struct Param_##name {}; \
988 using name = ::teeui::MetaParam<Param_##name, type>
989
990#define DECLARE_PARAMETER(name) DECLARE_TYPED_PARAMETER(name, ::teeui::pxs)
991
992#define CONSTANT(name, value) static constexpr const auto name = value
993
994#define BOTTOM_EDGE_OF(name) (name::pos_y + name::dim_h)
995
996#define CONVEX_OBJECT(...) makeConvexObject(__VA_ARGS__)
997
998#define CONVEX_OBJECTS(...) std::make_tuple(__VA_ARGS__)
999
1004#define NEW_LAYOUT(name, ...) using name = ::teeui::MetaList<__VA_ARGS__>
1005
1006#define NEW_PARAMETER_SET(name, ...) using name = ::teeui::MetaList<__VA_ARGS__>
1007
1008#define LABELS(name, ...) using ::teeui::MetaList<__VA_ARGS__>
1009
1010#define TEXT_ID(textId) static_cast<uint32_t>(textId)
1011#endif // TEEUI_LIBTEEUI_UTILS_H_
Definition: utils.h:39
static constexpr Array fill(const T &v)
Definition: utils.h:66
T[elements] array_type
Definition: utils.h:40
T * end()
Definition: utils.h:62
constexpr Array()
Definition: utils.h:43
T * begin()
Definition: utils.h:61
const T * end() const
Definition: utils.h:64
constexpr Array(const T(&data)[elements])
Definition: utils.h:44
const T * begin() const
Definition: utils.h:63
array_type data_
Definition: utils.h:75
constexpr size_t size() const
Definition: utils.h:59
const T * data() const
Definition: utils.h:58
constexpr Array(const std::initializer_list< uint8_t > &li)
Definition: utils.h:45
T * data()
Definition: utils.h:57
Definition: utils.h:722
Vec2d< Coord > extend() const
Definition: utils.h:760
Box(const Coord &x, const Coord &y, const Coord &w, const Coord &h)
Definition: utils.h:731
bool contains(const Box &other) const
Definition: utils.h:740
Coord h() const
Definition: utils.h:764
static Box boundingBox(const Point< Coord > *begin, const Point< Coord > *end)
Definition: utils.h:809
Box merge(const Box &other) const
Definition: utils.h:766
Vec2d< Coord > extend_
Definition: utils.h:724
Box merge(const Point< Coord > &p) const
Definition: utils.h:779
Box translate(const Point< Coord > &offset) &&
Definition: utils.h:834
Coord x() const
Definition: utils.h:761
Point< Coord > bottomRight() const
Definition: utils.h:758
bool fitsInside(const Box &other) const
Definition: utils.h:757
Box(const Box< Coordinate< typename Coord::unit_t, N > > &other)
Definition: utils.h:729
bool overlaps(const Box &other) const
Definition: utils.h:746
Box translate(const Point< Coord > &offset) const &
Definition: utils.h:826
Box()
Definition: utils.h:727
Coord w() const
Definition: utils.h:763
Box merge(const Point< Coord > *begin, const Point< Coord > *end) const
Definition: utils.h:793
Box(const Point< Coord > &topLeft, const Vec2d< Coord > &extend)
Definition: utils.h:733
Point< Coord > topLeft_
Definition: utils.h:723
Coord y() const
Definition: utils.h:762
Point< Coord > topLeft() const
Definition: utils.h:759
bool contains(Point< Coord > p) const
Definition: utils.h:735
Box & translateSelf(const Point< Coord > &offset)
Definition: utils.h:819
Definition: utils.h:85
const uint8_t * begin() const
Definition: utils.h:113
const uint8_t * data_
Definition: utils.h:117
size_t size() const
Definition: utils.h:111
const uint8_t * data() const
Definition: utils.h:110
ByteBufferProxy(const uint8_t(&buffer)[size])
Definition: utils.h:106
size_t size_
Definition: utils.h:118
ByteBufferProxy(const T &buffer, decltype(buffer.data())=nullptr)
Definition: utils.h:94
ByteBufferProxy()
Definition: utils.h:108
const uint8_t * end() const
Definition: utils.h:114
ByteBufferProxy(const char(&buffer)[size])
Definition: utils.h:100
Definition: utils.h:635
ConvexObject(const ConvexObject &other)=default
ConvexObject(ConvexObject &&other)=default
friend class ConvexObject
Definition: utils.h:636
ConvexObject & operator=(ConvexObject &&other)=default
constexpr size_t size() const
Definition: utils.h:655
size_t fill_
Definition: utils.h:640
void push_back(const PxPoint &p)
Definition: utils.h:698
optional< ConvexObject< result_cap > > intersect(const PxPoint *begin, const PxPoint *end) const
Definition: utils.h:683
optional< ConvexObject< result_cap > > intersect(const ConvexObject< arg_cap > &other) const
Definition: utils.h:678
constexpr ConvexObject(std::initializer_list< PxPoint > l)
Definition: utils.h:644
constexpr const PxPoint * begin() const
Definition: utils.h:657
ConvexObject & operator=(const ConvexObject &other)=default
ConvexObject()
Definition: utils.h:643
constexpr const PxPoint * end() const
Definition: utils.h:658
pxs area() const
Definition: utils.h:696
PxPoint points_[capacity]
Definition: utils.h:639
optional< ConvexObject< result_cap > > intersect(const PxPoint &A, const PxPoint &B) const
Definition: utils.h:661
Definition: utils.h:332
constexpr bool operator==(const Coordinate &v) const
Definition: utils.h:378
Coordinate & operator=(const Coordinate &rhs)=default
Coordinate floor() const
Definition: utils.h:375
Coordinate(const Coordinate< Unit, N > &other)
Definition: utils.h:341
constexpr bool operator<(const Coordinate &v) const
Definition: utils.h:380
Numeric count() const
Definition: utils.h:398
constexpr Coordinate & operator+=(const Coordinate &v)
Definition: utils.h:357
constexpr bool operator!=(const Coordinate &v) const
Definition: utils.h:379
constexpr Coordinate & operator*=(const Coordinate &v)
Definition: utils.h:362
constexpr Coordinate operator/(const Coordinate &v) const
Definition: utils.h:366
constexpr Coordinate & operator/=(const Coordinate &v)
Definition: utils.h:367
Coordinate abs() const
Definition: utils.h:373
constexpr Coordinate operator-(const Coordinate &v) const
Definition: utils.h:351
constexpr add< Coordinate, T, Numeric > operator+(const T &v) const
Definition: utils.h:385
constexpr Coordinate operator-() const
Definition: utils.h:371
constexpr sub< Coordinate, T, Numeric > operator-(const T &v) const
Definition: utils.h:388
Coordinate(Coordinate &&)=default
Numeric value_
Definition: utils.h:333
Coordinate sqrt() const
Definition: utils.h:376
constexpr bool operator>(const Coordinate &v) const
Definition: utils.h:381
constexpr Coordinate & operator-=(const Coordinate &v)
Definition: utils.h:353
constexpr Coordinate operator*(const Coordinate &v) const
Definition: utils.h:361
Coordinate & operator=(Coordinate &&rhs)=default
constexpr Coordinate()
Definition: utils.h:337
constexpr mul< Coordinate, T, Numeric > operator*(const T &v) const
Definition: utils.h:391
constexpr bool operator<=(const Coordinate &v) const
Definition: utils.h:382
constexpr Coordinate(Numeric value)
Definition: utils.h:338
constexpr Coordinate operator+(const Coordinate &v) const
Definition: utils.h:352
constexpr bool operator>=(const Coordinate &v) const
Definition: utils.h:383
Coordinate(const Coordinate &)=default
constexpr div< Coordinate, T, Numeric > operator/(const T &v) const
Definition: utils.h:394
Coordinate ceil() const
Definition: utils.h:374
Definition: error.h:26
@ OK
Definition: error.h:29
Definition: utils.h:131
static optional< Hmac > hmac256(const AuthTokenKey &key, const Data &... data)
Definition: utils.h:134
Definition: utils.h:316
ParamType param_
Definition: utils.h:318
ParamType * operator->()
Definition: utils.h:329
Param & operator=(Param &&)=default
Param & operator=(const Param &)=default
const ParamType * operator->() const
Definition: utils.h:328
Param(const Param &)=default
ParamType & operator*()
Definition: utils.h:327
Param()
Definition: utils.h:321
Param(Param &&)=default
const ParamType & operator*() const
Definition: utils.h:326
Definition: utils.h:954
Iterator begin_
Definition: utils.h:955
const Iterator end() const
Definition: utils.h:961
Range(Iterator begin, Iterator end)
Definition: utils.h:959
const Iterator begin() const
Definition: utils.h:960
Iterator end_
Definition: utils.h:956
Definition: utils.h:531
constexpr Vec2d()
Definition: utils.h:535
Vec2d & operator*=(const Coord &f)
Definition: utils.h:560
Vec2d(const Vec2d &)=default
Vec2d operator-(const Vec2d &rhs) const
Definition: utils.h:546
Vec2d operator+(const Vec2d &rhs) const
Definition: utils.h:547
Vec2d & operator-=(const Vec2d &rhs)
Definition: utils.h:548
Coord operator*(const Vec2d &rhs) const
Definition: utils.h:558
Coord y_
Definition: utils.h:532
bool operator==(const Vec2d &rhs) const
Definition: utils.h:571
Coord length() const
Definition: utils.h:572
Vec2d & operator+=(const Vec2d &rhs)
Definition: utils.h:553
Coord x_
Definition: utils.h:532
Vec2d & operator/=(const Coord &f)
Definition: utils.h:566
Vec2d & operator=(Vec2d &&rhs)=default
Vec2d operator/(const Coord &f)
Definition: utils.h:565
Vec2d & operator=(const Vec2d &rhs)=default
Coord y() const
Definition: utils.h:578
Vec2d(Vec2d &&)=default
Vec2d unit() const
Definition: utils.h:576
Vec2d(const Vec2d< Coordinate< typename Coord::unit_t, N > > &other)
Definition: utils.h:540
Coord x() const
Definition: utils.h:577
Vec2d operator*(const Coord &f) const
Definition: utils.h:559
constexpr Vec2d(Coord x, Coord y)
Definition: utils.h:536
Proxy(Numeric valuepx, Numeric mm2px, Numeric dp2px)
Definition: utils.h:450
void setParam(const Coordinate< Unit, N > &v)
Definition: utils.h:487
void setParam(const Coordinate< px, Numeric > &v)
Definition: utils.h:481
Proxy operator=(const Coordinate< mm, Numeric > &rhs) const
Definition: utils.h:500
std::tuple< Param< ParamsNames, ParamTypes >... > params_
Definition: utils.h:443
std::enable_if_t< isCoordinateParam< MetaParam< ParamName, ParamType > >::value, Proxy > operator=(const MetaParam< ParamName, ParamType > &) const
Definition: utils.h:512
context(Numeric mm2px, Numeric dp2px)
Definition: utils.h:466
void setParam(std::enable_if_t<!isCoordinateParam< MetaParam >::value, const typename metaParam2ParamType< MetaParam >::type > &v)
Definition: utils.h:492
std::enable_if_t<!isCoordinateParam< MetaParam< ParamName, ParamType > >::value, const ParamType & > operator=(const MetaParam< ParamName, ParamType > &) const
Definition: utils.h:517
Proxy operator=(const Coordinate< dp, Numeric > &rhs) const
Definition: utils.h:503
Proxy operator=(const Coordinate< px, Numeric > &rhs) const
Definition: utils.h:497
Proxy operator=(const BinOp< T1, T2, Numeric, Op > &rhs) const
Definition: utils.h:507
Definition: utils.h:437
#define min(a, b)
Definition: ext4_utils.h:44
int capacity()
Definition: health.cpp:64
char data[Size]
Definition: incremental_server.cpp:1
uint32_t size
Definition: io.h:2
Size< 0 > B
Definition: storage_literals.h:36
std::set< Range >::iterator Iterator
Definition: disjoint_range_set.cc:64
void Proxy(SharedFD server, std::function< SharedFD()> conn_factory)
Definition: socket2socket_proxy.cpp:191
std::vector< std::string_view > Args
Definition: incremental.h:28
std::ostream & operator<<(std::ostream &os, const ServiceInfo &service_info)
Definition: mdns_service_info.h:43
long double ceil(long double v)
Definition: utils.h:197
static constexpr const ssize_t kIntersectEmpty
Definition: utils.h:614
long double floor(long double v)
Definition: utils.h:205
long double sqrt(long double v)
Definition: utils.h:213
ssize_t intersect(const PxPoint *oBegin, const PxPoint *oEnd, const PxPoint &lineA, const PxPoint &lineB, PxPoint *nBegin, PxPoint *nEnd)
Definition: utils.cpp:155
double floor(double v)
Definition: utils.h:209
static constexpr const ssize_t kIntersectAllPositive
Definition: utils.h:618
double round(double v)
Definition: utils.h:229
pxs area(const PxPoint *begin, const PxPoint *end)
Definition: utils.cpp:250
double sqrt(double v)
Definition: utils.h:217
long double abs(long double v)
Definition: utils.h:190
double ceil(double v)
Definition: utils.h:201
float round(float v)
Definition: utils.h:221
Definition: layout.h:28
EventType
Definition: utils.h:848
bool operator==(const ByteBufferProxy &lhs, const ByteBufferProxy &rhs)
Definition: utils.cpp:22
Array< uint8_t, kAuthTokenKeySize > AuthTokenKey
Definition: utils.h:123
std::tuple< Elements... > instantiateLayout(MetaList< Elements... >, const Context &context)
Definition: utils.h:907
constexpr const char * str< dp >
Definition: utils.h:183
constexpr const char * str< mm >
Definition: utils.h:184
constexpr const char * str< px >
Definition: utils.h:182
constexpr ConvexObject< capacity > initConvexObject(const Context &context, const Tuple &outline, std::index_sequence< I... >)
Definition: utils.h:927
constexpr const char * str
Definition: utils.h:180
auto bytesCast(const T &v) -> const uint8_t(&)[sizeof(T)]
Definition: utils.h:78
Range< Iterator > makeRange(Iterator begin, Iterator end)
Definition: utils.h:964
PixelDrawerHelper< Fn > makePixelDrawer(Fn fn)
Definition: utils.h:890
Color drawCirclePoint(Point< pxs > center, pxs r, Point< pxs > px_origin, Color c)
Definition: utils.cpp:117
IntType hton(const IntType &value)
Definition: utils.h:159
uint32_t Color
Definition: utils.h:594
constexpr const uint8_t kHmacKeySize
Definition: utils.h:122
typename MetaList2Layout< T >::type layout_t
Definition: utils.h:918
optional< PxPoint > intersect(const PxVec &a, const PxPoint &b, const PxVec &c, const PxPoint &d)
Definition: utils.cpp:128
float DefaultNumericType
Definition: utils.h:186
constexpr const uint8_t kAuthTokenKeySize
Definition: utils.h:121
constexpr void initConvexObjectArray(const Context &context, ConvexObject< capacity >(&out)[size], const Tuple &t, std::index_sequence< I... >)
Definition: utils.h:939
Unit
Definition: utils.h:168
constexpr std::tuple< Vec2d< Coords >... > makeConvexObject(const Vec2d< Coords > &... points)
Definition: utils.h:921
Vec2d< pxs > PxVec
Definition: utils.h:604
IntType ntoh(const IntType &value)
Definition: utils.h:163
Color drawLinePoint(Point< pxs > a, Point< pxs > b, Point< pxs > px_origin, Color c, pxs width=pxs(1.0))
Definition: utils.cpp:91
Callback< Ret(Args...)> makeCallback(Ret(*fn)(Args..., void *), void *priv_data)
Definition: utils.h:869
Coordinate< px > pxs
Definition: utils.h:529
uint8_t type
Definition: pairing_connection.h:0
Definition: utils.h:237
static constexpr Coordinate< px, Numeric > eval(const Coordinate< px, Numeric > &v1, const Coordinate< px, Numeric > &v2)
Definition: utils.h:238
Definition: utils.h:269
constexpr mul< BinOp, T, Numeric > operator*(const T &v) const
Definition: utils.h:290
constexpr div< BinOp, T, Numeric > operator/(const T &v) const
Definition: utils.h:293
BinOp(BinOp &&)=default
Coordinate< px, Numeric > eval(const Context &ctx) const
Definition: utils.h:279
constexpr BinOp(const T1 &v1, const T2 &v2)
Definition: utils.h:275
T2 v2_
Definition: utils.h:272
constexpr sub< BinOp, T, Numeric > operator-(const T &v) const
Definition: utils.h:287
BinOp(const BinOp &)=default
constexpr add< BinOp, T, Numeric > operator+(const T &v) const
Definition: utils.h:284
T1 v1_
Definition: utils.h:271
Definition: utils.h:86
static int * f(const U *u, decltype(u->data()))
Definition: utils.h:88
static int f(const U *, const void *)
Definition: utils.h:87
static constexpr bool value
Definition: utils.h:89
Definition: utils.h:873
Fn fn_
Definition: utils.h:874
Ret operator()(Args... args) const
Definition: utils.h:865
void * priv_data_
Definition: utils.h:864
Definition: utils.h:860
Definition: utils.h:255
static constexpr Coordinate< px, Numeric > eval(const Coordinate< px, Numeric > &v1, const Coordinate< px, Numeric > &v2)
Definition: utils.h:256
Definition: utils.h:854
uint32_t x_
Definition: utils.h:855
EventType event_
Definition: utils.h:857
uint32_t y_
Definition: utils.h:856
Definition: utils.h:894
LayoutElement(const Context &context)
Definition: utils.h:898
Box< pxs > bounds_
Definition: utils.h:895
Error hit(const Event &)
Definition: utils.h:903
Error draw(const PixelDrawer &)
Definition: utils.h:902
std::tuple< Elements... > type
Definition: utils.h:915
Definition: utils.h:912
Definition: utils.h:401
constexpr mul< MetaParam, T, Numeric > operator*(const T &v) const
Definition: utils.h:308
constexpr div< MetaParam, T, Numeric > operator/(const T &v) const
Definition: utils.h:311
constexpr sub< MetaParam, T, Numeric > operator-(const T &v) const
Definition: utils.h:305
constexpr add< MetaParam, T, Numeric > operator+(const T &v) const
Definition: utils.h:302
Definition: utils.h:298
Definition: utils.h:249
static constexpr Coordinate< px, Numeric > eval(const Coordinate< px, Numeric > &v1, const Coordinate< px, Numeric > &v2)
Definition: utils.h:250
Definition: utils.h:243
static constexpr Coordinate< px, Numeric > eval(const Coordinate< px, Numeric > &v1, const Coordinate< px, Numeric > &v2)
Definition: utils.h:244
Definition: utils.h:174
static constexpr const Unit value
Definition: utils.h:174
static IntType hton(const IntType &value)
Definition: utils.h:156
static IntType hton(const IntType &value)
Definition: utils.h:144
Definition: utils.h:141
Definition: utils.h:423
Definition: utils.h:417
static constexpr const bool value
Definition: utils.h:417
Definition: utils.h:430
static constexpr const bool value
Definition: utils.h:430
Definition: utils.h:410
Definition: utils.h:403
#define TEEUI_LOG
Definition: log.h:27
#define ENDL
Definition: log.h:28