説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

UniWebViewEmbeddedToolbar.cs 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using UnityEngine;
  2. /// <summary>
  3. /// Represents the embedded toolbar in a web view.
  4. ///
  5. /// You do not create an instance of this class directly. Instead, use the `EmbeddedWebView` property in `UniWebView` to
  6. /// get the current embedded toolbar in the web view and interact with it.
  7. ///
  8. /// The embedded toolbar of a web view expands its width to match the web view's frame width. It is displayed at either
  9. /// top or bottom of the web view, based on the setting received through `SetPosition`. By default, the toolbar contains
  10. /// a main title, a back button, a forward button and a done button to close the web view. You can use methods in this
  11. /// class to customize the toolbar to match your app's style.
  12. /// </summary>
  13. public class UniWebViewEmbeddedToolbar {
  14. private readonly UniWebViewNativeListener listener;
  15. internal UniWebViewEmbeddedToolbar(UniWebViewNativeListener listener) {
  16. this.listener = listener;
  17. }
  18. /// <summary>
  19. /// Sets the position of the embedded toolbar. You can put the toolbar at either top or bottom of your web view.
  20. /// The default position is `Top`.
  21. /// </summary>
  22. /// <param name="position">The desired position of the toolbar.</param>
  23. public void SetPosition(UniWebViewToolbarPosition position) {
  24. UniWebViewInterface.SetEmbeddedToolbarOnTop(listener.Name, position == UniWebViewToolbarPosition.Top);
  25. }
  26. /// <summary>
  27. /// Shows the toolbar.
  28. /// </summary>
  29. public void Show() {
  30. UniWebViewInterface.SetShowEmbeddedToolbar(listener.Name, true);
  31. }
  32. /// <summary>
  33. /// Hides the toolbar.
  34. /// </summary>
  35. public void Hide() {
  36. UniWebViewInterface.SetShowEmbeddedToolbar(listener.Name, false);
  37. }
  38. /// <summary>
  39. /// Sets the text of the done button. The default text is "Done".
  40. /// </summary>
  41. /// <param name="text">The desired text to display as the done button.</param>
  42. public void SetDoneButtonText(string text) {
  43. UniWebViewInterface.SetEmbeddedToolbarDoneButtonText(listener.Name, text);
  44. }
  45. /// <summary>
  46. /// Sets the text of the back button. The default text is "❮" ("\u276E").
  47. /// </summary>
  48. /// <param name="text">The desired text to display as the back button.</param>
  49. public void SetGoBackButtonText(string text) {
  50. UniWebViewInterface.SetEmbeddedToolbarGoBackButtonText(listener.Name, text);
  51. }
  52. /// <summary>
  53. /// Sets the text of the forward button. The default text is "❯" ("\u276F").
  54. /// </summary>
  55. /// <param name="text">The desired text to display as the forward button.</param>
  56. public void SetGoForwardButtonText(string text) {
  57. UniWebViewInterface.SetEmbeddedToolbarGoForwardButtonText(listener.Name, text);
  58. }
  59. /// <summary>
  60. /// Sets the text of toolbar title. The default is empty. The space is limited, setting a long text as title might
  61. /// not fit in the space.
  62. /// </summary>
  63. /// <param name="text">The desired text to display as the title in the toolbar.</param>
  64. public void SetTitleText(string text) {
  65. UniWebViewInterface.SetEmbeddedToolbarTitleText(listener.Name, text);
  66. }
  67. /// <summary>
  68. /// Sets the background color of the toolbar.
  69. /// </summary>
  70. /// <param name="color">The desired color of toolbar's background.</param>
  71. public void SetBackgroundColor(Color color) {
  72. UniWebViewInterface.SetEmbeddedToolbarBackgroundColor(listener.Name, color);
  73. }
  74. /// <summary>
  75. /// Sets the buttons color of the toolbar. This color affects the back, forward and done button.
  76. /// </summary>
  77. /// <param name="color">The desired color of toolbar's buttons.</param>
  78. public void SetButtonTextColor(Color color) {
  79. UniWebViewInterface.SetEmbeddedToolbarButtonTextColor(listener.Name, color);
  80. }
  81. /// <summary>
  82. /// Sets the text color of the toolbar title.
  83. /// </summary>
  84. /// <param name="color">The desired color of the toolbar's title.</param>
  85. public void SetTitleTextColor(Color color) {
  86. UniWebViewInterface.SetEmbeddedToolbarTitleTextColor(listener.Name, color);
  87. }
  88. /// <summary>
  89. /// Hides the navigation buttons on the toolbar.
  90. ///
  91. /// When called, the back button and forward button will not be shown.
  92. /// By default, the navigation buttons are shown.
  93. /// </summary>
  94. public void HideNavigationButtons() {
  95. UniWebViewInterface.SetEmeddedToolbarNavigationButtonsShow(listener.Name, false);
  96. }
  97. /// <summary>
  98. /// Shows the navigation buttons on the toolbar.
  99. ///
  100. /// When called, the back button and forward button will be shown.
  101. /// By default, the navigation buttons are shown.
  102. /// </summary>
  103. public void ShowNavigationButtons() {
  104. UniWebViewInterface.SetEmeddedToolbarNavigationButtonsShow(listener.Name, true);
  105. }
  106. }