1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

extern crate ordered_float;
#[cfg(feature = "serde_support")]
extern crate serde;
#[macro_use]
#[cfg(feature = "serde_support")]
extern crate serde_derive;

// API created by bindgen
mod internal {
	#![allow(dead_code)]
	include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
	pub use self::root::*;
}

// Public re-exports of Yoga enums
mod ffi_types {
	pub mod align;
	pub mod config_ref;
	pub mod dimension;
	pub mod direction;
	pub mod display;
	pub mod edge;
	pub mod flex_direction;
	pub mod justify;
	pub mod log_level;
	pub mod measure_mode;
	pub mod node_ref;
	pub mod node_type;
	pub mod overflow;
	pub mod position_type;
	pub mod print_options;
	pub mod size;
	pub mod style_unit;
	pub mod undefined;
	pub mod wrap;
}

pub mod prelude;
pub mod traits;
pub mod types;

use std::any::Any;
pub use types::*;

#[repr(C)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Config {
	inner_config: ConfigRef,
}

#[repr(C)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Node {
	inner_node: NodeRef,
}

impl Config {
	pub fn new() -> Config {
		Config {
			inner_config: unsafe { internal::YGConfigNew() },
		}
	}
}

impl Node {
	pub fn new() -> Node {
		Node {
			inner_node: unsafe { internal::YGNodeNew() },
		}
	}

	pub fn new_with_config(config: &mut Config) -> Node {
		Node {
			inner_node: unsafe { internal::YGNodeNewWithConfig(config.inner_config) },
		}
	}

	pub fn reset(&mut self) {
		unsafe {
			internal::YGNodeReset(self.inner_node);
		}
	}

	pub fn mark_dirty(&mut self) {
		unsafe {
			internal::YGNodeMarkDirty(self.inner_node);
		}
	}

	pub fn apply_styles<'a, I>(&mut self, styles: I)
	where
		I: IntoIterator<Item = &'a FlexStyle>,
	{
		for style in styles {
			self.apply_style(style);
		}
	}

	pub fn apply_style(&mut self, style: &FlexStyle) {
		use FlexStyle::*;

		match *style {
			AlignContent(align) => self.set_align_content(align),
			AlignItems(align) => self.set_align_items(align),
			AlignSelf(align) => self.set_align_self(align),
			AspectRatio(a) => self.set_aspect_ratio(a.into_inner()),
			BorderBottom(b) => self.set_border(Edge::Bottom, b.into_inner()),
			BorderEnd(b) => self.set_border(Edge::End, b.into_inner()),
			BorderLeft(b) => self.set_border(Edge::Left, b.into_inner()),
			BorderRight(b) => self.set_border(Edge::Right, b.into_inner()),
			BorderStart(b) => self.set_border(Edge::Start, b.into_inner()),
			BorderTop(b) => self.set_border(Edge::Top, b.into_inner()),
			Border(b) => self.set_border(Edge::All, b.into_inner()),
			Bottom(b) => self.set_position(Edge::Bottom, b),
			Display(d) => self.set_display(d),
			End(e) => self.set_position(Edge::End, e),
			Flex(f) => self.set_flex(f.into_inner()),
			FlexBasis(f) => self.set_flex_basis(f),
			FlexGrow(f) => self.set_flex_grow(f.into_inner()),
			FlexDirection(flex_direction) => self.set_flex_direction(flex_direction),
			FlexShrink(f) => self.set_flex_shrink(f.into_inner()),
			FlexWrap(wrap) => self.set_flex_wrap(wrap),
			Height(h) => self.set_height(h),
			JustifyContent(justify) => self.set_justify_content(justify),
			Left(l) => self.set_position(Edge::Left, l),
			Margin(m) => self.set_margin(Edge::All, m),
			MarginBottom(m) => self.set_margin(Edge::Bottom, m),
			MarginEnd(m) => self.set_margin(Edge::End, m),
			MarginHorizontal(m) => self.set_margin(Edge::Horizontal, m),
			MarginLeft(m) => self.set_margin(Edge::Left, m),
			MarginRight(m) => self.set_margin(Edge::Right, m),
			MarginStart(m) => self.set_margin(Edge::Start, m),
			MarginTop(m) => self.set_margin(Edge::Top, m),
			MarginVertical(m) => self.set_margin(Edge::Vertical, m),
			MaxHeight(h) => self.set_max_height(h),
			MaxWidth(w) => self.set_max_width(w),
			MinHeight(h) => self.set_min_height(h),
			MinWidth(w) => self.set_min_width(w),
			Overflow(o) => self.set_overflow(o),
			Padding(p) => self.set_padding(Edge::All, p),
			PaddingBottom(p) => self.set_padding(Edge::Bottom, p),
			PaddingEnd(p) => self.set_padding(Edge::End, p),
			PaddingHorizontal(p) => self.set_padding(Edge::Horizontal, p),
			PaddingLeft(p) => self.set_padding(Edge::Left, p),
			PaddingRight(p) => self.set_padding(Edge::Right, p),
			PaddingStart(p) => self.set_padding(Edge::Start, p),
			PaddingTop(p) => self.set_padding(Edge::Top, p),
			PaddingVertical(p) => self.set_padding(Edge::Vertical, p),
			Position(position_type) => self.set_position_type(position_type),
			Right(r) => self.set_position(Edge::Right, r),
			Start(s) => self.set_position(Edge::Start, s),
			Top(t) => self.set_position(Edge::Top, t),
			Width(w) => self.set_width(w),
		}
	}

