ngscopeclient v0.2.2
Loading...
Searching...
No Matches
Dialog.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2026 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
35#ifndef Dialog_h
36#define Dialog_h
37
38#include "imgui_stdlib.h"
39
40class MainWindow;
41
45class Dialog
46{
47public:
48 Dialog(const std::string& title, const std::string& id, ImVec2 defaultSize = ImVec2(300, 100),Session* session = nullptr, MainWindow* parent = nullptr);
49 virtual ~Dialog();
50
51 virtual bool Render();
52 void RenderAsChild();
53 virtual bool DoRender() =0;
54
55 const std::string& GetID()
56 { return m_id; }
57
58 std::string GetTitleAndID()
59 { return m_title + "###" + m_id; }
60
61 //TODO: this might be better off as a global method?
62 static bool Combo(const std::string& label, const std::vector<std::string>& items, int& selection, bool* open = nullptr);
64 const std::string& label,
65 std::string& currentValue,
66 float& committedValue,
67 Unit unit);
69 const std::string& label,
70 std::string& currentValue,
71 double& committedValue,
72 Unit unit);
74 const std::string& label,
75 std::string& currentValue,
77 Unit unit);
78 static bool TextInputWithImplicitApply(
79 const std::string& label,
80 std::string& currentValue,
81 std::string& committedValue);
82
83protected:
84 bool TextInputWithExplicitApply(const std::string& label,std::string& currentValue,std::string& committedValue);
85 bool IntInputWithImplicitApply(const std::string& label, int& currentValue, int& committedValue);
87 const std::string& label,
88 std::string& currentValue,
89 float& committedValue,
90 Unit unit);
91 void renderNumericValue(const std::string& value, bool &clicked, bool &hovered, std::optional<ImVec4> optcolor = std::nullopt, bool allow7SegmentDisplay = false, float digitHeight = 0, bool clickable = true);
92 void renderReadOnlyProperty(float width, const std::string& label, const std::string& value, const char* tooltip = nullptr);
93 template<typename T>
94 bool renderEditableProperty(float width, const std::string& label, std::string& currentValue, T& committedValue, Unit unit, const char* tooltip = nullptr, std::optional<ImVec4> optcolor = std::nullopt, bool allow7SegmentDisplay = false, bool explicitApply = false);
95 template<typename T>
96 bool renderEditablePropertyWithExplicitApply(float width, const std::string& label, std::string& currentValue, T& committedValue, Unit unit, const char* tooltip = nullptr, std::optional<ImVec4> optcolor = std::nullopt, bool allow7SegmentDisplay = false);
97 void renderBadge(float width, ImVec4 color, const std::string& label);
98
99public:
100 static void Tooltip(const std::string& str, bool allowDisabled = false);
101 static void HelpMarker(const std::string& str);
102 static void HelpMarker(const std::string& header, const std::vector<std::string>& bullets);
103
104protected:
105 void RenderErrorPopup();
106 void ShowErrorPopup(const std::string& title, const std::string& msg);
107
109 void Render7SegmentValue(const std::string& value, ImVec4 color, float digitHeight);
110 void Render7SegmentValue(const std::string& value, ImVec4 color, float digitHeight, bool &clicked, bool &hovered, bool clickable = true);
111
112 bool m_open;
113 std::string m_id;
114 std::string m_title;
115 ImVec2 m_defaultSize;
116
117 std::string m_errorPopupTitle;
118 std::string m_errorPopupMessage;
119
122
125
128
131};
132
133#endif
Definition AcceleratorBuffer.h:204
Generic dialog box or other popup window.
Definition Dialog.h:46
bool UnitInputWithExplicitApply(const std::string &label, std::string &currentValue, float &committedValue, Unit unit)
Input box for a floating point value with an associated unit and an "apply" button.
Definition Dialog.cpp:374
ImGuiID m_editedItemId
Id of the item currently beeing edited.
Definition Dialog.h:127
static bool UnitInputWithImplicitApply(const std::string &label, std::string &currentValue, float &committedValue, Unit unit)
Input box for a floating point value with an associated unit.
Definition Dialog.cpp:276
static void Tooltip(const std::string &str, bool allowDisabled=false)
Helper based on imgui demo for displaying tooltip text over the previously rendered widget.
Definition Dialog.cpp:194
void Render7SegmentDigit(ImDrawList *drawList, uint8_t digit, ImVec2 size, ImVec2 position, float thikness, ImU32 colorOn, ImU32 colorOff)
Render a single digit in 7 segment display style.
Definition Dialog.cpp:844
void renderReadOnlyProperty(float width, const std::string &label, const std::string &value, const char *tooltip=nullptr)
Render a read-only instrument property value.
Definition Dialog.cpp:473
void RenderAsChild()
Runs the dialog's contents directly into a parent window.
Definition Dialog.cpp:101
void renderNumericValue(const std::string &value, bool &clicked, bool &hovered, std::optional< ImVec4 > optcolor=std::nullopt, bool allow7SegmentDisplay=false, float digitHeight=0, bool clickable=true)
Render a numeric value.
Definition Dialog.cpp:393
static bool Combo(const std::string &label, const std::vector< std::string > &items, int &selection, bool *open=nullptr)
Displays a combo box from a vector<string>
Definition Dialog.cpp:142
void ShowErrorPopup(const std::string &title, const std::string &msg)
Opens the error popup.
Definition Dialog.cpp:112
ImGuiID m_lastEditedItemId
Id of the last edited item.
Definition Dialog.h:130
virtual bool Render()
Renders the dialog and handles UI events.
Definition Dialog.cpp:71
void renderBadge(float width, ImVec4 color, const std::string &label)
Render a badge with text inside.
Definition Dialog.cpp:797
void Render7SegmentValue(const std::string &value, ImVec4 color, float digitHeight)
Render a numeric value with a 7 segment display style.
Definition Dialog.cpp:925
bool renderEditablePropertyWithExplicitApply(float width, const std::string &label, std::string &currentValue, T &committedValue, Unit unit, const char *tooltip=nullptr, std::optional< ImVec4 > optcolor=std::nullopt, bool allow7SegmentDisplay=false)
Render an editable numeric value with explicit apply (if the input value needs to explicitly be appli...
Definition Dialog.cpp:781
void RenderErrorPopup()
Popup message when we fail to connect.
Definition Dialog.cpp:122
MainWindow * m_parent
optional reference to parent MainWindow
Definition Dialog.h:124
Session * m_session
optional reference to session
Definition Dialog.h:121
Top level application window.
Definition MainWindow.h:168
A Session stores all of the instrument configuration and other state the user has open.
Definition Session.h:126
A unit of measurement, plus conversion to pretty-printed output.
Definition Unit.h:59