Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Yafc.UI/ImGui/ImGuiUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ public static bool WithTooltip(this ButtonEvent evt, ImGui gui, string tooltip,

return evt;
}
public static bool WithTooltipConditional(this ButtonEvent evt, bool condition, ImGui gui, string tooltip, Rect? rect = null) {
Copy link
Owner

Choose a reason for hiding this comment

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

This function duplicates the code of WithTooltip, with the only difference of an in-built check for boolean. This function has only one usage.

Why not just check this boolean condition in a short-circuiting if before deciding if you want to show the tooltip?

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, I start to understand why, but I wonder if there's a better way. Will look into that.

Copy link
Owner

Choose a reason for hiding this comment

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

Something like the following to prevent code duplication. What do you guys think?

        if (condition) {
            return WithTooltip(evt, gui, tooltip, rect);
        }
        else {
            return evt;
        }

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hiding this logic in the new function is cleaner to me, as it does not have this logic all over the place and can directly returned.

So we'd get a function bool WithTooltipConditional that returns evt

if (evt == ButtonEvent.MouseOver && condition) {
gui.ShowTooltip(rect ?? gui.lastRect, tooltip);
}

return evt;
}

public static bool BuildCheckBox(this ImGui gui, string text, bool value, out bool newValue, SchemeColor color = SchemeColor.None,
RectAllocator allocator = RectAllocator.LeftRow, string? tooltip = null) {
Expand Down
1 change: 1 addition & 0 deletions Yafc/Data/locale/en/yafc.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ open-secondary-page=Open as secondary
shortcut-ctrl-click=Ctrl+Click
close-secondary-page=Close secondary
duplicate-page=Duplicate page
tooltip-close-page=Click to close\nCtrl+Click to remove

; ObjectTooltip.cs
name-with-type=__1__ (__2__)
Expand Down
11 changes: 9 additions & 2 deletions Yafc/Widgets/MainScreenTabBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,19 @@ private void BuildContents(ImGui gui) {
}

gui.BuildText(page.name);
if (gui.BuildButton(Icon.Close, size: 0.8f)) {
if (gui.BuildButton(Icon.Close, size: 0.8f).WithTooltipConditional(page.canDelete, gui, LSs.TooltipClosePage)) {
if (isActive || isSecondary) {
changePageTo = prevPage;
changePage = isActive ? 1 : 2;
}
screen.ClosePage(pageGuid);

if (InputSystem.Instance.control && page.canDelete) {
project.RemovePage(page);
}
else {
screen.ClosePage(pageGuid);
}

i--;
}
}
Expand Down