Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/cpp/include/slint.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ inline bool open_url(const SharedString &url, const WindowAdapterRc &window_adap
return cbindgen_private::slint_open_url(&url, &window_adapter.handle());
}

inline void bring_all_to_front()
{
cbindgen_private::slint_bring_all_to_front();
}

inline SharedString translate_from_bundle(std::span<const char8_t *const> strs,
cbindgen_private::Slice<SharedString> arguments)
{
Expand Down
5 changes: 5 additions & 0 deletions api/cpp/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ pub unsafe extern "C" fn slint_open_url(
i_slint_core::open_url(url, window_adapter.window()).is_ok()
}

#[unsafe(no_mangle)]
pub extern "C" fn slint_bring_all_to_front() {
i_slint_core::bring_all_to_front()
}

#[unsafe(no_mangle)]
pub extern "C" fn slint_string_to_styled_text(text: &SharedString, out: &mut StyledText) {
*out = i_slint_core::styled_text::string_to_styled_text(text.to_string());
Expand Down
1 change: 1 addition & 0 deletions api/rs/slint/private_unstable_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub mod re_exports {
};
pub use i_slint_core::animations::{EasingCurve, animation_tick, current_tick};
pub use i_slint_core::api::LogicalPosition;
pub use i_slint_core::bring_all_to_front;
pub use i_slint_core::callbacks::Callback;
pub use i_slint_core::context::SlintContext;
pub use i_slint_core::data_transfer::DataTransfer;
Expand Down
7 changes: 7 additions & 0 deletions internal/compiler/builtins.slint
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,13 @@ export global Platform {
function open-url(url: string) -> bool {
return false;
}
/// Brings all application windows to the front of the screen.
///
/// On macOS this invokes `[NSApp arrangeInFront:]`, which raises every application window
/// to the top of the window stack. On other platforms this function is a no-op.
///
/// This corresponds to the standard macOS **Window › Bring All to Front** menu item.
function bring-all-to-front() { }
/// The decimal separator currently used for localized float to string and vice versa conversions
/// For more information about localization and how to change the decimal separator see <Link type="translations" label="translations page"/>.
out property <string> decimal-separator;
Expand Down
4 changes: 4 additions & 0 deletions internal/compiler/expression_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ pub enum BuiltinFunction {
StopTimer,
RestartTimer,
OpenUrl,
BringAllToFront,
ParseMarkdown,
StringToStyledText,
DecimalSeparator,
Expand Down Expand Up @@ -305,6 +306,7 @@ declare_builtin_function_types!(
ParseMarkdown: (Type::String, Type::Array(Type::StyledText.into())) -> Type::StyledText,
StringToStyledText: (Type::String) -> Type::StyledText
OpenUrl: (Type::String) -> Type::Bool,
BringAllToFront: () -> Type::Void,
);

impl Default for BuiltinFunctionTypes {
Expand Down Expand Up @@ -415,6 +417,7 @@ impl BuiltinFunction {
BuiltinFunction::ParseMarkdown => false,
BuiltinFunction::StringToStyledText => true,
BuiltinFunction::OpenUrl => false,
BuiltinFunction::BringAllToFront => false,
}
}

Expand Down Expand Up @@ -501,6 +504,7 @@ impl BuiltinFunction {
BuiltinFunction::ParseMarkdown => true,
BuiltinFunction::StringToStyledText => true,
BuiltinFunction::OpenUrl => false,
BuiltinFunction::BringAllToFront => false,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions internal/compiler/generator/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4932,6 +4932,9 @@ fn compile_builtin_function_call(
let window = access_window_field(ctx);
format!("slint::private_api::open_url({url}, {window})")
}
BuiltinFunction::BringAllToFront => {
"slint::private_api::bring_all_to_front()".to_owned()
}
BuiltinFunction::ParseMarkdown => {
let format_string = a.next().unwrap();
let args = a.next().unwrap();
Expand Down
3 changes: 3 additions & 0 deletions internal/compiler/generator/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4164,6 +4164,9 @@ fn compile_builtin_function_call(
let window_adapter_tokens = access_window_adapter_field(ctx);
quote!(sp::open_url(&#url, #window_adapter_tokens.window()).is_ok())
}
BuiltinFunction::BringAllToFront => {
quote!(sp::bring_all_to_front())
}
BuiltinFunction::ParseMarkdown => {
let format_string = a.next().unwrap();
let args = a.next().unwrap();
Expand Down
1 change: 1 addition & 0 deletions internal/compiler/llr/optim_passes/inline_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ fn builtin_function_cost(function: &BuiltinFunction) -> isize {
BuiltinFunction::ParseMarkdown => isize::MAX,
BuiltinFunction::StringToStyledText => ALLOC_COST,
BuiltinFunction::OpenUrl => isize::MAX,
BuiltinFunction::BringAllToFront => isize::MAX,
}
}

Expand Down
6 changes: 6 additions & 0 deletions internal/compiler/passes/lower_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ pub fn lower_platform(component: &Rc<Component>, type_loader: &mut crate::typelo
{
*function = BuiltinFunction::OpenUrl.into();
}
Expression::FunctionCall { function, .. }
if matches!(&*function, Callable::Function(nr)
if is_platform(nr) && nr.name() == "bring-all-to-front") =>
{
*function = BuiltinFunction::BringAllToFront.into();
}
_ => {}
})
})
Expand Down
11 changes: 11 additions & 0 deletions internal/core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,14 @@ pub fn is_apple_platform() -> bool {
pub fn open_url(url: &str, window: &crate::api::Window) -> Result<(), crate::api::PlatformError> {
crate::window::WindowInner::from_pub(window).context().platform().open_url(url)
}

#[cfg(target_os = "macos")]
pub fn bring_all_to_front() {
use objc2::MainThreadMarker;
use objc2_app_kit::NSApplication;
let Some(mtm) = MainThreadMarker::new() else { return };
NSApplication::sharedApplication(mtm).arrangeInFront(None);
}

#[cfg(not(target_os = "macos"))]
pub fn bring_all_to_front() {}
4 changes: 4 additions & 0 deletions internal/interpreter/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,6 +1724,10 @@ fn call_builtin_function(
let window_adapter = local_context.component_instance.window_adapter();
Value::Bool(corelib::open_url(&url, window_adapter.window()).is_ok())
}
BuiltinFunction::BringAllToFront => {
corelib::bring_all_to_front();
Value::Void
}
BuiltinFunction::ParseMarkdown => {
let format_string: SharedString =
eval_expression(&arguments[0], local_context).try_into().unwrap();
Expand Down
31 changes: 31 additions & 0 deletions tests/cases/globals/bring_all_to_front.slint
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

// Test that Platform.bring-all-to-front() compiles and runs (it is a no-op on non-macOS).

export component TestCase inherits Window {
public function do-bring-all-to-front() {
Platform.bring-all-to-front();
}
out property <bool> test: true;
}

/*
```rust
let instance = TestCase::new().unwrap();
instance.invoke_do_bring_all_to_front();
assert!(instance.get_test());
```

```cpp
auto instance = TestCase::create();
instance->invoke_do_bring_all_to_front();
assert(instance->get_test());
```

```js
let instance = new slint.TestCase({});
instance.do_bring_all_to_front();
assert(instance.test);
```
*/
Loading