Skip to content

Commit

Permalink
C++: Add slint::Window::scale_factor() getter (#3004)
Browse files Browse the repository at this point in the history
Fixes #3003
  • Loading branch information
tronical committed Jun 28, 2023
1 parent a0dd643 commit 83ccd07
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,8 @@ All notable changes to this project are documented in this file.

### C++

- Added `slint::Window::scale_factor()` as getter to read the system device pixel ratio.

### LSP

- Correctly use the CARGO_MANIFEST_DIR as the base for import and image in `slint!` macro
Expand Down
4 changes: 4 additions & 0 deletions api/cpp/include/slint.h
Expand Up @@ -496,6 +496,10 @@ class Window
/// a window frame (if present).
void set_size(const slint::PhysicalSize &size) { inner.set_physical_size(size); }

/// This function returns the scale factor that allows converting between logical and
/// physical pixels.
float scale_factor() const { return inner.scale_factor(); }

/// Dispatch a key press event to the scene.
///
/// Use this when you're implementing your own backend and want to forward user input events.
Expand Down
16 changes: 16 additions & 0 deletions api/cpp/tests/window.cpp
Expand Up @@ -28,3 +28,19 @@ TEST_CASE("Basic Window Visibility")
instance->hide();
REQUIRE(instance->window().is_visible() == false);
}

TEST_CASE("Window Scale Factory Existence")
{
using namespace slint::interpreter;
using namespace slint;

ComponentCompiler compiler;
auto comp_def = compiler.build_from_source(R"(
export App := Window {
}
)",
"");
REQUIRE(comp_def.has_value());
auto instance = comp_def->create();
REQUIRE(instance->window().scale_factor() > 0);
}

0 comments on commit 83ccd07

Please sign in to comment.