{"id":397,"date":"2013-09-25T05:28:52","date_gmt":"2013-09-25T05:28:52","guid":{"rendered":"http:\/\/www.benbarefield.com\/blog\/?p=397"},"modified":"2013-09-25T05:28:52","modified_gmt":"2013-09-25T05:28:52","slug":"layout-controls-layoutbutton","status":"publish","type":"post","link":"https:\/\/www.benbarefield.com\/blog\/2013\/09\/25\/layout-controls-layoutbutton\/","title":{"rendered":"Layout Controls: LayoutButton"},"content":{"rendered":"<p>LayoutButton is an implementation of LayoutCapable to give layout capabilities to buttons and is attached to an NGUI UIButton.<\/p>\n<p><a href=\"http:\/\/www.benbarefield.com\/blog\/wp-content\/uploads\/2013\/09\/layoutButtonHierarchy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-423\" alt=\"LayoutButton Hierarchy\" src=\"http:\/\/www.benbarefield.com\/blog\/wp-content\/uploads\/2013\/09\/layoutButtonHierarchy.png\" width=\"380\" height=\"46\" srcset=\"https:\/\/www.benbarefield.com\/blog\/wp-content\/uploads\/2013\/09\/layoutButtonHierarchy.png 380w, https:\/\/www.benbarefield.com\/blog\/wp-content\/uploads\/2013\/09\/layoutButtonHierarchy-300x36.png 300w\" sizes=\"auto, (max-width: 380px) 100vw, 380px\" \/><\/a><\/p>\n<p>Just like a normal NGUI button, it has two children: a UISprite background and a UILabel for text. These need to be setup just like a normal NGUI button with the desired atlas, sprite, and font properties before they will display.<\/p>\n<p>LayoutButton does not have any additional properties over LayoutCapable, and the prefab will come with the LayoutCapable Background property already set.<\/p>\n<p><strong>CommandButton and DelegateCommand<\/strong><\/p>\n<p>The LayoutButton prefab also has the Command Button component on it. This allows for binding to the action that happens when the button is clicked. The target path when using a command button in data binding should be\u00a0<strong>Command<\/strong>. <strong>Command<\/strong> is of type DelegateCommand.<\/p>\n<p>DelegateCommand is a class with two properties:<\/p>\n<ul>\n<li><strong>Execute\u00a0<\/strong>is an Action&lt;object&gt;, meaning it can be set to any void method with one argument of type object. This will be called when the button is clicked with the button as the argument.<\/li>\n<li><strong>CanExecute<\/strong> is a Predicate&lt;object&gt;, meaning it can be set to any method that returns bool and has one argument of type object. This is called after the button is clicked but before\u00a0<strong>Execute<\/strong> is called, and is called with the button as its argument. If this returns false,\u00a0<strong>Execute<\/strong>\u00a0will not be called.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>LayoutButton is an implementation of LayoutCapable to give layout capabilities to buttons and is attached to an NGUI UIButton. Just like a normal NGUI button, it has two children: a UISprite background and a UILabel for text. These need to &hellip; <a href=\"https:\/\/www.benbarefield.com\/blog\/2013\/09\/25\/layout-controls-layoutbutton\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-397","post","type-post","status-publish","format-standard","hentry","category-layout-controls"],"_links":{"self":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/posts\/397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/comments?post=397"}],"version-history":[{"count":4,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/posts\/397\/revisions"}],"predecessor-version":[{"id":450,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/posts\/397\/revisions\/450"}],"wp:attachment":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/media?parent=397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/categories?post=397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/tags?post=397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}