| 17 | namespace EE { namespace UI { namespace Tools { |
| 18 | |
| 19 | UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIconSize, |
| 20 | std::function<void()> highlightToggle, |
| 21 | std::function<void()> drawBoxesToggle, |
| 22 | std::function<void()> drawDebugDataToggle ) { |
| 23 | static ModelIndex lastModelIndex = {}; |
| 24 | auto wtv = sceneNode->getRoot()->hasChild( "widget-tree-view" ); |
| 25 | if ( wtv ) { |
| 26 | wtv->toFront(); |
| 27 | return nullptr; |
| 28 | } |
| 29 | UIWindow* uiWin = UIWindow::New(); |
| 30 | uiWin->setId( "widget-tree-view" ); |
| 31 | uiWin->setMinWindowSize( 600, 400 ); |
| 32 | uiWin->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_RESIZEABLE | UI_WIN_MAXIMIZE_BUTTON ); |
| 33 | static const auto WIDGET_LAYOUT = R"xml( |
| 34 | <vbox lw="mp" lh="mp"> |
| 35 | <hbox lw="wc" lh="wc"> |
| 36 | <PushButton id="pick_widget" lh="18dp" icon="icon(inspect, 12dp)" text='@string(pick_widget, "Pick Widget")' text-as-fallback="true" /> |
| 37 | <CheckBox id="debug-draw-highlight" text='@string(debug_draw_highlight, "Highlight Focus & Hover")' margin-left="4dp" lg="center" /> |
| 38 | <CheckBox id="debug-draw-boxes" text='@string(debug_draw_boxes, "Draw Boxes")' margin-left="4dp" lg="center" /> |
| 39 | <CheckBox id="debug-draw-debug-data" text='@string(debug_draw_debug_data, "Draw Debug Data")' margin-left="4dp" lg="center" />" |
| 40 | <PushButton id="widget-tree-search-collapse" layout_width="wrap_content" layout_height="18dp" tooltip='@string(collapse_all, "Collapse All")' margin-left="8dp" icon="menu-fold" text-as-fallback="true" /> |
| 41 | <PushButton id="widget-tree-search-expand" layout_width="wrap_content" layout_height="18dp" tooltip='@string(expand_all, "Expand All")' margin-left="8dp" icon="menu-unfold" text-as-fallback="true" /> |
| 42 | <PushButton id="open-texture-viewer" lh="18dp" text="@string(texture_viewer, Texture Viewer)" margin-left="8dp" /> |
| 43 | </hbox> |
| 44 | <Splitter layout_width="match_parent" lh="fixed" lw8="1" splitter-partition="50%"> |
| 45 | <treeview lw="fixed" lh="mp" /> |
| 46 | <tableview lw="fixed" lh="mp" /> |
| 47 | </Splitter> |
| 48 | </vbox> |
| 49 | )xml"; |
| 50 | UIWidget* cont = sceneNode->loadLayoutFromString( WIDGET_LAYOUT, uiWin->getContainer() ); |
| 51 | UITreeView* widgetTree = cont->findByType<UITreeView>( UI_TYPE_TREEVIEW ); |
| 52 | widgetTree->on( Event::OnRowCreated, [sceneNode]( const Event* event ) { |
| 53 | UITableRow* row = event->asRowCreatedEvent()->getRow(); |
| 54 | row->on( Event::MouseOver, [row, sceneNode]( const Event* ) { |
| 55 | if ( lastModelIndex.isValid() && lastModelIndex != row->getCurIndex() && |
| 56 | sceneNode->getRoot()->inNodeTree( lastModelIndex.ref<UINode>() ) ) { |
| 57 | lastModelIndex.ref<UINode>()->unsetFlags( UI_HIGHLIGHT ); |
| 58 | } |
| 59 | if ( row->getCurIndex().internalData() && row->getCurIndex().ref<Node>()->isUINode() ) { |
| 60 | row->getCurIndex().ref<UINode>()->setFlags( UI_HIGHLIGHT ); |
| 61 | lastModelIndex = row->getCurIndex(); |
| 62 | } |
| 63 | } ); |
| 64 | row->on( Event::MouseLeave, [row, sceneNode]( const Event* ) { |
| 65 | if ( row->getCurIndex().internalData() && |
| 66 | sceneNode->getRoot()->inNodeTree( row->getCurIndex().ref<UINode>() ) && |
| 67 | row->getCurIndex().ref<Node>()->isUINode() ) |
| 68 | row->getCurIndex().ref<UINode>()->unsetFlags( UI_HIGHLIGHT ); |
| 69 | } ); |
| 70 | } ); |
| 71 | widgetTree->setHeadersVisible( true ); |
| 72 | widgetTree->setExpanderIconSize( menuIconSize ); |
| 73 | widgetTree->setAutoColumnsWidth( true ); |
| 74 | auto model = WidgetTreeModel::New( sceneNode ); |
| 75 | widgetTree->setModel( model ); |
| 76 | widgetTree->tryOpenModelIndex( model->getRoot() ); |
nothing calls this directly
no test coverage detected