Input layer opacity value with numerical input

As mentioned in 100% instead of 256? - #4 by dacap, it would be nice to be able to edit the layer opacity with numerical input.

Currently I’m trying to restore / use the same opacity number everywhere and I need to drag the mouse precisely on the gauge…

I tried to enter numbers after focusing the gauge but it didn’t work.

image

EDIT: looking at other popups using a slider gauge like A little love for slices I realise that a universal solution to support both gauge slider and numerical input may be better. In some apps we can click once (without moving the mouse), right-click or double-click on a slider gauge to enter a numerical value, while still able to drag to select an approximate value. I personally like the right-click approach since it doesn’t do anything else at the moment. And if applied to all gauge widgets, this would fix the issue for all gauges, native or from third-party scripts, at once.

I made you a simple script. Put this file in the scripts folder. I hope it helps!


-- Get the active layer
local layer = app.activeLayer

if layer == nil then
  return app.alert("There is no active layer, please select a layer and try again.")
end

-- Get the active layer
local layer = app.activeLayer

if layer == nil then
  return app.alert("There is no active layer")
end

-- Prompt the user for the new opacity value
local dlg = Dialog("Set Layer Opacity")
dlg:number {
  id="opacity",
  label="Opacity (0-255):",
  value=layer.opacity
}
dlg:button {
  text="OK",
  onclick=function()
    -- Get the opacity value from the dialog
    local opacity = dlg.data.opacity
    if opacity < 0 then
      opacity = 0
    end
    if opacity > 255 then
      opacity = 255
    end
    -- Set the opacity of the active layer
    layer.opacity = opacity
    app.refresh()
    return

  end
}
dlg:button {
  text="Cancel",
  onclick=function()
    -- Close the dialog without changing anything
    dlg:close()
  end
}
dlg:show{wait=false}

Thanks, it works! I can bind it to a shortcut to be faster too!

Should be easy enough to add a field to use percentage too!