1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Pass clip rectangle to PaintCallback

This commit is contained in:
Emil Ernerfeldt
2022-04-15 10:31:33 +02:00
parent 2745699bd6
commit f3e31391e0
4 changed files with 67 additions and 35 deletions

View File

@@ -99,11 +99,25 @@ fn paint_with_three_d(three_d: &three_d::Context, info: &egui::PaintCallbackInfo
// Based on https://github.com/asny/three-d/blob/master/examples/triangle/src/main.rs
use three_d::*;
// Set where to paint
let viewport = info.viewport_in_pixels();
let viewport = Viewport {
x: info.viewport_left_px().round() as _,
y: info.viewport_from_bottom_px().round() as _,
width: info.viewport_width_px().round() as _,
height: info.viewport_height_px().round() as _,
x: viewport.left_px.round() as _,
y: viewport.from_bottom_px.round() as _,
width: viewport.width_px.round() as _,
height: viewport.height_px.round() as _,
};
// Respect the egui clip region (e.g. if we are inside an `egui::ScrollArea`).
let clip_rect = info.clip_rect_in_pixels();
let render_states = RenderStates {
clip: Clip::Enabled {
x: clip_rect.left_px.round() as _,
y: clip_rect.from_bottom_px.round() as _,
width: clip_rect.width_px.round() as _,
height: clip_rect.height_px.round() as _,
},
..Default::default()
};
let camera = Camera::new_perspective(
@@ -135,8 +149,11 @@ fn paint_with_three_d(three_d: &three_d::Context, info: &egui::PaintCallbackInfo
..Default::default()
};
// Construct a model, with a default color material, thereby transferring the mesh data to the GPU
let mut model = Model::new(three_d, &cpu_mesh).unwrap();
let material = ColorMaterial {
render_states,
..Default::default()
};
let mut model = Model::new_with_material(three_d, &cpu_mesh, material).unwrap();
// Set the current transformation of the triangle
model.set_transformation(Mat4::from_angle_y(radians(angle)));

View File

@@ -15,17 +15,16 @@ fn heading3() -> TextStyle {
fn configure_text_styles(ctx: &egui::Context) {
use FontFamily::Proportional;
use TextStyle::*;
let mut style = (*ctx.style()).clone();
style.text_styles = [
(Heading, FontId::new(30.0, Proportional)),
(TextStyle::Heading, FontId::new(30.0, Proportional)),
(heading2(), FontId::new(25.0, Proportional)),
(heading3(), FontId::new(23.0, Proportional)),
(Body, FontId::new(18.0, Proportional)),
(Monospace, FontId::new(14.0, Proportional)),
(Button, FontId::new(14.0, Proportional)),
(Small, FontId::new(10.0, Proportional)),
(TextStyle::Body, FontId::new(18.0, Proportional)),
(TextStyle::Monospace, FontId::new(14.0, Proportional)),
(TextStyle::Button, FontId::new(14.0, Proportional)),
(TextStyle::Small, FontId::new(10.0, Proportional)),
]
.into();
ctx.set_style(style);