Skip to main content

ferroui_controls/presentation_source/
presentation_source_render_root.rs

1use super::renderer_factory::ITopLevelRenderer;
2use super::PresentationSource;
3use ferroui_base::layout::LayoutHelper;
4use ferroui_base::rendering::{IHitTester, ManagedHitTester, SceneInvalidatedEventArgs};
5use ferroui_base::{PixelPoint, Point, Size};
6use std::rc::Rc;
7
8impl PresentationSource {
9    /// The renderer of the tree.
10    pub fn typed_renderer(&self) -> &Rc<dyn ITopLevelRenderer> {
11        self.renderer.get().expect("the renderer is created with the presentation source")
12    }
13
14    /// The hit tester of the tree: the override when one is set, otherwise
15    /// the hit tester of the renderer, otherwise one that walks the visual
16    /// tree.
17    pub fn hit_tester(&self) -> Rc<dyn IHitTester> {
18        if let Some(hit_tester) = self.hit_tester_override.borrow().clone() {
19            return hit_tester;
20        }
21        self.typed_renderer().hit_tester().unwrap_or_else(|| Rc::new(ManagedHitTester::new()))
22    }
23
24    /// The hit tester used instead of the renderer's, for unit tests that
25    /// do not set up a hit-testable visual tree.
26    pub fn hit_tester_override(&self) -> Option<Rc<dyn IHitTester>> {
27        self.hit_tester_override.borrow().clone()
28    }
29
30    pub fn set_hit_tester_override(&self, value: Option<Rc<dyn IHitTester>>) {
31        *self.hit_tester_override.borrow_mut() = value;
32    }
33
34    /// The scaling factor to use in rendering.
35    pub fn render_scaling(&self) -> f64 {
36        self.render_scaling.get()
37    }
38
39    /// The size of the client area of the platform implementation.
40    pub fn client_size(&self) -> Size {
41        self.platform_impl().map(|platform_impl| platform_impl.client_size()).unwrap_or_default()
42    }
43
44    pub(super) fn scene_invalidated(&self, e: &SceneInvalidatedEventArgs) {
45        let pre_processor = self.pointer_over_pre_processor.borrow().clone();
46        if let Some(pre_processor) = pre_processor {
47            pre_processor.scene_invalidated(e.dirty_rect());
48        }
49    }
50
51    /// Converts a point from client to screen coordinates.
52    pub fn point_to_screen(&self, point: Point) -> Option<PixelPoint> {
53        self.platform_impl().map(|platform_impl| platform_impl.point_to_screen(point))
54    }
55
56    /// Converts a point from screen to client coordinates.
57    pub fn point_to_client(&self, point: PixelPoint) -> Option<Point> {
58        self.platform_impl().map(|platform_impl| platform_impl.point_to_client(point))
59    }
60
61    pub(super) fn handle_scaling_changed(&self, scaling: f64) {
62        self.render_scaling.set(LayoutHelper::validate_scaling(scaling));
63    }
64}