Skip to content

Commit

Permalink
Help window, setting to show/hide Tooltips
Browse files Browse the repository at this point in the history
Menu and keyboard shortcut declaration centralized. List of all keyboard shortcuts. ImGuiToolkit unified tooltips.
  • Loading branch information
brunoherbelin committed Dec 12, 2021
1 parent 731a1af commit a7689a8
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 99 deletions.
59 changes: 35 additions & 24 deletions ImGuiToolkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "ImGuiToolkit.h"

bool tooltips_enabled = true;
unsigned int textureicons = 0;
std::map <ImGuiToolkit::font_style, ImFont*>fontmap;

Expand Down Expand Up @@ -71,7 +72,7 @@ bool ImGuiToolkit::ButtonToggle( const char* label, bool* toggle, const char *to
}


bool ImGuiToolkit::ButtonSwitch(const char* label, bool* toggle, const char* help)
bool ImGuiToolkit::ButtonSwitch(const char* label, bool* toggle, const char* shortcut)
{
bool ret = false;

Expand Down Expand Up @@ -114,9 +115,9 @@ bool ImGuiToolkit::ButtonSwitch(const char* label, bool* toggle, const char* hel
col_bg = ImGui::GetColorU32(ImLerp(colors[ImGuiCol_FrameBg], colors[ImGuiCol_TabActive], t));

// draw help text if present
if (help) {
if (shortcut) {
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.6, 0.6, 0.6, 0.9f));
ImGui::RenderText(draw_pos, help);
ImGui::RenderText(draw_pos, shortcut);
ImGui::PopStyleColor(1);
}

Expand Down Expand Up @@ -233,11 +234,7 @@ bool ImGuiToolkit::IconButton(int i, int j, const char *tooltip)

// tooltip
if (tooltip != nullptr && hovered)
{
ImGui::BeginTooltip();
ImGui::Text("%s", tooltip);
ImGui::EndTooltip();
}
ImGuiToolkit::ToolTip(tooltip);

// draw icon
ImGui::SetCursorScreenPos(draw_pos);
Expand Down Expand Up @@ -267,11 +264,7 @@ bool ImGuiToolkit::IconButton(const char* icon, const char *tooltip)
ImGui::Text(icon);

if (tooltip != nullptr && ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text("%s", tooltip);
ImGui::EndTooltip();
}
ImGuiToolkit::ToolTip(tooltip);

ImGui::PopID();
return ret;
Expand Down Expand Up @@ -304,11 +297,7 @@ bool ImGuiToolkit::IconToggle(int i, int j, int i_toggle, int j_toggle, bool* to

int tooltipid = *toggle ? 1 : 0;
if (tooltips != nullptr && tooltips[tooltipid] != nullptr && ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text("%s", tooltips[tooltipid]);
ImGui::EndTooltip();
}
ImGuiToolkit::ToolTip(tooltips[tooltipid]);

ImGui::PopID();
return ret;
Expand Down Expand Up @@ -510,8 +499,22 @@ void ImGuiToolkit::ShowIconsWindow(bool* p_open)
}
}


void ImGuiToolkit::setToolTipsEnabled (bool on)
{
tooltips_enabled = on;
}

bool ImGuiToolkit::toolTipsEnabled ()
{
return tooltips_enabled;
}

void ImGuiToolkit::ToolTip(const char* desc, const char* shortcut)
{
if (!tooltips_enabled)
return;

ImGuiToolkit::PushFont(ImGuiToolkit::FONT_DEFAULT);
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetFontSize() * 14.0f);
Expand All @@ -531,16 +534,24 @@ void ImGuiToolkit::ToolTip(const char* desc, const char* shortcut)
// Helper to display a little (?) mark which shows a tooltip when hovered.
void ImGuiToolkit::HelpMarker(const char* desc, const char* icon, const char* shortcut)
{
ImGui::TextDisabled( icon );
if (ImGui::IsItemHovered())
ToolTip(desc, shortcut);
if (tooltips_enabled) {
ImGui::TextDisabled( icon );
if (ImGui::IsItemHovered())
ImGuiToolkit::ToolTip(desc, shortcut);
}
else
ImGui::Text(" ");
}

void ImGuiToolkit::HelpIcon(const char* desc, int i, int j, const char* shortcut)
{
ImGuiToolkit::Icon(i, j, false);
if (ImGui::IsItemHovered())
ToolTip(desc, shortcut);
if (tooltips_enabled) {
ImGuiToolkit::Icon(i, j, false);
if (ImGui::IsItemHovered())
ImGuiToolkit::ToolTip(desc, shortcut);
}
else
ImGui::Text(" ");
}


Expand Down
6 changes: 4 additions & 2 deletions ImGuiToolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ namespace ImGuiToolkit

// buttons
bool ButtonToggle (const char* label, bool* toggle, const char *tooltip = nullptr);
bool ButtonSwitch (const char* label, bool* toggle, const char *help = nullptr);
bool ButtonSwitch (const char* label, bool* toggle, const char *shortcut = nullptr);
void ButtonOpenUrl (const char* label, const char* url, const ImVec2& size_arg = ImVec2(0,0));

// tooltip and mouse over
// tooltip and mouse over help
void setToolTipsEnabled (bool on);
bool toolTipsEnabled ();
void ToolTip (const char* desc, const char* shortcut = nullptr);
void HelpMarker (const char* desc, const char* icon = ICON_FA_QUESTION_CIRCLE, const char* shortcut = nullptr);
void HelpIcon (const char* desc, int i = 19, int j = 5, const char* shortcut = nullptr);
Expand Down
2 changes: 2 additions & 0 deletions Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void Settings::Save(uint64_t runtime)
applicationNode->SetAttribute("save_snapshot", application.save_version_snapshot);
applicationNode->SetAttribute("smooth_cursor", application.smooth_cursor);
applicationNode->SetAttribute("action_history_follow_view", application.action_history_follow_view);
applicationNode->SetAttribute("show_tooptips", application.show_tooptips);
applicationNode->SetAttribute("accept_connections", application.accept_connections);
applicationNode->SetAttribute("pannel_history_mode", application.pannel_current_session_mode);
pRoot->InsertEndChild(applicationNode);
Expand Down Expand Up @@ -339,6 +340,7 @@ void Settings::Load()
applicationNode->QueryBoolAttribute("save_snapshot", &application.save_version_snapshot);
applicationNode->QueryBoolAttribute("smooth_cursor", &application.smooth_cursor);
applicationNode->QueryBoolAttribute("action_history_follow_view", &application.action_history_follow_view);
applicationNode->QueryBoolAttribute("show_tooptips", &application.show_tooptips);
applicationNode->QueryBoolAttribute("accept_connections", &application.accept_connections);
applicationNode->QueryIntAttribute("pannel_history_mode", &application.pannel_current_session_mode);
}
Expand Down
2 changes: 2 additions & 0 deletions Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ struct Application
bool smooth_transition;
bool smooth_cursor;
bool action_history_follow_view;
bool show_tooptips;

int pannel_current_session_mode;

Expand Down Expand Up @@ -257,6 +258,7 @@ struct Application
save_version_snapshot = false;
smooth_cursor = false;
action_history_follow_view = false;
show_tooptips = true;
accept_connections = false;
pannel_current_session_mode = 0;
current_view = 1;
Expand Down
2 changes: 1 addition & 1 deletion Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ void CloneSource::accept(Visitor& v)

glm::ivec2 CloneSource::icon() const
{
return glm::ivec2(9, 2);
return glm::ivec2(ICON_SOURCE_CLONE);
}

std::string CloneSource::info() const
Expand Down
Loading

0 comments on commit a7689a8

Please sign in to comment.