{"id":173,"date":"2019-04-28T08:23:47","date_gmt":"2019-04-28T08:23:47","guid":{"rendered":"https:\/\/docs.sisus.co\/power-inspector\/?p=173"},"modified":"2019-09-16T16:06:12","modified_gmt":"2019-09-16T16:06:12","slug":"drawers-for-class-members","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/power-inspector\/extending-power-inspector\/drawers-for-class-members\/","title":{"rendered":"05. Drawers For Class Members"},"content":{"rendered":"<h1>Extending A Base Class<\/h1>\n<p>For most drawer that represent class members, you have to base classes you can inherit from that implement the <strong>IFieldDrawer<\/strong> interface.<\/p>\n<h2><strong>1. PrefixControlComboDrawer<\/strong><\/h2>\n<p>For simple class members that don&#8217;t have any member drawers and consist only of a prefix label and a single control, you can derive from PrefixControlComboDrawer.<\/p>\n<pre><strong>Example: <\/strong>ToggleDrawer<\/pre>\n<h2><strong>2. ParentFieldDrawer<\/strong><\/h2>\n<p>For more complex class members that have one or more member drawers, you can derive from ParentFieldDrawer.<\/p>\n<pre><strong>Example: <\/strong>Vector3Drawer<\/pre>\n<h1>DrawerForFieldAttribute<\/h1>\n<p>For Power Inspector to know which elements inside the inspector should be handled by your drawer, you&#8217;ll need to add the DrawerForField attribute to the class.<\/p>\n<p>Here is an example of the attribute being used:<\/p>\n<pre>\/\/\/ &lt;summary&gt;\r\n\/\/\/ Draws a toggle control which can be backed by a boolean field or property.\r\n\/\/\/ &lt;\/summary&gt;\r\n[Serializable, DrawerForField(typeof(bool))]\r\npublic class ToggleDrawer : PrefixControlComboDrawer&lt;bool&gt;<\/pre>\n<h1><strong>Setup<\/strong><\/h1>\n<p>When Power Inspector prepares a drawer for use inside an Inspector, it will call two methods inside the drawer class:<\/p>\n<ol>\n<li>First, it will call the <strong>SetupInterface<\/strong> method (as defined in the IFieldDrawer interface).<\/li>\n<li>After that has finished, it will call the <strong>LateSetup<\/strong> method (as defined in the base IDrawer interface).<\/li>\n<\/ol>\n<p>All drawer class also contain a <strong>Setup<\/strong> method. The only job of the <strong>SetupInterface <\/strong>method is to take the parameters provided by Power Inspector, and to convert them into a form that the main Setup method can accept, and then call that Setup method.<\/p>\n<p>You can <strong>override<\/strong> the Setup and LateSetup methods if you want to customize the setup phase.<\/p>\n<pre><strong>IMPORTANT:<\/strong> If you override Setup or LateSetup, remember to always also call <strong>base.Setup <\/strong>and <strong>base.LateSetup<\/strong><strong>!<\/strong><\/pre>\n<h1>DoGenerateMemberBuildList<\/h1>\n<p>When extending the ParentFieldDrawer, you can override the DoGenerateMemberBuildList method to gain control over which members to include inside the drawer. This is done through deciding which LinkedMemberInfos are placed inside the memberBuildList.<\/p>\n<h1>DoBuildMembers<\/h1>\n<p>You can also override DoBuildMembers of ParentFieldDrawer to customize exactly how member drawers are built from the memberBuildList that was previously generated by the DoGenerateMemberBuildList method.<\/p>\n<p>During the execution of this method all member drawers should be created and placed into the members array.<\/p>\n<p>You can use ParentDrawerUtility.BuildMembers to automatically generate members based on the contents of the memberBuildList.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Extending A Base Class For most drawer that represent class members, you have to base classes you can inherit from that implement the IFieldDrawer interface. 1. PrefixControlComboDrawer For simple class members that don&#8217;t have any member drawers and consist only of a prefix label and a single control, you can derive from PrefixControlComboDrawer. Example: ToggleDrawer ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/power-inspector\/extending-power-inspector\/drawers-for-class-members\/\" title=\"read more\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/173"}],"collection":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/comments?post=173"}],"version-history":[{"count":12,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/173\/revisions"}],"predecessor-version":[{"id":1032,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/173\/revisions\/1032"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/media?parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/categories?post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/tags?post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}