Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 1 addition & 20 deletions src/ngscopeclient/AboutDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,7 @@ AboutDialog::~AboutDialog()
*/
bool AboutDialog::DoRender()
{
pair<ImFont*, float> headings[] =
{
m_parent->GetFontPref("Appearance.Markdown.heading_1_font"),
m_parent->GetFontPref("Appearance.Markdown.heading_2_font"),
m_parent->GetFontPref("Appearance.Markdown.heading_3_font")
};

ImGui::MarkdownConfig mdConfig
{
nullptr, //linkCallback
nullptr, //tooltipCallback
nullptr, //imageCallback
"", //linkIcon (not used)
{
{ headings[0].first, headings[0].second, true },
{ headings[1].first, headings[1].second, true },
{ headings[2].first, headings[2].second, false }
},
nullptr //userData
};
auto mdConfig = m_parent->GetMarkdownConfig();

float iconsize = 5 * ImGui::GetFontSize();
float width = ImGui::GetContentRegionAvail().x;
Expand Down
54 changes: 23 additions & 31 deletions src/ngscopeclient/FilterGraphEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,8 @@ void FilterGraphEditor::DoNodeForGroupInputs(shared_ptr<FilterGraphGroup> group)
//Set size/position
auto headerfont = m_parent->GetFontPref("Appearance.Filter Graph.header_font");
ImGui::PushFont(headerfont.first, headerfont.second);
auto headerfontsize = ImGui::GetFontSize();
float headerheight = ImGui::GetFontSize() * 1.5;
ImGui::PopFont();
float headerheight = headerfontsize * 1.5;
auto gborder = ax::NodeEditor::GetStyle().GroupBorderWidth;
auto gpad = ax::NodeEditor::GetStyle().NodePadding.x;
ImVec2 pos(
Expand Down Expand Up @@ -883,9 +882,8 @@ void FilterGraphEditor::DoNodeForGroupOutputs(shared_ptr<FilterGraphGroup> group
//Set size/position
auto headerfont = m_parent->GetFontPref("Appearance.Filter Graph.header_font");
ImGui::PushFont(headerfont.first, headerfont.second);
auto headerfontsize = ImGui::GetFontSize();
float headerheight = ImGui::GetFontSize() * 1.5;
ImGui::PopFont();
float headerheight = headerfontsize * 1.5;
auto gborder = ax::NodeEditor::GetStyle().GroupBorderWidth;
auto gpad = ax::NodeEditor::GetStyle().NodePadding.x;
ImVec2 pos(
Expand Down Expand Up @@ -1887,10 +1885,6 @@ void FilterGraphEditor::DoNodeForTrigger(Trigger* trig)
auto id = GetID(trig);
auto headercolor = prefs.GetColor("Appearance.Filter Graph.header_text_color");
auto headerfont = m_parent->GetFontPref("Appearance.Filter Graph.header_font");
ImGui::PushFont(headerfont.first, headerfont.second);
auto headerfontsize = ImGui::GetFontSize();
ImGui::PopFont();
float headerheight = headerfontsize * 1.5;
float rounding = ax::NodeEditor::GetStyle().NodeRounding;

ax::NodeEditor::BeginNode(id);
Expand All @@ -1904,9 +1898,12 @@ void FilterGraphEditor::DoNodeForTrigger(Trigger* trig)
headerText = trig->GetScope()->m_nickname + ": " + headerText;

//Figure out how big the header text is and reserve space for it
auto headerSize = CalcTextSizeForFont(headerfont, headerText.c_str());
ImGui::PushFont(headerfont.first, headerfont.second);
float headerheight = ImGui::GetFontSize() * 1.5;
auto headerSize = ImGui::CalcTextSize(headerText.c_str());
float nodewidth = max(15*tsize, headerSize.x);
ImGui::Dummy(ImVec2(nodewidth, headerheight));
ImGui::PopFont();

//Table of ports
static ImGuiTableFlags flags = 0;
Expand Down Expand Up @@ -1949,6 +1946,7 @@ void FilterGraphEditor::DoNodeForTrigger(Trigger* trig)
ax::NodeEditor::EndNode();

//Draw header after the node is done
ImGui::PushFont(headerfont.first, headerfont.second);
auto bgList = ax::NodeEditor::GetNodeBackgroundDrawList(id);
bgList->AddRectFilled(
ImVec2(pos.x + 1, pos.y + 1),
Expand All @@ -1957,11 +1955,10 @@ void FilterGraphEditor::DoNodeForTrigger(Trigger* trig)
rounding,
ImDrawFlags_RoundCornersTop);
bgList->AddText(
headerfont.first,
headerfont.second,
ImVec2(pos.x + headerfontsize*0.5, pos.y + headerfontsize*0.25),
ImVec2(pos.x + ImGui::GetFontSize()*0.5, pos.y + ImGui::GetFontSize()*0.25),
headercolor,
headerText.c_str());
ImGui::PopFont();
}

/**
Expand Down Expand Up @@ -1989,14 +1986,8 @@ void FilterGraphEditor::DoNodeForChannel(
auto color = ColorFromString(displaycolor);
auto headercolor = prefs.GetColor("Appearance.Filter Graph.header_text_color");
auto headerfont = m_parent->GetFontPref("Appearance.Filter Graph.header_font");
ImGui::PushFont(headerfont.first, headerfont.second);
auto headerfontsize = ImGui::GetFontSize();
ImGui::PopFont();
auto textfont = m_parent->GetFontPref("Appearance.Filter Graph.icon_caption_font");
ImGui::PushFont(textfont.first, textfont.second);
auto textfontsize = ImGui::GetFontSize();
ImGui::PopFont();
float headerheight = headerfontsize * 1.5;
float rounding = ax::NodeEditor::GetStyle().NodeRounding;

auto id = GetID(channel);
Expand All @@ -2013,7 +2004,10 @@ void FilterGraphEditor::DoNodeForChannel(
headerText = inst->m_nickname + ": " + headerText;

//Figure out how big the header text is
auto headerSize = CalcTextSizeForFont(headerfont, headerText.c_str());
ImGui::PushFont(headerfont.first, headerfont.second);
float headerheight = ImGui::GetFontSize() * 1.5;
auto headerSize = ImGui::CalcTextSize(headerText.c_str());
ImGui::PopFont();

//Format block type early, even though it's not drawn until later
//so that we know how much space to allocate
Expand All @@ -2039,7 +2033,7 @@ void FilterGraphEditor::DoNodeForChannel(
blocktype = "Hardware input";
}
ImVec2 iconsize(ImGui::GetFontSize() * 6, ImGui::GetFontSize() * 3);
auto captionsize = CalcTextSizeForFont(textfont, blocktype.c_str());
auto captionsize = ImGui::CalcTextSize(blocktype.c_str());

//Reserve space for the center icon and node type caption
float iconwidth = max(iconsize.x, captionsize.x);
Expand All @@ -2053,13 +2047,13 @@ void FilterGraphEditor::DoNodeForChannel(
{
auto name = string("‣ ") + channel->GetInputName(i);
inames.push_back(name);
iportmax = max(iportmax, CalcTextSizeForFont(textfont, name.c_str()).x);
iportmax = max(iportmax, ImGui::CalcTextSize(name.c_str()).x);
}
for(size_t i=0; i<channel->GetStreamCount(); i++)
{
auto name = channel->GetStreamName(i) + " ‣";
onames.push_back(name);
oportmax = max(oportmax, CalcTextSizeForFont(textfont, name.c_str()).x);
oportmax = max(oportmax, ImGui::CalcTextSize(name.c_str()).x);
}
float colswidth = iportmax + oportmax + iconwidth;
float nodewidth = max(colswidth, headerSize.x) + 3*ImGui::GetStyle().ItemSpacing.x;
Expand Down Expand Up @@ -2131,7 +2125,7 @@ void FilterGraphEditor::DoNodeForChannel(

//Reserve space for icon and caption if needed
float contentHeight = ImGui::GetCursorPos().y - bodystart.y;
float minHeight = iconsize.y + 3*ImGui::GetStyle().ItemSpacing.y + textfontsize;
float minHeight = iconsize.y + 3*ImGui::GetStyle().ItemSpacing.y + ImGui::GetFontSize();
if(contentHeight < minHeight)
ImGui::Dummy(ImVec2(1, minHeight - contentHeight));

Expand Down Expand Up @@ -2159,6 +2153,7 @@ void FilterGraphEditor::DoNodeForChannel(
ax::NodeEditor::EndNode();

//Draw header after the node is done
ImGui::PushFont(headerfont.first, headerfont.second);
auto bgList = ax::NodeEditor::GetNodeBackgroundDrawList(id);
bgList->AddRectFilled(
ImVec2(pos.x + 1, pos.y + 1),
Expand All @@ -2167,9 +2162,7 @@ void FilterGraphEditor::DoNodeForChannel(
rounding,
ImDrawFlags_RoundCornersTop);
bgList->AddText(
headerfont.first,
headerfont.second,
ImVec2(pos.x + headerfontsize*0.5, pos.y + headerfontsize*0.25),
ImVec2(pos.x + ImGui::GetFontSize()*0.5, pos.y + ImGui::GetFontSize()*0.25),
headercolor,
headerText.c_str());

Expand All @@ -2179,7 +2172,7 @@ void FilterGraphEditor::DoNodeForChannel(
if(runtime > 0)
{
auto runtimeText = fs.PrettyPrint(runtime, 3);
auto runtimeSize = CalcTextSizeForFont(headerfont, runtimeText.c_str());
auto runtimeSize = ImGui::CalcTextSize(runtimeText.c_str());

auto timebgColor = ColorFromString("#404040");
auto timeTextColor = ColorFromString("#ffffff");
Expand Down Expand Up @@ -2209,12 +2202,11 @@ void FilterGraphEditor::DoNodeForChannel(
clockiconpos + clockiconsize );

bgList->AddText(
headerfont.first,
headerfont.second,
textpos,
timeTextColor,
runtimeText.c_str());
}
ImGui::PopFont(); // headerfont

//Draw the force vector
if(ImGui::IsKeyDown(ImGuiKey_Q))
Expand All @@ -2231,11 +2223,11 @@ void FilterGraphEditor::DoNodeForChannel(
pos + icondelta +
ImVec2(0, iconsize.y + ImGui::GetStyle().ItemSpacing.y*3);
bgList->AddText(
textfont.first,
textfont.second,
textpos + ImVec2( (iconwidth - captionsize.x)/2, 0),
textColor,
blocktype.c_str());

ImGui::PopFont(); // textfont
}

void FilterGraphEditor::RenderForceVector(ImDrawList* list, ImVec2 pos, ImVec2 size, ImVec2 vec)
Expand Down
15 changes: 0 additions & 15 deletions src/ngscopeclient/FontManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,3 @@ void FontManager::AddFontDescriptions(PreferenceCategory& cat, set<FontDescripti
}
}
}

/**
@brief Wrapper around ImGui::CalcTextSize that uses an explicit font
*/
ImVec2 CalcTextSizeForFont(
FontWithSize font,
const char* text,
bool hide_text_after_double_hash,
float wrap_width)
{
ImGui::PushFont(font.first, font.second);
ImVec2 size = ImGui::CalcTextSize(text, nullptr, hide_text_after_double_hash, wrap_width);
ImGui::PopFont();
return size;
}
6 changes: 0 additions & 6 deletions src/ngscopeclient/FontManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,4 @@ class FontManager
std::map<FontDescription, ImFont*> m_fonts;
};

ImVec2 CalcTextSizeForFont(
FontWithSize font,
const char* text,
bool hide_text_after_double_hash = false,
float wrap_width = -1.0f);

#endif
53 changes: 28 additions & 25 deletions src/ngscopeclient/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,11 +601,8 @@ void MainWindow::RenderUI()
glfwSetWindowTitle(m_window, title.c_str());
}

//Set default font including size, since this is no longer part of the ImFont
//Scale to a nominal 13 point default font
auto defaultFont = GetFontPref("Appearance.General.default_font");
float defaultFontScale = 13.0 / ImGui::GetFontSize();
ImGui::PushFont(defaultFont.first, defaultFont.second * defaultFontScale);
ImGui::PushFont(defaultFont.first, defaultFont.second);

//Set up colors
switch(m_session.GetPreferences().GetEnumRaw("Appearance.General.theme"))
Expand Down Expand Up @@ -1741,6 +1738,32 @@ void MainWindow::RenderErrorPopup()
}
}

