Skip to content

Commit c169dd1

Browse files
committed
support swipe gesture handler debugging
1 parent f999fac commit c169dd1

File tree

2 files changed

+63
-33
lines changed

2 files changed

+63
-33
lines changed

internal/core/items/input_items.rs

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -226,34 +226,13 @@ impl Item for TouchArea {
226226
self_rc: &ItemRc,
227227
size: LogicalSize,
228228
) -> RenderingResult {
229-
if let Some(color) = (*backend).window().debug_touch_area.get() {
230-
let d = DebugTouchArea { color };
231-
let debug = Pin::new(&d);
232-
(*backend).draw_border_rectangle(debug, self_rc, size, &self.cached_rendering_data);
229+
if let Some(color) = (*backend).window().debug_touch.get() {
230+
debug_rect(color, backend, self_rc, size, &self.cached_rendering_data);
233231
}
234232
RenderingResult::ContinueRenderingChildren
235233
}
236234
}
237235

238-
struct DebugTouchArea {
239-
color: crate::Color,
240-
}
241-
242-
impl crate::item_rendering::RenderBorderRectangle for DebugTouchArea {
243-
fn background(self: Pin<&Self>) -> crate::Brush {
244-
crate::Brush::SolidColor(self.color)
245-
}
246-
fn border_width(self: Pin<&Self>) -> LogicalLength {
247-
LogicalLength::new(0.0)
248-
}
249-
fn border_radius(self: Pin<&Self>) -> crate::lengths::LogicalBorderRadius {
250-
crate::lengths::LogicalBorderRadius::new(0.0, 0.0, 0.0, 0.0)
251-
}
252-
fn border_color(self: Pin<&Self>) -> crate::Brush {
253-
crate::Brush::SolidColor(crate::Color::from_argb_u8(0, 0, 0, 0))
254-
}
255-
}
256-
257236
impl ItemConsts for TouchArea {
258237
const cached_rendering_data_offset: const_field_offset::FieldOffset<
259238
TouchArea,
@@ -545,10 +524,14 @@ impl Item for SwipeGestureHandler {
545524

546525
fn render(
547526
self: Pin<&Self>,
548-
_backend: &mut ItemRendererRef,
549-
_self_rc: &ItemRc,
550-
_size: LogicalSize,
527+
backend: &mut ItemRendererRef,
528+
self_rc: &ItemRc,
529+
size: LogicalSize,
551530
) -> RenderingResult {
531+
if let Some(color) = (*backend).window().debug_swipe.get() {
532+
debug_rect(color, backend, self_rc, size, &self.cached_rendering_data);
533+
}
534+
552535
RenderingResult::ContinueRenderingChildren
553536
}
554537
}
@@ -587,3 +570,34 @@ pub unsafe extern "C" fn slint_swipegesturehandler_cancel(
587570
let self_rc = ItemRc::new(self_component.clone(), self_index);
588571
s.cancel(window_adapter, &self_rc);
589572
}
573+
574+
fn debug_rect(
575+
color: crate::Color,
576+
backend: &mut ItemRendererRef,
577+
self_rc: &ItemRc,
578+
size: LogicalSize,
579+
cached_rendering_data: &CachedRenderingData,
580+
) {
581+
let d = DebugTouchArea { color };
582+
let debug = Pin::new(&d);
583+
(*backend).draw_border_rectangle(debug, self_rc, size, cached_rendering_data);
584+
}
585+
586+
struct DebugTouchArea {
587+
color: crate::Color,
588+
}
589+
590+
impl crate::item_rendering::RenderBorderRectangle for DebugTouchArea {
591+
fn background(self: Pin<&Self>) -> crate::Brush {
592+
crate::Brush::SolidColor(self.color)
593+
}
594+
fn border_width(self: Pin<&Self>) -> LogicalLength {
595+
LogicalLength::new(0.0)
596+
}
597+
fn border_radius(self: Pin<&Self>) -> crate::lengths::LogicalBorderRadius {
598+
crate::lengths::LogicalBorderRadius::new(0.0, 0.0, 0.0, 0.0)
599+
}
600+
fn border_color(self: Pin<&Self>) -> crate::Brush {
601+
crate::Brush::SolidColor(crate::Color::from_argb_u8(0, 0, 0, 0))
602+
}
603+
}

internal/core/window.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ pub struct WindowInner {
455455
click_state: ClickState,
456456
pub(crate) ctx: once_cell::unsync::Lazy<crate::SlintContext>,
457457

458-
pub(crate) debug_touch_area: Cell<Option<crate::Color>>,
458+
pub(crate) debug_touch: Cell<Option<crate::Color>>,
459+
pub(crate) debug_swipe: Cell<Option<crate::Color>>,
459460
}
460461

461462
impl Drop for WindowInner {
@@ -523,7 +524,8 @@ impl WindowInner {
523524
ctx: once_cell::unsync::Lazy::new(|| {
524525
crate::context::GLOBAL_CONTEXT.with(|ctx| ctx.get().unwrap().clone())
525526
}),
526-
debug_touch_area: Cell::new(None),
527+
debug_touch: Cell::new(None),
528+
debug_swipe: Cell::new(None),
527529
}
528530
}
529531

@@ -1353,15 +1355,29 @@ impl WindowInner {
13531355
}
13541356

13551357
/// Returns whether debug touch areas is enabled
1356-
pub fn get_debug_touch_area(&self) -> Option<crate::Color> {
1357-
self.debug_touch_area.get()
1358+
pub fn get_debug_touch(&self) -> Option<crate::Color> {
1359+
self.debug_touch.get()
13581360
}
13591361

13601362
/// Set debug touch areas to enabled or disabled
1361-
pub fn set_debug_touch_area(&self, color: Option<crate::Color>) {
1362-
self.debug_touch_area.set(color);
1363+
pub fn set_debug_touch(&self, color: Option<crate::Color>) {
1364+
self.debug_touch.set(color);
1365+
self.full_redraw();
1366+
}
1367+
1368+
/// Returns whether debug swipe areas is enabled
1369+
pub fn get_debug_swipe(&self) -> Option<crate::Color> {
1370+
self.debug_swipe.get()
1371+
}
1372+
1373+
/// Set debug swipe areas to enabled or disabled
1374+
pub fn set_debug_swipe(&self, color: Option<crate::Color>) {
1375+
self.debug_swipe.set(color);
1376+
self.full_redraw();
1377+
}
13631378

1364-
// mark the entire window as dirty to ensure a full redraw
1379+
// mark the entire window as dirty to ensure a full redraw
1380+
fn full_redraw(&self) {
13651381
let adapter = self.window_adapter();
13661382
let scale_factor = self.scale_factor();
13671383
let physical_size = adapter.size();

0 commit comments

Comments
 (0)