Druid-Extension/docs/modules/DruidEvent.html
2023-08-05 20:10:32 +03:00

327 lines
9.4 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Defold Druid UI Framework</title>
<link rel="stylesheet" href="../ldoc_fixed.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>Druid</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions</a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/BackHandler.html">BackHandler</a></li>
<li><a href="../modules/BaseComponent.html">BaseComponent</a></li>
<li><a href="../modules/Blocker.html">Blocker</a></li>
<li><a href="../modules/Button.html">Button</a></li>
<li><a href="../modules/Checkbox.html">Checkbox</a></li>
<li><a href="../modules/CheckboxGroup.html">CheckboxGroup</a></li>
<li><a href="../modules/DataList.html">DataList</a></li>
<li><a href="../modules/Drag.html">Drag</a></li>
<li><a href="../modules/Druid.html">Druid</a></li>
<li><strong>DruidEvent</strong></li>
<li><a href="../modules/DruidInstance.html">DruidInstance</a></li>
<li><a href="../modules/DynamicGrid.html">DynamicGrid</a></li>
<li><a href="../modules/Helper.html">Helper</a></li>
<li><a href="../modules/Hotkey.html">Hotkey</a></li>
<li><a href="../modules/Hover.html">Hover</a></li>
<li><a href="../modules/Input.html">Input</a></li>
<li><a href="../modules/LangText.html">LangText</a></li>
<li><a href="../modules/Layout.html">Layout</a></li>
<li><a href="../modules/PinKnob.html">PinKnob</a></li>
<li><a href="../modules/Progress.html">Progress</a></li>
<li><a href="../modules/RadioGroup.html">RadioGroup</a></li>
<li><a href="../modules/RichInput.html">RichInput</a></li>
<li><a href="../modules/RichText.html">RichText</a></li>
<li><a href="../modules/Scroll.html">Scroll</a></li>
<li><a href="../modules/Slider.html">Slider</a></li>
<li><a href="../modules/StaticGrid.html">StaticGrid</a></li>
<li><a href="../modules/Swipe.html">Swipe</a></li>
<li><a href="../modules/Text.html">Text</a></li>
<li><a href="../modules/Timer.html">Timer</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>DruidEvent</code></h1>
<p>Druid Event Module
<p> The Event module provides a simple class for handling callbacks.</p>
<p> It is used in many Druid components.
<p> You can subscribe to an event using the `:subscribe` method and unsubscribe using the `:unsubscribe` method.</p>
<h2><a href="#Functions">Functions</a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#clear">clear(self)</a></td>
<td class="summary">Clear the all event handlers</td>
</tr>
<tr>
<td class="name" nowrap><a href="#initialize">initialize(self[, initial_callback])</a></td>
<td class="summary">DruidEvent constructor</td>
</tr>
<tr>
<td class="name" nowrap><a href="#is_exist">is_exist(self)</a></td>
<td class="summary">Return true, if event have at lease one handler</td>
</tr>
<tr>
<td class="name" nowrap><a href="#subscribe">subscribe(self, callback[, context])</a></td>
<td class="summary">Subscribe callback on event</td>
</tr>
<tr>
<td class="name" nowrap><a href="#trigger">trigger(self, ...)</a></td>
<td class="summary">Trigger the event and call all subscribed callbacks</td>
</tr>
<tr>
<td class="name" nowrap><a href="#unsubscribe">unsubscribe(self, callback[, context])</a></td>
<td class="summary">Unsubscribe callback on event</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions</h2>
<dl class="function">
<dt>
<a name = "clear"></a>
<strong>clear(self)</strong>
</dt>
<dd>
Clear the all event handlers
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example">button.on_long_click:clear()</pre>
</ul>
</dd>
<dt>
<a name = "initialize"></a>
<strong>initialize(self[, initial_callback])</strong>
</dt>
<dd>
DruidEvent constructor
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
<li><span class="parameter">initial_callback</span>
<span class="types"><span class="type">function</span></span>
Subscribe the callback on new event, if callback exist
(<em>optional</em>)
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> Event = <span class="global">require</span>(<span class="string">"druid.event"</span>)
...
<span class="keyword">local</span> event = Event(initial_callback)</pre>
</ul>
</dd>
<dt>
<a name = "is_exist"></a>
<strong>is_exist(self)</strong>
</dt>
<dd>
Return true, if event have at lease one handler
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">bool</span></span>
True if event have handlers
</ol>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> is_long_click_handler_exists = button.on_long_click:is_exist()</pre>
</ul>
</dd>
<dt>
<a name = "subscribe"></a>
<strong>subscribe(self, callback[, context])</strong>
</dt>
<dd>
Subscribe callback on event
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
<li><span class="parameter">callback</span>
<span class="types"><span class="type">function</span></span>
Callback itself
</li>
<li><span class="parameter">context</span>
<span class="types"><span class="type">Any</span></span>
Additional context as first param to callback call, usually it's self
(<em>optional</em>)
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> <span class="keyword">function</span> on_long_callback(self)
<span class="global">print</span>(<span class="string">"Long click!"</span>)
<span class="keyword">end</span>
...
<span class="keyword">local</span> button = self.druid:new_button(<span class="string">"button"</span>, callback)
button.on_long_click:subscribe(on_long_callback, self)</pre>
</ul>
</dd>
<dt>
<a name = "trigger"></a>
<strong>trigger(self, ...)</strong>
</dt>
<dd>
Trigger the event and call all subscribed callbacks
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
<li><span class="parameter">...</span>
<span class="types"><span class="type">Any</span></span>
All event params
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> Event = <span class="global">require</span>(<span class="string">"druid.event"</span>)
...
<span class="keyword">local</span> event = Event()
event:trigger(<span class="string">"Param1"</span>, <span class="string">"Param2"</span>)</pre>
</ul>
</dd>
<dt>
<a name = "unsubscribe"></a>
<strong>unsubscribe(self, callback[, context])</strong>
</dt>
<dd>
Unsubscribe callback on event
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">self</span>
<span class="types"><span class="type">DruidEvent</span></span>
<a href="../modules/DruidEvent.html#">DruidEvent</a>
</li>
<li><span class="parameter">callback</span>
<span class="types"><span class="type">function</span></span>
Callback itself
</li>
<li><span class="parameter">context</span>
<span class="types"><span class="type">Any</span></span>
Additional context as first param to callback call
(<em>optional</em>)
</li>
</ul>
<h3>Usage:</h3>
<ul>
<pre class="example"><span class="keyword">local</span> <span class="keyword">function</span> on_long_callback(self)
<span class="global">print</span>(<span class="string">"Long click!"</span>)
<span class="keyword">end</span>
...
button.on_long_click:unsubscribe(on_long_callback, self)</pre>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc TESTING</a></i>
<i style="float:right;">Last updated 2015-01-01 12:00:00 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>