ImGui::MarkdownConfig MainWindow::GetMarkdownConfig()
{
pair<ImFont*, float> headings[] =
{
GetFontPref("Appearance.Markdown.heading_1_font"),
GetFontPref("Appearance.Markdown.heading_2_font"),
GetFontPref("Appearance.Markdown.heading_3_font")
};

ImGui::MarkdownConfig mdConfig
{
nullptr, //linkCallback
nullptr, //tooltipCallback
nullptr, //imageCallback
"", //linkIcon (not used)
{
{ headings[0].first, headings[0].second, true },
{ headings[1].first, headings[1].second, true },
{ headings[2].first, headings[2].second, false }
},
nullptr //userData
};

return mdConfig;
}

/**
@brief Popup message when loading a file that might not match the current hardware setup
*/
Expand Down Expand Up @@ -1773,32 +1796,12 @@ void MainWindow::RenderLoadWarningPopup()
"Please review your lab notes and confirm that the experimental setup matches your previous session."
);

pair<ImFont*, float> headings[] =
{
GetFontPref("Appearance.Markdown.heading_1_font"),
GetFontPref("Appearance.Markdown.heading_2_font"),
GetFontPref("Appearance.Markdown.heading_3_font")
};

ImGui::MarkdownConfig mdConfig
{
nullptr, //linkCallback
nullptr, //tooltipCallback
nullptr, //imageCallback
"", //linkIcon (not used)
{
{ headings[0].first, headings[0].second, true },
{ headings[1].first, headings[1].second, true },
{ headings[2].first, headings[2].second, false }
},
nullptr //userData
};

