2021-01-27 00:00:20 +01:00
|
|
|
#pragma once
|
|
|
|
|
2022-02-08 22:25:25 +01:00
|
|
|
#include <hex.hpp>
|
|
|
|
|
2023-08-26 23:43:35 +02:00
|
|
|
#include <cstddef>
|
2022-03-03 09:24:09 +01:00
|
|
|
#include <string>
|
2023-08-26 23:43:35 +02:00
|
|
|
#include <span>
|
2021-01-27 12:04:42 +01:00
|
|
|
|
2021-01-27 00:00:20 +01:00
|
|
|
#include <imgui.h>
|
|
|
|
|
2021-12-31 01:10:06 +01:00
|
|
|
#include <hex/helpers/fmt.hpp>
|
2023-10-13 23:46:48 +02:00
|
|
|
#include <hex/helpers/concepts.hpp>
|
2023-12-05 10:49:51 +01:00
|
|
|
#include <hex/helpers/fs.hpp>
|
2021-08-21 00:51:50 +02:00
|
|
|
|
2023-08-13 17:08:17 +02:00
|
|
|
#include <wolv/utils/string.hpp>
|
|
|
|
|
2024-01-21 18:39:32 +01:00
|
|
|
enum ImGuiCustomCol : int {
|
2021-08-21 00:51:50 +02:00
|
|
|
ImGuiCustomCol_DescButton,
|
|
|
|
ImGuiCustomCol_DescButtonHovered,
|
|
|
|
ImGuiCustomCol_DescButtonActive,
|
|
|
|
|
|
|
|
ImGuiCustomCol_ToolbarGray,
|
|
|
|
ImGuiCustomCol_ToolbarRed,
|
|
|
|
ImGuiCustomCol_ToolbarYellow,
|
|
|
|
ImGuiCustomCol_ToolbarGreen,
|
|
|
|
ImGuiCustomCol_ToolbarBlue,
|
|
|
|
ImGuiCustomCol_ToolbarPurple,
|
|
|
|
ImGuiCustomCol_ToolbarBrown,
|
|
|
|
|
2023-10-20 12:30:21 +02:00
|
|
|
ImGuiCustomCol_LoggerDebug,
|
|
|
|
ImGuiCustomCol_LoggerInfo,
|
|
|
|
ImGuiCustomCol_LoggerWarning,
|
|
|
|
ImGuiCustomCol_LoggerError,
|
|
|
|
ImGuiCustomCol_LoggerFatal,
|
|
|
|
|
|
|
|
ImGuiCustomCol_AchievementUnlocked,
|
|
|
|
|
|
|
|
ImGuiCustomCol_FindHighlight,
|
|
|
|
|
|
|
|
ImGuiCustomCol_DiffAdded,
|
|
|
|
ImGuiCustomCol_DiffRemoved,
|
|
|
|
ImGuiCustomCol_DiffChanged,
|
|
|
|
|
|
|
|
ImGuiCustomCol_AdvancedEncodingASCII,
|
|
|
|
ImGuiCustomCol_AdvancedEncodingSingleChar,
|
|
|
|
ImGuiCustomCol_AdvancedEncodingMultiChar,
|
|
|
|
ImGuiCustomCol_AdvancedEncodingUnknown,
|
|
|
|
|
2021-08-28 16:02:53 +02:00
|
|
|
ImGuiCustomCol_Highlight,
|
|
|
|
|
2023-10-20 12:30:21 +02:00
|
|
|
ImGuiCustomCol_Patches,
|
|
|
|
ImGuiCustomCol_PatternSelected,
|
|
|
|
|
2023-05-19 21:18:38 +02:00
|
|
|
ImGuiCustomCol_IEEEToolSign,
|
|
|
|
ImGuiCustomCol_IEEEToolExp,
|
|
|
|
ImGuiCustomCol_IEEEToolMantissa,
|
|
|
|
|
2023-05-23 13:20:18 +02:00
|
|
|
ImGuiCustomCol_BlurBackground,
|
|
|
|
|
2021-08-21 00:51:50 +02:00
|
|
|
ImGuiCustomCol_COUNT
|
|
|
|
};
|
|
|
|
|
2023-05-22 12:00:35 +02:00
|
|
|
enum ImGuiCustomStyle {
|
|
|
|
ImGuiCustomStyle_WindowBlur,
|
|
|
|
|
|
|
|
ImGuiCustomStyle_COUNT
|
|
|
|
};
|
|
|
|
|
2023-11-16 22:24:06 +01:00
|
|
|
namespace ImGuiExt {
|
2021-01-27 00:00:20 +01:00
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
class Texture {
|
|
|
|
public:
|
2024-02-24 18:54:35 +01:00
|
|
|
enum class Filter : int {
|
2023-12-09 22:00:35 +01:00
|
|
|
Linear,
|
|
|
|
Nearest
|
|
|
|
};
|
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
Texture() = default;
|
|
|
|
Texture(const Texture&) = delete;
|
|
|
|
Texture(Texture&& other) noexcept;
|
2021-08-18 22:36:46 +02:00
|
|
|
|
2024-05-01 20:36:10 +02:00
|
|
|
static Texture fromImage(const ImU8 *buffer, int size, Filter filter = Filter::Nearest);
|
|
|
|
static Texture fromImage(std::span<const std::byte> buffer, Filter filter = Filter::Nearest);
|
|
|
|
static Texture fromImage(const char *path, Filter filter = Filter::Nearest);
|
|
|
|
static Texture fromImage(const std::fs::path &path, Filter filter = Filter::Nearest);
|
|
|
|
static Texture fromGLTexture(unsigned int texture, int width, int height);
|
|
|
|
static Texture fromBitmap(const ImU8 *buffer, int size, int width, int height, Filter filter = Filter::Nearest);
|
|
|
|
static Texture fromBitmap(std::span<const std::byte> buffer, int width, int height, Filter filter = Filter::Nearest);
|
|
|
|
static Texture fromSVG(const char *path, int width = 0, int height = 0, Filter filter = Filter::Nearest);
|
|
|
|
static Texture fromSVG(const std::fs::path &path, int width = 0, int height = 0, Filter filter = Filter::Nearest);
|
|
|
|
static Texture fromSVG(std::span<const std::byte> buffer, int width = 0, int height = 0, Filter filter = Filter::Nearest);
|
|
|
|
|
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
~Texture();
|
|
|
|
|
2022-10-02 17:30:26 +02:00
|
|
|
Texture& operator=(const Texture&) = delete;
|
|
|
|
Texture& operator=(Texture&& other) noexcept;
|
2022-09-18 20:38:45 +02:00
|
|
|
|
|
|
|
[[nodiscard]] constexpr bool isValid() const noexcept {
|
2023-12-19 13:10:25 +01:00
|
|
|
return m_textureId != nullptr;
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
|
|
|
|
2023-12-05 10:49:51 +01:00
|
|
|
[[nodiscard]] operator ImTextureID() const noexcept {
|
2023-12-19 13:10:25 +01:00
|
|
|
return m_textureId;
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
|
|
|
|
2023-12-05 10:49:51 +01:00
|
|
|
[[nodiscard]] operator intptr_t() const noexcept {
|
2023-12-19 13:10:25 +01:00
|
|
|
return reinterpret_cast<intptr_t>(m_textureId);
|
2023-12-05 10:49:51 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
[[nodiscard]] auto getSize() const noexcept {
|
2023-12-19 13:10:25 +01:00
|
|
|
return ImVec2(m_width, m_height);
|
2021-08-18 22:36:46 +02:00
|
|
|
}
|
2022-02-06 01:32:15 +01:00
|
|
|
|
2022-09-18 20:38:45 +02:00
|
|
|
[[nodiscard]] constexpr auto getAspectRatio() const noexcept {
|
2023-12-19 13:10:25 +01:00
|
|
|
if (m_height == 0) return 1.0F;
|
2022-02-06 01:32:15 +01:00
|
|
|
|
2023-12-19 13:10:25 +01:00
|
|
|
return float(m_width) / float(m_height);
|
2022-02-06 01:32:15 +01:00
|
|
|
}
|
2022-09-18 20:38:45 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
ImTextureID m_textureId = nullptr;
|
|
|
|
int m_width = 0, m_height = 0;
|
2021-08-18 22:36:46 +02:00
|
|
|
};
|
|
|
|
|
2021-12-07 22:47:41 +01:00
|
|
|
int UpdateStringSizeCallback(ImGuiInputTextCallbackData *data);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
bool IconHyperlink(const char *icon, const char *label, const ImVec2 &size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
|
|
|
bool Hyperlink(const char *label, const ImVec2 &size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
|
|
|
bool BulletHyperlink(const char *label, const ImVec2 &size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
|
|
|
bool DescriptionButton(const char *label, const char *description, const ImVec2 &size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
2023-11-16 13:23:28 +01:00
|
|
|
bool DescriptionButtonProgress(const char *label, const char *description, float fraction, const ImVec2 &size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0);
|
2021-01-27 12:04:42 +01:00
|
|
|
|
2024-05-18 20:32:57 +02:00
|
|
|
void HelpHover(const char *text, const char *icon = "(?)", ImU32 iconColor = ImGui::GetColorU32(ImGuiCol_ButtonActive));
|
2023-05-11 12:00:45 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void UnderlinedText(const char *label, ImColor color = ImGui::GetStyleColorVec4(ImGuiCol_Text), const ImVec2 &size_arg = ImVec2(0, 0));
|
2021-01-27 00:00:20 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
void TextSpinner(const char *label);
|
2021-02-25 00:17:41 +01:00
|
|
|
|
2021-03-02 13:49:45 +01:00
|
|
|
void Header(const char *label, bool firstEntry = false);
|
2021-08-28 16:02:53 +02:00
|
|
|
void HeaderColored(const char *label, ImColor color, bool firstEntry);
|
2021-03-02 13:49:45 +01:00
|
|
|
|
2023-12-05 10:49:51 +01:00
|
|
|
bool InfoTooltip(const char *text = "",bool = false);
|
2021-08-18 23:12:27 +02:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
bool TitleBarButton(const char *label, ImVec2 size_arg);
|
|
|
|
bool ToolBarButton(const char *symbol, ImVec4 color);
|
|
|
|
bool IconButton(const char *symbol, ImVec4 color, ImVec2 size_arg = ImVec2(0, 0));
|
2021-08-21 00:51:50 +02:00
|
|
|
|
2023-01-18 14:30:44 +01:00
|
|
|
bool InputIntegerPrefix(const char* label, const char *prefix, void *value, ImGuiDataType type, const char *format, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-05-30 16:36:46 +02:00
|
|
|
bool InputHexadecimal(const char* label, u32 *value, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-02-08 22:25:25 +01:00
|
|
|
bool InputHexadecimal(const char* label, u64 *value, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-02-08 21:10:48 +01:00
|
|
|
|
2024-05-19 10:21:54 +02:00
|
|
|
bool SliderBytes(const char *label, u64 *value, u64 min, u64 max, ImGuiSliderFlags flags = ImGuiSliderFlags_None);
|
|
|
|
|
2021-06-07 18:13:54 +02:00
|
|
|
inline bool HasSecondPassed() {
|
|
|
|
return static_cast<ImU32>(ImGui::GetTime() * 100) % 100 <= static_cast<ImU32>(ImGui::GetIO().DeltaTime * 100);
|
|
|
|
}
|
|
|
|
|
2021-09-28 12:34:55 +02:00
|
|
|
void OpenPopupInWindow(const char *window_name, const char *popup_name);
|
2021-02-25 00:17:41 +01:00
|
|
|
|
|
|
|
struct ImHexCustomData {
|
|
|
|
ImVec4 Colors[ImGuiCustomCol_COUNT];
|
2023-05-22 12:00:35 +02:00
|
|
|
|
|
|
|
struct Styles {
|
|
|
|
float WindowBlur = 0.0F;
|
impr: Convert all hex editor popups to floating, movable windows (#1658)
### Problem description
In previous versions of ImHex, all tool windows were implemented as
static popups fixed in the upper left position of the hex view. This PR
refactors all tool popups to use floating windows that can be dragged
around by the user, or closed with a dedicated close button on the title
bar. These popup also support a stylable transparency when the user is
not hovering their mouse over the window.
### Implementation description
I rewrote the logic in `ViewHexEditor::drawPopup()` to use a custom
`ImGuiExt::BeginHoveringPopup` function for rendering the popup windows.
This new function is an almost exact replica of the built-in
`ImGui::BeginPopupModal`, except it does also displays the default
window title bar with a close button.
A second custom function, `ImGuiExt::PopupTitleBarButton` was also added
for rendering small icon-based buttons into the title bar of the parent
popup window. This new function was used to implement an optional
"Pinning" feature that individual popup implementations can specify. If
a window is pinned, it won't close automatically when its main action is
executed. For example, the "Select" button on the Select dialog will
close the popup by default, unless the window is pinned.
### Screenshots
Popup dialogs before:
![image](https://github.com/WerWolv/ImHex/assets/45818400/7c253181-8284-4076-a066-089403554f0f)
Popup dialogs after:
https://github.com/WerWolv/ImHex/assets/45818400/99d1a628-8ac1-40ac-9146-9062091bb0db
### Additional things
- When the user stops hovering their mouse over a popup window, it
becomes semi-transparent, making it easier to see the content behind it
- This PR also introduces the `styles.imhex.popup-alpha` style, making
the transparency effect configurable, including the ability to disable
the effect completely by setting `popup-alpha` to `1.0`.
- Fixed a bug that caused some popup windows to ignore the Enter and the
KeypadEnter keys. With this PR, all tool windows will execute their main
action when the user presses either one of the two Enter keys, and will
also close automatically unless the window is pinned.
### Possible changes and improvements
- Should the transparency effect be disabled if a window is pinned?
- Should the transparency factor be modifiable on the Settings/Interface
page?
- A keyboard shortcut could be added for quickly pinning / unpinning the
current window.
- Can the pin icon stay on the left, or should it be moved next to the
close button, with a similar circular background?
---------
Co-authored-by: WerWolv <werwolv98@gmail.com>
2024-05-10 21:21:19 +02:00
|
|
|
float PopupWindowAlpha = 0.0F; // Alpha used by Popup tool windows when the user is not hovering over them
|
2023-05-22 12:00:35 +02:00
|
|
|
} styles;
|
2021-02-25 00:17:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
ImU32 GetCustomColorU32(ImGuiCustomCol idx, float alpha_mul = 1.0F);
|
2021-08-21 00:51:50 +02:00
|
|
|
ImVec4 GetCustomColorVec4(ImGuiCustomCol idx, float alpha_mul = 1.0F);
|
2021-02-25 00:17:41 +01:00
|
|
|
|
2023-05-22 12:00:35 +02:00
|
|
|
inline ImHexCustomData::Styles& GetCustomStyle() {
|
2023-11-30 14:40:07 +01:00
|
|
|
auto &customData = *static_cast<ImHexCustomData *>(ImGui::GetIO().UserData);
|
2023-05-22 12:00:35 +02:00
|
|
|
|
|
|
|
return customData.styles;
|
|
|
|
}
|
|
|
|
|
|
|
|
float GetCustomStyleFloat(ImGuiCustomStyle idx);
|
|
|
|
ImVec2 GetCustomStyleVec2(ImGuiCustomStyle idx);
|
|
|
|
|
2021-02-25 00:17:41 +01:00
|
|
|
void StyleCustomColorsDark();
|
|
|
|
void StyleCustomColorsLight();
|
|
|
|
void StyleCustomColorsClassic();
|
2021-12-16 23:48:52 +01:00
|
|
|
|
|
|
|
void SmallProgressBar(float fraction, float yOffset = 0.0F);
|
2021-12-31 01:10:06 +01:00
|
|
|
|
2024-05-31 16:59:52 +02:00
|
|
|
inline void TextFormatted(std::string_view fmt, auto &&...args) {
|
2021-12-31 01:10:06 +01:00
|
|
|
ImGui::TextUnformatted(hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
|
|
|
}
|
|
|
|
|
2024-05-31 16:59:52 +02:00
|
|
|
inline void TextFormattedSelectable(std::string_view fmt, auto &&...args) {
|
2023-08-13 17:08:17 +02:00
|
|
|
auto text = hex::format(fmt, std::forward<decltype(args)>(args)...);
|
|
|
|
|
|
|
|
ImGui::PushID(text.c_str());
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2());
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4());
|
|
|
|
|
2024-04-29 21:20:54 +02:00
|
|
|
ImGui::PushItemWidth(ImGui::CalcTextSize(text.c_str()).x + ImGui::GetStyle().FramePadding.x * 2);
|
|
|
|
ImGui::InputText("##", const_cast<char *>(text.c_str()), text.size(), ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_NoHorizontalScroll);
|
2023-08-13 17:08:17 +02:00
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
}
|
|
|
|
|
2024-05-31 16:59:52 +02:00
|
|
|
inline void TextFormattedColored(ImColor color, std::string_view fmt, auto &&...args) {
|
2021-12-31 01:10:06 +01:00
|
|
|
ImGui::TextColored(color, "%s", hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
|
|
|
}
|
2022-01-15 14:14:53 +01:00
|
|
|
|
2024-05-31 16:59:52 +02:00
|
|
|
inline void TextFormattedDisabled(std::string_view fmt, auto &&...args) {
|
2022-01-15 14:14:53 +01:00
|
|
|
ImGui::TextDisabled("%s", hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
|
|
|
}
|
|
|
|
|
2024-05-31 16:59:52 +02:00
|
|
|
inline void TextFormattedWrapped(std::string_view fmt, auto &&...args) {
|
2022-01-15 14:14:53 +01:00
|
|
|
ImGui::TextWrapped("%s", hex::format(fmt, std::forward<decltype(args)>(args)...).c_str());
|
|
|
|
}
|
2022-01-24 00:46:19 +01:00
|
|
|
|
2024-05-31 16:59:52 +02:00
|
|
|
inline void TextFormattedWrappedSelectable(std::string_view fmt, auto &&...args) {
|
2023-10-04 12:00:32 +02:00
|
|
|
// Manually wrap text, using the letter M (generally the widest character in non-monospaced fonts) to calculate the character width to use.
|
2023-08-13 17:08:17 +02:00
|
|
|
auto text = wolv::util::wrapMonospacedString(
|
|
|
|
hex::format(fmt, std::forward<decltype(args)>(args)...),
|
|
|
|
ImGui::CalcTextSize("M").x,
|
|
|
|
ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ScrollbarSize - ImGui::GetStyle().FrameBorderSize
|
|
|
|
);
|
|
|
|
|
|
|
|
ImGui::PushID(text.c_str());
|
|
|
|
|
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2());
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4());
|
|
|
|
|
2024-04-29 21:20:54 +02:00
|
|
|
ImGui::PushItemWidth(ImGui::CalcTextSize(text.c_str()).x + ImGui::GetStyle().FramePadding.x * 2);
|
2023-08-13 17:08:17 +02:00
|
|
|
ImGui::InputTextMultiline(
|
|
|
|
"##",
|
|
|
|
const_cast<char *>(text.c_str()),
|
|
|
|
text.size(),
|
|
|
|
ImVec2(0, -FLT_MIN),
|
|
|
|
ImGuiInputTextFlags_ReadOnly | ImGuiInputTextFlags_NoHorizontalScroll
|
|
|
|
);
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
|
|
|
|
ImGui::PopStyleColor();
|
|
|
|
ImGui::PopStyleVar();
|
|
|
|
|
|
|
|
ImGui::PopID();
|
|
|
|
}
|
|
|
|
|
2023-12-02 23:46:20 +01:00
|
|
|
void TextUnformattedCentered(const char *text);
|
2024-05-31 16:59:52 +02:00
|
|
|
inline void TextFormattedCentered(std::string_view fmt, auto &&...args) {
|
2022-02-19 18:02:44 +01:00
|
|
|
auto text = hex::format(fmt, std::forward<decltype(args)>(args)...);
|
2023-12-02 23:46:20 +01:00
|
|
|
TextUnformattedCentered(text.c_str());
|
2022-01-24 00:46:19 +01:00
|
|
|
}
|
2022-03-03 09:24:09 +01:00
|
|
|
|
2023-12-02 23:46:20 +01:00
|
|
|
|
2024-05-31 16:59:52 +02:00
|
|
|
inline void TextFormattedCenteredHorizontal(std::string_view fmt, auto &&...args) {
|
2023-07-06 10:08:47 +02:00
|
|
|
auto text = hex::format(fmt, std::forward<decltype(args)>(args)...);
|
|
|
|
auto availableSpace = ImGui::GetContentRegionAvail();
|
2023-11-20 21:40:54 +01:00
|
|
|
auto textSize = ImGui::CalcTextSize(text.c_str(), nullptr, false, availableSpace.x * 0.75F);
|
2023-07-06 10:08:47 +02:00
|
|
|
|
|
|
|
ImGui::SetCursorPosX(((availableSpace - textSize) / 2.0F).x);
|
|
|
|
|
2023-11-16 22:24:06 +01:00
|
|
|
ImGui::PushTextWrapPos(availableSpace.x * 0.75F);
|
|
|
|
ImGuiExt::TextFormattedWrapped("{}", text);
|
|
|
|
ImGui::PopTextWrapPos();
|
2023-07-06 10:08:47 +02:00
|
|
|
}
|
|
|
|
|
2022-09-19 11:29:51 +02:00
|
|
|
bool InputTextIcon(const char* label, const char *icon, std::string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
2022-05-27 20:42:07 +02:00
|
|
|
|
|
|
|
bool InputScalarCallback(const char* label, ImGuiDataType data_type, void* p_data, const char* format, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data);
|
|
|
|
|
|
|
|
void HideTooltip();
|
2022-05-29 14:57:59 +02:00
|
|
|
|
|
|
|
bool BitCheckbox(const char* label, bool* v);
|
2022-08-07 12:20:40 +02:00
|
|
|
|
2023-11-18 17:23:15 +01:00
|
|
|
bool DimmedButton(const char* label, ImVec2 size = ImVec2(0, 0));
|
|
|
|
bool DimmedIconButton(const char *symbol, ImVec4 color, ImVec2 size = ImVec2(0, 0));
|
2023-11-19 16:08:21 +01:00
|
|
|
bool DimmedButtonToggle(const char *icon, bool *v, ImVec2 size);
|
2023-07-23 09:14:00 +02:00
|
|
|
bool DimmedIconToggle(const char *icon, bool *v);
|
2023-12-05 10:49:51 +01:00
|
|
|
bool DimmedIconToggle(const char *iconOn, const char *iconOff, bool *v);
|
2023-05-05 22:00:17 +02:00
|
|
|
|
2023-08-30 10:04:06 +02:00
|
|
|
void TextOverlay(const char *text, ImVec2 pos);
|
2023-10-13 23:46:48 +02:00
|
|
|
|
2023-11-07 00:46:44 +01:00
|
|
|
bool BeginBox();
|
|
|
|
void EndBox();
|
|
|
|
|
2023-11-16 09:32:24 +01:00
|
|
|
void BeginSubWindow(const char *label, ImVec2 size = ImVec2(0, 0), ImGuiChildFlags flags = ImGuiChildFlags_None);
|
2023-11-15 22:22:57 +01:00
|
|
|
void EndSubWindow();
|
|
|
|
|
2023-11-30 14:40:07 +01:00
|
|
|
void ConfirmButtons(const char *textLeft, const char *textRight, const auto &leftButtonCallback, const auto &rightButtonCallback) {
|
|
|
|
auto width = ImGui::GetWindowWidth();
|
|
|
|
ImGui::SetCursorPosX(width / 9);
|
|
|
|
if (ImGui::Button(textLeft, ImVec2(width / 3, 0)))
|
|
|
|
leftButtonCallback();
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::SetCursorPosX(width / 9 * 5);
|
|
|
|
if (ImGui::Button(textRight, ImVec2(width / 3, 0)))
|
|
|
|
rightButtonCallback();
|
|
|
|
}
|
2023-12-05 10:49:51 +01:00
|
|
|
|
|
|
|
bool VSliderAngle(const char* label, ImVec2& size, float* v_rad, float v_degrees_min, float v_degrees_max, const char* format, ImGuiSliderFlags flags);
|
|
|
|
|
|
|
|
bool InputFilePicker(const char *label, std::fs::path &path, const std::vector<hex::fs::ItemFilter> &validExtensions);
|
|
|
|
|
2023-12-07 11:18:49 +01:00
|
|
|
bool ToggleSwitch(const char *label, bool *v);
|
|
|
|
bool ToggleSwitch(const char *label, bool v);
|
|
|
|
|
impr: Convert all hex editor popups to floating, movable windows (#1658)
### Problem description
In previous versions of ImHex, all tool windows were implemented as
static popups fixed in the upper left position of the hex view. This PR
refactors all tool popups to use floating windows that can be dragged
around by the user, or closed with a dedicated close button on the title
bar. These popup also support a stylable transparency when the user is
not hovering their mouse over the window.
### Implementation description
I rewrote the logic in `ViewHexEditor::drawPopup()` to use a custom
`ImGuiExt::BeginHoveringPopup` function for rendering the popup windows.
This new function is an almost exact replica of the built-in
`ImGui::BeginPopupModal`, except it does also displays the default
window title bar with a close button.
A second custom function, `ImGuiExt::PopupTitleBarButton` was also added
for rendering small icon-based buttons into the title bar of the parent
popup window. This new function was used to implement an optional
"Pinning" feature that individual popup implementations can specify. If
a window is pinned, it won't close automatically when its main action is
executed. For example, the "Select" button on the Select dialog will
close the popup by default, unless the window is pinned.
### Screenshots
Popup dialogs before:
![image](https://github.com/WerWolv/ImHex/assets/45818400/7c253181-8284-4076-a066-089403554f0f)
Popup dialogs after:
https://github.com/WerWolv/ImHex/assets/45818400/99d1a628-8ac1-40ac-9146-9062091bb0db
### Additional things
- When the user stops hovering their mouse over a popup window, it
becomes semi-transparent, making it easier to see the content behind it
- This PR also introduces the `styles.imhex.popup-alpha` style, making
the transparency effect configurable, including the ability to disable
the effect completely by setting `popup-alpha` to `1.0`.
- Fixed a bug that caused some popup windows to ignore the Enter and the
KeypadEnter keys. With this PR, all tool windows will execute their main
action when the user presses either one of the two Enter keys, and will
also close automatically unless the window is pinned.
### Possible changes and improvements
- Should the transparency effect be disabled if a window is pinned?
- Should the transparency factor be modifiable on the Settings/Interface
page?
- A keyboard shortcut could be added for quickly pinning / unpinning the
current window.
- Can the pin icon stay on the left, or should it be moved next to the
close button, with a similar circular background?
---------
Co-authored-by: WerWolv <werwolv98@gmail.com>
2024-05-10 21:21:19 +02:00
|
|
|
bool PopupTitleBarButton(const char* label, bool p_enabled);
|
|
|
|
void PopupTitleBarText(const char* text);
|
|
|
|
|
2023-10-13 23:46:48 +02:00
|
|
|
template<typename T>
|
|
|
|
constexpr ImGuiDataType getImGuiDataType() {
|
|
|
|
if constexpr (std::same_as<T, u8>) return ImGuiDataType_U8;
|
|
|
|
else if constexpr (std::same_as<T, u16>) return ImGuiDataType_U16;
|
|
|
|
else if constexpr (std::same_as<T, u32>) return ImGuiDataType_U32;
|
|
|
|
else if constexpr (std::same_as<T, u64>) return ImGuiDataType_U64;
|
|
|
|
else if constexpr (std::same_as<T, i8>) return ImGuiDataType_S8;
|
|
|
|
else if constexpr (std::same_as<T, i16>) return ImGuiDataType_S16;
|
|
|
|
else if constexpr (std::same_as<T, i32>) return ImGuiDataType_S32;
|
|
|
|
else if constexpr (std::same_as<T, i64>) return ImGuiDataType_S64;
|
|
|
|
else if constexpr (std::same_as<T, float>) return ImGuiDataType_Float;
|
|
|
|
else if constexpr (std::same_as<T, double>) return ImGuiDataType_Double;
|
|
|
|
else static_assert(hex::always_false<T>::value, "Invalid data type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
constexpr const char *getFormatLengthSpecifier() {
|
|
|
|
if constexpr (std::same_as<T, u8>) return "hh";
|
|
|
|
else if constexpr (std::same_as<T, u16>) return "h";
|
|
|
|
else if constexpr (std::same_as<T, u32>) return "l";
|
|
|
|
else if constexpr (std::same_as<T, u64>) return "ll";
|
|
|
|
else if constexpr (std::same_as<T, i8>) return "hh";
|
|
|
|
else if constexpr (std::same_as<T, i16>) return "h";
|
|
|
|
else if constexpr (std::same_as<T, i32>) return "l";
|
|
|
|
else if constexpr (std::same_as<T, i64>) return "ll";
|
|
|
|
else static_assert(hex::always_false<T>::value, "Invalid data type!");
|
|
|
|
}
|
|
|
|
|
2023-11-16 22:24:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// these functions are exception because they just allow conversion from string to char*, they do not really add anything
|
|
|
|
namespace ImGui {
|
|
|
|
bool InputText(const char* label, std::string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
|
|
|
bool InputText(const char *label, std::u8string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
|
|
|
bool InputTextMultiline(const char* label, std::string &buffer, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
|
|
|
bool InputTextWithHint(const char *label, const char *hint, std::string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
|
|
|
|
|
2021-01-27 00:00:20 +01:00
|
|
|
}
|