slint/api/sixtyfps-cpp/include/sixtyfps_testing.h
Simon Hausmann e5dfb3a4c0 Implement basic focus handling
Similar to the mouse_grabber, we use a VisitChildrenResult field to
track the focus item within a component. Unlike the mouse grabber
however, it is set/cleared using dedicated focus events.

The key event now routes the key event directly to the focus item.

The focus can be requested via set_focus_item on a window, which the
TextItem does.
2020-09-25 10:43:47 +02:00

50 lines
1.8 KiB
C++

/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
SPDX-License-Identifier: GPL-3.0-only
This file is also available under commercial licensing terms.
Please contact info@sixtyfps.io for more information.
LICENSE END */
#pragma once
#include "sixtyfps.h"
#include <iostream>
namespace sixtyfps::testing {
inline void mock_elapsed_time(int64_t time_in_ms)
{
cbindgen_private::sixtyfps_mock_elapsed_time(time_in_ms);
}
template<typename Component>
inline void send_mouse_click(Component &component, float x, float y)
{
cbindgen_private::sixtyfps_send_mouse_click({ &Component::component_type, &component }, x, y,
&component.window);
}
template<typename Component>
inline void send_keyboard_string_sequence(Component &component, const sixtyfps::SharedString &str)
{
cbindgen_private::send_keyboard_string_sequence({ &Component::component_type, &component },
&str, &component.window);
}
#define assert_eq(A, B) \
sixtyfps::testing::private_api::assert_eq_impl(A, B, #A, #B, __FILE__, __LINE__)
namespace private_api {
template<typename A, typename B>
void assert_eq_impl(const A &a, const B &b, const char *a_str, const char *b_str, const char *file,
int line)
{
if (a != b) {
std::cerr << file << ":" << line << ": assert_eq FAILED!\n"
<< a_str << ": " << a << "\n"
<< b_str << ": " << b << std::endl;
std::abort();
}
}
}
} // namespace sixtyfps