	pub fn insert_child(&mut self, child: &mut Node, index: u32) {
		unsafe {
			internal::YGNodeInsertChild(self.inner_node, child.inner_node, index);
		}
	}

	pub fn remove_child(&mut self, child: &mut Node) {
		unsafe {
			internal::YGNodeRemoveChild(self.inner_node, child.inner_node);
		}
	}

	pub fn child_count(&self) -> u32 {
		unsafe { internal::YGNodeGetChildCount(self.inner_node) }
	}

	pub fn set_direction(&mut self, direction: Direction) {
		unsafe {
			internal::YGNodeStyleSetDirection(
				self.inner_node,
				internal::YGDirection::from(direction),
			);
		}
	}

	pub fn set_flex_direction(&mut self, direction: FlexDirection) {
		unsafe {
			internal::YGNodeStyleSetFlexDirection(
				self.inner_node,
				internal::YGFlexDirection::from(direction),
			);
		}
	}

	pub fn set_justify_content(&mut self, justify: Justify) {
		unsafe {
			internal::YGNodeStyleSetJustifyContent(
				self.inner_node,
				internal::YGJustify::from(justify),
			);
		}
	}

	pub fn set_align_content(&mut self, align: Align) {
		unsafe {
			internal::YGNodeStyleSetAlignContent(self.inner_node, internal::YGAlign::from(align));
		}
	}

	pub fn set_align_items(&mut self, align: Align) {
		unsafe {
			internal::YGNodeStyleSetAlignItems(self.inner_node, internal::YGAlign::from(align));
		}
	}

	pub fn set_align_self(&mut self, align: Align) {
		unsafe {
			internal::YGNodeStyleSetAlignSelf(self.inner_node, internal::YGAlign::from(align));
		}
	}

	pub fn set_position_type(&mut self, position_type: PositionType) {
		unsafe {
			internal::YGNodeStyleSetPositionType(
				self.inner_node,
				internal::YGPositionType::from(position_type),
			);
		}
	}

