MCPcopy Create free account
hub / github.com/SpartanJ/eepp / addInteractiveNotification

Method addInteractiveNotification

src/tools/ecode/notificationcenter.cpp:99–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97}
98
99void NotificationCenter::addInteractiveNotification( String text, String actionText,
100 std::function<void()> onInteraction,
101 const Time& delay, bool allowCopy ) {
102 auto action = [this, text = std::move( text ), actionText = std::move( actionText ), delay,
103 allowCopy, onInteraction = std::move( onInteraction )]() {
104 static const auto layout = R"xml(
105 <vbox lw="mp" class="notification">
106 <TextView lw="mp" wordwrap="true" />
107 <hbox lg="right">
108 <PushButton />
109 </hbox>
110 </vbox>
111 )xml";
112 UILinearLayout* lay = mLayout->getUISceneNode()
113 ->loadLayoutFromString( layout, mLayout )
114 ->asType<UILinearLayout>();
115 UITextView* tv = lay->findByType( UI_TYPE_TEXTVIEW )->asType<UITextView>();
116 tv->setText( text );
117 tv->setTextSelectionEnabled( allowCopy );
118 tv->on( Event::MouseClick, [allowCopy, lay]( const Event* event ) {
119 const MouseEvent* mouseEvent = static_cast<const MouseEvent*>( event );
120 if ( mouseEvent->getFlags() &
121 ( allowCopy ? EE_BUTTON_MMASK : ( EE_BUTTON_LMASK | EE_BUTTON_RMASK ) ) )
122 lay->close();
123 } );
124 UIPushButton* pb = lay->findByType( UI_TYPE_PUSHBUTTON )->asType<UIPushButton>();
125 pb->setText( actionText );
126 pb->onClick( [actionText, onInteraction = std::move( onInteraction )]( const MouseEvent* ) {
127 if ( onInteraction )
128 onInteraction();
129 } );
130 Action* sequence = Actions::Sequence::New(
131 { Actions::FadeIn::New( Seconds( 0.125 ) ), Actions::Delay::New( delay ),
132 Actions::FadeOut::New( Seconds( 0.125 ) ), Actions::Close::New() } );
133 mLayout->toFront();
134 lay->runAction( sequence );
135 };
136
137 mLayout->ensureMainThread( action );
138}
139
140} // namespace ecode

Callers 1

Calls 14

SecondsFunction · 0.85
loadLayoutFromStringMethod · 0.80
findByTypeMethod · 0.80
getFlagsMethod · 0.80
toFrontMethod · 0.80
runActionMethod · 0.80
ensureMainThreadMethod · 0.80
closeMethod · 0.65
NewFunction · 0.50
getUISceneNodeMethod · 0.45
setTextMethod · 0.45

Tested by

no test coverage detected