| 1 | fn test_struct_embedding_with_interface() { |
| 2 | mut ll := LinearLayout{} |
| 3 | mut lv := ListView{} |
| 4 | ll.add(lv) |
| 5 | ret := ll.layout() |
| 6 | |
| 7 | println(ret) |
| 8 | assert ret.count('ListView') == 2 |
| 9 | } |
| 10 | |
| 11 | interface Container { |
| 12 | mut: |
| 13 | layout() string |
| 14 | } |
| 15 | |
| 16 | interface Layoutable { |
| 17 | get_pos() (int, int) |
| 18 | mut: |
| 19 | set_pos(int, int) |
| 20 | } |
| 21 | |
| 22 | pub struct LayouterBase { |
| 23 | mut: |
| 24 | layoutables []Layoutable |
| 25 | } |
| 26 | |
| 27 | pub fn (mut lb LayouterBase) add(layoutable Layoutable) { |
| 28 | lb.layoutables << layoutable |
| 29 | } |
| 30 | |
| 31 | pub fn (lb LayouterBase) get_pos() (int, int) { |
| 32 | return 0, 0 |
| 33 | } |
| 34 | |
| 35 | pub fn (mut lb LayouterBase) set_pos(x int, y int) {} |
| 36 | |
| 37 | pub struct LinearLayout { |
| 38 | LayouterBase |
| 39 | } |
| 40 | |
| 41 | pub fn (mut ll LinearLayout) layout() string { |
| 42 | mut output := '' |
| 43 | for mut l in ll.layoutables { |
| 44 | dump(l.type_name()) |
| 45 | output += '${l.type_name()}\n' |
| 46 | if mut l is Container { |
| 47 | dump(l.type_name()) |
| 48 | output += '${l.type_name()}\n' |
| 49 | } |
| 50 | } |
| 51 | return output |
| 52 | } |
| 53 | |
| 54 | pub struct ListView { |
| 55 | LayouterBase |
| 56 | } |
| 57 | |
| 58 | pub fn (mut lv ListView) layout() string { |
| 59 | return '' |
| 60 | } |
| 61 | |