| 55 | }; |
| 56 | |
| 57 | ImageInfoWindow::ImageInfoWindow(Widget* parent, const shared_ptr<Image>& image, function<void()> closeCallback) : |
| 58 | Window{parent, "Info"}, mCloseCallback{closeCallback} { |
| 59 | |
| 60 | auto closeButton = new Button{button_panel(), "", FA_TIMES}; |
| 61 | closeButton->set_callback(mCloseCallback); |
| 62 | |
| 63 | static constexpr int WINDOW_WIDTH = 700; |
| 64 | static constexpr int WINDOW_HEIGHT = 680; |
| 65 | |
| 66 | set_layout(new GroupLayout{}); |
| 67 | set_fixed_width(WINDOW_WIDTH); |
| 68 | |
| 69 | mTabWidget = new TabWidget{this}; |
| 70 | mTabWidget->set_fixed_height(WINDOW_HEIGHT - 12); |
| 71 | |
| 72 | // Each attributes entry is a tab |
| 73 | for (const auto& tab : image->attributes()) { |
| 74 | Widget* tmp = new Widget(mTabWidget); |
| 75 | |
| 76 | VScrollPanel* scrollPanel = new VScrollPanel{tmp}; |
| 77 | scrollPanel->set_fixed_height(WINDOW_HEIGHT - 40); |
| 78 | scrollPanel->set_fixed_width(WINDOW_WIDTH - 40); |
| 79 | |
| 80 | mTabWidget->append_tab(tab.name, tmp); |
| 81 | |
| 82 | Widget* container = new Widget(scrollPanel); |
| 83 | container->set_layout(new GroupLayout{}); |
| 84 | |
| 85 | // Each top-level child of the attribute is a section |
| 86 | for (const auto& section : tab.children) { |
| 87 | new Label{container, section.name, "sans-bold", 18}; |
| 88 | auto attributes = new Widget{container}; |
| 89 | attributes->set_layout(new BoxLayout{Orientation::Vertical, Alignment::Fill, 0, 0}); |
| 90 | |
| 91 | for (const auto& c : section.children) { |
| 92 | addRows(attributes, c, 0); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | perform_layout(screen()->nvg_context()); |
| 98 | |
| 99 | mTabWidget->set_callback([this](int id) mutable { |
| 100 | mTabWidget->set_selected_id(id); |
| 101 | mScrollPanel = dynamic_cast<VScrollPanel*>(mTabWidget->child_at(0)->child_at(0)); |
| 102 | }); |
| 103 | |
| 104 | if (mTabWidget->tab_count() > 0) { |
| 105 | mTabWidget->set_selected_id(0); |
| 106 | mScrollPanel = dynamic_cast<VScrollPanel*>(mTabWidget->child_at(0)->child_at(0)); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | bool ImageInfoWindow::keyboard_event(int key, int scancode, int action, int modifiers) { |
| 111 | if (Window::keyboard_event(key, scancode, action, modifiers)) { |
nothing calls this directly
no test coverage detected