using UnityEngine;
///
/// Represents the embedded toolbar in a web view.
///
/// You do not create an instance of this class directly. Instead, use the `EmbeddedWebView` property in `UniWebView` to
/// get the current embedded toolbar in the web view and interact with it.
///
/// The embedded toolbar of a web view expands its width to match the web view's frame width. It is displayed at either
/// top or bottom of the web view, based on the setting received through `SetPosition`. By default, the toolbar contains
/// a main title, a back button, a forward button and a done button to close the web view. You can use methods in this
/// class to customize the toolbar to match your app's style.
///
public class UniWebViewEmbeddedToolbar {
private readonly UniWebViewNativeListener listener;
internal UniWebViewEmbeddedToolbar(UniWebViewNativeListener listener) {
this.listener = listener;
}
///
/// Sets the position of the embedded toolbar. You can put the toolbar at either top or bottom of your web view.
/// The default position is `Top`.
///
/// The desired position of the toolbar.
public void SetPosition(UniWebViewToolbarPosition position) {
UniWebViewInterface.SetEmbeddedToolbarOnTop(listener.Name, position == UniWebViewToolbarPosition.Top);
}
///
/// Shows the toolbar.
///
public void Show() {
UniWebViewInterface.SetShowEmbeddedToolbar(listener.Name, true);
}
///
/// Hides the toolbar.
///
public void Hide() {
UniWebViewInterface.SetShowEmbeddedToolbar(listener.Name, false);
}
///
/// Sets the text of the done button. The default text is "Done".
///
/// The desired text to display as the done button.
public void SetDoneButtonText(string text) {
UniWebViewInterface.SetEmbeddedToolbarDoneButtonText(listener.Name, text);
}
///
/// Sets the text of the back button. The default text is "❮" ("\u276E").
///
/// The desired text to display as the back button.
public void SetGoBackButtonText(string text) {
UniWebViewInterface.SetEmbeddedToolbarGoBackButtonText(listener.Name, text);
}
///
/// Sets the text of the forward button. The default text is "❯" ("\u276F").
///
/// The desired text to display as the forward button.
public void SetGoForwardButtonText(string text) {
UniWebViewInterface.SetEmbeddedToolbarGoForwardButtonText(listener.Name, text);
}
///
/// Sets the text of toolbar title. The default is empty. The space is limited, setting a long text as title might
/// not fit in the space.
///
/// The desired text to display as the title in the toolbar.
public void SetTitleText(string text) {
UniWebViewInterface.SetEmbeddedToolbarTitleText(listener.Name, text);
}
///
/// Sets the background color of the toolbar.
///
/// The desired color of toolbar's background.
public void SetBackgroundColor(Color color) {
UniWebViewInterface.SetEmbeddedToolbarBackgroundColor(listener.Name, color);
}
///
/// Sets the buttons color of the toolbar. This color affects the back, forward and done button.
///
/// The desired color of toolbar's buttons.
public void SetButtonTextColor(Color color) {
UniWebViewInterface.SetEmbeddedToolbarButtonTextColor(listener.Name, color);
}
///
/// Sets the text color of the toolbar title.
///
/// The desired color of the toolbar's title.
public void SetTitleTextColor(Color color) {
UniWebViewInterface.SetEmbeddedToolbarTitleTextColor(listener.Name, color);
}
///
/// Hides the navigation buttons on the toolbar.
///
/// When called, the back button and forward button will not be shown.
/// By default, the navigation buttons are shown.
///
public void HideNavigationButtons() {
UniWebViewInterface.SetEmeddedToolbarNavigationButtonsShow(listener.Name, false);
}
///
/// Shows the navigation buttons on the toolbar.
///
/// When called, the back button and forward button will be shown.
/// By default, the navigation buttons are shown.
///
public void ShowNavigationButtons() {
UniWebViewInterface.SetEmeddedToolbarNavigationButtonsShow(listener.Name, true);
}
}