Page 1 of 1

New gui elements for use

Posted: Sat Jun 22, 2019 1:58 am
by Staplergun
I'm looking at some of the built in gui elements and I'm curious if we could get some new styles or elements available to us:
  • Horizontal or vertical dividers (ie: agui::HorizontalLine/VerticalLine)
  • Fillers available as an element (vertical and horizontal)
  • Tabbed frames (agui::TabbedFrames)
  • Sliders with stepping options

Re: New gui elements for use

Posted: Sat Jun 22, 2019 4:14 am
by raiguard
+1 for the stepped slider. You can already create a "notched slider" using the notched_slider style, but as you can see in this screenshot, it doesn't actually behave like a notched slider:
2019-06-21 22_09_38-Window.png
2019-06-21 22_09_38-Window.png (9.55 KiB) Viewed 4354 times
I suppose one could manually round the value to the nearest integer every time the slider moves, but that would be very performance-unfriendly. Dragging this slider around a bunch already causes my mod to use more than 16ms per tick, and all it's doing is updating a value in global and reflecting the new value in the adjacent textfield!

Re: New gui elements for use

Posted: Sat Jun 22, 2019 7:05 am
by eradicator
Raiguard wrote: Sat Jun 22, 2019 4:14 am Dragging this slider around a bunch already causes my mod to use more than 16ms per tick, and all it's doing is updating a value in global and reflecting the new value in the adjacent textfield!
And writing happily to the log file? 16ms for updating a slider smells fishy.

Re: New gui elements for use

Posted: Sat Jun 22, 2019 9:15 am
by Therenas
Maybe the event related to changing the slider fires very frequently while the slider is being dragged?

Re: New gui elements for use

Posted: Sat Jun 22, 2019 9:23 am
by eduran
Seconded, give us more GUI elements to play with :)
Staplergun wrote: Sat Jun 22, 2019 1:58 am
  • Tabbed frames (agui::TabbedFrames)
Already possible with what we currently have, but it is a hassle. A proper implementation would make using them so much easier.

Therenas wrote: Sat Jun 22, 2019 9:15 am Maybe the event related to changing the slider fires a lot of times per second when someone is dragging it?
It would have to fire a few hundred times per tick to be that slow. That indicates either something is buggy with the slider/event itself or the implementation for rounding and updating the text is super-slow.

Re: New gui elements for use

Posted: Sat Jun 22, 2019 12:08 pm
by nuhll
Yes dragging sliders make factorio very laggy and unresponsive, i dont know if its wrong implemented or not but this is the mod i mean:
https://mods.factorio.com/mod/Actual_Craft_Time

Re: New gui elements for use

Posted: Sat Jun 22, 2019 12:32 pm
by eradicator
Or maybe @OP is reading the statistics wrong. I get 0.03ms with the following:

Code: Select all

/c
game.player.gui.center
  .add{type='frame'}
  .add{type='slider',minimum_value=1,maximum_value=4}
  .style = 'notched_slider'

script.on_event(defines.events.on_gui_value_changed,function(e)
  local slider = e.element
  slider.slider_value = math.floor(slider.slider_value+0.5)
  end)
I wholly support the request for a proper notched slider though. Snapping it like this looks very ugly.

Re: New gui elements for use

Posted: Sat Jun 22, 2019 12:53 pm
by eradicator
nuhll wrote: Sat Jun 22, 2019 12:08 pm Yes dragging sliders make factorio very laggy and unresponsive, i dont know if its wrong implemented or not but this is the mod i mean:
https://mods.factorio.com/mod/Actual_Craft_Time
Looked at the code and as expected the mod is naively doing *all* of the calculations *every* time the slider changes in the slightest way. As this can happen several tens of times *per tick* *per player* if you drag fast it's quite expensive to do (i can see it go up to 30.0ms). It'd be trivial to insert a check to at least do it only once per tick, or better per maybe 30 ticks, which would make it instantly several orders of magnitude faster.

Re: New gui elements for use

Posted: Sat Jun 22, 2019 1:02 pm
by nuhll
yeah, thats how it feels. Maybe you could tell him how to do better? (if you want ofc)

Re: New gui elements for use

Posted: Sat Jun 22, 2019 4:45 pm
by Bilka
I added lines in the next version. For the filler you can just use the graphical set from the style, set it on a flow/frame and use that as the filler texture.

Re: New gui elements for use

Posted: Sat Jun 22, 2019 4:57 pm
by raiguard
Thanks bilka!

Back on the topic of stepped sliders, I went ahead and added logic for it to my mod. However, then it looks like this:
jiggly slider.gif
jiggly slider.gif (49.13 KiB) Viewed 4294 times
That's one jiggly boi. The problem is that by the time the change event fires, the game has already graphically updated the slider position. So even if you use math to round it, it will result in this flickering. The only "real" fix is to add native support for it to the API.

Re: New gui elements for use

Posted: Wed Jun 26, 2019 12:42 pm
by nuhll
that gif make me lol. Thats how it feels to play factorio... xDDDDDDDDDDDDDDDD

Re: New gui elements for use

Posted: Thu Jul 25, 2019 2:42 pm
by Bilka
Filler was added as empty-widget (it accepts the style) and stepping is now an option for sliders. Tabs are also a thing.