	pub fn set_position(&mut self, edge: Edge, position: StyleUnit) {
		unsafe {
			match position {
				StyleUnit::UndefinedValue => internal::YGNodeStyleSetPosition(
					self.inner_node,
					internal::YGEdge::from(edge),
					Undefined,
				),
				StyleUnit::Point(val) => internal::YGNodeStyleSetPosition(
					self.inner_node,
					internal::YGEdge::from(edge),
					val.into_inner(),
				),
				StyleUnit::Percent(val) => internal::YGNodeStyleSetPositionPercent(
					self.inner_node,
					internal::YGEdge::from(edge),
					val.into_inner(),
				),
				// auto is not a valid value for position
				StyleUnit::Auto => internal::YGNodeStyleSetPosition(
					self.inner_node,
					internal::YGEdge::from(edge),
					Undefined,
				),
			}
		}
	}

	pub fn set_flex_wrap(&mut self, wrap: Wrap) {
		unsafe {
			internal::YGNodeStyleSetFlexWrap(self.inner_node, internal::YGWrap::from(wrap));
		}
	}

	pub fn set_overflow(&mut self, overflow: Overflow) {
		unsafe {
			internal::YGNodeStyleSetOverflow(self.inner_node, internal::YGOverflow::from(overflow));
		}
	}

	pub fn set_flex(&mut self, flex: f32) {
		unsafe {
			internal::YGNodeStyleSetFlex(self.inner_node, flex);
		}
	}

	pub fn set_flex_grow(&mut self, flex_grow: f32) {
		unsafe {
			internal::YGNodeStyleSetFlexGrow(self.inner_node, flex_grow);
		}
	}

	pub fn set_flex_shrink(&mut self, flex_shrink: f32) {
		unsafe {
			internal::YGNodeStyleSetFlexShrink(self.inner_node, flex_shrink);
		}
	}

	pub fn set_flex_basis(&mut self, flex_basis: StyleUnit) {
		unsafe {
			match flex_basis {
				StyleUnit::UndefinedValue => {
					internal::YGNodeStyleSetFlexBasis(self.inner_node, Undefined)
				}
				StyleUnit::Point(val) => {
					internal::YGNodeStyleSetFlexBasis(self.inner_node, val.into_inner())
				}
				StyleUnit::Percent(val) => {
					internal::YGNodeStyleSetFlexBasisPercent(self.inner_node, val.into_inner())
				}
				StyleUnit::Auto => internal::YGNodeStyleSetFlexBasisAuto(self.inner_node),
			}
		}
	}

	pub fn set_edge_position(&mut self, edge: Edge, position: f32) {
		unsafe {
			internal::YGNodeStyleSetPosition(
				self.inner_node,
				internal::YGEdge::from(edge),
				position,
			);
		}
	}

	pub fn set_margin(&mut self, edge: Edge, margin: StyleUnit) {
		unsafe {
			match margin {
				StyleUnit::UndefinedValue => internal::YGNodeStyleSetMargin(
					self.inner_node,
					internal::YGEdge::from(edge),
					Undefined,
				),
				StyleUnit::Point(val) => internal::YGNodeStyleSetMargin(
					self.inner_node,
					internal::YGEdge::from(edge),
					val.into_inner(),
				),
				StyleUnit::Percent(val) => internal::YGNodeStyleSetMarginPercent(
					self.inner_node,
					internal::YGEdge::from(edge),
					val.into_inner(),
				),
				StyleUnit::Auto => internal::YGNodeStyleSetMarginAuto(
					self.inner_node,
					internal::YGEdge::from(edge),
				),
			}
		}
	}

	pub fn set_padding(&mut self, edge: Edge, padding: StyleUnit) {
		unsafe {
			match padding {
				StyleUnit::UndefinedValue => internal::YGNodeStyleSetPadding(
					self.inner_node,
					internal::YGEdge::from(edge),
					Undefined,
				),
				StyleUnit::Point(val) => internal::YGNodeStyleSetPadding(
					self.inner_node,
					internal::YGEdge::from(edge),
					val.into_inner(),
				),
				StyleUnit::Percent(val) => internal::YGNodeStyleSetPaddingPercent(
					self.inner_node,
					internal::YGEdge::from(edge),
					val.into_inner(),
				),
				// auto is not a valid value for padding
				StyleUnit::Auto => internal::YGNodeStyleSetPadding(
					self.inner_node,
					internal::YGEdge::from(edge),
					Undefined,
				),
			}
		}
	}