if (ImGui::BeginChild("labnotes",
ImVec2(-FLT_MIN, ImGui::GetTextLineHeightWithSpacing() * 10),
ImGuiChildFlags_Border | ImGuiChildFlags_ResizeY))
{
ImGui::Markdown( m_session.m_setupNotes.c_str(), m_session.m_setupNotes.length(), mdConfig );
ImGui::Markdown( m_session.m_setupNotes.c_str(), m_session.m_setupNotes.length(), GetMarkdownConfig());
ImGui::EndChild();
}
}
Expand Down
13 changes: 4 additions & 9 deletions src/ngscopeclient/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "StreamBrowserDialog.h"
#include "TriggerPropertiesDialog.h"
#include "Workspace.h"
#include "imgui_markdown.h"

#include "../scopehal/PacketDecoder.h"

Expand Down Expand Up @@ -552,17 +553,9 @@ class MainWindow : public VulkanWindow
FontWithSize GetFontPref(const std::string& name)
{
auto desc = m_session.GetPreferences().GetFont(name.c_str());
return std::pair<ImFont*, float>(m_fontmgr.GetFont(desc), desc.second * GetFontScale());
return std::pair<ImFont*, float>(m_fontmgr.GetFont(desc), desc.second);
}

/**
@brief Get scaling factor for fonts being drawn with ImDrawList

For now, normalize everything to a nominal size 13 default font
*/
float GetFontScale()
{ return ImGui::GetFontSize() / 13; }

