Docs: add a note that only exported global from the main file are exposed

This commit is contained in:
Olivier Goffart 2022-02-09 14:48:57 +01:00
parent d6e835d4ff
commit 3d209287c2
4 changed files with 18 additions and 3 deletions

View file

@ -84,7 +84,10 @@ public:
/// Sets the callback handler for the `hello` callback.
template<typename Functor> inline void on_hello (Functor && callback_handler) const;
// Returns a reference to a global singleton that's exported.
/// Returns a reference to a global singleton that's exported.
///
/// **Note:** Only globals that are exported or re-exported from the main .slint file will
/// be exposed in the API
inline template<typename T>
const T &global() const;

View file

@ -680,8 +680,8 @@ public:
/// Set the value for a property within an exported global singleton.
///
/// For example, if the main file has an exported global `TheGlobal` with a `property <int>
/// hello`, we can set this property
/// For example, if the main file has an exported global `TheGlobal` with a
/// `property <int> hello`, we can set this property
/// ```
/// instance->set_global_property("TheGlobal", "hello", 42);
/// ```
@ -689,6 +689,9 @@ public:
/// Returns true if the property was correctly set. Returns false if the property
/// could not be set because it either does not exist (was not declared in .slint) or if
/// the value is not of the correct type for the property's type.
///
/// **Note:** Only globals that are exported or re-exported from the main .slint file will
/// be accessible
bool set_global_property(std::string_view global, std::string_view prop_name,
const Value &value) const
{
@ -728,6 +731,9 @@ public:
/// return SharedString(arg1);
/// })
/// ```
///
/// **Note:** Only globals that are exported or re-exported from the main .slint file will
/// be accessible
template<typename F>
bool set_global_callback(std::string_view global, std::string_view name, F callback) const
{

View file

@ -172,6 +172,9 @@ impl crate::window::WindowHandleAccess for Window {
/// ```
///
/// See also the [language reference for global singletons](docs/langref/index.html#global-singletons) for more information.
///
/// **Note:** Only globals that are exported or re-exported from the main .slint file will
/// be exposed in the API
pub trait Global<'a, Component> {
/// Returns a reference that's tied to the life time of the provided component.
fn get(component: &'a Component) -> Self;

View file

@ -645,6 +645,9 @@ impl ComponentDefinition {
}
/// Returns the names of all exported global singletons
///
/// **Note:** Only globals that are exported or re-exported from the main .slint file will
/// be exposed in the API
pub fn globals(&self) -> impl Iterator<Item = String> + '_ {
// We create here a 'static guard, because unfortunately the returned type would be restricted to the guard lifetime
// which is not required, but this is safe because there is only one instance of the unerased type