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

Convert all tool Popups to floating windows #1658

Merged
merged 23 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
badc2bd
Refactored tool popup code to use floating windows instead of fixed p…
SparkyTD May 8, 2024
356c175
Fixed scaling issues with the new floating tool window UI
SparkyTD May 8, 2024
6a46960
All popups now react to both the Enter and KeypadEnter keys
SparkyTD May 8, 2024
56cf190
Set the correct popup title localization key in Select popup title, a…
SparkyTD May 8, 2024
86bacdb
Specified the getTitle() override for all Popup windows, removed old …
SparkyTD May 8, 2024
483a98c
Fixed the first hex input on the Select popup not always getting auto…
SparkyTD May 8, 2024
1086991
changed getTitle() to return UnlocalizedString, moved localization co…
SparkyTD May 8, 2024
b6a5037
Fixed the background not being rendered correctly on the transparent …
SparkyTD May 8, 2024
92ad4f4
Added support for customizable transparency for Popup windows when th…
SparkyTD May 8, 2024
e9cf4ef
Prevents the popup from initially appearing with the transparency eff…
SparkyTD May 8, 2024
e3ffd2a
Fixed bug that made popups transparent while interacting with a widget
SparkyTD May 8, 2024
919590c
Fixed issue that made Popups disappear completely with a misconfigure…
SparkyTD May 8, 2024
dc0dd93
Improved alpha handling in ViewHexEditor::drawPopup to be more standard
SparkyTD May 8, 2024
cc12859
Whitespace fixes
SparkyTD May 8, 2024
0bfb402
Whitespace fixes
SparkyTD May 8, 2024
1d7f0ad
Refactor popup logic to use regular windows
WerWolv May 8, 2024
62b585f
Deleted redundant ImGuiExt::BeginHoveringPopup() function
SparkyTD May 8, 2024
07f7fe9
Replaced redundant `justOpened` flag with `ImGui::IsWindowAppearing()`
SparkyTD May 8, 2024
fb9c65b
Added missing scaling multiplier to the Pin icon offset calculation
SparkyTD May 9, 2024
3b014fa
Whitespace fixes
SparkyTD May 9, 2024
72701a6
Fixed bug that was causing popup windows outside the root window to d…
SparkyTD May 9, 2024
02dc312
Updated scaling calculations to use the _scaled UDL instead of manual…
SparkyTD May 9, 2024
c555195
Merge branch 'master' into dev_floating_popups
WerWolv May 10, 2024
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
4 changes: 4 additions & 0 deletions lib/libimhex/include/hex/ui/imgui_imhex_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ namespace ImGuiExt {

struct Styles {
float WindowBlur = 0.0F;
float PopupWindowAlpha = 0.0F; // Alpha used by Popup tool windows when the user is not hovering over them
} styles;
};

Expand Down Expand Up @@ -304,6 +305,9 @@ namespace ImGuiExt {
bool ToggleSwitch(const char *label, bool *v);
bool ToggleSwitch(const char *label, bool v);

bool PopupTitleBarButton(const char* label, bool p_enabled);
void PopupTitleBarText(const char* text);

template<typename T>
constexpr ImGuiDataType getImGuiDataType() {
if constexpr (std::same_as<T, u8>) return ImGuiDataType_U8;
Expand Down
53 changes: 53 additions & 0 deletions lib/libimhex/source/ui/imgui_imhex_extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,59 @@ namespace ImGuiExt {
return ToggleSwitch(label, &v);
}

bool PopupTitleBarButton(const char* label, bool p_enabled)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
const ImGuiID id = window->GetID(label);
const ImRect title_rect = window->TitleBarRect();
const ImVec2 size(g.FontSize, g.FontSize); // Button size matches font size for aesthetic consistency.
const ImVec2 pos = window->DC.CursorPos;
const ImVec2 max_pos = pos + size;
const ImRect bb(pos.x, title_rect.Min.y, max_pos.x, title_rect.Max.y);

ImGui::PushClipRect(title_rect.Min, title_rect.Max, false);

// Check for item addition (similar to how clipping is handled in the original button functions).
bool is_clipped = !ItemAdd(bb, id);
bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held, ImGuiButtonFlags_None);
if (is_clipped)
{
ImGui::PopClipRect();
return pressed;
}

// const ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button);
// window->DrawList->AddCircleFilled(bb.GetCenter(), ImMax(2.0f, g.FontSize * 0.5f + 1.0f), bg_col);

SparkyTD marked this conversation as resolved.
Show resolved Hide resolved
// Draw the label in the center
ImU32 text_col = GetColorU32(p_enabled || hovered ? ImGuiCol_Text : ImGuiCol_TextDisabled);
window->DrawList->AddText(bb.GetCenter() - ImVec2(g.FontSize * 0.45F, g.FontSize * 0.5F), text_col, label);

// Return the button press state
ImGui::PopClipRect();
return pressed;
}

