Skip to content
Snippets Groups Projects

Resolves #343 GUI and Frame Refactor

Merged Nicolas Pope requested to merge feature/gui2 into master
Compare and Show latest version
20 files
+ 184
150
Compare changes
  • Side-by-side
  • Inline
Files
20
@@ -8,6 +8,7 @@
#include <nanogui/button.h>
#include <nanogui/vscrollpanel.h>
#include <nanogui/tabwidget.h>
#include <nanogui/formhelper.h>
#include <loguru.hpp>
@@ -34,12 +35,75 @@ AddSourceWindow::AddSourceWindow(nanogui::Widget* parent, AddCtrl *ctrl) :
close->setBackgroundColor(theme()->mWindowHeaderGradientBot);
close->setCallback([this](){ this->close();});
auto *title = new Label(this, "Add Source", "sans-bold");
title->setFontSize(28);
tabs_ = new TabWidget(this);
auto *recent_tab = tabs_->createTab("Recent");
recent_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
VScrollPanel *vscroll = new VScrollPanel(recent_tab);
vscroll->setFixedHeight(200);
Widget *recentscroll = new Widget(vscroll);
recentscroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
auto *group_tab = tabs_->createTab("Groups");
group_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
vscroll = new VScrollPanel(group_tab);
vscroll->setFixedHeight(200);
Widget *groupscroll = new Widget(vscroll);
groupscroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
auto *dev_tab = tabs_->createTab("Devices");
dev_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
vscroll = new VScrollPanel(dev_tab);
vscroll->setFixedHeight(200);
Widget *devscroll = new Widget(vscroll);
devscroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
auto *host_tab = tabs_->createTab("Hosts");
host_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
vscroll = new VScrollPanel(host_tab);
vscroll->setFixedHeight(200);
Widget *hostscroll = new Widget(vscroll);
hostscroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
auto *stream_tab = tabs_->createTab("Streams");
stream_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
vscroll = new VScrollPanel(stream_tab);
vscroll->setFixedHeight(200);
Widget *streamscroll = new Widget(vscroll);
streamscroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
auto *file_tab = tabs_->createTab("Files");
file_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
vscroll = new VScrollPanel(file_tab);
vscroll->setFixedHeight(200);
Widget *filescroll = new Widget(vscroll);
filescroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
tab_items_.resize(6);
tab_items_[0] = recentscroll;
tab_items_[1] = groupscroll;
tab_items_[2] = devscroll;
tab_items_[3] = hostscroll;
tab_items_[4] = streamscroll;
tab_items_[5] = filescroll;
uptodate_.test_and_set();
rebuild();
tabs_->setActiveTab(0);
new_source_handle_ = ctrl_->feed()->onNewSources([this](int a) {
LOG(INFO) << "NEW SOURCES";
UNIQUE_LOCK(mutex_, lk);
do_rebuild_ = true;
uptodate_.clear();
return true;
});
}
@@ -83,104 +147,76 @@ nanogui::Button *AddSourceWindow::_addButton(const std::string &s, nanogui::Widg
void AddSourceWindow::rebuild() {
using namespace nanogui;
auto *title = new Label(this, "Add Source", "sans-bold");
title->setFontSize(28);
auto *tabs = new TabWidget(this);
auto *recent_tab = tabs->createTab("Recent");
recent_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
VScrollPanel *vscroll = new VScrollPanel(recent_tab);
vscroll->setFixedHeight(200);
Widget *recentscroll = new Widget(vscroll);
recentscroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
for (auto *w : tab_items_) {
while (w->childCount() > 0) w->removeChild(w->childCount()-1);
}
Button *button;
auto srcs = ctrl_->getRecent();
for (auto &s : srcs) {
_addButton(s.uri, recentscroll);
_addButton(s.uri, tab_items_[0]);
}
auto *group_tab = tabs->createTab("Groups");
group_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
vscroll = new VScrollPanel(group_tab);
vscroll->setFixedHeight(150);
Widget *groupscroll = new Widget(vscroll);
groupscroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
auto groups = ctrl_->getGroups();
for (auto &s : groups) {
_addButton(s, groupscroll);
_addButton(s, tab_items_[1]);
}
auto *dev_tab = tabs->createTab("Devices");
dev_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
vscroll = new VScrollPanel(dev_tab);
vscroll->setFixedHeight(150);
Widget *devscroll = new Widget(vscroll);
devscroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
auto devsrcs = ctrl_->getDeviceSources();
for (auto &s : devsrcs) {
_addButton(s, devscroll);
_addButton(s, tab_items_[2]);
}
auto *host_tab = tabs->createTab("Hosts");
host_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
vscroll = new VScrollPanel(host_tab);
vscroll->setFixedHeight(150);
Widget *hostscroll = new Widget(vscroll);
hostscroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
auto *host_menu = new Widget(tab_items_[3]);
host_menu->setLayout(new BoxLayout(nanogui::Orientation::Horizontal, nanogui::Alignment::Maximum, 5,4));
button = new Button(hostscroll, "Add Host", ENTYPO_ICON_PLUS);
button->setIconPosition(Button::IconPosition::Left);
button->setIconExtraScale(1.2);
button = new Button(host_menu, "Add", ENTYPO_ICON_PLUS);
button->setFontSize(18);
button->setTooltip("Manually add a new connection URI");
button->setTooltip("Connect to a new machine");
button->setCallback([this]() {
FormHelper *fh = new FormHelper(screen());
auto *win = fh->addWindow(Vector2i(10,10), "Add Host");
win->center();
win->setTheme(dynamic_cast<ftl::gui2::Screen*>(win->screen())->getTheme("window_dark"));
//win->setWidth(200);
fh->addVariable<std::string>("URI", [this,win](const std::string &v) {
try {
ctrl_->add(v);
} catch (const ftl::exception &e) {
LOG(ERROR) << "Add failed: " << e.what();
}
win->dispose();
}, [this]() {
return "";
})->setFixedWidth(150);
win->screen()->performLayout();
delete fh;
});
button = new Button(host_menu, "Clear", ENTYPO_ICON_CYCLE);
button->setFontSize(18);
button->setTooltip("Clear host history");
button->setCallback([this]() {
ctrl_->feed()->clearHostHistory();
uptodate_.clear();
});
auto hostsrcs = ctrl_->getHosts();
for (auto &s : hostsrcs) {
_addButton(s, hostscroll);
_addButton(s, tab_items_[3]);
}
auto *stream_tab = tabs->createTab("Streams");
stream_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
vscroll = new VScrollPanel(stream_tab);
vscroll->setFixedHeight(150);
Widget *streamscroll = new Widget(vscroll);
streamscroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
auto streamsrcs = ctrl_->getNetSources();
for (auto &s : streamsrcs) {
_addButton(s, streamscroll);
_addButton(s, tab_items_[4]);
}
auto *file_tab = tabs->createTab("Files");
file_tab->setLayout(new nanogui::BoxLayout
(nanogui::Orientation::Vertical, nanogui::Alignment::Fill, 0, 0));
vscroll = new VScrollPanel(file_tab);
vscroll->setFixedHeight(150);
Widget *filescroll = new Widget(vscroll);
filescroll->setLayout(new BoxLayout(Orientation::Vertical, Alignment::Fill, 10, 4));
auto *file_menu = new Widget(tab_items_[5]);
file_menu->setLayout(new BoxLayout(nanogui::Orientation::Horizontal, nanogui::Alignment::Maximum, 5,4));
button = new Button(filescroll, "Open", ENTYPO_ICON_PLUS);
button->setIconPosition(Button::IconPosition::Left);
button->setIconExtraScale(1.2);
button = new Button(file_menu, "Open", ENTYPO_ICON_PLUS);
button->setFontSize(18);
button->setTooltip("Open FTL File");
button->setCallback([this]() {
@@ -205,64 +241,18 @@ void AddSourceWindow::rebuild() {
close();
});
auto filesrcs = ctrl_->getFileSources();
button = new Button(file_menu, "Clear", ENTYPO_ICON_CYCLE);
button->setFontSize(18);
button->setTooltip("Clear file history");
button->setCallback([this]() {
ctrl_->feed()->clearFileHistory();
uptodate_.clear();
});
auto filesrcs = ctrl_->getFileSources();
for (auto &s : filesrcs) {
_addButton(s, filescroll);
_addButton(s, tab_items_[5]);
}
tabs->setActiveTab(0);
/*button = new Button(devicebuttons, "Camera(s)");
button->setCallback([this]() { ctrl_->add("device:camera"); close(); });
button = new Button(devicebuttons, "Realsense");
button->setCallback([this]() { ctrl_->add("device:realsense"); close(); });
button = new Button(devicebuttons, "Screen");
button->setCallback([this]() { ctrl_->add("device:screen"); close(); });
button = new Button(devicebuttons, "3D Camera");
button->setCallback([this]() { ctrl_->add("device:render"); close(); });
button = new Button(devicebuttons, "OpenVR");
button->setCallback([this]() { ctrl_->add("device:openvr"); close(); });*/
/*new Label(this, "Network Sources", "sans-bold");
auto *netbuttons = new Widget(this);
netbuttons->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 4));
auto netsrcs = ctrl_->getNetSources();
for (auto &s : netsrcs) {
button = new Button(netbuttons, ctrl_->getSourceName(s));
if (ctrl_->isSourceActive(s)) {
button->setBackgroundColor(Color(0, 255, 0, 25));
}
button->setCallback([this, s]() {
ctrl_->add(s);
close();
});
}*/
//new Label(this, "Files", "sans-bold");
//auto *filebuttons = new Widget(this);
//filebuttons->setLayout(new BoxLayout(Orientation::Horizontal, Alignment::Middle, 0, 4));
/*auto filesrcs = ctrl_->getFileSources();
for (auto &s : filesrcs) {
button = new Button(filebuttons, ctrl_->getSourceName(s));
if (ctrl_->isSourceActive(s)) {
button->setBackgroundColor(Color(0, 255, 0, 25));
}
button->setCallback([this, s]() {
ctrl_->add(s);
close();
});
}*/
}
void AddSourceWindow::close() {
@@ -274,10 +264,8 @@ void AddSourceWindow::close() {
void AddSourceWindow::draw(NVGcontext *ctx) {
{
UNIQUE_LOCK(mutex_, lk);
if (do_rebuild_) {
do_rebuild_ = false;
// Note the 1, first widget is the title bar buttons
while(childCount() > 1) { removeChild(childCount()-1); }
if (!uptodate_.test_and_set()) {
tabs_->requestFocus(); // Must ensure focus item not deleted
rebuild();
screen()->performLayout();
}
Loading