Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imtui #2505

Merged
merged 1,100 commits into from May 2, 2024
Merged

Imtui #2505

merged 1,100 commits into from May 2, 2024

Conversation

20k
Copy link
Contributor

@20k 20k commented Dec 17, 2022

Hello! This is a branch to potentially use the imtui fork of ImGui for DFHack scripts, so that they can have a nice modern UI behind them. Myk002 asked me to file a PR for this to keep a record

So far its all gone surprisingly smoothly:

button.webm
multiwin.webm
colourswork.webm

On a technical note, each viewscreen has its own imgui context, which means that every view is fully independent of every other view. The other alternative would be to have one global imgui context (which would allow different viewscreens to have interacting windows, for eg drag + drop), but this adds more complexity

Todo:

  • Basic Text Rendering
  • Colour internally
  • Reference mechanism for APIs that take pointers

Basic widgets functionality:

  • Button
  • Checkbox
  • PushStyleColor/PopStyleColor (necessary for eg coloured buttons)
  • Selectable (necessary for full width buttons)
  • Input boxes (for search)
  • Rework current colour system to reuse existing lua constants

Tedious but easy widget functionality:

  • IsItem* + IsWindow*

More difficult

  • Keyboard Controls. ImGui has this built in, so I'm hopeful that we can piggyback off this

Things that will inherently never work:

  • Anything involving colour, like ColorPicker3

Technical Questions:

  • Is one context per viewscreen the right approach?
  • Overlay interop
  • Non lua plugins

CMakeLists.txt Outdated Show resolved Hide resolved
ImGui::Text("%s", str.c_str());
}

static bool imgui_button(std::string name)
Copy link
Member

@myk002 myk002 Dec 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that simple intermediate functions like this are not necessary. You could just WRAPM the module API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha ok! I'll keep this in mind for simple stuff - things like buttons do have default arguments that I'll add down the line

@20k
Copy link
Contributor Author

20k commented Dec 18, 2022

dfoverlay.webm

Lots more progress, putting together a basic overlay config example

@20k
Copy link
Contributor Author

20k commented Dec 23, 2022

overlayintegrations.webm

Current state: the high level integration is mostly (entirely?) done, barring any bugs or unknown unknowns. ImGui windows respect viewscreen sorting, and the technical/architectural work is mostly done. So the current state is that there are a couple of minor local bugfixes, and lots of widgets to add. And the code needs a lot of cleanup

I've been more thoroughly keeping track of what I'm working on over here in case anyone wants more detail of what's to be done generally

https://trello.com/b/zW9Oc48o/df

@@ -31,3 +31,6 @@
[submodule "depends/googletest"]
path = depends/googletest
url = ../../google/googletest.git
[submodule "depends/imgui"]
path = depends/imgui
url = https://github.com/20k/dfhack-imgui.git
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be sure to use a relative path so the submodule uses the same transport mechanism as the parent fork.

also, before we merge this, we'll want to fork imgui into the DFHack org like most of the dependencies in this file

@@ -419,6 +419,7 @@ include_directories(depends/tthread)
include_directories(${ZLIB_INCLUDE_DIRS})
include_directories(depends/clsocket/src)
include_directories(depends/xlsxio/include)
include_directories(depends/imgui)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will plugin code be using this API directly, or will it just be through the DFHack module? If the latter, we should probably restrict the include to target that directly depend on it. Something like:

target_include_directories(imgui INTERFACE depends/imgui)

(this would have to appear below the add_subdirectory(imgui) line below so the target exists

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent a while fixing up the C++ support, so the current design should directly allow for plugins to use ImGui directly without many restrictions. I do need to add some testing, but yes ImGui itself would be directly available to any plugins as long as they also decorate their render/feed code correctly from the module itself

@@ -129,6 +129,7 @@ set(MODULE_HEADERS
include/modules/Graphic.h
include/modules/Gui.h
include/modules/GuiHooks.h
include/modules/ImTuiImpl.h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a module name, I'd suggest something like Widgets.h or UI.h

myk002 and others added 23 commits February 1, 2023 17:39
allow tile in Label tokens to be either pen or id
add textures used by new gui/control-panel
[nestboxes] update and simplify; persist state
support offset text in graphics mode for pens
display PAUSE FORCED instead of a pause icon
scripts: master
scripts: master
scripts: master
Co-authored-by: Myk <myk.taylor@gmail.com>
Co-authored-by: Myk <myk.taylor@gmail.com>
Co-authored-by: Myk <myk.taylor@gmail.com>
minimum required to make work:
* realign the job table
* add code to flip/flop the work detail enable flag
johncosker and others added 25 commits February 9, 2023 08:30
autoslab: Improve check for existing engraved slab.
library/xml: master
scripts: master
Detect manual save when persisting data
scripts: master
The rewrite in DFHack#2773 introduced a bug (identified by KMFrench on Discord) where
nestboxes themselves would be forbidden, which prevents egglaying citizens from
using them since the nestboxes would be claimed before use. The previous version
of the plugin handled this by skipping the first item in `contained_items`,
which is the building material (in this case, the nestbox).

This fix limits the `forbid` flag manipulation to egg items only, which should
be a reasonable limitation that still allows the plugin to serve its purpose.
scripts: master
@myk002 myk002 changed the base branch from v0.47.05 to develop April 27, 2024 08:26
@myk002 myk002 changed the base branch from develop to imtui May 2, 2024 20:42
@myk002
Copy link
Member

myk002 commented May 2, 2024

saving this work in DFHack/dfhack/imtui

@myk002 myk002 merged commit b176675 into DFHack:imtui May 2, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet