mirror of https://github.com/teverse/teverse
Compare commits
3 Commits
68cff74b1f
...
a82eddab75
Author | SHA1 | Date |
---|---|---|
![]() |
a82eddab75 | |
![]() |
d4e72f6336 | |
![]() |
a4b9b6d0f5 |
|
@ -1,3 +1,6 @@
|
||||||
|
local shared = require("tevgit:core/teverseUI/shared.lua")
|
||||||
|
local draggableUi = shared.draggableUi
|
||||||
|
|
||||||
local container = teverse.construct("guiFrame", {
|
local container = teverse.construct("guiFrame", {
|
||||||
parent = teverse.coreInterface,
|
parent = teverse.coreInterface,
|
||||||
size = guiCoord(0.1, 150, 0.4, 200),
|
size = guiCoord(0.1, 150, 0.4, 200),
|
||||||
|
@ -9,19 +12,22 @@ local container = teverse.construct("guiFrame", {
|
||||||
visible = false
|
visible = false
|
||||||
})
|
})
|
||||||
|
|
||||||
teverse.construct("guiTextBox", {
|
local top = teverse.construct("guiTextBox", {
|
||||||
parent = container,
|
parent = container,
|
||||||
size = guiCoord(1, -10, 0, 20),
|
size = guiCoord(1, 0, 0, 20),
|
||||||
position = guiCoord(0, 5, 0, 0),
|
position = guiCoord(0, 0, 0, 0),
|
||||||
backgroundAlpha = 0.0,
|
backgroundAlpha = 0.5,
|
||||||
textSize = 20,
|
textSize = 20,
|
||||||
textAlign = "middleLeft",
|
textAlign = "middleLeft",
|
||||||
text = "Console"
|
-- bit hacky but works for slight indent
|
||||||
|
text = " Console",
|
||||||
|
backgroundColour = colour.rgb(112, 112, 112)
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
local logContainer = teverse.construct("guiScrollView", {
|
local logContainer = teverse.construct("guiScrollView", {
|
||||||
parent = container,
|
parent = container,
|
||||||
size = guiCoord(1, -10, 1, -22),
|
size = guiCoord(1, -10, 1, -27),
|
||||||
position = guiCoord(0, 5, 0, 20),
|
position = guiCoord(0, 5, 0, 20),
|
||||||
backgroundAlpha = 0.0,
|
backgroundAlpha = 0.0,
|
||||||
canvasSize = guiCoord(1, -1, 10, 0),
|
canvasSize = guiCoord(1, -1, 10, 0),
|
||||||
|
@ -29,6 +35,8 @@ local logContainer = teverse.construct("guiScrollView", {
|
||||||
scrollbarRadius = 2
|
scrollbarRadius = 2
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
draggableUi(container, top)
|
||||||
local lastPos = 0
|
local lastPos = 0
|
||||||
function addLog (msg, time)
|
function addLog (msg, time)
|
||||||
local txt = teverse.construct("guiTextBox", {
|
local txt = teverse.construct("guiTextBox", {
|
||||||
|
@ -68,4 +76,5 @@ else
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return container
|
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