Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: if a SLINT_SCALE_FACTOR is set at compile time, default to that #5016

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 8 additions & 8 deletions api/cpp/esp-idf/slint/src/slint-esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ void EspPlatform::run_event_loop()
}
#endif

int last_touch_x = 0;
int last_touch_y = 0;
float last_touch_x = 0;
float last_touch_y = 0;
bool touch_down = false;

while (true) {
Expand Down Expand Up @@ -192,21 +192,21 @@ void EspPlatform::run_event_loop()
*touch_handle, touchpad_x, touchpad_y, NULL, &touchpad_cnt, 1);

if (touchpad_pressed && touchpad_cnt > 0) {
auto scale_factor = m_window->window().scale_factor();
// ESP_LOGI(TAG, "x: %i, y: %i", touchpad_x[0], touchpad_y[0]);
last_touch_x = touchpad_x[0];
last_touch_y = touchpad_y[0];
last_touch_x = float(touchpad_x[0]) / scale_factor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

last_touch_y = float(touchpad_y[0]) / scale_factor;
m_window->window().dispatch_pointer_move_event(
slint::LogicalPosition({ float(last_touch_x), float(last_touch_y) }));
slint::LogicalPosition({ last_touch_x, last_touch_y }));
if (!touch_down) {
m_window->window().dispatch_pointer_press_event(
slint::LogicalPosition(
{ float(last_touch_x), float(last_touch_y) }),
slint::LogicalPosition({ last_touch_x, last_touch_y }),
slint::PointerEventButton::Left);
}
touch_down = true;
} else if (touch_down) {
m_window->window().dispatch_pointer_release_event(
slint::LogicalPosition({ float(last_touch_x), float(last_touch_y) }),
slint::LogicalPosition({ last_touch_x, last_touch_y }),
slint::PointerEventButton::Left);
m_window->window().dispatch_pointer_exit_event();
touch_down = false;
Expand Down
8 changes: 8 additions & 0 deletions api/cpp/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ pub unsafe extern "C" fn slint_window_adapter_new(
set_position,
});

if let Some(scale_factor) =
option_env!("SLINT_SCALE_FACTOR").and_then(|x| x.parse::<f32>().ok()).filter(|f| *f > 0.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that a little dangerous for regular C++ users? Or is it safe because it'll be overridden anyway later when a windowing system is used?

I guess ideally this would be a cmake cache variable that - if set - maps to an environment variable set for corrosion to pass to cargo. Maybe the cache variable could still be called SLINT_SCALE_FACTOR but the environment variable would be CMAKE_SLINT_SCALE_FACTOR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the C++ programmer set a C++ scale factor at runtime, it will be overridden.
But you're right that this probably should be a cmake setting rather than a env variable.

{
window.window().dispatch_event(i_slint_core::platform::WindowEvent::ScaleFactorChanged {
scale_factor,
});
}

core::ptr::write(target as *mut Rc<dyn WindowAdapter>, window);
}

Expand Down
Loading