mirror of https://github.com/teverse/teverse
Compare commits
2 Commits
f4e0ae6139
...
d4e72f6336
Author | SHA1 | Date |
---|---|---|
Josh Muir | d4e72f6336 | |
Josh Muir | a4b9b6d0f5 |
|
@ -1,3 +1,6 @@
|
|||
local shared = require("tevgit:core/teverseUI/shared.lua")
|
||||
local draggableUi = shared.draggableUi
|
||||
|
||||
local container = teverse.construct("guiFrame", {
|
||||
parent = teverse.coreInterface,
|
||||
size = guiCoord(0.1, 150, 0.4, 200),
|
||||
|
@ -9,19 +12,22 @@ local container = teverse.construct("guiFrame", {
|
|||
visible = false
|
||||
})
|
||||
|
||||
teverse.construct("guiTextBox", {
|
||||
local top = teverse.construct("guiTextBox", {
|
||||
parent = container,
|
||||
size = guiCoord(1, -10, 0, 20),
|
||||
position = guiCoord(0, 5, 0, 0),
|
||||
backgroundAlpha = 0.0,
|
||||
size = guiCoord(1, 0, 0, 20),
|
||||
position = guiCoord(0, 0, 0, 0),
|
||||
backgroundAlpha = 0.5,
|
||||
textSize = 20,
|
||||
textAlign = "middleLeft",
|
||||
text = "Console"
|
||||
-- bit hacky but works for slight indent
|
||||
text = " Console",
|
||||
backgroundColour = colour.rgb(112, 112, 112)
|
||||
|
||||
})
|
||||
|
||||
local logContainer = teverse.construct("guiScrollView", {
|
||||
parent = container,
|
||||
size = guiCoord(1, -10, 1, -22),
|
||||
size = guiCoord(1, -10, 1, -27),
|
||||
position = guiCoord(0, 5, 0, 20),
|
||||
backgroundAlpha = 0.0,
|
||||
canvasSize = guiCoord(1, -1, 10, 0),
|
||||
|
@ -29,6 +35,8 @@ local logContainer = teverse.construct("guiScrollView", {
|
|||
scrollbarRadius = 2
|
||||
})
|
||||
|
||||
|
||||
draggableUi(container, top)
|
||||
local lastPos = 0
|
||||
function addLog (msg, time)
|
||||
local txt = teverse.construct("guiTextBox", {
|
||||
|
@ -68,4 +76,5 @@ else
|
|||
end
|
||||
|
||||
|
||||
|
||||
return container
|
|
@ -0,0 +1,33 @@
|
|||
function draggableUi (uiToMove, activator)
|
||||
local mouseIsDown = false
|
||||
if not uiToMove then
|
||||
return error("Failed to create draggableUi: No UI provided!")
|
||||
end
|
||||
if not activator then
|
||||
activator = uiToMove
|
||||
end
|
||||
local evA = activator:on("mouseLeftDown", function( mousePos )
|
||||
mouseIsDown = true
|
||||
local startPos = uiToMove.position:get2D(teverse.input.screenSize)
|
||||
local offset = teverse.input.mousePosition - startPos
|
||||
|
||||
spawn(function ()
|
||||
while mouseIsDown do
|
||||
-- Calculate new position relative to the mouse pointer
|
||||
local mousePos = teverse.input.mousePosition
|
||||
local targetPos = mousePos - offset
|
||||
|
||||
uiToMove.position = guiCoord(0, targetPos.x, 0, targetPos.y)
|
||||
sleep()
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
local evB = teverse.input:on("mouseLeftUp", function( mousePosition )
|
||||
mouseIsDown = false
|
||||
end)
|
||||
end
|
||||
return {
|
||||
draggableUi = draggableUi
|
||||
|
||||
}
|
Loading…
Reference in New Issue