diff --git a/include/eepp/ui/uitooltip.hpp b/include/eepp/ui/uitooltip.hpp index 75cedf083..450520f72 100644 --- a/include/eepp/ui/uitooltip.hpp +++ b/include/eepp/ui/uitooltip.hpp @@ -16,7 +16,7 @@ class EE_API UITooltip : public UIWidget { public: static UITooltip* New(); - static Vector2f getTooltipPosition( UITooltip* toolip, const Vector2f& requestedPosition ); + static Vector2f getTooltipPosition( UIWidget* toolip, const Vector2f& requestedPosition ); UITooltip(); diff --git a/src/eepp/ui/uitooltip.cpp b/src/eepp/ui/uitooltip.cpp index 24e9c3ac2..4e7050616 100644 --- a/src/eepp/ui/uitooltip.cpp +++ b/src/eepp/ui/uitooltip.cpp @@ -14,7 +14,7 @@ UITooltip* UITooltip::New() { return eeNew( UITooltip, () ); } -Vector2f UITooltip::getTooltipPosition( UITooltip* toolip, const Vector2f& requestedPosition ) { +Vector2f UITooltip::getTooltipPosition( UIWidget* toolip, const Vector2f& requestedPosition ) { UISceneNode* uiSceneNode = toolip->getUISceneNode(); if ( NULL == uiSceneNode ) @@ -259,7 +259,8 @@ void UITooltip::onAutoSize() { } void UITooltip::autoAlign() { - if ( mTextCache == nullptr ) return; + if ( mTextCache == nullptr ) + return; Uint32 Width = mSize.getWidth() - mPaddingPx.Left - mPaddingPx.Right; Uint32 Height = mSize.getHeight() - mPaddingPx.Top - mPaddingPx.Bottom; diff --git a/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.cpp b/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.cpp index 45dadba09..3131c3239 100644 --- a/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.cpp +++ b/src/tools/ecode/plugins/debugger/dap/debuggerclientdap.cpp @@ -151,8 +151,8 @@ void DebuggerClientDap::requestLaunchCommand() { void DebuggerClientDap::requestInitialize() { const nlohmann::json capabilities{ - { DAP_CLIENT_ID, "ecode-dap" }, - { DAP_CLIENT_NAME, "ecode dap" }, + { DAP_CLIENT_ID, "ecode" }, + { DAP_CLIENT_NAME, "ecode" }, { DAP_LOCALE, mProtocol.locale }, { DAP_ADAPTER_ID, "ecode-dap" }, { DAP_LINES_START_AT1, mProtocol.linesStartAt1 }, diff --git a/src/tools/ecode/plugins/debugger/debuggerplugin.cpp b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp index cf0ff3e03..b7d969145 100644 --- a/src/tools/ecode/plugins/debugger/debuggerplugin.cpp +++ b/src/tools/ecode/plugins/debugger/debuggerplugin.cpp @@ -904,6 +904,10 @@ void DebuggerPlugin::buildStatusBar() { mExpressionsHolder = std::make_shared( getUISceneNode() ); resetExpressions(); } + + if ( !mHoverExpressionsHolder ) { + mHoverExpressionsHolder = std::make_shared( getUISceneNode() ); + } } void DebuggerPlugin::updateSidePanelTab() { @@ -2021,64 +2025,77 @@ static Action::UniqueID getMouseMoveHash( UICodeEditor* editor ) { reinterpret_cast( editor ) ); } -void DebuggerPlugin::hideTooltip( UICodeEditor* editor ) { - UITooltip* tooltip = nullptr; - if ( editor && ( tooltip = editor->getTooltip() ) && tooltip->isVisible() && - tooltip->getData() == String::hash( "debugger" ) ) { - editor->setTooltipText( "" ); - tooltip->hide(); - // Restore old tooltip state - tooltip->setData( 0 ); - tooltip->setFontStyle( mOldTextStyle ); - tooltip->setHorizontalAlign( mOldTextAlign ); - tooltip->setUsingCustomStyling( mOldUsingCustomStyling ); - tooltip->setDontAutoHideOnMouseMove( mOldDontAutoHideOnMouseMove ); - tooltip->setBackgroundColor( mOldBackgroundColor ); - tooltip->setWordWrap( mOldWordWrap ); - tooltip->setMaxWidthEq( mOldMaxWidth ); - } +void DebuggerPlugin::hideTooltip( UICodeEditor* ) { + // if ( mHoverTooltip ) { + // mHoverTooltip->hide(); + // } } -void DebuggerPlugin::displayTooltip( UICodeEditor* editor, const EvaluateInfo& resp, - const Vector2f& position ) { - // HACK: Gets the old font style to restore it when the tooltip is hidden - UITooltip* tooltip = editor->createTooltip(); - if ( tooltip == nullptr ) - return; - mOldWordWrap = tooltip->isWordWrap(); - mOldMaxWidth = tooltip->getMaxWidthEq(); - tooltip->setWordWrap( true ); - tooltip->setMaxWidthEq( "50vw" ); - editor->setTooltipText( resp.result ); - mOldTextStyle = tooltip->getFontStyle(); - mOldTextAlign = tooltip->getHorizontalAlign(); - mOldDontAutoHideOnMouseMove = tooltip->dontAutoHideOnMouseMove(); - mOldUsingCustomStyling = tooltip->getUsingCustomStyling(); - mOldBackgroundColor = tooltip->getBackgroundColor(); - if ( Color::Transparent == mOldBackgroundColor ) { - tooltip->reloadStyle( true, true, true, true ); - mOldBackgroundColor = tooltip->getBackgroundColor(); - } - tooltip->setHorizontalAlign( UI_HALIGN_LEFT ); - tooltip->setPixelsPosition( tooltip->getTooltipPosition( position ) ); - tooltip->setDontAutoHideOnMouseMove( true ); - tooltip->setUsingCustomStyling( true ); - tooltip->setFontStyle( Text::Regular ); - tooltip->setData( String::hash( "debugger" ) ); - tooltip->setBackgroundColor( editor->getColorScheme().getEditorColor( "background"_sst ) ); - tooltip->getUIStyle()->setStyleSheetProperty( StyleSheetProperty( - "background-color", - editor->getColorScheme().getEditorColor( "background"_sst ).toHexString(), true, - StyleSheetSelectorRule::SpecificityImportant ) ); - - if ( tooltip->getText().empty() ) - return; +void DebuggerPlugin::displayTooltip( UICodeEditor* editor, const std::string& expression, + const EvaluateInfo& info, const Vector2f& position ) { + if ( mHoverTooltip == nullptr ) { + UIWindow* win = + UIWindow::NewOpt( UIMessageBox::WindowBaseContainerType::VERTICAL_LINEAR_LAYOUT ); + win->setMinWindowSize( 400, 250 ); + win->setKeyBindingCommand( "closeWindow", [this, win, editor] { + win->closeWindow(); + if ( getPluginContext()->getSplitter() && + getPluginContext()->getSplitter()->editorExists( editor ) ) + editor->setFocus(); + } ); + win->getKeyBindings().addKeybind( { KEY_ESCAPE }, "closeWindow" ); + win->setWindowFlags( UI_WIN_NO_DECORATION | UI_WIN_SHADOW | UI_WIN_EPHEMERAL ); + win->center(); + win->on( Event::OnWindowClose, [this]( auto ) { mHoverTooltip = nullptr; } ); + win->on( Event::OnWindowReady, [win]( auto ) { win->setFocus(); } ); + + UITreeView* tv = UITreeView::New(); + tv->setHeadersVisible( false ); + tv->setAutoExpandOnSingleColumn( true ); + tv->setAutoColumnsWidth( true ); + tv->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::Fixed ); + tv->setLayoutWeight( 1 ); + tv->setParent( win->getContainer() ); + tv->setModel( mHoverExpressionsHolder->getModel() ); + tv->expandAll(); + tv->setFocusOnSelection( false ); + + tv->on( Event::OnModelEvent, [this]( const Event* event ) { + const ModelEvent* modelEvent = static_cast( event ); + if ( mDebugger && mListener && + modelEvent->getModelEventType() == Abstract::ModelEventType::OpenTree ) { + ModelVariableNode* node = + static_cast( modelEvent->getModelIndex().internalData() ); + mDebugger->variables( + node->var.variablesReference, Variable::Type::Both, + [this]( const int variablesReference, std::vector&& vars ) { + mHoverExpressionsHolder->addVariables( variablesReference, + std::move( vars ) ); + } ); + } + } ); + + mHoverTooltip = win; + } + + mHoverExpressionsHolder->clear( true ); + + Variable var; + var.evaluateName = expression; + var.name = std::move( expression ); + var.value = info.result; + var.type = info.type; + var.variablesReference = info.variablesReference; + var.indexedVariables = info.indexedVariables; + var.namedVariables = info.namedVariables; + var.memoryReference = info.memoryReference; + mHoverExpressionsHolder->upsertRootChild( std::move( var ) ); - tooltip->notifyTextChangedFromTextCache(); + mHoverTooltip->setData( String::hash( "debugger" ) ); + mHoverTooltip->setPixelsPosition( UITooltip::getTooltipPosition( mHoverTooltip, position ) ); - if ( editor->hasFocus() && !tooltip->isVisible() && - !tooltip->getTextCache()->getString().empty() ) - tooltip->show(); + if ( editor->hasFocus() && !mHoverTooltip->isVisible() ) + mHoverTooltip->showWhenReady(); } void DebuggerPlugin::tryHideTooltip( UICodeEditor* editor, const Vector2i& position ) { @@ -2126,10 +2143,12 @@ bool DebuggerPlugin::onMouseMove( UICodeEditor* editor, const Vector2i& position mDebugger->evaluate( expression, "hover", mListener->getCurrentFrameId(), - [this, editor]( const std::string&, const std::optional& info ) { + [this, editor, expression]( const std::string&, + const std::optional& info ) { if ( info && mManager->getSplitter()->editorExists( editor ) && !info->result.empty() ) { - editor->runOnMainThread( [this, editor, info = std::move( *info )]() { + editor->runOnMainThread( [this, editor, info = std::move( *info ), + expression]() { auto mousePos = editor->getUISceneNode()->getWindow()->getInput()->getMousePos(); if ( !editor->getScreenRect().contains( mousePos.asFloat() ) ) @@ -2141,7 +2160,7 @@ bool DebuggerPlugin::onMouseMove( UICodeEditor* editor, const Vector2i& position if ( mCurrentHover.contains( range ) ) { mCurrentHover = range; - displayTooltip( editor, info, mousePos.asFloat() ); + displayTooltip( editor, expression, info, mousePos.asFloat() ); } } ); } diff --git a/src/tools/ecode/plugins/debugger/debuggerplugin.hpp b/src/tools/ecode/plugins/debugger/debuggerplugin.hpp index db4196dfa..861f03088 100644 --- a/src/tools/ecode/plugins/debugger/debuggerplugin.hpp +++ b/src/tools/ecode/plugins/debugger/debuggerplugin.hpp @@ -105,19 +105,14 @@ class DebuggerPlugin : public PluginBase { StatusDebuggerController::State mDebuggingState{ StatusDebuggerController::State::NotStarted }; std::vector mExpressions; std::shared_ptr mExpressionsHolder; + std::shared_ptr mHoverExpressionsHolder; UnorderedMap mDapInputs; // Begin Hover Stuff Uint32 mHoverWaitCb{ 0 }; TextRange mCurrentHover; Time mHoverDelay{ Seconds( 1.f ) }; - bool mOldDontAutoHideOnMouseMove{ false }; - bool mOldUsingCustomStyling{ false }; - bool mOldWordWrap{ false }; - Uint32 mOldTextStyle{ 0 }; - Uint32 mOldTextAlign{ 0 }; - Color mOldBackgroundColor; - std::string mOldMaxWidth; + UIWindow* mHoverTooltip{ nullptr }; // End hover stuff struct PanelBoxButtons { @@ -210,7 +205,8 @@ class DebuggerPlugin : public PluginBase { void hideTooltip( UICodeEditor* editor ); - void displayTooltip( UICodeEditor* editor, const EvaluateInfo& resp, const Vector2f& position ); + void displayTooltip( UICodeEditor* editor, const std::string& expression, + const EvaluateInfo& info, const Vector2f& position ); void tryHideTooltip( UICodeEditor* editor, const Vector2i& position );