Page 1 of 1

Visual Label Adjustment

Posted: Thu Sep 27, 2018 6:34 pm
by Jor'Mox
Ever wanted to just drop down a label, and drag it around to get it where you wanted it, without all the hassle of figure out what the right numbers are to make it go where you want? Now there is a script for that.

This script either takes an existing Geyser label, or the necessary info to create one for you, and enables you to click and drag to move and resize the label as desired. And when you are done, you can set the label to have either fixed or percentage based size and/or position. I made this as a stepping stone toward something else, so I'm not really sure how useful it is in general, but it is still pretty neat.

To use it: GUIlabel.adjustLabel(label variable, OR table with info to create label in Geyser, OR name, x, y, width, height, color)
Then click and drag in the middle to move it around, or near an edge (within 10 pixels) to resize that edge, and yes you can do two at once by clicking near a corner.
To finish adjusting the label: GUIlabel.finishLabel(label variable, size_as_percent, position_as_percent)
If either size or position is set as a percent, the finishLabel function gets their current absolute values in pixels and converts them into a percentage of the main window, so that as it is resized, the label maintains that percentage size or position.
Code: [show] | [select all] lua
GUIlabel = GUIlabel or {}
local adjustInfo

GUIlabel.adjustLabel = function(name, x, y, w, h, c)
    local info, lbl
    if type(name) == "table" then
        if name.type == "label" then
            lbl = name
            info = name
        info = {name = name, x = x, y = y, width = w, height = h, color = c}
    if not lbl then
        lbl = Geyser.Label:new(info)
    if info then
        return lbl

local function make_percent(num)
    num = math.floor(10000*num)/100
    num = tostring(num).."%"
    return num

GUIlabel.finishLabel = function(lbl, size_as_percent, position_as_percent)
    local x, y, w, h = lbl:get_x(), lbl:get_y(), lbl:get_width(), lbl:get_height()
    local winw, winh = getMainWindowSize()
    x, y, w, h = make_percent(x/winw), make_percent(y/winh), make_percent(w/winw), make_percent(h/winh)
    if size_as_percent then lbl:resize(w,h) end
    if position_as_percent then lbl:move(x,y) end

GUIlabel.onClick = function(lbl, event)
    if event.button == "LeftButton" then
        local x, y = getMousePosition()
        local w, h = lbl:get_width(), lbl:get_height()
        local x1, y1 = x - event.x, y - event.y
        local x2, y2 = x1 + w, y1 + h
        local left, right, top, bottom = event.x <= 10, x >= x2 - 10, event.y <= 10, y >= y2 - 10
        if right and left then left = false end
        if top and bottom then top = false end
        local move = not (right or left or top or bottom)
        adjustInfo = {name =, top = top, bottom = bottom, left = left, right = right, move = move, x = x, y = y}

GUIlabel.onRelease = function(lbl, event)
    if event.button == "LeftButton"  and adjustInfo and == then
        adjustInfo = nil

GUIlabel.onMove = function(lbl, event)
    if adjustInfo and == then
        local x, y = getMousePosition()
        local winw, winh = getMainWindowSize()
        local x1, y1, w, h = lbl.get_x(), lbl.get_y(), lbl:get_width(), lbl:get_height()
        local dx, dy = adjustInfo.x - x, adjustInfo.y - y
        local max, min = math.max, math.min
        if adjustInfo.move then
            local tx, ty = max(0,x1-dx), max(0,y1-dy)
            tx, ty = min(tx, winw - w), min(ty, winh - h)
            lbl:move(tx, ty)
            local w2, h2, x2, y2 = w - dx, h - dy, x1 - dx, y1 - dy
            local tx, ty, tw, th = x1, y1, w, h
            if then
                ty, th = y2, h + dy
            elseif adjustInfo.bottom then
                th = h2
            if adjustInfo.left then
                tx, tw = x2, w + dx
            elseif adjustInfo.right then
                tw = w2
            tx, ty, tw, th = max(0,tx), max(0,ty), max(10,tw), max(10,th)
            tw, th = min(tw, winw), min(th, winh)
            tx, ty = min(tx, winw-tw), min(ty, winh-th)
            lbl:move(tx, ty)
            lbl:resize(tw, th)
        adjustInfo.x, adjustInfo.y = x, y
Edit: Minor tweak to keep label from flipping sides if it gets too close to the edges, and similar mischief. Label limited to actual area of main window.

Re: Visual Label Adjustment

Posted: Thu Apr 25, 2019 7:59 am
by jieiku
hmmm, need a little more info on how to use this to resize labels. Moving the labels seems to be working.

Re: Visual Label Adjustment

Posted: Thu Apr 25, 2019 11:20 am
by Jor'Mox
To do the resizing, you just need to click near enough to the edges of the label, and when you drag it will change the size of the label, rather than move it around.

Re: Visual Label Adjustment

Posted: Thu Apr 25, 2019 1:36 pm
by jieiku
This feature still works for you? I cannot get it to work on 3.19.0

I even created a blank profile, as well as inserting multiple echo("\nTESTING\n") messages. It seems the script is not being called at all...

Any chance I could get you to test resizing a label on 3.19.0? With none of my echo debug messages even firing I am not sure where to begin debugging this.

click this image to view the gif recording:

Re: Visual Label Adjustment

Posted: Thu Apr 25, 2019 1:42 pm
by Jor'Mox
I just tested it in 3.19.0, on a Mac, and it worked as expected. When I click and drag in the middle of the label, it moves around. When I click and drag within the label close to the edges, it resizes the label.

Re: Visual Label Adjustment

Posted: Thu Apr 25, 2019 1:51 pm
by jieiku
I just realized there are geyzer labels and then there are mapper labels. Does this also work to resize mapper labels?

Re: Visual Label Adjustment

Posted: Thu Apr 25, 2019 1:52 pm
by Jor'Mox
No, only for Geyser labels.