	pub fn set_border(&mut self, edge: Edge, border: f32) {
		unsafe {
			internal::YGNodeStyleSetBorder(self.inner_node, internal::YGEdge::from(edge), border);
		}
	}

	pub fn set_width(&mut self, width: StyleUnit) {
		unsafe {
			match width {
				StyleUnit::UndefinedValue => {
					internal::YGNodeStyleSetWidth(self.inner_node, Undefined)
				}
				StyleUnit::Point(val) => {
					internal::YGNodeStyleSetWidth(self.inner_node, val.into_inner())
				}
				StyleUnit::Percent(val) => {
					internal::YGNodeStyleSetWidthPercent(self.inner_node, val.into_inner())
				}
				StyleUnit::Auto => internal::YGNodeStyleSetWidthAuto(self.inner_node),
			}
		}
	}

	pub fn set_height(&mut self, height: StyleUnit) {
		unsafe {
			match height {
				StyleUnit::UndefinedValue => {
					internal::YGNodeStyleSetHeight(self.inner_node, Undefined)
				}
				StyleUnit::Point(val) => {
					internal::YGNodeStyleSetHeight(self.inner_node, val.into_inner())
				}
				StyleUnit::Percent(val) => {
					internal::YGNodeStyleSetHeightPercent(self.inner_node, val.into_inner())
				}
				StyleUnit::Auto => internal::YGNodeStyleSetHeightAuto(self.inner_node),
			}
		}
	}

	pub fn set_min_width(&mut self, min_width: StyleUnit) {
		unsafe {
			match min_width {
				StyleUnit::UndefinedValue => {
					internal::YGNodeStyleSetMinWidth(self.inner_node, Undefined)
				}
				StyleUnit::Point(val) => {
					internal::YGNodeStyleSetMinWidth(self.inner_node, val.into_inner())
				}
				StyleUnit::Percent(val) => {
					internal::YGNodeStyleSetMinWidthPercent(self.inner_node, val.into_inner())
				}
				// auto is not a valid value for min_width
				StyleUnit::Auto => internal::YGNodeStyleSetMinWidth(self.inner_node, Undefined),
			}
		}
	}

	pub fn set_min_height(&mut self, min_height: StyleUnit) {
		unsafe {
			match min_height {
				StyleUnit::UndefinedValue => {
					internal::YGNodeStyleSetMinHeight(self.inner_node, Undefined)
				}
				StyleUnit::Point(val) => {
					internal::YGNodeStyleSetMinHeight(self.inner_node, val.into_inner())
				}
				StyleUnit::Percent(val) => {
					internal::YGNodeStyleSetMinHeightPercent(self.inner_node, val.into_inner())
				}
				// auto is not a valid value for min_height
				StyleUnit::Auto => internal::YGNodeStyleSetMinHeight(self.inner_node, Undefined),
			}
		}
	}

	pub fn set_max_width(&mut self, max_width: StyleUnit) {
		unsafe {
			match max_width {
				StyleUnit::UndefinedValue => {
					internal::YGNodeStyleSetMaxWidth(self.inner_node, Undefined)
				}
				StyleUnit::Point(val) => {
					internal::YGNodeStyleSetMaxWidth(self.inner_node, val.into_inner())
				}
				StyleUnit::Percent(val) => {
					internal::YGNodeStyleSetMaxWidthPercent(self.inner_node, val.into_inner())
				}
				// auto is not a valid value for max_width
				StyleUnit::Auto => internal::YGNodeStyleSetMaxWidth(self.inner_node, Undefined),
			}
		}
	}

