Rename GuiGrouping to GuiPath

Add GuiPath to existing scenegraph nodes
Add option to toggle tree representation
Add caption font to UI
This commit is contained in:
Alexander Bock
2017-10-13 13:08:59 -04:00
parent ebd506975c
commit bb5f4d4381
57 changed files with 600 additions and 418 deletions
+2
View File
@@ -92,6 +92,8 @@ private:
};
void CaptionText(const char* text);
} // namespace openspace::gui
#endif // __OPENSPACE_MODULE_IMGUI___GUI___H__
+5 -1
View File
@@ -47,9 +47,11 @@ public:
using SourceFunction = std::function<std::vector<properties::PropertyOwner*>()>;
using UseTreeLayout = ghoul::Boolean;
using IsTopLevelWindow = ghoul::Boolean;
GuiPropertyComponent(std::string name, UseTreeLayout useTree = UseTreeLayout::No);
GuiPropertyComponent(std::string name, UseTreeLayout useTree = UseTreeLayout::No,
IsTopLevelWindow isTopLevel = IsTopLevelWindow::No);
// This is the function that evaluates to the list of Propertyowners that this
// component should render
@@ -72,6 +74,8 @@ protected:
/// This variable only has an impact on which \c setPropertyValue function is called
bool _hasOnlyRegularProperties = false;
UseTreeLayout _useTreeLayout;
bool _currentUseTreeLayout;
IsTopLevelWindow _isTopLevel;
};
} // namespace openspace::gui
+18 -1
View File
@@ -60,6 +60,8 @@ std::unique_ptr<ghoul::opengl::ProgramObject> _program;
std::unique_ptr<ghoul::opengl::Texture> _fontTexture;
char* iniFileBuffer = nullptr;
ImFont* captionFont = nullptr;
static void RenderDrawLists(ImDrawData* drawData) {
// Avoid rendering when minimized, scale coordinates for retina displays
// (screen coordinates != framebuffer coordinates)
@@ -234,10 +236,20 @@ void addScreenSpaceRenderableOnline(std::string texturePath) {
namespace openspace::gui {
void CaptionText(const char* text) {
ImGui::PushFont(captionFont);
ImGui::Text("%s", text);
ImGui::PopFont();
}
GUI::GUI()
: GuiComponent("Main")
, _globalProperty("Global")
, _property("Properties", GuiPropertyComponent::UseTreeLayout::Yes)
, _property(
"Properties",
GuiPropertyComponent::UseTreeLayout::Yes,
GuiPropertyComponent::IsTopLevelWindow::Yes
)
, _screenSpaceProperty("ScreenSpace Properties")
, _virtualProperty("Virtual Properties")
, _featuredProperties("Featured Properties")
@@ -301,6 +313,11 @@ void GUI::initialize() {
FontSize
);
captionFont = io.Fonts->AddFontFromFileTTF(
absPath(GuiFont).c_str(),
FontSize * 1.5f
);
ImGuiStyle& style = ImGui::GetStyle();
style.WindowPadding = { 4.f, 4.f };
style.WindowRounding = 0.f;
+24 -12
View File
@@ -127,9 +127,11 @@ namespace {
namespace openspace::gui {
GuiPropertyComponent::GuiPropertyComponent(std::string name, UseTreeLayout useTree)
GuiPropertyComponent::GuiPropertyComponent(std::string name, UseTreeLayout useTree, IsTopLevelWindow topLevel)
: GuiComponent(std::move(name))
, _useTreeLayout(useTree)
, _isTopLevel(topLevel)
, _currentUseTreeLayout(useTree)
{}
void GuiPropertyComponent::setSource(SourceFunction function) {
@@ -209,11 +211,21 @@ void GuiPropertyComponent::renderPropertyOwner(properties::PropertyOwner* owner)
}
void GuiPropertyComponent::render() {
bool v = _isEnabled;
ImGui::Begin(name().c_str(), &v, size, 0.75f);
_isEnabled = v;
if (_isTopLevel) {
ImGui::Begin(name().c_str(), nullptr, size, 0.75f);
}
else {
bool v = _isEnabled;
ImGui::Begin(name().c_str(), &v, size, 0.75f);
_isEnabled = v;
}
if (_function) {
if (_useTreeLayout) {
ImGui::Checkbox("Use Tree layout", &_currentUseTreeLayout);
}
std::vector<properties::PropertyOwner*> owners = _function();
std::sort(
@@ -224,7 +236,7 @@ void GuiPropertyComponent::render() {
}
);
if (_useTreeLayout) {
if (_currentUseTreeLayout) {
for (properties::PropertyOwner* owner : owners) {
ghoul_assert(
dynamic_cast<SceneGraphNode*>(owner),
@@ -239,8 +251,8 @@ void GuiPropertyComponent::render() {
owners.begin(),
owners.end(),
[](properties::PropertyOwner* lhs, properties::PropertyOwner* rhs) {
std::string lhsGroup = static_cast<SceneGraphNode*>(lhs)->guiGroup();
std::string rhsGroup = static_cast<SceneGraphNode*>(rhs)->guiGroup();
std::string lhsGroup = static_cast<SceneGraphNode*>(lhs)->guiPath();
std::string rhsGroup = static_cast<SceneGraphNode*>(rhs)->guiPath();
if (lhsGroup.empty()) {
return false;
@@ -260,7 +272,7 @@ void GuiPropertyComponent::render() {
bool noGuiGroups =
owners.empty() ||
(dynamic_cast<SceneGraphNode*>(*owners.begin()) &&
dynamic_cast<SceneGraphNode*>(*owners.begin())->guiGroup().empty());
dynamic_cast<SceneGraphNode*>(*owners.begin())->guiPath().empty());
auto renderProp = [&](properties::PropertyOwner* pOwner) {
int count = nVisibleProperties(pOwner->propertiesRecursive(), _visibility);
@@ -291,7 +303,7 @@ void GuiPropertyComponent::render() {
}
};
if (!_useTreeLayout || noGuiGroups) {
if (!_currentUseTreeLayout || noGuiGroups) {
std::for_each(owners.begin(), owners.end(), renderProp);
}
else { // _useTreeLayout && gui groups exist
@@ -301,13 +313,13 @@ void GuiPropertyComponent::render() {
// We checked above that pOwner is a SceneGraphNode
SceneGraphNode* nOwner = static_cast<SceneGraphNode*>(pOwner);
if (nOwner->guiGroup().empty()) {
if (nOwner->guiPath().empty()) {
// We know that we are done now since we stable_sort:ed them above
break;
}
std::vector<std::string> paths = ghoul::tokenizeString(
nOwner->guiGroup().substr(1),
nOwner->guiPath().substr(1),
'/'
);
@@ -322,7 +334,7 @@ void GuiPropertyComponent::render() {
// We checked above that pOwner is a SceneGraphNode
SceneGraphNode* nOwner = static_cast<SceneGraphNode*>(pOwner);
if (!nOwner->guiGroup().empty()) {
if (!nOwner->guiPath().empty()) {
continue;
}
+7 -7
View File
@@ -24,8 +24,10 @@
#include <modules/imgui/include/guispacetimecomponent.h>
#include <modules/imgui/include/gui.h>
#include <modules/imgui/include/imgui_include.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/util/timemanager.h>
#include <openspace/util/time.h>
@@ -43,11 +45,7 @@ namespace openspace::gui {
GuiSpaceTimeComponent::GuiSpaceTimeComponent() : GuiComponent("Space/Time") {}
void GuiSpaceTimeComponent::render() {
bool v = _isEnabled;
ImGui::Begin(name().c_str(), &v, size, 0.5f, ImGuiWindowFlags_AlwaysAutoResize);
_isEnabled = v;
ImGui::Begin(name().c_str(), nullptr, size, 0.5f, ImGuiWindowFlags_AlwaysAutoResize);
std::vector<SceneGraphNode*> nodes =
OsEng.renderEngine().scene()->allSceneGraphNodes();
@@ -69,8 +67,8 @@ void GuiSpaceTimeComponent::render() {
);
}
CaptionText("Focus Selection");
ImGui::Text("%s", "Focus selection");
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10.f);
ImGui::Text("%s", "Focus on:");
@@ -137,7 +135,9 @@ void GuiSpaceTimeComponent::render() {
"These elements determine the simulation time inside OpenSpace."
);
}
ImGui::Text("%s", "Time Controls");
CaptionText("Time Controls");
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10.f);
constexpr int BufferSize = 256;
static char Buffer[BufferSize];