impr: Move various settings from settings window to hex editor and pattern data view

This commit is contained in:
WerWolv
2023-06-05 09:07:58 +02:00
parent e78c21cbfb
commit ae48ae659b
18 changed files with 673 additions and 1181 deletions

View File

@@ -694,8 +694,10 @@ namespace hex {
class DataVisualizer {
public:
DataVisualizer(u16 bytesPerCell, u16 maxCharsPerCell)
: m_bytesPerCell(bytesPerCell), m_maxCharsPerCell(maxCharsPerCell) {}
DataVisualizer(std::string unlocalizedName, u16 bytesPerCell, u16 maxCharsPerCell)
: m_unlocalizedName(std::move(unlocalizedName)),
m_bytesPerCell(bytesPerCell),
m_maxCharsPerCell(maxCharsPerCell) { }
virtual ~DataVisualizer() = default;
@@ -705,12 +707,16 @@ namespace hex {
[[nodiscard]] u16 getBytesPerCell() const { return this->m_bytesPerCell; }
[[nodiscard]] u16 getMaxCharsPerCell() const { return this->m_maxCharsPerCell; }
[[nodiscard]] const std::string& getUnlocalizedName() const { return this->m_unlocalizedName; }
protected:
const static int TextInputFlags;
bool drawDefaultScalarEditingTextBox(u64 address, const char *format, ImGuiDataType dataType, u8 *data, ImGuiInputTextFlags flags) const;
bool drawDefaultTextEditingTextBox(u64 address, std::string &data, ImGuiInputTextFlags flags) const;
private:
std::string m_unlocalizedName;
u16 m_bytesPerCell;
u16 m_maxCharsPerCell;
};
@@ -730,8 +736,9 @@ namespace hex {
* @param args The arguments to pass to the constructor of the data visualizer
*/
template<std::derived_from<DataVisualizer> T, typename... Args>
void addDataVisualizer(const std::string &unlocalizedName, Args &&...args) {
return impl::addDataVisualizer(unlocalizedName, new T(std::forward<Args>(args)...));
void addDataVisualizer(Args &&...args) {
auto visualizer = new T(std::forward<Args>(args)...);
return impl::addDataVisualizer(visualizer->getUnlocalizedName(), visualizer);
}
}

View File

@@ -95,7 +95,7 @@ namespace ImGui {
void Header(const char *label, bool firstEntry = false);
void HeaderColored(const char *label, ImColor color, bool firstEntry);
void InfoTooltip(const char *text);
bool InfoTooltip(const char *text = "");
bool TitleBarButton(const char *label, ImVec2 size_arg);
bool ToolBarButton(const char *symbol, ImVec4 color);

View File

@@ -319,23 +319,30 @@ namespace ImGui {
ImGui::Separator();
}
void InfoTooltip(const char *text) {
bool InfoTooltip(const char *text) {
static double lastMoveTime;
static ImGuiID lastHoveredID;
double currTime = ImGui::GetTime();
ImGuiID hoveredID = ImGui::GetHoveredID();
bool result = false;
if (IsItemHovered() && (currTime - lastMoveTime) >= 0.5 && hoveredID == lastHoveredID) {
BeginTooltip();
TextUnformatted(text);
EndTooltip();
if (!std::string_view(text).empty()) {
BeginTooltip();
TextUnformatted(text);
EndTooltip();
}
result = true;
}
if (hoveredID != lastHoveredID) {
lastMoveTime = currTime;
}
lastHoveredID = hoveredID;
return result;
}
ImU32 GetCustomColorU32(ImGuiCustomCol idx, float alpha_mul) {