dlangui/signals.html

269 lines
11 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link href='https://fonts.googleapis.com/css?family=Chivo:900' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen" />
<link rel="stylesheet" type="text/css" href="stylesheets/pygment_trac.css" media="screen" />
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print" />
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<title>DlangUI - cross platform GUI library for D programming language - dlangui.core.signals</title>
</head>
<body>
<div id="container">
<div class="inner">
<header>
<h1>DlangUI</h1>
<h2>Cross Platform GUI for D programming language</h2>
</header>
<section id="downloads" class="clearfix">
<a href="index.html" id="home" class="button"><span>Home</span></a>
<a href="api.html" id="home" class="button"><span>API Docs</span></a>
<a href="screenshots.html" id="home" class="button"><span>Screenshots</span></a>
<a href="https://github.com/buggins/dlangui/zipball/master" id="download-zip" class="button"><span>Download .zip</span></a>
<!--a href="https://github.com/buggins/dlangui/tarball/master" id="download-tar-gz" class="button"><span>Download .tar.gz</span></a-->
<a href="https://github.com/buggins/dlangui" id="view-on-github" class="button"><span>View on GitHub</span></a>
</section>
<hr>
<section id="main_content">
<h1>dlangui.core.signals</h1>
<!-- Generated by Ddoc from src\dlangui\core\signals.d -->
This module contains definition of <u>signals</u> / listeners.
<br><br>
Similar to std.<u>signals</u>.
<br><br>
Unlike std.<u>signals</u>, supports any types of delegates, and as well interfaces with single method.
<br><br>
Unlike std.<u>signals</u>, can support return types for slots.
<br><br>
<b>Caution:</b><br>
unlike std.<u>signals</u>, does not disconnect signal from slots belonging to destroyed objects.
<br><br>
Listener here stand for holder of single delegate (slot).
Signal is the same but supports multiple slots.
<br><br>
Can be declared either using list of result value and argument types, or by interface name with single method.
<br><br>
<br><br>
<b>Synopsis:</b><br>
<pre class="d_code"><font color=blue>import</font> dlangui.core.<u>signals</u>;
<font color=blue>interface</font> SomeInterface {
<font color=blue>bool</font> someMethod(string s, <font color=blue>int</font> n);
}
<font color=blue>class</font> Foo : SomeInterface {
<font color=blue>override</font> <font color=blue>bool</font> someMethod(string s, <font color=blue>int</font> n) {
writeln(<font color=red>"someMethod called "</font>, s, <font color=red>", "</font>, n);
<font color=blue>return</font> n &gt; 10; <font color=green>// can return value
</font> }
}
<font color=green>// Listener! can hold arbitrary number of connected slots
</font>
<font color=green>// declare using list of return value and parameter types
</font>Listener!(<font color=blue>bool</font>, string, n) signal1;
Foo f = <font color=blue>new</font> Foo();
<font color=green>// when signal is defined as type list, you can use delegate
</font>signal1 = <font color=blue>bool</font> <font color=blue>delegate</font>(string s, <font color=blue>int</font> n) { writeln(<font color=red>"inside delegate - "</font>, s, n); <font color=blue>return</font> <font color=blue>false</font>; }
<font color=green>// or method reference
</font>signal1 = &amp;f.someMethod;
<font color=green>// declare using interface with single method
</font>Listener!SomeInterface signal2;
<font color=green>// you still can use any delegate
</font>signal2 = <font color=blue>bool</font> <font color=blue>delegate</font>(string s, <font color=blue>int</font> n) { writeln(<font color=red>"inside delegate - "</font>, s, n); <font color=blue>return</font> <font color=blue>false</font>; }
<font color=green>// but for class method which overrides interface method, you can use simple syntax
</font>signal2 = f; <font color=green>// it will automatically take &amp;f.someMethod
</font>
<font color=green>// call listener(s) either by opcall or explicit emit
</font>signal1(<font color=red>"text"</font>, 1);
signal1.emit(<font color=red>"text"</font>, 2);
signal2.emit(<font color=red>"text"</font>, 3);
<font color=green>// check if any slit is connected
</font><font color=blue>if</font> (signal1.assigned)
writeln(<font color=red>"has listeners"</font>);
<font color=green>// Signal! can hold arbitrary number of connected slots
</font>
<font color=green>// declare using list of return value and parameter types
</font>Signal!(<font color=blue>bool</font>, string, n) signal3;
<font color=green>// add listeners via connect call
</font>signal3.connect(<font color=blue>bool</font> <font color=blue>delegate</font>(string, <font color=blue>int</font>) { <font color=blue>return</font> <font color=blue>false</font>; });
<font color=green>// or via ~= operator
</font>signal3 ~= <font color=blue>bool</font> <font color=blue>delegate</font>(string, <font color=blue>int</font>) { <font color=blue>return</font> <font color=blue>false</font>; };
<font color=green>// declare using interface with single method
</font>Signal!SomeInterface signal4;
<font color=green>// you can connect several slots to signal
</font>signal4 ~= f;
signal4 ~= <font color=blue>bool</font> <font color=blue>delegate</font>(string, <font color=blue>int</font>) { <font color=blue>return</font> <font color=blue>true</font>; }
<font color=green>// calling of listeners of Signal! is similar to Listener!
</font><font color=green>// using opCall
</font><font color=blue>bool</font> res = signal4(<font color=red>"blah"</font>, 5);
<font color=green>// call listeners using emit
</font><font color=blue>bool</font> res = signal4.emit(<font color=red>"blah"</font>, 5);
<font color=green>// you can disconnect individual slots
</font><font color=green>// using disconnect()
</font>signal4.disconnect(f);
<font color=green>// or -= operator
</font>signal4 -= f;
</pre>
<br><br>
<b>License:</b><br>
Boost License 1.0
<br><br>
<b>Authors:</b><br>
Vadim Lopatin, coolreader.org@gmail.com<br><br>
<dl><dt><big><a name="Listener"></a>struct <u>Listener</u>(T1) if (is(T1 == interface) &amp;&amp; __traits(allMembers, T1).length == 1);
</big></dt>
<dd>Single listener; parameter is interface with single method<br><br>
<dl><dt><big><a name="Listener.assigned"></a>final bool <u>assigned</u>();
</big></dt>
<dd>returns <b>true</b> if listener is <u>assigned</u><br><br>
</dd>
<dt><big><a name="Listener.opAssign"></a>final void <u>opAssign</u>(slot_t <i>listenerDelegate</i>);
</big></dt>
<dd>assign delegate<br><br>
</dd>
<dt><big><a name="Listener.opAssign"></a>final void <u>opAssign</u>(T1 <i>listenerObject</i>);
</big></dt>
<dd>assign object implementing interface<br><br>
</dd>
</dl>
</dd>
<dt><big><a name="Listener"></a>struct <u>Listener</u>(RETURN_T, T1...);
</big></dt>
<dd>Single listener; implicitly specified return and parameter types<br><br>
<dl><dt><big><a name="Listener.assigned"></a>final bool <u>assigned</u>();
</big></dt>
<dd>returns <b>true</b> if listener is <u>assigned</u><br><br>
</dd>
</dl>
</dd>
<dt><big><a name="Signal"></a>struct <u>Signal</u>(T1) if (is(T1 == interface) &amp;&amp; __traits(allMembers, T1).length == 1);
</big></dt>
<dd>Multiple listeners; implicitly specified return and parameter types<br><br>
<dl><dt><big><a name="Signal.assigned"></a>final bool <u>assigned</u>();
</big></dt>
<dd>returns <b>true</b> if listener is <u>assigned</u><br><br>
</dd>
<dt><big><a name="Signal.opAssign"></a>final void <u>opAssign</u>(slot_t <i>listener</i>);
</big></dt>
<dd>replace all previously assigned listeners with new one (if <b>null</b> passed, remove all listeners)<br><br>
</dd>
<dt><big><a name="Signal.opAssign"></a>final void <u>opAssign</u>(T1 <i>listener</i>);
</big></dt>
<dd>replace all previously assigned listeners with new one (if <b>null</b> passed, remove all listeners)<br><br>
</dd>
<dt><big><a name="Signal.opCall"></a>final return_t <u>opCall</u>(params_t <i>params</i>);
</big></dt>
<dd>call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero<br><br>
</dd>
<dt><big><a name="Signal.emit"></a>final return_t <u>emit</u>(params_t <i>params</i>);
</big></dt>
<dd>call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero<br><br>
</dd>
<dt><big><a name="Signal.connect"></a>final void <u>connect</u>(slot_t <i>listener</i>);
</big></dt>
<dd>add <i>listener</i><br><br>
</dd>
<dt><big><a name="Signal.disconnect"></a>final void <u>disconnect</u>(slot_t <i>listener</i>);
</big></dt>
<dd>remove <i>listener</i><br><br>
</dd>
<dt><big><a name="Signal.connect"></a>final void <u>connect</u>(T1 <i>listener</i>);
</big></dt>
<dd>add <i>listener</i> - as interface member<br><br>
</dd>
<dt><big><a name="Signal.disconnect"></a>final void <u>disconnect</u>(T1 <i>listener</i>);
</big></dt>
<dd>add <i>listener</i> - as interface member<br><br>
</dd>
</dl>
</dd>
<dt><big><a name="Signal"></a>struct <u>Signal</u>(RETURN_T, T1...);
</big></dt>
<dd>Multiple listeners; implicitly specified return and parameter types<br><br>
<dl><dt><big><a name="Signal.assigned"></a>final bool <u>assigned</u>();
</big></dt>
<dd>returns <b>true</b> if listener is <u>assigned</u><br><br>
</dd>
<dt><big><a name="Signal.opAssign"></a>final void <u>opAssign</u>(slot_t <i>listener</i>);
</big></dt>
<dd>replace all previously assigned listeners with new one (if <b>null</b> passed, remove all listeners)<br><br>
</dd>
<dt><big><a name="Signal.opCall"></a>final RETURN_T <u>opCall</u>(T1 <i>params</i>);
</big></dt>
<dd>call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero<br><br>
</dd>
<dt><big><a name="Signal.emit"></a>final RETURN_T <u>emit</u>(T1 <i>params</i>);
</big></dt>
<dd>call all listeners; for signals having non-void return type, stop iterating when first return value is nonzero<br><br>
</dd>
<dt><big><a name="Signal.connect"></a>final void <u>connect</u>(slot_t <i>listener</i>);
</big></dt>
<dd>add <i>listener</i><br><br>
</dd>
<dt><big><a name="Signal.disconnect"></a>final void <u>disconnect</u>(slot_t <i>listener</i>);
</big></dt>
<dd>remove <i>listener</i><br><br>
</dd>
</dl>
</dd>
</dl>
</section>
<footer>
Dlangui is maintained by <a href="https://github.com/buggins">buggins</a><br>
This page was generated by <a href="http://pages.github.com">GitHub Pages</a>. Tactile theme by <a href="https://twitter.com/jasonlong">Jason Long</a>.
</footer>
</div>
</div>
</body>
</html>