void PopupTitleBarText(const char* text) {
SparkyTD marked this conversation as resolved.
Show resolved Hide resolved
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
const ImRect title_rect = window->TitleBarRect();
const ImVec2 size(g.FontSize, g.FontSize); // Button size matches font size for aesthetic consistency.
const ImVec2 pos = window->DC.CursorPos;
const ImVec2 max_pos = pos + size;
const ImRect bb(pos.x, title_rect.Min.y, max_pos.x, title_rect.Max.y);

ImGui::PushClipRect(title_rect.Min, title_rect.Max, false);

// Draw the label in the center
ImU32 text_col = GetColorU32(ImGuiCol_Text);
window->DrawList->AddText(bb.GetCenter() - ImVec2(g.FontSize * 0.45F, g.FontSize * 0.5F), text_col, text);

// Return the button press state
ImGui::PopClipRect();
}
}

namespace ImGui {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace hex::plugin::builtin {
TaskHolder m_searchTask;

void processInputString();

[[nodiscard]] UnlocalizedString getTitle() const override;
};

} // namespace hex::plugin::builtin
11 changes: 11 additions & 0 deletions plugins/builtin/include/content/views/view_hex_editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ namespace hex::plugin::builtin {
public:
virtual ~Popup() = default;
virtual void draw(ViewHexEditor *editor) = 0;

[[nodiscard]] virtual UnlocalizedString getTitle() const { return {}; }

[[nodiscard]] virtual bool canBePinned() const { return false; }
[[nodiscard]] bool isPinned() const { return m_isPinned; }
void setPinned(const bool pinned) { m_isPinned = pinned; }
private:
bool m_isPinned = false;
};

[[nodiscard]] bool isAnyPopupOpen() const {
Expand Down Expand Up @@ -71,6 +79,9 @@ namespace hex::plugin::builtin {
ui::HexEditor m_hexEditor;

bool m_shouldOpenPopup = false;
bool m_currentPopupHasHovered = false; // This flag prevents the popup from initially appearing with the transparency effect
bool m_currentPopupHover = false;
bool m_currentPopupDetached = false;
std::unique_ptr<Popup> m_currPopup;

PerProvider<std::optional<u64>> m_selectionStart, m_selectionEnd;
Expand Down
3 changes: 2 additions & 1 deletion plugins/builtin/romfs/themes/classic.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@
]
},
"imhex": {
"window-blur": 0.0
"window-blur": 0.0,
"popup-alpha": 0.65
}
}
}
3 changes: 2 additions & 1 deletion plugins/builtin/romfs/themes/dark.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@
]
},
"imhex": {
"window-blur": 0.0
"window-blur": 0.0,
"popup-alpha": 0.65
}
}
}
3 changes: 2 additions & 1 deletion plugins/builtin/romfs/themes/light.json
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@
]
},
"imhex": {
"window-blur": 0.0
"window-blur": 0.0,
"popup-alpha": 0.65
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ namespace hex::plugin::builtin {
}

void PopupFind::draw(ViewHexEditor *editor) {
ImGui::TextUnformatted("hex.builtin.view.hex_editor.menu.file.search"_lang);

auto lastMode = *s_searchMode;
if (ImGui::BeginTabBar("##find_tabs")) {
if (ImGui::BeginTabItem("hex.builtin.view.hex_editor.search.hex"_lang)) {
Expand Down Expand Up @@ -302,4 +300,8 @@ namespace hex::plugin::builtin {
break;
}
}

[[nodiscard]] UnlocalizedString PopupFind::getTitle() const {
return "hex.builtin.view.hex_editor.menu.file.search";
}
}
1 change: 1 addition & 0 deletions plugins/builtin/source/content/themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ namespace hex::plugin::builtin {
auto &style = ImGuiExt::GetCustomStyle();
const static ThemeManager::StyleMap ImHexStyleMap = {
{ "window-blur", { &style.WindowBlur, 0.0F, 1.0F, true } },
{ "popup-alpha", { &style.PopupWindowAlpha, 0.0F, 1.0F, false } },
};

ThemeManager::addStyleHandler("imhex", ImHexStyleMap);
Expand Down
Loading
Loading