Skip to content

Commit

Permalink
Better tab controls (#336)
Browse files Browse the repository at this point in the history
This is a continuation of the bare-bones tooling added by #332; the
layout and rendering of a tab control is now encapsulated into a
`TabControl` class. That class takes care of rendering all the tabs and
drawing only the correct tab content, as long as you give it string for
each title and a `GuiBuilder` to render each tab body.

For testing, I declared various sets of tabs, changed the `TabControl`
properties, and made sure the tabs rendered and reacted as expected.
Eventually I ended up with this monstrosity:
```
    private readonly TabControl tabControl = new(("General", DrawGeneral), ("Progression", DrawProgression), ("Tab 1", null), ("Tab 2", null), ("Tab 3", null), ("Tab 4", null), ("Tab 5's title text causes fewer problems", null), ("Tab 6", null), ("Tab 7", null), ("Tab 8 has an obscenely long title text for the purpose of causing as many problems as physically possible", null), ("Tab 9 wants three lines\nin its text, but\nthat doesn't work", null));
```
I expected Tab 9's title to render on three lines of text, but it only
renders on one line. I decided to leave multi-line tab titles as an
project for another time.
  • Loading branch information
shpaass authored Oct 29, 2024
2 parents 4a68750 + 6733564 commit 9e96d3e
Show file tree
Hide file tree
Showing 3 changed files with 503 additions and 129 deletions.
7 changes: 6 additions & 1 deletion Yafc.UI/ImGui/ImGuiLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public sealed class OverlappingAllocations : IDisposable {
private readonly ImGui gui;
private readonly bool initialDrawState;
private readonly float initialTop;
private float maximumBottom;

internal OverlappingAllocations(ImGui gui, bool alsoDraw) {
this.gui = gui;
Expand All @@ -282,10 +283,14 @@ internal OverlappingAllocations(ImGui gui, bool alsoDraw) {
/// If <see langword="false"/>, subsequent drawing commands (for the next tab page) will allocate space, but will not draw their controls.</param>
public void StartNextAllocatePass(bool alsoDraw) {
gui.enableDrawing = initialDrawState && alsoDraw;
maximumBottom = Math.Max(gui.state.top, maximumBottom);
gui.state.top = initialTop;
}

public void Dispose() => gui.enableDrawing = initialDrawState;
public void Dispose() {
gui.enableDrawing = initialDrawState;
gui.state.top = maximumBottom;
}
}

public void SetMinWidth(float width) {
Expand Down
Loading

0 comments on commit 9e96d3e

Please sign in to comment.