MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
mostlyharmless_WebviewBase.h
Go to the documentation of this file.
1//
2// Created by Syl Morrison on 20/09/2024.
3//
4
5#ifndef MOSTLYHARMLESS_MOSTLYHARMLESS_WEBVIEWBASE_H
6#define MOSTLYHARMLESS_MOSTLYHARMLESS_WEBVIEWBASE_H
9#include <choc/gui/choc_WebView.h>
16 [[nodiscard]] std::optional<std::string> getMimeType(const std::string& filename);
17
35 class WebviewBase : public core::IEditor {
36 public:
43 struct Resource {
44 Resource() = default;
50 Resource(std::string_view content, std::string mimeType_);
54 std::vector<std::uint8_t> data;
58 std::string mimeType;
59 };
60
64 struct Options {
68 bool enableDebug{ false };
84 std::function<std::optional<Resource>(const std::string&)> contentProvider{ nullptr };
89 std::optional<std::string> initScript{};
90 };
91 WebviewBase(std::uint32_t initialWidth, std::uint32_t initialHeight, Colour backgroundColour);
92 ~WebviewBase() noexcept override;
93 void setOptions(Options&& options) noexcept;
94 void initialise() override;
95 void destroy() override;
96 void setSize(std::uint32_t width, std::uint32_t height) override;
97 void getSize(std::uint32_t* width, std::uint32_t* height) override;
98 void setParent(void* parentHandle) override;
99 void show() override;
100 void hide() override;
101 void onParamEvent(events::ProcToGuiParamEvent event) override = 0;
102
103 protected:
104 choc::ui::WebView* m_internalWebview{ nullptr };
105
106 private:
107 class Impl;
108 std::unique_ptr<Impl> m_impl;
109 };
110} // namespace mostly_harmless::gui
111#endif // MOSTLYHARMLESS_MOSTLYHARMLESS_WEBVIEWBASE_H
~WebviewBase() noexcept override
void setParent(void *parentHandle) override
WebviewBase(std::uint32_t initialWidth, std::uint32_t initialHeight, Colour backgroundColour)
void setOptions(Options &&options) noexcept
choc::ui::WebView * m_internalWebview
Definition mostlyharmless_WebviewBase.h:104
void getSize(std::uint32_t *width, std::uint32_t *height) override
void setSize(std::uint32_t width, std::uint32_t height) override
void onParamEvent(events::ProcToGuiParamEvent event) override=0
Contains classes and functions related to events.
Definition mostlyharmless_InputEventContext.h:4
Contains GUI related classes & functions.
Definition mostlyharmless_WebviewBase.h:10
std::optional< std::string > getMimeType(const std::string &filename)
Tries to retrieve the MIME type for a given filename.
Interface for the plugin's gui functionality.
Definition mostlyharmless_IEditor.h:19
Convenience struct representing a colour.
Definition mostlyharmless_Colour.h:12
Contains a set of options to construct the internal webview with.
Definition mostlyharmless_WebviewBase.h:64
std::optional< std::string > initScript
Definition mostlyharmless_WebviewBase.h:89
std::function< std::optional< Resource >(const std::string &)> contentProvider
Definition mostlyharmless_WebviewBase.h:84
bool enableDebug
Definition mostlyharmless_WebviewBase.h:68
Resource(std::string_view content, std::string mimeType_)
std::vector< std::uint8_t > data
Definition mostlyharmless_WebviewBase.h:54
std::string mimeType
Definition mostlyharmless_WebviewBase.h:58