API Question Get Zoom

Hello,
I am working on a script for the software Aseprite, but I was some problem with the zoom function.

Backstory, I try to create a sidebar for pc tablet users like the Surface Go model. The dialog windows offer easy access for multiple shortcuts.

My problems are the zoom function, I try to configure the slider with the zoom. (app.zoom or app.command.zoom etc.)

  :separator{ label="padZoom", text="Zoom" }
  :button{ text="-", onclick=function() app.command.zoom {["percentage"]= tonumber("percentage")-50,} end}
  :button{ text="=", onclick=function()  app.command.zoom {["percentage"]="100",} end }
  :button{ text="+", onclick=function()
  app.command.zoom { ["percentage"]="percentage"+50,} end }
  :newrow()
  :slider{ id="sliderZoom", label="Zoom", min=0, max=6400, value= "100"}

I am sorry if my code looks strange, I honestly tried my best to understand, and I am tired at the same time lol.

I tried to create variable and get the actual zoom information but I always found errors. I also tried to read example on others scripts projects, but its wasn’T succefful.

You can get value out of a slider from dialog’s data, e.g.dlg.data["sliderId"].

Slider widget does not have an onchange function you could add that would make It responsive. You’d need a button to actually set zoom to the value from a slider.

This works (sort of):

local dialog = Dialog("Zoom")

dialog
    :separator{
        label = "padZoom",
        text = "Zoom"
    }
    :slider{
        id = "sliderZoom",
        label = "Zoom",
        min = 0,
        max = 6400,
        value = 100
    }
    :button{
        text = "     Zoom     ",
        onclick = function()
            app.command.zoom {["percentage"] = dialog.data["sliderZoom"]};
        end
    }
    :show{wait = false};
1 Like

It’s not a very robust solution and I couldn’t find a way to add + and - buttons that would be convenient to use.

1 Like

Thank you very much. I will try that solution.

1 Like

I find a way to get it working!!! I am not sure if it the right way, but it works haha! If anyone has trouble with slider, I let my anwser here:

:slider{
  id = "sliderZoom",
  label = "Zoom",
  min = 0,
  max = 6400,
  value = 100
}
:button{
  text = "Set Zoom",
  onclick = function()
      local dataZoom = dlgMain.data
      local sliderZoom = dataZoom.sliderZoom
      app.command.zoom {["percentage"] =sliderZoom };
  end
}
1 Like