ImU32 GetColorPref(const std::string& name)
{ return m_session.GetPreferences().GetColor(name); }

Expand All @@ -576,6 +569,8 @@ class MainWindow : public VulkanWindow

std::string GetIconForWaveformShape(FunctionGenerator::WaveShape shape);

ImGui::MarkdownConfig GetMarkdownConfig();

protected:
FontManager m_fontmgr;

Expand Down
23 changes: 1 addition & 22 deletions src/ngscopeclient/NotesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,6 @@ void NotesDialog::GeneralNotes()
*/
void NotesDialog::MarkdownEditor(string& str)
{
pair<ImFont*, float> headings[] =
{
m_parent->GetFontPref("Appearance.Markdown.heading_1_font"),
m_parent->GetFontPref("Appearance.Markdown.heading_2_font"),
m_parent->GetFontPref("Appearance.Markdown.heading_3_font")
};

ImGui::MarkdownConfig mdConfig
{
nullptr, //linkCallback
nullptr, //tooltipCallback
nullptr, //imageCallback
"", //linkIcon (not used)
{
{ headings[0].first, headings[0].second, true },
{ headings[1].first, headings[1].second, true },
{ headings[2].first, headings[2].second, false }
},
nullptr //userData
};

//Table with one col for live view and one for editor
static ImGuiTableFlags flags =
ImGuiTableFlags_Resizable |
Expand All @@ -149,7 +128,7 @@ void NotesDialog::MarkdownEditor(string& str)

//Render the markdown
ImGui::TableSetColumnIndex(1);
ImGui::Markdown( str.c_str(), str.length(), mdConfig );
ImGui::Markdown(str.c_str(), str.length(), m_parent->GetMarkdownConfig());

ImGui::EndTable();
}
Expand Down
Loading
Loading