Skip to content

Commit

Permalink
let's try now
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnemotechnician committed Jan 2, 2022
1 parent 8eda34b commit 1a3d082
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ abstract class Window {
var isCollapsed = false
internal set

/** Whether the window is being dragged by the user right now */
var isDragging = false
internal set

/** Name of this window displayed in the top bar */
open var name = "unnamed window"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import arc.*
import arc.math.*
import arc.util.*
import arc.struct.*
import arc.input.*
import arc.scene.event.*
import arc.scene.ui.*
import arc.scene.ui.layout.*
Expand Down Expand Up @@ -38,6 +39,9 @@ object WindowManager {
Mathf.clamp(pos.y, root.getPrefHeight() / 2, windowGroup.height - root.getPrefHeight() / 2)
);

root.color.a = if (it.isDragging) 0.5f else 1f
it.table.setSize(it.table.prefWidth, it.table.prefHeight)

it.onUpdate()
}
}
Expand All @@ -63,12 +67,28 @@ object WindowManager {
window.onToggle(it)
}

dragged { x, y ->
val oldPos = window.rootTable.localToParentCoordinates(Tmp.v1.set(x, y))
window.rootTable.setPosition(oldPos.x, oldPos.y)
//making it draggable
addListener(object : InputListener() {
var dragx = 0f
var dragy = 0f;

window.onDrag()
}
override fun touchDown(event: InputEvent, x: Float, y: Float, pointer: Int, button: KeyCode): Boolean {
dragx = x; dragy = y;
window.isDragging = true;
return true;
}

override fun touchDragged(event: InputEvent, x: Float, y: Float, pointer: Int) {
val oldPos = window.rootTable.localToParentCoordinates(Tmp.v1.set(x, y))
window.rootTable.setPosition(oldPos.x, oldPos.y)

window.onDrag()
}

override fun touchUp(e: InputEvent, x: Float, y: Float, pointer: Int, button: KeyCode) {
window.isDragging = false;
}
})
}.fillX().marginBottom(5f)

row()
Expand Down

0 comments on commit 1a3d082

Please sign in to comment.