	pub fn set_max_height(&mut self, max_height: StyleUnit) {
		unsafe {
			match max_height {
				StyleUnit::UndefinedValue => {
					internal::YGNodeStyleSetMaxHeight(self.inner_node, Undefined)
				}
				StyleUnit::Point(val) => {
					internal::YGNodeStyleSetMaxHeight(self.inner_node, val.into_inner())
				}
				StyleUnit::Percent(val) => {
					internal::YGNodeStyleSetMaxHeightPercent(self.inner_node, val.into_inner())
				}
				// auto is not a valid value for max_height
				StyleUnit::Auto => internal::YGNodeStyleSetMaxHeight(self.inner_node, Undefined),
			}
		}
	}

	pub fn set_aspect_ratio(&mut self, aspect_ratio: f32) {
		unsafe {
			internal::YGNodeStyleSetAspectRatio(self.inner_node, aspect_ratio);
		}
	}

	pub fn calculate_layout(
		&mut self,
		available_width: f32,
		available_height: f32,
		parent_direction: Direction,
	) {
		unsafe {
			internal::YGNodeCalculateLayout(
				self.inner_node,
				available_width,
				available_height,
				internal::YGDirection::from(parent_direction),
			);
		}
	}

	pub fn get_layout(&self) -> Layout {
		unsafe {
			Layout::new(
				internal::YGNodeLayoutGetLeft(self.inner_node),
				internal::YGNodeLayoutGetRight(self.inner_node),
				internal::YGNodeLayoutGetTop(self.inner_node),
				internal::YGNodeLayoutGetBottom(self.inner_node),
				internal::YGNodeLayoutGetWidth(self.inner_node),
				internal::YGNodeLayoutGetHeight(self.inner_node),
			)
		}
	}

	pub fn get_child_count(&self) -> u32 {
		unsafe { internal::YGNodeGetChildCount(self.inner_node) }
	}

	pub fn get_child(&self, index: u32) -> NodeRef {
		unsafe { internal::YGNodeGetChild(self.inner_node, index) }
	}

	pub fn get_style_direction(&self) -> Direction {
		unsafe { internal::YGNodeStyleGetDirection(self.inner_node).into() }
	}

	pub fn get_flex_direction(&self) -> FlexDirection {
		unsafe { internal::YGNodeStyleGetFlexDirection(self.inner_node).into() }
	}

	pub fn get_justify_content(&self) -> Justify {
		unsafe { internal::YGNodeStyleGetJustifyContent(self.inner_node).into() }
	}

	pub fn get_align_content(&self) -> Align {
		unsafe { internal::YGNodeStyleGetAlignContent(self.inner_node).into() }
	}

	pub fn get_align_items(&self) -> Align {
		unsafe { internal::YGNodeStyleGetAlignItems(self.inner_node).into() }
	}

	pub fn get_align_self(&self) -> Align {
		unsafe { internal::YGNodeStyleGetAlignSelf(self.inner_node).into() }
	}

	pub fn get_position_type(&self) -> PositionType {
		unsafe { internal::YGNodeStyleGetPositionType(self.inner_node).into() }
	}

	pub fn get_flex_wrap(&self) -> Wrap {
		unsafe { internal::YGNodeStyleGetFlexWrap(self.inner_node).into() }
	}

	pub fn get_overflow(&self) -> Overflow {
		unsafe { internal::YGNodeStyleGetOverflow(self.inner_node).into() }
	}

	pub fn get_flex_grow(&self) -> f32 {
		unsafe { internal::YGNodeStyleGetFlexGrow(self.inner_node) }
	}

	pub fn get_flex_shrink(&self) -> f32 {
		unsafe { internal::YGNodeStyleGetFlexShrink(self.inner_node) }
	}

