Commit fa5c4a6a authored by David's avatar David

Now it works on *any* node for marquee

parent 69e42600
......@@ -9,10 +9,9 @@ import io.reactivex.schedulers.Schedulers
import javafx.animation.Animation
import javafx.animation.KeyFrame
import javafx.animation.Timeline
import javafx.beans.property.SimpleIntegerProperty
import javafx.collections.FXCollections
import javafx.event.ActionEvent
import javafx.event.EventHandler
import javafx.scene.Node
import javafx.scene.layout.Pane
import javafx.scene.shape.Rectangle
import javafx.scene.text.Text
......@@ -24,12 +23,11 @@ import java.time.format.DateTimeFormatter
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.concurrent.thread
data class TickerEntry(
val title: String,
val content: String
val content: Node
) {
//TODO: A way to add rendering logic
//TODO: a way to have a notification when it's cleared, for ones that want to be re-executed
......@@ -63,18 +61,29 @@ class TickerView : View() {
this.add(marqueeView)
}
private fun createText(content: String): Text {
//How is this getting in there?
val text = Text(content)
text.layoutY = 20.0
text.style {
fill = c("white")
}
return text
}
override fun onDock() {
//Submit a text to be marquee'd
//After some kind of delay maybe
//Race condition, the thing hadn't completely sized before adding it, only a problem early on
// making sure to have a delay int here lays it out proper
val entries = listOf(
TickerEntry("blorp", "Third!"),
TickerEntry("blerp", "this is the second"),
TickerEntry("test", sampleText),
TickerEntry("more", "Some more words"),
TickerEntry("another", "This is happening"),
TickerEntry("time", ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME))
TickerEntry("blorp", createText("Third!")),
TickerEntry("blerp", createText("this is the second")),
TickerEntry("test", createText(sampleText)),
TickerEntry("more", createText("Some more words")),
TickerEntry("another", createText("This is happening")),
TickerEntry("time", createText(ZonedDateTime.now().format(DateTimeFormatter.ISO_ZONED_DATE_TIME)))
)
Observable.fromIterable(entries)
.observeOn(Schedulers.computation())
......@@ -103,7 +112,7 @@ class MarqueeView : View() {
data class ClearedTick(val entry: TickerEntry)
private val pane: Pane = pane()
private val singleThread = Executors.newSingleThreadExecutor()
private val singleThread = Executors.newSingleThreadExecutor() //TODO: really need a way to clean this up
override val root = pane
......@@ -112,6 +121,7 @@ class MarqueeView : View() {
pane.prefWidthProperty().bind(of.widthProperty())
pane.prefHeightProperty().bind(of.heightProperty())
}
init {
val rectangle = Rectangle(25.0, 25.0)
......@@ -161,34 +171,24 @@ class MarqueeView : View() {
.subscribe()
}
private fun createText(content: String): Text {
//How is this getting in there?
val text = Text(content)
text.layoutY = 20.0
text.style {
fill = c("white")
}
return text
}
//Will need to fire one of these for each thing, with some space detection, based on when one is ending.
private fun animateText(entry: TickerEntry, publishSubject: PublishProcessor<ClearedTick>) {
val text = createText(entry.content)
val content = entry.content
val emptyStart = root.prefWidth //It's weird, like a race condition
logger.debug("NEW LAYOUT START X: ${emptyStart}")
text.layoutX = emptyStart //I think this is right
root.add(text) //stick it in there, and start animating it
content.layoutX = emptyStart //I think this is right
root.add(content) //stick it in there, and start animating it
val cleared = AtomicBoolean(false)
val timeline = Timeline()
val updateFrame = KeyFrame(Duration.millis(35.0), EventHandler<ActionEvent> {
//I don't intend to bounce this
val textWidth = text.layoutBounds.width
val textWidth = content.layoutBounds.width
val paneWidth = root.width
val layoutX = text.layoutX
val layoutX = content.layoutX
//instead I want to move completely from the right all the way off until it's gone
//end state of this text is the entire width of the text off the right so layoutX <= 0 - textWidth - offset
......@@ -204,7 +204,7 @@ class MarqueeView : View() {
//Done animating, it's finished
timeline.stop()
} else {
text.layoutX = text.layoutX - 1 //TODO: I should probably do animation in larger chunks perhaps, so that it can use less CPU?
content.layoutX = content.layoutX - 1 //TODO: I should probably do animation in larger chunks perhaps, so that it can use less CPU?
//TODO: this might be where I need to make other animation happen
}
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment