Skip to content

Commit

Permalink
Cleaned up some help popups
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Aug 28, 2024
1 parent 04dc566 commit e5e6daa
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 54 deletions.
4 changes: 3 additions & 1 deletion src/ngscopeclient/FilterGraphEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ ax::NodeEditor::PinId FilterGraphEditor::GetSinkPinForLink(StreamDescriptor sour
*/
bool FilterGraphEditor::DoRender()
{
bool windowHovered = ImGui::IsWindowHovered();

ax::NodeEditor::SetCurrentEditor(m_context);
ax::NodeEditor::Begin("Filter Graph", ImVec2(0, 0));

Expand Down Expand Up @@ -601,7 +603,7 @@ bool FilterGraphEditor::DoRender()
HandleOverlaps();

//Add top level help text if there's nothing else
if(!ax::NodeEditor::GetHoveredNode() && !ax::NodeEditor::GetHoveredLink())
if(!ax::NodeEditor::GetHoveredNode() && !ax::NodeEditor::GetHoveredLink() && windowHovered)
{
m_parent->AddStatusHelp("mouse_lmb_drag", "Select multiple");
m_parent->AddStatusHelp("mouse_wheel", "Zoom");
Expand Down
39 changes: 6 additions & 33 deletions src/ngscopeclient/FilterGraphWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "FilterGraphWorkspace.h"
#include "FilterGraphEditor.h"
#include "CreateFilterBrowser.h"
#include "MainWindow.h"

using namespace std;

Expand All @@ -44,46 +45,23 @@ using namespace std;

FilterGraphWorkspace::FilterGraphWorkspace(
Session& session,
MainWindow* parent,
shared_ptr<FilterGraphEditor> graphEditor,
shared_ptr<CreateFilterBrowser> palette)
: Workspace(session)
: Workspace(session, parent)
, m_firstRun(true)
, m_graphEditor(graphEditor)
, m_palette(palette)
{
m_title = "Filter Graph";
}

bool FilterGraphWorkspace::Render()
void FilterGraphWorkspace::DoRender(ImGuiID id)
{
//Closed, nothing to do
if(!m_open)
return false;

auto dockspace_id = ImGui::GetID(m_id.c_str());

string name = m_title + "###" + m_id;
ImGui::SetNextWindowSize(m_defaultSize, ImGuiCond_Appearing);
if(!ImGui::Begin(name.c_str(), &m_open, ImGuiWindowFlags_NoCollapse))
{
//If we get here, the window is tabbed out or the content area is otherwise not visible.
//Need to keep the dockspace node alive still, though!
ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_KeepAliveOnly, nullptr);

ImGui::End();
return true;
}

if(ImGui::BeginPopupContextItem())
{
ImGui::InputText("Name", &m_title);
ImGui::EndPopup();
}

//First run? special case
if(m_firstRun)
{
auto topNode = ImGui::DockBuilderGetNode(dockspace_id);
auto topNode = ImGui::DockBuilderGetNode(id);
if(topNode)
{
//Split the top into two sub nodes
Expand All @@ -93,17 +71,12 @@ bool FilterGraphWorkspace::Render()

ImGui::DockBuilderDockWindow(m_graphEditor->GetTitleAndID().c_str(), leftPanelID);
ImGui::DockBuilderDockWindow(m_palette->GetTitleAndID().c_str(), rightPanelID);
ImGui::DockBuilderFinish(dockspace_id);
ImGui::DockBuilderFinish(id);

//Remove references in case user wants to close the dialogs later
m_graphEditor = nullptr;
m_palette = nullptr;
m_firstRun = false;
}
}

ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), 0, nullptr);

ImGui::End();
return true;
}
6 changes: 4 additions & 2 deletions src/ngscopeclient/FilterGraphWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "Workspace.h"
class FilterGraphEditor;
class CreateFilterBrowser;
class MainWindow;

/**
@brief Helper class for building the default filter graph editor workspace
Expand All @@ -47,15 +48,16 @@ class FilterGraphWorkspace : public Workspace
public:
FilterGraphWorkspace(
Session& session,
MainWindow* parent,
std::shared_ptr<FilterGraphEditor> graphEditor,
std::shared_ptr<CreateFilterBrowser> palette
);
virtual ~FilterGraphWorkspace()
{}

virtual bool Render() override;

protected:
virtual void DoRender(ImGuiID id) override;

bool m_firstRun;
std::shared_ptr<FilterGraphEditor> m_graphEditor;
std::shared_ptr<CreateFilterBrowser> m_palette;
Expand Down
4 changes: 2 additions & 2 deletions src/ngscopeclient/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void MainWindow::InitializeDefaultSession()
AddDialog(m_filterPalette);

//Spawn a new workspace for the filter graph stuff
auto w = make_shared<FilterGraphWorkspace>(m_session, m_graphEditor, m_filterPalette);
auto w = make_shared<FilterGraphWorkspace>(m_session, this, m_graphEditor, m_filterPalette);
m_workspaces.emplace(w);

//Dock it
Expand Down Expand Up @@ -2737,7 +2737,7 @@ bool MainWindow::LoadUIConfiguration(int version, const YAML::Node& node)
LogIndenter li2;

for(auto w : workspaces)
m_workspaces.emplace(make_shared<Workspace>(w, m_session));
m_workspaces.emplace(make_shared<Workspace>(w, m_session, this));
}

//Measurements
Expand Down
2 changes: 1 addition & 1 deletion src/ngscopeclient/MainWindow_Menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,7 @@ void MainWindow::WindowMenu()
ImGui::EndDisabled();

if(ImGui::MenuItem("New Workspace"))
m_workspaces.emplace(make_shared<Workspace>(m_session));
m_workspaces.emplace(make_shared<Workspace>(m_session, this));

ImGui::EndMenu();
}
Expand Down
16 changes: 11 additions & 5 deletions src/ngscopeclient/WaveformGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ bool WaveformGroup::Render()
if(!ImGui::Begin(GetID().c_str(), &open, ImGuiWindowFlags_NoScrollWithMouse))
{
//tabbed out, don't draw anything until we're back in the foreground
TitleHoverHelp();
ImGui::End();
return true;
}
Expand All @@ -157,11 +158,7 @@ bool WaveformGroup::Render()
ImGui::EndPopup();
}

if(ImGui::IsItemHovered())
{
m_parent->AddStatusHelp("mouse_lmb_drag", "Move group");
m_parent->AddStatusHelp("mouse_rmb", "Rename group");
}
TitleHoverHelp();

auto pos = ImGui::GetCursorScreenPos();
ImVec2 clientArea = ImGui::GetContentRegionMax();
Expand Down Expand Up @@ -243,6 +240,15 @@ bool WaveformGroup::Render()
return open;
}

void WaveformGroup::TitleHoverHelp()
{
if(ImGui::IsItemHovered())
{
m_parent->AddStatusHelp("mouse_lmb_drag", "Move group");
m_parent->AddStatusHelp("mouse_rmb", "Rename group");
}
}

/**
@brief Run the popup window with cursor values
*/
Expand Down
2 changes: 2 additions & 0 deletions src/ngscopeclient/WaveformGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class WaveformGroup
void RenderMarkers(ImVec2 pos, ImVec2 size);
void DoCursorReadouts();

void TitleHoverHelp();

float GetInBandPower(WaveformBase* wfm, Unit yunit, int64_t t1, int64_t t2);

bool IsMouseOverButtonInWaveformArea();
Expand Down
26 changes: 19 additions & 7 deletions src/ngscopeclient/Workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
#include "ngscopeclient.h"
#include "Workspace.h"
#include "Session.h"
#include "MainWindow.h"

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

Workspace::Workspace(Session& session)
Workspace::Workspace(Session& session, MainWindow* parent)
: m_session(session)
, m_parent(parent)
, m_open(true)
, m_title("New Workspace")
, m_defaultSize(800, 600)
Expand All @@ -52,8 +54,9 @@ Workspace::Workspace(Session& session)
m_id = string("Workspace ") + to_string(id);
}

Workspace::Workspace(const YAML::Node& node, Session& session)
Workspace::Workspace(const YAML::Node& node, Session& session, MainWindow* parent)
: m_session(session)
, m_parent(parent)
, m_open(true)
, m_defaultSize(800, 600)
{
Expand Down Expand Up @@ -94,6 +97,8 @@ bool Workspace::Render()
ImGui::SetNextWindowSize(m_defaultSize, ImGuiCond_Appearing);
if(!ImGui::Begin(name.c_str(), &m_open, ImGuiWindowFlags_NoCollapse))
{
TitleHoverHelp();

//If we get here, the window is tabbed out or the content area is otherwise not visible.
//Need to keep the dockspace node alive still, though!
ImGui::DockSpace(id, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_KeepAliveOnly, nullptr);
Expand All @@ -108,14 +113,21 @@ bool Workspace::Render()
ImGui::EndPopup();
}

if(ImGui::BeginItemTooltip())
{
ImGui::Text("Right click to rename this workspace");
ImGui::EndTooltip();
}
TitleHoverHelp();

DoRender(id);

ImGui::DockSpace(id, ImVec2(0.0f, 0.0f), 0, nullptr);

ImGui::End();
return true;
}

void Workspace::TitleHoverHelp()
{
if(ImGui::IsItemHovered())
{
m_parent->AddStatusHelp("mouse_lmb_drag", "Move workspace");
m_parent->AddStatusHelp("mouse_rmb", "Rename workspace");
}
}
14 changes: 11 additions & 3 deletions src/ngscopeclient/Workspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,31 @@
#ifndef Workspace_h
#define Workspace_h

class MainWindow;

class Workspace
{
public:
Workspace(const YAML::Node& node, Session& session);
Workspace(Session& session);
Workspace(const YAML::Node& node, Session& session, MainWindow* parent);
Workspace(Session& session, MainWindow* parent);
virtual ~Workspace()
{}

virtual bool Render();
bool Render();

YAML::Node Serialize();

std::string GetTitleAndID()
{ return m_title + "###" + m_id; }

protected:
virtual void DoRender([[maybe_unused]] ImGuiID id)
{}

void TitleHoverHelp();

Session& m_session;
MainWindow* m_parent;

bool m_open;
std::string m_id;
Expand Down

0 comments on commit e5e6daa

Please sign in to comment.