druid icon indicating copy to clipboard operation
druid copied to clipboard

vertical sliders

Open czinczaar opened this issue 2 years ago • 2 comments

Hi, about vertical sliders: it seems the end pos can only be positive? If not, how do you make a proper vertical slider? Thanks.

czinczaar avatar May 25 '23 00:05 czinczaar

Hello! Scrolls are fine, they can work in any direction

You have a kind if camera (scroll_view node) and game map (scroll_content). So you can scroll through all the map

You can check the examples here https://insality.github.io/druid/druid/ and also make note how the GUI layout is created (for scroll view/content)

If you have any concrete question, please answer :)

Insality avatar May 25 '23 07:05 Insality

I'm fairly sure there is a bug in the sliders. I cannot drag the pin if the end_pos is negative.

I moved the pin to the 0 position for testing purposes. image

Works

This works as expected. I can use mouse to drag the pin to the right to increase the value. --->

local scroll_slider = self.druid:new_slider("grid_scroll_pin", vmath.vector3(287, 0, 0), function (_, value)
    grid_scroll:scroll_to_percent(vmath.vector3(value, 0, 0), true)
end)

Does not work

Cannot use mouse to drag the pin. Pin should be draggable to the left to increase the value <--- but it does not move.

local scroll_slider = self.druid:new_slider("grid_scroll_pin", vmath.vector3(-287, 0, 0), function (_, value)
    grid_scroll:scroll_to_percent(vmath.vector3(value, 0, 0), true)
end)

This issue persist for both horizontal and vertical. I tried to make a vertical scroll but got stopped by this issue when trying to make a slider where 0 value is at the top and 1 value is at the bottom. There was a broken success by rotating the grid_scroll_slider Z by 180 degrees but then dragging motion was opposite of the pin go direction.

Edit

Looks like a small change fixed this but I have no idea yet if it breaks something. https://github.com/Insality/druid/blob/master/druid/extended/slider.lua#L135 > into ~=

if self.dist.x ~= 0 then
    self.value = (self.target_pos.x - self.start_pos.x) / self.dist.x
end

if self.dist.y ~= 0 then
    self.value = (self.target_pos.y - self.start_pos.y) / self.dist.y
end

Edit 2

Okay.. the above is not the fix. For now I got a vertical slider with a static grid working. So far the issue was that the pivot for grid_content and grid_scroll_slider were wrong. They need to the north and south respectively. There is an issue with the pin initial position though, but for now it can be fixed with a simple gui.set_position after the druid slider is created.

Now to try to get it working with a data list..

Edit 3

I had a huge headache when trying to get the slider to scroll the data list without it going too far when moving too fast. This problem fixed itself when I commented out this line in scroll.lua. The pin is scrolling the data list by calculating the list item index from percent.

NaakkaDev avatar Jan 04 '24 15:01 NaakkaDev

Hello! Scrolls are fine, they can work in any direction ... If you have any concrete question, please answer :)

No, he meant Sliders Vertical Sliders

No scrolls

So, I have this issue too I just want vertical sliders, but I don't know how to do that...

https://github.com/user-attachments/assets/63271437-7e60-4e13-bda3-331a1c254a5f

So. how you can see, it works only with horizontal dragging. But I want normal vertical dragging works. How can I do that with druid Framework?

Dolbaeb777K avatar Oct 15 '24 07:10 Dolbaeb777K

There is a bug with a sliders, it currently don'y work in negative direction as I remember (so you can try from bottom to up in this case)

Will be fixed in next release and will add several examples

Insality avatar Oct 15 '24 09:10 Insality

... (so you can try from bottom to up in this case)

Sorry. What do you mean?

Dolbaeb777K avatar Oct 15 '24 13:10 Dolbaeb777K

Sorry. What do you mean?

You set start position of "pin_node" in your GUI and set a target position in the code, when you call new_slider(node, target_position)

For vertical slider the current workaround is to place the "pin_node" at the bottom (ex. vmath.vector3(0, -100, 0)) and set the target position, where Y will be bigger than start position (ex vmath.vector3(0, 100, 0))

Insality avatar Oct 15 '24 15:10 Insality

You set start position of "pin_node" in your GUI and set a target position in the code, when you call new_slider(node, target_position)

For vertical slider the current workaround is to place the "pin_node" at the bottom (ex. vmath.vector3(0, -100, 0)) and set the target position, where Y will be bigger than start position (ex vmath.vector3(0, 100, 0))

So, That's work, Thanks!

But it works "crutchily"... I needed to separate slider_back_simple texture, I mean just choosing slider_back texture for new created node (slider_back), and turn off visible option of slider_back_simple node then rotate pin_node into horizontal position, for it works. Because pin_node just get horizontal position near slider_back_simple node without that crutches ) Look,

https://github.com/user-attachments/assets/1eaf80ac-7002-4678-8481-4cc278c65156

Dolbaeb777K avatar Oct 16 '24 07:10 Dolbaeb777K

You can make it without rotation. Just place a "pin" node at bottom and use the higher position to set in the code

https://github.com/user-attachments/assets/5f6684f2-b373-45b6-b13f-2b8a3927dcae

Insality avatar Oct 16 '24 17:10 Insality

Thanks!

https://github.com/user-attachments/assets/5cbe1925-1eae-47c0-a555-6cf97ffd320d

I am leaving a video to share with everyone.

Dolbaeb777K avatar Oct 17 '24 02:10 Dolbaeb777K

Oh, no. Why it doesn't work 😭 ...

https://github.com/user-attachments/assets/17d40ef3-61e0-477e-a7e9-a6cb5bee21a9

It just get a nil value. Why?

INFO:ENGINE: Initialised sound device 'default'
DEBUG:SCRIPT: [Druid]: The component slider is extended component. You have to register it via druid.register to use it
DEBUG:SCRIPT: [Druid]: Use next code:
DEBUG:SCRIPT: local slider = require("druid.extended.slider")
DEBUG:SCRIPT: druid.register("slider", slider)
ERROR:SCRIPT: main/GUI/Slider_Up.gui_script:9: attempt to index local 'slider' (a nil value)
stack traceback:
  main/GUI/Slider_Up.gui_script:9: in function <main/GUI/Slider_Up.gui_script:4>

ERROR:GAMESYS: Error when initializing gui component: RESULT_SCRIPT_ERROR.

WARNING! I use https://github.com/Insality/druid/archive/refs/heads/update.zip for my project because I use the latest Defold version.

Dolbaeb777K avatar Oct 17 '24 03:10 Dolbaeb777K

DEBUG:SCRIPT: [Druid]: The component slider is extended component. You have to register it via druid.register to use it DEBUG:SCRIPT: [Druid]: Use next code: DEBUG:SCRIPT: local slider = require("druid.extended.slider") DEBUG:SCRIPT: druid.register("slider", slider)

local slider = require("druid.extended.slider")
druid.register("slider", slider)

Insality avatar Oct 17 '24 06:10 Insality

local slider = require("druid.extended.slider") druid.register("slider", slider)

Bruh. Bro, sorry... I am linux user but I forgot that I have to read errors completely ) My bad, man. Thanks a lot again! )

So, now it works the best! )

Dolbaeb777K avatar Oct 17 '24 14:10 Dolbaeb777K