	pub fn get_flex_basis(&self) -> StyleUnit {
		unsafe { internal::YGNodeStyleGetFlexBasis(self.inner_node).into() }
	}

	pub fn get_style_position_left(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPosition(self.inner_node, internal::YGEdge::from(Edge::Left))
				.into()
		}
	}

	pub fn get_style_position_right(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPosition(self.inner_node, internal::YGEdge::from(Edge::Right))
				.into()
		}
	}

	pub fn get_style_position_top(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPosition(self.inner_node, internal::YGEdge::from(Edge::Top))
				.into()
		}
	}

	pub fn get_style_position_bottom(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPosition(self.inner_node, internal::YGEdge::from(Edge::Bottom))
				.into()
		}
	}

	pub fn get_style_position_start(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPosition(self.inner_node, internal::YGEdge::from(Edge::Start))
				.into()
		}
	}

	pub fn get_style_position_end(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPosition(self.inner_node, internal::YGEdge::from(Edge::End))
				.into()
		}
	}

	pub fn get_style_margin_left(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetMargin(self.inner_node, internal::YGEdge::from(Edge::Left))
				.into()
		}
	}

	pub fn get_style_margin_right(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetMargin(self.inner_node, internal::YGEdge::from(Edge::Right))
				.into()
		}
	}

	pub fn get_style_margin_top(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetMargin(self.inner_node, internal::YGEdge::from(Edge::Top))
				.into()
		}
	}

	pub fn get_style_margin_bottom(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetMargin(self.inner_node, internal::YGEdge::from(Edge::Bottom))
				.into()
		}
	}

	pub fn get_style_margin_start(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetMargin(self.inner_node, internal::YGEdge::from(Edge::Start))
				.into()
		}
	}

	pub fn get_style_margin_end(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetMargin(self.inner_node, internal::YGEdge::from(Edge::End))
				.into()
		}
	}

	pub fn get_style_padding_left(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPadding(self.inner_node, internal::YGEdge::from(Edge::Left))
				.into()
		}
	}

	pub fn get_style_padding_right(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPadding(self.inner_node, internal::YGEdge::from(Edge::Right))
				.into()
		}
	}

	pub fn get_style_padding_top(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPadding(self.inner_node, internal::YGEdge::from(Edge::Top))
				.into()
		}
	}

	pub fn get_style_padding_bottom(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPadding(self.inner_node, internal::YGEdge::from(Edge::Bottom))
				.into()
		}
	}

	pub fn get_style_padding_start(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPadding(self.inner_node, internal::YGEdge::from(Edge::Start))
				.into()
		}
	}

	pub fn get_style_padding_end(&self) -> StyleUnit {
		unsafe {
			internal::YGNodeStyleGetPadding(self.inner_node, internal::YGEdge::from(Edge::End))
				.into()
		}
	}

	pub fn get_style_border_left(&self) -> f32 {
		unsafe {
			internal::YGNodeStyleGetBorder(self.inner_node, internal::YGEdge::from(Edge::Left))
		}
	}

	pub fn get_style_border_right(&self) -> f32 {
		unsafe {
			internal::YGNodeStyleGetBorder(self.inner_node, internal::YGEdge::from(Edge::Right))
		}
	}

	pub fn get_style_border_top(&self) -> f32 {
		unsafe {
			internal::YGNodeStyleGetBorder(self.inner_node, internal::YGEdge::from(Edge::Top))
		}
	}

	pub fn get_style_border_bottom(&self) -> f32 {
		unsafe {
			internal::YGNodeStyleGetBorder(self.inner_node, internal::YGEdge::from(Edge::Bottom))
		}
	}

	pub fn get_style_border_start(&self) -> f32 {
		unsafe {
			internal::YGNodeStyleGetBorder(self.inner_node, internal::YGEdge::from(Edge::Start))
		}
	}

	pub fn get_style_border_end(&self) -> f32 {
		unsafe {
			internal::YGNodeStyleGetBorder(self.inner_node, internal::YGEdge::from(Edge::End))
		}
	}

	pub fn get_style_width(&self) -> StyleUnit {
		unsafe { internal::YGNodeStyleGetWidth(self.inner_node).into() }
	}

	pub fn get_style_height(&self) -> StyleUnit {
		unsafe { internal::YGNodeStyleGetHeight(self.inner_node).into() }
	}

	pub fn get_style_min_width(&self) -> StyleUnit {
		unsafe { internal::YGNodeStyleGetMinWidth(self.inner_node).into() }
	}

	pub fn get_style_min_height(&self) -> StyleUnit {
		unsafe { internal::YGNodeStyleGetMinHeight(self.inner_node).into() }
	}

	pub fn get_style_max_width(&self) -> StyleUnit {
		unsafe { internal::YGNodeStyleGetMaxWidth(self.inner_node).into() }
	}

	pub fn get_style_max_height(&self) -> StyleUnit {
		unsafe { internal::YGNodeStyleGetMaxHeight(self.inner_node).into() }
	}

	// Layout Getters
	pub fn get_layout_margin_left(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetMargin(self.inner_node, internal::YGEdge::from(Edge::Left))
		}
	}

	pub fn get_layout_margin_right(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetMargin(self.inner_node, internal::YGEdge::from(Edge::Right))
		}
	}

	pub fn get_layout_margin_top(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetMargin(self.inner_node, internal::YGEdge::from(Edge::Top))
		}
	}

	pub fn get_layout_margin_bottom(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetMargin(self.inner_node, internal::YGEdge::from(Edge::Bottom))
		}
	}

	pub fn get_layout_margin_start(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetMargin(self.inner_node, internal::YGEdge::from(Edge::Start))
		}
	}

	pub fn get_layout_margin_end(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetMargin(self.inner_node, internal::YGEdge::from(Edge::End))
		}
	}

	pub fn get_layout_padding_left(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetPadding(self.inner_node, internal::YGEdge::from(Edge::Left))
		}
	}

	pub fn get_layout_padding_right(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetPadding(self.inner_node, internal::YGEdge::from(Edge::Right))
		}
	}

	pub fn get_layout_padding_top(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetPadding(self.inner_node, internal::YGEdge::from(Edge::Top))
		}
	}

	pub fn get_layout_padding_bottom(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetPadding(self.inner_node, internal::YGEdge::from(Edge::Bottom))
		}
	}

	pub fn get_layout_padding_start(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetPadding(self.inner_node, internal::YGEdge::from(Edge::Start))
		}
	}

	pub fn get_layout_padding_end(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetPadding(self.inner_node, internal::YGEdge::from(Edge::End))
		}
	}

	pub fn get_layout_left(&self) -> f32 {
		unsafe { internal::YGNodeLayoutGetLeft(self.inner_node) }
	}

	pub fn get_layout_right(&self) -> f32 {
		unsafe { internal::YGNodeLayoutGetRight(self.inner_node) }
	}

	pub fn get_layout_top(&self) -> f32 {
		unsafe { internal::YGNodeLayoutGetTop(self.inner_node) }
	}

	pub fn get_layout_bottom(&self) -> f32 {
		unsafe { internal::YGNodeLayoutGetBottom(self.inner_node) }
	}

	pub fn get_layout_border_left(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetBorder(self.inner_node, internal::YGEdge::from(Edge::Left))
		}
	}

	pub fn get_layout_border_right(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetBorder(self.inner_node, internal::YGEdge::from(Edge::Right))
		}
	}

	pub fn get_layout_border_top(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetBorder(self.inner_node, internal::YGEdge::from(Edge::Top))
		}
	}

	pub fn get_layout_border_bottom(&self) -> f32 {
		unsafe {
			internal::YGNodeLayoutGetBorder(self.inner_node, internal::YGEdge::from(Edge::Bottom))
		}
	}

	pub fn get_layout_width(&self) -> f32 {
		unsafe { internal::YGNodeLayoutGetWidth(self.inner_node) }
	}

	pub fn get_layout_height(&self) -> f32 {
		unsafe { internal::YGNodeLayoutGetHeight(self.inner_node) }
	}

	pub fn get_layout_direction(&self) -> Direction {
		unsafe { internal::YGNodeLayoutGetDirection(self.inner_node).into() }
	}

	pub fn is_dirty(&self) -> bool {
		unsafe { internal::YGNodeIsDirty(self.inner_node) }
	}

	pub fn copy_style(&self, src_node: &Node) {
		unsafe { internal::YGNodeCopyStyle(self.inner_node, src_node.inner_node) }
	}

	pub fn set_display(&mut self, display: Display) {
		unsafe {
			internal::YGNodeStyleSetDisplay(self.inner_node, display.into());
		}
	}

	pub fn set_measure_func(&mut self, func: MeasureFunc) {
		match func {
			Some(f) => unsafe {
				type Callback = unsafe extern "C" fn(
					internal::YGNodeRef,
					f32,
					internal::YGMeasureMode,
					f32,
					internal::YGMeasureMode,
				) -> internal::YGSize;
				let casted_func: Callback = std::mem::transmute(f as usize);
				internal::YGNodeSetMeasureFunc(self.inner_node, Some(casted_func));
			},
			None => unsafe {
				internal::YGNodeSetMeasureFunc(self.inner_node, None);
			},
		}
	}

	pub fn set_baseline_func(&mut self, func: BaselineFunc) {
		match func {
			Some(f) => unsafe {
				type Callback = unsafe extern "C" fn(internal::YGNodeRef, f32, f32) -> f32;
				let casted_func: Callback = std::mem::transmute(f as usize);
				internal::YGNodeSetBaselineFunc(self.inner_node, Some(casted_func));
			},
			None => unsafe {
				internal::YGNodeSetBaselineFunc(self.inner_node, None);
			},
		}
	}

	pub fn set_context(&mut self, value: Option<Context>) {
		self.drop_context();

		let raw = value.map_or_else(|| std::ptr::null_mut(), |context| context.into_raw());
		unsafe { internal::YGNodeSetContext(self.inner_node, raw) }
	}

	pub fn get_context(node_ref: &NodeRef) -> Option<&Box<dyn Any>> {
		let raw = unsafe { internal::YGNodeGetContext(*node_ref) };
		Context::get_inner_ref(raw)
	}

	pub fn get_context_mut(node_ref: &NodeRef) -> Option<&mut Box<dyn Any>> {
		let raw = unsafe { internal::YGNodeGetContext(*node_ref) };
		Context::get_inner_mut(raw)
	}

	pub fn get_own_context(&self) -> Option<&Box<dyn Any>> {
		Node::get_context(&self.inner_node)
	}

	pub fn get_own_context_mut(&self) -> Option<&mut Box<dyn Any>> {
		Node::get_context_mut(&self.inner_node)
	}

	pub fn drop_context(&mut self) {
		let prev_raw = unsafe { internal::YGNodeGetContext(self.inner_node) };
		Context::drop_raw(prev_raw);
	}
}

impl Drop for Node {
	fn drop(&mut self) {
		self.set_context(None);

		unsafe {
			// In the current revision (a20bde8444474e7a34352a78073de23c26e08fc5),
			// YGNodeFree does not mark the parent as dirty, but YGNodeRemoveChild does.
			// TODO remove the following lines when upgrading to a more recent revision of yoga.
			let parent = internal::YGNodeGetParent(self.inner_node);
			if parent != 0 as NodeRef {
				internal::YGNodeRemoveChild(
					internal::YGNodeGetParent(self.inner_node),
					self.inner_node,
				);
			}

			internal::YGNodeFree(self.inner_node);
		}
	}
}