ngscopeclient 0.1-dev+51fbda87c
Dialog.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2024 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
43class Dialog
44{
45public:
46 Dialog(const std::string& title, const std::string& id, ImVec2 defaultSize = ImVec2(300, 100) );
47 virtual ~Dialog();
48
49 virtual bool Render();
50 void RenderAsChild();
51 virtual bool DoRender() =0;
52
53 const std::string& GetID()
54 { return m_id; }
55
56 std::string GetTitleAndID()
57 { return m_title + "###" + m_id; }
58
59 //TODO: this might be better off as a global method?
60 static bool Combo(const std::string& label, const std::vector<std::string>& items, int& selection);
62 const std::string& label,
63 std::string& currentValue,
64 float& committedValue,
65 Unit unit);
67 const std::string& label,
68 std::string& currentValue,
69 double& committedValue,
70 Unit unit);
72 const std::string& label,
73 std::string& currentValue,
74 int64_t& committedValue,
75 Unit unit);
76 static bool TextInputWithImplicitApply(
77 const std::string& label,
78 std::string& currentValue,
79 std::string& committedValue);
80
81protected:
82 bool FloatInputWithApplyButton(const std::string& label, float& currentValue, float& committedValue);
83 bool TextInputWithApplyButton(const std::string& label, std::string& currentValue, std::string& committedValue);
84 bool IntInputWithImplicitApply(const std::string& label, int& currentValue, int& committedValue);
86 const std::string& label,
87 std::string& currentValue,
88 float& committedValue,
89 Unit unit);
90public:
91 static void Tooltip(const std::string& str, bool allowDisabled = false);
92 static void HelpMarker(const std::string& str);
93 static void HelpMarker(const std::string& header, const std::vector<std::string>& bullets);
94
95protected:
96 void RenderErrorPopup();
97 void ShowErrorPopup(const std::string& title, const std::string& msg);
98
99 bool m_open;
100 std::string m_id;
101 std::string m_title;
102 ImVec2 m_defaultSize;
103
104 std::string m_errorPopupTitle;
105 std::string m_errorPopupMessage;
106};
107
108#endif
Generic dialog box or other popup window.
Definition: Dialog.h:44
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:399
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:302
bool FloatInputWithApplyButton(const std::string &label, float &currentValue, float &committedValue)
Helper for displaying a floating-point input box with an "apply" button.
Definition: Dialog.cpp:218
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:180
void RenderAsChild()
Runs the dialog's contents directly into a parent window.
Definition: Dialog.cpp:94
void ShowErrorPopup(const std::string &title, const std::string &msg)
Opens the error popup.
Definition: Dialog.cpp:105
virtual bool Render()
Renders the dialog and handles UI events.
Definition: Dialog.cpp:64
static bool Combo(const std::string &label, const std::vector< std::string > &items, int &selection)
Displays a combo box from a vector<string>
Definition: Dialog.cpp:133
void RenderErrorPopup()
Popup message when we fail to connect.
Definition: Dialog.cpp:115
A unit of measurement, plus conversion to pretty-printed output.
Definition: Unit.h:57