Files
FTXUI/collapsible_8cpp_source.html
2025-04-30 10:23:00 +00:00

189 lines
21 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- HTML header for doxygen 1.8.14-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="cache-control" content="max-age=86400"/>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FTXUI: src/ftxui/component/collapsible.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen_extra.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">FTXUI
&#160;<span id="projectnumber">6.1.1</span>
</div>
<div id="projectbrief">C++ functional terminal UI.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.8 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function() { init_codefold(0); });
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('collapsible_8cpp_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="headertitle"><div class="title">collapsible.cpp</div></div>
</div><!--header-->
<div class="contents">
<a href="collapsible_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span><span class="comment">// Copyright 2021 Arthur Sonzogni. All rights reserved.</span></div>
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno"> 2</span><span class="comment">// Use of this source code is governed by the MIT license that can be found in</span></div>
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno"> 3</span><span class="comment">// the LICENSE file.</span></div>
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno"> 4</span><span class="preprocessor">#include &lt;functional&gt;</span> <span class="comment">// for function</span></div>
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno"> 5</span><span class="preprocessor">#include &lt;utility&gt;</span> <span class="comment">// for move</span></div>
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno"> 6</span> </div>
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno"> 7</span><span class="preprocessor">#include &quot;<a class="code" href="component_8hpp.html">ftxui/component/component.hpp</a>&quot;</span> <span class="comment">// for Checkbox, Maybe, Make, Vertical, Collapsible</span></div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno"> 8</span><span class="preprocessor">#include &quot;<a class="code" href="component__base_8hpp.html">ftxui/component/component_base.hpp</a>&quot;</span> <span class="comment">// for Component, ComponentBase</span></div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno"> 9</span><span class="preprocessor">#include &quot;<a class="code" href="component__options_8hpp.html">ftxui/component/component_options.hpp</a>&quot;</span> <span class="comment">// for CheckboxOption, EntryState</span></div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"> 10</span><span class="preprocessor">#include &quot;<a class="code" href="elements_8hpp.html">ftxui/dom/elements.hpp</a>&quot;</span> <span class="comment">// for operator|=, text, hbox, Element, bold, inverted</span></div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span><span class="preprocessor">#include &quot;<a class="code" href="ref_8hpp.html">ftxui/util/ref.hpp</a>&quot;</span> <span class="comment">// for Ref, ConstStringRef</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span> </div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span><span class="keyword">namespace </span><a class="code hl_namespace" href="namespaceftxui.html">ftxui</a> {</div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span><span class="comment"></span> </div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span><span class="comment">/// @brief A collapsible component. It display a checkbox with an arrow. Once</span></div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span><span class="comment">/// activated, the children is displayed.</span></div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span><span class="comment">/// @param label The label of the checkbox.</span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"> 18</span><span class="comment">/// @param child The children to display.</span></div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span><span class="comment">/// @param show Hold the state about whether the children is displayed or not.</span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span><span class="comment">///</span></div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span><span class="comment">/// ### Example</span></div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span><span class="comment">/// ```cpp</span></div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span><span class="comment">/// auto component = Collapsible(&quot;Show details&quot;, details);</span></div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span><span class="comment">/// ```</span></div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span><span class="comment">///</span></div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span><span class="comment">/// ### Output</span></div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span><span class="comment">/// ```</span></div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span><span class="comment">///</span></div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span><span class="comment">/// ▼ Show details</span></div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span><span class="comment">/// &lt;details component&gt;</span></div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span><span class="comment">///  ```</span></div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span><span class="comment"></span><span class="comment">// NOLINTNEXTLINE</span></div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span><a class="code hl_typedef" href="namespaceftxui.html#a3149fb57ff17207d2516790b82503002">Component</a> <a class="code hl_function" href="namespaceftxui.html#af75c40d83714ba0748a68d11ff5e25dd">Collapsible</a>(ConstStringRef label, <a class="code hl_typedef" href="namespaceftxui.html#a3149fb57ff17207d2516790b82503002">Component</a> <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">child</a>, Ref&lt;bool&gt; <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">show</a>) {</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span> <span class="keyword">class </span><a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">Impl</a> : <span class="keyword">public</span> ComponentBase {</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span> <span class="keyword">public</span>:</div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno"> 36</span> <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">Impl</a>(ConstStringRef label, <a class="code hl_typedef" href="namespaceftxui.html#a3149fb57ff17207d2516790b82503002">Component</a> <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">child</a>, Ref&lt;bool&gt; <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">show</a>) : <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">show_</a>(<a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">show</a>) {</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno"> 37</span> CheckboxOption <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">opt</a>;</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span> <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">opt</a>.transform = [](EntryState s) { <span class="comment">// NOLINT</span></div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span> <span class="keyword">auto</span> <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">prefix</a> = <a class="code hl_function" href="namespaceftxui.html#a75baaa2734ed76a9f478beaafa87ae57">text</a>(s.state ? <span class="stringliteral">&quot;&quot;</span> : <span class="stringliteral">&quot;&quot;</span>); <span class="comment">// NOLINT</span></div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span> <span class="keyword">auto</span> t = <a class="code hl_function" href="namespaceftxui.html#a75baaa2734ed76a9f478beaafa87ae57">text</a>(s.label);</div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span> <span class="keywordflow">if</span> (s.active) {</div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> t |= <a class="code hl_function" href="namespaceftxui.html#a353c769068e25303eb41fa2da565c604">bold</a>;</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> }</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> <span class="keywordflow">if</span> (s.focused) {</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> t |= <a class="code hl_function" href="namespaceftxui.html#a672456b8f2091b615a30ff755418b37b">inverted</a>;</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> }</div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> <span class="keywordflow">return</span> <a class="code hl_function" href="namespaceftxui.html#a552ba6d33b3c9bec586b99fba4c243ac">hbox</a>({<a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">prefix</a>, t});</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span> };</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno"> 49</span> Add(<a class="code hl_function" href="namespaceftxui_1_1Container.html#a6471e39f5664d059144746c5801d37e6">Container::Vertical</a>({</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"> 50</span> <a class="code hl_function" href="namespaceftxui.html#ae0d441d2c83740f187f62db566bbefcd">Checkbox</a>(std::move(label), <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">show_</a>.operator-&gt;(), <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">opt</a>),</div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno"> 51</span> <a class="code hl_function" href="namespaceftxui.html#a20b66a70c1cd4ff3f0ff571a4507d2b4">Maybe</a>(std::move(<a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">child</a>), <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">show_</a>.operator-&gt;()),</div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno"> 52</span> }));</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"> 53</span> }</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> Ref&lt;bool&gt; <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">show_</a>;</div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno"> 55</span> };</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno"> 56</span> </div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno"> 57</span> <span class="keywordflow">return</span> <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">Make&lt;Impl&gt;</a>(std::move(label), std::move(<a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">child</a>), <a class="code hl_function" href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">show</a>);</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span>}</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> </div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span>} <span class="comment">// namespace ftxui</span></div>
<div class="ttc" id="acomponent_8hpp_html"><div class="ttname"><a href="component_8hpp.html">component.hpp</a></div></div>
<div class="ttc" id="acomponent__base_8hpp_html"><div class="ttname"><a href="component__base_8hpp.html">component_base.hpp</a></div></div>
<div class="ttc" id="acomponent__options_8hpp_html"><div class="ttname"><a href="component__options_8hpp.html">component_options.hpp</a></div></div>
<div class="ttc" id="aelements_8hpp_html"><div class="ttname"><a href="elements_8hpp.html">elements.hpp</a></div></div>
<div class="ttc" id="anamespaceftxui_1_1Container_html_a6471e39f5664d059144746c5801d37e6"><div class="ttname"><a href="namespaceftxui_1_1Container.html#a6471e39f5664d059144746c5801d37e6">ftxui::Container::Vertical</a></div><div class="ttdeci">Component Vertical(Components children)</div><div class="ttdoc">A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...</div><div class="ttdef"><b>Definition</b> <a href="container_8cpp_source.html#l00317">container.cpp:317</a></div></div>
<div class="ttc" id="anamespaceftxui_html"><div class="ttname"><a href="namespaceftxui.html">ftxui</a></div><div class="ttdef"><b>Definition</b> <a href="animation_8hpp_source.html#l00010">animation.hpp:10</a></div></div>
<div class="ttc" id="anamespaceftxui_html_a20b66a70c1cd4ff3f0ff571a4507d2b4"><div class="ttname"><a href="namespaceftxui.html#a20b66a70c1cd4ff3f0ff571a4507d2b4">ftxui::Maybe</a></div><div class="ttdeci">Component Maybe(Component, const bool *show)</div><div class="ttdoc">Decorate a component |child|. It is shown only when |show| is true.</div><div class="ttdef"><b>Definition</b> <a href="maybe_8cpp_source.html#l00074">maybe.cpp:74</a></div></div>
<div class="ttc" id="anamespaceftxui_html_a2b8973dc71334f1d98e2e6f55de8b5ae"><div class="ttname"><a href="namespaceftxui.html#a2b8973dc71334f1d98e2e6f55de8b5ae">ftxui::Make</a></div><div class="ttdeci">std::shared_ptr&lt; T &gt; Make(Args &amp;&amp;... args)</div><div class="ttdef"><b>Definition</b> <a href="component_8hpp_source.html#l00026">component.hpp:26</a></div></div>
<div class="ttc" id="anamespaceftxui_html_a3149fb57ff17207d2516790b82503002"><div class="ttname"><a href="namespaceftxui.html#a3149fb57ff17207d2516790b82503002">ftxui::Component</a></div><div class="ttdeci">std::shared_ptr&lt; ComponentBase &gt; Component</div><div class="ttdef"><b>Definition</b> <a href="component__base_8hpp_source.html#l00024">component_base.hpp:24</a></div></div>
<div class="ttc" id="anamespaceftxui_html_a353c769068e25303eb41fa2da565c604"><div class="ttname"><a href="namespaceftxui.html#a353c769068e25303eb41fa2da565c604">ftxui::bold</a></div><div class="ttdeci">Element bold(Element)</div><div class="ttdoc">Use a bold font, for elements with more emphasis.</div><div class="ttdef"><b>Definition</b> <a href="bold_8cpp_source.html#l00033">bold.cpp:33</a></div></div>
<div class="ttc" id="anamespaceftxui_html_a552ba6d33b3c9bec586b99fba4c243ac"><div class="ttname"><a href="namespaceftxui.html#a552ba6d33b3c9bec586b99fba4c243ac">ftxui::hbox</a></div><div class="ttdeci">Element hbox(Elements)</div><div class="ttdoc">A container displaying elements horizontally one by one.</div><div class="ttdef"><b>Definition</b> <a href="hbox_8cpp_source.html#l00094">hbox.cpp:94</a></div></div>
<div class="ttc" id="anamespaceftxui_html_a672456b8f2091b615a30ff755418b37b"><div class="ttname"><a href="namespaceftxui.html#a672456b8f2091b615a30ff755418b37b">ftxui::inverted</a></div><div class="ttdeci">Element inverted(Element)</div><div class="ttdoc">Add a filter that will invert the foreground and the background colors.</div><div class="ttdef"><b>Definition</b> <a href="inverted_8cpp_source.html#l00034">inverted.cpp:34</a></div></div>
<div class="ttc" id="anamespaceftxui_html_a75baaa2734ed76a9f478beaafa87ae57"><div class="ttname"><a href="namespaceftxui.html#a75baaa2734ed76a9f478beaafa87ae57">ftxui::text</a></div><div class="ttdeci">Element text(std::wstring text)</div><div class="ttdoc">Display a piece of unicode text.</div><div class="ttdef"><b>Definition</b> <a href="text_8cpp_source.html#l00160">text.cpp:160</a></div></div>
<div class="ttc" id="anamespaceftxui_html_ae0d441d2c83740f187f62db566bbefcd"><div class="ttname"><a href="namespaceftxui.html#ae0d441d2c83740f187f62db566bbefcd">ftxui::Checkbox</a></div><div class="ttdeci">Component Checkbox(CheckboxOption options)</div><div class="ttdoc">Draw checkable element.</div><div class="ttdef"><b>Definition</b> <a href="checkbox_8cpp_source.html#l00108">checkbox.cpp:108</a></div></div>
<div class="ttc" id="anamespaceftxui_html_af75c40d83714ba0748a68d11ff5e25dd"><div class="ttname"><a href="namespaceftxui.html#af75c40d83714ba0748a68d11ff5e25dd">ftxui::Collapsible</a></div><div class="ttdeci">Component Collapsible(ConstStringRef label, Component child, Ref&lt; bool &gt; show=false)</div></div>
<div class="ttc" id="aref_8hpp_html"><div class="ttname"><a href="ref_8hpp.html">ref.hpp</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.14-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
</div>
</body>
</html>