Fix rendering of Flickable

It should clip to its geometry
This commit is contained in:
Simon Hausmann 2021-02-01 15:35:36 +01:00
parent d065e7e879
commit 69508575ec
4 changed files with 14 additions and 12 deletions

View file

@ -13,7 +13,7 @@ LICENSE END */
use super::graphics::RenderingCache;
use super::items::*;
use crate::component::ComponentRc;
use crate::graphics::Point;
use crate::graphics::{Point, Rect};
use crate::item_tree::ItemVisitorResult;
use core::pin::Pin;
use std::cell::{Cell, RefCell};
@ -107,7 +107,7 @@ pub trait ItemRenderer {
fn draw_text_input(&mut self, pos: Point, text_input: Pin<&TextInput>);
fn draw_path(&mut self, pos: Point, path: Pin<&Path>);
fn draw_box_shadow(&mut self, pos: Point, box_shadow: Pin<&BoxShadow>);
fn combine_clip(&mut self, pos: Point, clip: Pin<&Clip>);
fn combine_clip(&mut self, pos: Point, rect: Rect);
fn save_state(&mut self);
fn restore_state(&mut self);

View file

@ -534,7 +534,7 @@ impl Item for Clip {
fn focus_event(self: Pin<&Self>, _: &FocusEvent, _window: &ComponentWindow) {}
fn render(self: Pin<&Self>, pos: Point, backend: &mut ItemRendererRef) {
(*backend).combine_clip(pos, self)
(*backend).combine_clip(pos, self.geometry())
}
}
@ -668,7 +668,9 @@ impl Item for Flickable {
fn focus_event(self: Pin<&Self>, _: &FocusEvent, _window: &ComponentWindow) {}
fn render(self: Pin<&Self>, _pos: Point, _backend: &mut ItemRendererRef) {}
fn render(self: Pin<&Self>, pos: Point, backend: &mut ItemRendererRef) {
(*backend).combine_clip(pos, self.geometry())
}
}
impl ItemConsts for Flickable {

View file

@ -1062,8 +1062,8 @@ impl ItemRenderer for GLItemRenderer {
})
}
fn combine_clip(&mut self, pos: Point, clip: std::pin::Pin<&sixtyfps_corelib::items::Clip>) {
let clip_rect = clip.geometry().translate([pos.x, pos.y].into());
fn combine_clip(&mut self, pos: Point, rect: Rect) {
let clip_rect = rect.translate([pos.x, pos.y].into());
self.shared_data.canvas.borrow_mut().intersect_scissor(
clip_rect.min_x(),
clip_rect.min_y(),

View file

@ -10,7 +10,7 @@ LICENSE END */
use cpp::*;
use items::{ImageFit, TextHorizontalAlignment, TextVerticalAlignment};
use sixtyfps_corelib::graphics::{Color, FontRequest, Point, RenderingCache};
use sixtyfps_corelib::graphics::{Color, FontRequest, Point, Rect, RenderingCache};
use sixtyfps_corelib::input::{InternalKeyCode, KeyEvent, KeyEventType, MouseEventType};
use sixtyfps_corelib::item_rendering::{CachedRenderingData, ItemRenderer};
use sixtyfps_corelib::items::{self, ItemRef, TextOverflow, TextWrap};
@ -439,12 +439,12 @@ impl ItemRenderer for QtItemRenderer<'_> {
);
}
fn combine_clip(&mut self, pos: Point, clip: Pin<&items::Clip>) {
fn combine_clip(&mut self, pos: Point, rect: Rect) {
let clip_rect = qttypes::QRectF {
x: (clip.x() + pos.x as f32) as _,
y: (clip.y() + pos.y as f32) as _,
width: clip.width() as _,
height: clip.height() as _,
x: (rect.min_x() + pos.x as f32) as _,
y: (rect.min_y() + pos.y as f32) as _,
width: rect.width() as _,
height: rect.height() as _,
};
let painter: &mut QPainter = &mut *self.painter;
cpp! { unsafe [painter as "QPainter*", clip_rect as "QRectF"] {