A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/AlmasB/FXGL/commit/d5c546a9b below:

ViewComponent.getChild() allows retrieving a specific child tha… · AlmasB/FXGL@d5c546a · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+23

-0

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+23

-0

lines changed Original file line number Diff line number Diff line change

@@ -173,6 +173,13 @@ class ViewComponent : Component() {

173 173

updatableViews += node

174 174

}

175 175 176 +

/**

177 +

* @return a child node at given [index] which is then cast into [type]

178 +

*/

179 +

fun <T : Node> getChild(index: Int, type: Class<T>): T {

180 +

return type.cast(children[index])

181 +

}

182 + 176 183

/**

177 184

* Remove a child from this view.

178 185

*/

Original file line number Diff line number Diff line change

@@ -14,6 +14,7 @@ import javafx.scene.Node

14 14

import javafx.scene.Parent

15 15

import javafx.scene.input.MouseButton

16 16

import javafx.scene.input.MouseEvent

17 +

import javafx.scene.shape.Circle

17 18

import javafx.scene.shape.Rectangle

18 19

import org.hamcrest.CoreMatchers.`is`

19 20

import org.hamcrest.MatcherAssert.assertThat

@@ -68,6 +69,21 @@ class ViewComponentTest {

68 69

assertThat(rect2.parent.transforms.size, `is`(0))

69 70

}

70 71 72 +

@Test

73 +

fun `Get child with cast`() {

74 +

val rect = Rectangle()

75 +

val circle = Circle()

76 + 77 +

view.addChild(rect)

78 +

view.addChild(circle)

79 + 80 +

val rect2: Rectangle = view.getChild(0, Rectangle::class.java)

81 +

val circle2: Circle = view.getChild(1, Circle::class.java)

82 + 83 +

assertThat(rect2, `is`(rect))

84 +

assertThat(circle2, `is`(circle))

85 +

}

86 + 71 87

@Test

72 88

fun `View type children are correctly updated onUpdate and disposed on remove`() {

73 89

val child = TestView()

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4