factoriolib / flib

A set of high-quality, commonly-used utilities for creating Factorio mods.
https://mods.factorio.com/mod/flib
MIT License
61 stars 15 forks source link

Howto define tabbed-pane with flib.gui-lite #60

Closed hahoyer closed 4 months ago

hahoyer commented 7 months ago

I cannot find how to define a tabbed-pane with gui-lite. Please help.

Sil3ntStorm commented 7 months ago

More like any documentation about how to do anything GUI in the first place. I guess one is expected to read source code and make sense of Lua in some fashion... (good luck with that lol) There are some style guides, but no example or details whatsoever on how to do any of that in the first place.

Little aside: If one has to write 20+ lines of GUI description oneself just to make an empty window (that meets the proposed style?) what exactly is the purpose of using a UI library if there is no easy / convenient way to create a window that follows the proposed style guide by the same author?

No hard feelings, just severely disappointed / frustrated by the lack of virtually any documentation.

raiguard commented 7 months ago

The lack of documentation for flib is a large issue, but a good documentation generator for EmmyLua annotations simply doesn't exist. The reason it hasn't happened yet is because I would have to write such a documentation generator from scratch.

I have experimented with making generic GUI templates but haven't found a solution I'm entirely happy with yet. Flib 0.14 will have a gui-templates module that includes a technology slot generator, but that's the only one so far. GUI event handling in Factorio is a bit of a pain due to how mods work.

If you need a tutorial for making GUIs, check out Therenas' Untitled GUI Guide.

raiguard commented 7 months ago

@hahoyer As for your original question, here's how to define an elem definition for a tabbed pane:

flib_gui.add(parent, {
  type = "tabbed-pane",
  {tab = {type = "tab", caption = "Tab 1"}, content = {type = "empty-widget"}},
  {tab = {type = "tab", caption = "Tab 2"}, content = {type = "empty-widget"}},
})

content can be any elem definition, I just used empty widgets for brevity. You'd probably want to use flows to hold your content.

hahoyer commented 7 months ago

thank you. But now I am stuck at the next function: hook_events. Have no idea what is the replacement in gui-lite. I think I'll leave the update to gui-lite for now. There was actually a very nice documentation before. Where did it go?

raiguard commented 4 months ago

I switched from LDoc to EmmyLua annotations so that flib can hook into LuaLS for autocomplete and inline documentation in your editor. Unfortunately, nobody has made an HTML docs generator for EmmyLua yet. I will do it myself some time in the future if it still doesn't exist then.