| 1 | #pragma once |
| 2 | |
| 3 | /* Generated with cbindgen:0.26.0 */ |
| 4 | |
| 5 | #include <cstdarg> |
| 6 | #include <cstdint> |
| 7 | #include <cstdlib> |
| 8 | #include <ostream> |
| 9 | #include <new> |
| 10 | #include "slint_enums_internal.h" |
| 11 | |
| 12 | namespace slint { |
| 13 | namespace cbindgen_private { |
| 14 | namespace types { |
| 15 | |
| 16 | /// PathMoveTo describes the event of setting the cursor on the path to use as starting |
| 17 | /// point for sub-sequent events, such as `LineTo`. Moving the cursor also implicitly closes |
| 18 | /// sub-paths and therefore beings a new sub-path. |
| 19 | struct PathMoveTo { |
| 20 | /// The x coordinate where the current position should be. |
| 21 | float x; |
| 22 | /// The y coordinate where the current position should be. |
| 23 | float y; |
| 24 | |
| 25 | bool operator==(const PathMoveTo& other) const { |
| 26 | return x == other.x && |
| 27 | y == other.y; |
| 28 | } |
| 29 | bool operator!=(const PathMoveTo& other) const { |
| 30 | return x != other.x || |
| 31 | y != other.y; |
| 32 | } |
| 33 | }; |
| 34 | |
| 35 | /// PathLineTo describes the event of moving the cursor on the path to the specified location |
| 36 | /// along a straight line. |
| 37 | struct PathLineTo { |
| 38 | /// The x coordinate where the line should go to. |
| 39 | float x; |
| 40 | /// The y coordinate where the line should go to. |
| 41 | float y; |
| 42 | |
| 43 | bool operator==(const PathLineTo& other) const { |
| 44 | return x == other.x && |
| 45 | y == other.y; |
| 46 | } |
| 47 | bool operator!=(const PathLineTo& other) const { |
| 48 | return x != other.x || |
| 49 | y != other.y; |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | /// PathArcTo describes the event of moving the cursor on the path across an arc to the specified |
| 54 | /// x/y coordinates, with the specified x/y radius and additional properties. |
| 55 | struct PathArcTo { |
| 56 | /// The x coordinate where the arc should end up. |
| 57 | float x; |
| 58 | /// The y coordinate where the arc should end up. |
| 59 | float y; |
| 60 | /// The radius on the x-axis of the arc. |
| 61 | float radius_x; |
| 62 | /// The radius on the y-axis of the arc. |
| 63 | float radius_y; |
| 64 | /// The rotation along the x-axis of the arc in degrees. |
| 65 | float x_rotation; |
| 66 | /// large_arc indicates whether to take the long or the shorter path to complete the arc. |
| 67 | bool large_arc; |
| 68 | /// sweep indicates the direction of the arc. If true, a clockwise direction is chosen, |
| 69 | /// otherwise counter-clockwise. |
| 70 | bool sweep; |
| 71 | |
| 72 | bool operator==(const PathArcTo& other) const { |
| 73 | return x == other.x && |
| 74 | y == other.y && |
| 75 | radius_x == other.radius_x && |
| 76 | radius_y == other.radius_y && |
| 77 | x_rotation == other.x_rotation && |
| 78 | large_arc == other.large_arc && |
| 79 | sweep == other.sweep; |
| 80 | } |
| 81 | bool operator!=(const PathArcTo& other) const { |
| 82 | return x != other.x || |
| 83 | y != other.y || |
| 84 | radius_x != other.radius_x || |
| 85 | radius_y != other.radius_y || |
| 86 | x_rotation != other.x_rotation || |
| 87 | large_arc != other.large_arc || |
| 88 | sweep != other.sweep; |
| 89 | } |
| 90 | }; |
| 91 | |
| 92 | /// PathCubicTo describes a smooth Bézier curve from the path's current position |
| 93 | /// to the specified x/y location, using two control points. |
| 94 | struct PathCubicTo { |
| 95 | /// The x coordinate of the curve's end point. |
| 96 | float x; |
| 97 | /// The y coordinate of the curve's end point. |
| 98 | float y; |
| 99 | /// The x coordinate of the curve's first control point. |
| 100 | float control_1_x; |
| 101 | /// The y coordinate of the curve's first control point. |
| 102 | float control_1_y; |
| 103 | /// The x coordinate of the curve's second control point. |
| 104 | float control_2_x; |
| 105 | /// The y coordinate of the curve's second control point. |
| 106 | float control_2_y; |
| 107 | |
| 108 | bool operator==(const PathCubicTo& other) const { |
| 109 | return x == other.x && |
| 110 | y == other.y && |
| 111 | control_1_x == other.control_1_x && |
| 112 | control_1_y == other.control_1_y && |
| 113 | control_2_x == other.control_2_x && |
| 114 | control_2_y == other.control_2_y; |
| 115 | } |
| 116 | bool operator!=(const PathCubicTo& other) const { |
| 117 | return x != other.x || |
| 118 | y != other.y || |
| 119 | control_1_x != other.control_1_x || |
| 120 | control_1_y != other.control_1_y || |
| 121 | control_2_x != other.control_2_x || |
| 122 | control_2_y != other.control_2_y; |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | /// PathCubicTo describes a smooth Bézier curve from the path's current position |
| 127 | /// to the specified x/y location, using one control points. |
| 128 | struct PathQuadraticTo { |
| 129 | /// The x coordinate of the curve's end point. |
| 130 | float x; |
| 131 | /// The y coordinate of the curve's end point. |
| 132 | float y; |
| 133 | /// The x coordinate of the curve's control point. |
| 134 | float control_x; |
| 135 | /// The y coordinate of the curve's control point. |
| 136 | float control_y; |
| 137 | |
| 138 | bool operator==(const PathQuadraticTo& other) const { |
| 139 | return x == other.x && |
| 140 | y == other.y && |
| 141 | control_x == other.control_x && |
| 142 | control_y == other.control_y; |
| 143 | } |
| 144 | bool operator!=(const PathQuadraticTo& other) const { |
| 145 | return x != other.x || |
| 146 | y != other.y || |
| 147 | control_x != other.control_x || |
| 148 | control_y != other.control_y; |
| 149 | } |
| 150 | }; |
| 151 | |
| 152 | /// PathElement describes a single element on a path, such as move-to, line-to, etc. |
| 153 | struct PathElement { |
| 154 | enum class Tag { |
| 155 | /// The MoveTo variant sets the current position on the path. |
| 156 | MoveTo, |
| 157 | /// The LineTo variant describes a line. |
| 158 | LineTo, |
| 159 | /// The PathArcTo variant describes an arc. |
| 160 | ArcTo, |
| 161 | /// The CubicTo variant describes a Bézier curve with two control points. |
| 162 | CubicTo, |
| 163 | /// The QuadraticTo variant describes a Bézier curve with one control point. |
| 164 | QuadraticTo, |
| 165 | /// Indicates that the path should be closed now by connecting to the starting point. |
| 166 | Close, |
| 167 | }; |
| 168 | |
| 169 | struct MoveTo_Body { |
| 170 | PathMoveTo _0; |
| 171 | |
| 172 | bool operator==(const MoveTo_Body& other) const { |
| 173 | return _0 == other._0; |
| 174 | } |
| 175 | bool operator!=(const MoveTo_Body& other) const { |
| 176 | return _0 != other._0; |
| 177 | } |
| 178 | }; |
| 179 | |
| 180 | struct LineTo_Body { |
| 181 | PathLineTo _0; |
| 182 | |
| 183 | bool operator==(const LineTo_Body& other) const { |
| 184 | return _0 == other._0; |
| 185 | } |
| 186 | bool operator!=(const LineTo_Body& other) const { |
| 187 | return _0 != other._0; |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | struct ArcTo_Body { |
| 192 | PathArcTo _0; |
| 193 | |
| 194 | bool operator==(const ArcTo_Body& other) const { |
| 195 | return _0 == other._0; |
| 196 | } |
| 197 | bool operator!=(const ArcTo_Body& other) const { |
| 198 | return _0 != other._0; |
| 199 | } |
| 200 | }; |
| 201 | |
| 202 | struct CubicTo_Body { |
| 203 | PathCubicTo _0; |
| 204 | |
| 205 | bool operator==(const CubicTo_Body& other) const { |
| 206 | return _0 == other._0; |
| 207 | } |
| 208 | bool operator!=(const CubicTo_Body& other) const { |
| 209 | return _0 != other._0; |
| 210 | } |
| 211 | }; |
| 212 | |
| 213 | struct QuadraticTo_Body { |
| 214 | PathQuadraticTo _0; |
| 215 | |
| 216 | bool operator==(const QuadraticTo_Body& other) const { |
| 217 | return _0 == other._0; |
| 218 | } |
| 219 | bool operator!=(const QuadraticTo_Body& other) const { |
| 220 | return _0 != other._0; |
| 221 | } |
| 222 | }; |
| 223 | |
| 224 | Tag tag; |
| 225 | union { |
| 226 | MoveTo_Body move_to; |
| 227 | LineTo_Body line_to; |
| 228 | ArcTo_Body arc_to; |
| 229 | CubicTo_Body cubic_to; |
| 230 | QuadraticTo_Body quadratic_to; |
| 231 | }; |
| 232 | |
| 233 | static PathElement MoveTo(const PathMoveTo &_0) { |
| 234 | PathElement result; |
| 235 | ::new (&result.move_to._0) (PathMoveTo)(_0); |
| 236 | result.tag = Tag::MoveTo; |
| 237 | return result; |
| 238 | } |
| 239 | |
| 240 | bool IsMoveTo() const { |
| 241 | return tag == Tag::MoveTo; |
| 242 | } |
| 243 | |
| 244 | static PathElement LineTo(const PathLineTo &_0) { |
| 245 | PathElement result; |
| 246 | ::new (&result.line_to._0) (PathLineTo)(_0); |
| 247 | result.tag = Tag::LineTo; |
| 248 | return result; |
| 249 | } |
| 250 | |
| 251 | bool IsLineTo() const { |
| 252 | return tag == Tag::LineTo; |
| 253 | } |
| 254 | |
| 255 | static PathElement ArcTo(const PathArcTo &_0) { |
| 256 | PathElement result; |
| 257 | ::new (&result.arc_to._0) (PathArcTo)(_0); |
| 258 | result.tag = Tag::ArcTo; |
| 259 | return result; |
| 260 | } |
| 261 | |
| 262 | bool IsArcTo() const { |
| 263 | return tag == Tag::ArcTo; |
| 264 | } |
| 265 | |
| 266 | static PathElement CubicTo(const PathCubicTo &_0) { |
| 267 | PathElement result; |
| 268 | ::new (&result.cubic_to._0) (PathCubicTo)(_0); |
| 269 | result.tag = Tag::CubicTo; |
| 270 | return result; |
| 271 | } |
| 272 | |
| 273 | bool IsCubicTo() const { |
| 274 | return tag == Tag::CubicTo; |
| 275 | } |
| 276 | |
| 277 | static PathElement QuadraticTo(const PathQuadraticTo &_0) { |
| 278 | PathElement result; |
| 279 | ::new (&result.quadratic_to._0) (PathQuadraticTo)(_0); |
| 280 | result.tag = Tag::QuadraticTo; |
| 281 | return result; |
| 282 | } |
| 283 | |
| 284 | bool IsQuadraticTo() const { |
| 285 | return tag == Tag::QuadraticTo; |
| 286 | } |
| 287 | |
| 288 | static PathElement Close() { |
| 289 | PathElement result; |
| 290 | result.tag = Tag::Close; |
| 291 | return result; |
| 292 | } |
| 293 | |
| 294 | bool IsClose() const { |
| 295 | return tag == Tag::Close; |
| 296 | } |
| 297 | |
| 298 | bool operator==(const PathElement& other) const { |
| 299 | if (tag != other.tag) { |
| 300 | return false; |
| 301 | } |
| 302 | switch (tag) { |
| 303 | case Tag::MoveTo: return move_to == other.move_to; |
| 304 | case Tag::LineTo: return line_to == other.line_to; |
| 305 | case Tag::ArcTo: return arc_to == other.arc_to; |
| 306 | case Tag::CubicTo: return cubic_to == other.cubic_to; |
| 307 | case Tag::QuadraticTo: return quadratic_to == other.quadratic_to; |
| 308 | default: break; |
| 309 | } |
| 310 | return true; |
| 311 | } |
| 312 | |
| 313 | bool operator!=(const PathElement& other) const { |
| 314 | return !(*this == other); |
| 315 | } |
| 316 | |
| 317 | private: |
| 318 | PathElement() { |
| 319 | |
| 320 | } |
| 321 | public: |
| 322 | |
| 323 | |
| 324 | ~PathElement() { |
| 325 | switch (tag) { |
| 326 | case Tag::MoveTo: move_to.~MoveTo_Body(); break; |
| 327 | case Tag::LineTo: line_to.~LineTo_Body(); break; |
| 328 | case Tag::ArcTo: arc_to.~ArcTo_Body(); break; |
| 329 | case Tag::CubicTo: cubic_to.~CubicTo_Body(); break; |
| 330 | case Tag::QuadraticTo: quadratic_to.~QuadraticTo_Body(); break; |
| 331 | default: break; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | PathElement(const PathElement& other) |
| 336 | : tag(other.tag) { |
| 337 | switch (tag) { |
| 338 | case Tag::MoveTo: ::new (&move_to) (MoveTo_Body)(other.move_to); break; |
| 339 | case Tag::LineTo: ::new (&line_to) (LineTo_Body)(other.line_to); break; |
| 340 | case Tag::ArcTo: ::new (&arc_to) (ArcTo_Body)(other.arc_to); break; |
| 341 | case Tag::CubicTo: ::new (&cubic_to) (CubicTo_Body)(other.cubic_to); break; |
| 342 | case Tag::QuadraticTo: ::new (&quadratic_to) (QuadraticTo_Body)(other.quadratic_to); break; |
| 343 | default: break; |
| 344 | } |
| 345 | } |
| 346 | PathElement& operator=(const PathElement& other) { |
| 347 | if (this != &other) { |
| 348 | this->~PathElement(); |
| 349 | new (this) PathElement(other); |
| 350 | } |
| 351 | return *this; |
| 352 | } |
| 353 | }; |
| 354 | |
| 355 | /// Expand Point so that cbindgen can see it. ( is in fact euclid::default::Point2D<f32>) |
| 356 | struct Point { |
| 357 | float x; |
| 358 | float y; |
| 359 | |
| 360 | bool operator==(const Point& other) const { |
| 361 | return x == other.x && |
| 362 | y == other.y; |
| 363 | } |
| 364 | bool operator!=(const Point& other) const { |
| 365 | return x != other.x || |
| 366 | y != other.y; |
| 367 | } |
| 368 | }; |
| 369 | |
| 370 | /// PathData represents a path described by either high-level elements or low-level |
| 371 | /// events and coordinates. |
| 372 | struct PathData { |
| 373 | enum class Tag { |
| 374 | /// None is the variant when the path is empty. |
| 375 | None, |
| 376 | /// The Elements variant is used to make a Path from shared arrays of elements. |
| 377 | Elements, |
| 378 | /// The Events variant describes the path as a series of low-level events and |
| 379 | /// associated coordinates. |
| 380 | Events, |
| 381 | /// The Commands variant describes the path as a series of SVG encoded path commands. |
| 382 | Commands, |
| 383 | }; |
| 384 | |
| 385 | struct Elements_Body { |
| 386 | SharedVector<PathElement> _0; |
| 387 | |
| 388 | bool operator==(const Elements_Body& other) const { |
| 389 | return _0 == other._0; |
| 390 | } |
| 391 | bool operator!=(const Elements_Body& other) const { |
| 392 | return _0 != other._0; |
| 393 | } |
| 394 | }; |
| 395 | |
| 396 | struct Events_Body { |
| 397 | SharedVector<PathEvent> _0; |
| 398 | SharedVector<Point> _1; |
| 399 | |
| 400 | bool operator==(const Events_Body& other) const { |
| 401 | return _0 == other._0 && |
| 402 | _1 == other._1; |
| 403 | } |
| 404 | bool operator!=(const Events_Body& other) const { |
| 405 | return _0 != other._0 || |
| 406 | _1 != other._1; |
| 407 | } |
| 408 | }; |
| 409 | |
| 410 | struct Commands_Body { |
| 411 | SharedString _0; |
| 412 | |
| 413 | bool operator==(const Commands_Body& other) const { |
| 414 | return _0 == other._0; |
| 415 | } |
| 416 | bool operator!=(const Commands_Body& other) const { |
| 417 | return _0 != other._0; |
| 418 | } |
| 419 | }; |
| 420 | |
| 421 | Tag tag; |
| 422 | union { |
| 423 | Elements_Body elements; |
| 424 | Events_Body events; |
| 425 | Commands_Body commands; |
| 426 | }; |
| 427 | |
| 428 | static PathData None() { |
| 429 | PathData result; |
| 430 | result.tag = Tag::None; |
| 431 | return result; |
| 432 | } |
| 433 | |
| 434 | bool IsNone() const { |
| 435 | return tag == Tag::None; |
| 436 | } |
| 437 | |
| 438 | static PathData Elements(const SharedVector<PathElement> &_0) { |
| 439 | PathData result; |
| 440 | ::new (&result.elements._0) (SharedVector<PathElement>)(_0); |
| 441 | result.tag = Tag::Elements; |
| 442 | return result; |
| 443 | } |
| 444 | |
| 445 | bool IsElements() const { |
| 446 | return tag == Tag::Elements; |
| 447 | } |
| 448 | |
| 449 | static PathData Events(const SharedVector<PathEvent> &_0, |
| 450 | const SharedVector<Point> &_1) { |
| 451 | PathData result; |
| 452 | ::new (&result.events._0) (SharedVector<PathEvent>)(_0); |
| 453 | ::new (&result.events._1) (SharedVector<Point>)(_1); |
| 454 | result.tag = Tag::Events; |
| 455 | return result; |
| 456 | } |
| 457 | |
| 458 | bool IsEvents() const { |
| 459 | return tag == Tag::Events; |
| 460 | } |
| 461 | |
| 462 | static PathData Commands(const SharedString &_0) { |
| 463 | PathData result; |
| 464 | ::new (&result.commands._0) (SharedString)(_0); |
| 465 | result.tag = Tag::Commands; |
| 466 | return result; |
| 467 | } |
| 468 | |
| 469 | bool IsCommands() const { |
| 470 | return tag == Tag::Commands; |
| 471 | } |
| 472 | |
| 473 | bool operator==(const PathData& other) const { |
| 474 | if (tag != other.tag) { |
| 475 | return false; |
| 476 | } |
| 477 | switch (tag) { |
| 478 | case Tag::Elements: return elements == other.elements; |
| 479 | case Tag::Events: return events == other.events; |
| 480 | case Tag::Commands: return commands == other.commands; |
| 481 | default: break; |
| 482 | } |
| 483 | return true; |
| 484 | } |
| 485 | |
| 486 | bool operator!=(const PathData& other) const { |
| 487 | return !(*this == other); |
| 488 | } |
| 489 | |
| 490 | private: |
| 491 | PathData() { |
| 492 | |
| 493 | } |
| 494 | public: |
| 495 | |
| 496 | |
| 497 | ~PathData() { |
| 498 | switch (tag) { |
| 499 | case Tag::Elements: elements.~Elements_Body(); break; |
| 500 | case Tag::Events: events.~Events_Body(); break; |
| 501 | case Tag::Commands: commands.~Commands_Body(); break; |
| 502 | default: break; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | PathData(const PathData& other) |
| 507 | : tag(other.tag) { |
| 508 | switch (tag) { |
| 509 | case Tag::Elements: ::new (&elements) (Elements_Body)(other.elements); break; |
| 510 | case Tag::Events: ::new (&events) (Events_Body)(other.events); break; |
| 511 | case Tag::Commands: ::new (&commands) (Commands_Body)(other.commands); break; |
| 512 | default: break; |
| 513 | } |
| 514 | } |
| 515 | PathData& operator=(const PathData& other) { |
| 516 | if (this != &other) { |
| 517 | this->~PathData(); |
| 518 | new (this) PathData(other); |
| 519 | } |
| 520 | return *this; |
| 521 | } |
| 522 | }; |
| 523 | |
| 524 | extern "C" { |
| 525 | |
| 526 | #if !defined(SLINT_TARGET_WASM) |
| 527 | /// This function is used for the low-level C++ interface to allocate the backing vector for a shared path element array. |
| 528 | void slint_new_path_elements(void *out, |
| 529 | const PathElement *first_element, |
| 530 | uintptr_t count); |
| 531 | #endif |
| 532 | |
| 533 | #if !defined(SLINT_TARGET_WASM) |
| 534 | /// This function is used for the low-level C++ interface to allocate the backing vector for a shared path event array. |
| 535 | void slint_new_path_events(void *out_events, |
| 536 | void *out_coordinates, |
| 537 | const PathEvent *first_event, |
| 538 | uintptr_t event_count, |
| 539 | const Point *first_coordinate, |
| 540 | uintptr_t coordinate_count); |
| 541 | #endif |
| 542 | |
| 543 | } // extern "C" |
| 544 | |
| 545 | } // namespace types |
| 546 | } // namespace cbindgen_private |
| 547 | } // namespace slint |
| 548 | |