diff --git a/README.md b/README.md index 2fd2ab4..82b5a69 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ fn main() { ``` ## Screenshot -The screenshot of another example. +The screenshot of another example, showcasing various widgets. ![Screenshot of an example program](screenshot.png) @@ -57,4 +57,4 @@ The following features will not be supported in this integration: 1. Rendering arbitrary meshes. 2. [Paint callbacks](https://docs.rs/epaint/0.28.1/epaint/struct.PaintCallback.html). -The primary reason behind this is that this integration does not rely on egui to tessellate its entire UI-mesh, but rather traverses the output shape tree and calls corresponding raylib functions on a draw handle. If necessary, these features can be obtained by using egui's built-in tessellation functionality to generate primitives that can be rendered directly. This approach was not chosen to allow the ui to be rendered on any draw handle that supports clipping. +The primary reason behind this is that this integration does not rely on egui to tessellate its entire UI-mesh, but rather traverses the output shape tree and calls corresponding raylib functions on a draw handle. If necessary, these features can be obtained by using egui's built-in tessellation functionality to generate primitives that can be rendered directly. This approach was not chosen to allow the ui to be rendered on any draw handle that supports clipping. \ No newline at end of file diff --git a/screenshot.png b/screenshot.png index ed5854d..119bb08 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/src/input.rs b/src/input.rs index 5a4b92d..fe8d16b 100644 --- a/src/input.rs +++ b/src/input.rs @@ -48,11 +48,12 @@ fn get_mouse_input( events: &mut Vec, pixels_per_point: f32, modifiers: Modifiers, + ctx: &egui::Context ) { let mouse_delta = rl.get_mouse_delta().scale_by(1.0 / pixels_per_point); let mouse_position = rl.get_mouse_position().scale_by(1.0 / pixels_per_point); - if mouse_delta.x > 0.0 || mouse_delta.y > 0.0 { + if mouse_delta.x > 0.0 || mouse_delta.y > 0.0 || ctx.wants_pointer_input() { events.push(Event::MouseMoved(Vec2::new(mouse_delta.x, mouse_delta.y))); events.push(Event::PointerMoved(Pos2::new( mouse_position.x, @@ -207,9 +208,7 @@ pub fn gather_input(opt: &InputOptions, ctx: &egui::Context, rl: &mut RaylibHand } } - // if ctx.wants_pointer_input() { - get_mouse_input(rl, &mut events, pixels_per_point, modifiers); - // } + get_mouse_input(rl, &mut events, pixels_per_point, modifiers, ctx); let dropped_files = if rl.is_file_dropped() { rl.load_dropped_files() diff --git a/src/paint.rs b/src/paint.rs index 516c73f..871fa64 100644 --- a/src/paint.rs +++ b/src/paint.rs @@ -6,7 +6,7 @@ use egui::{ ahash::HashMap, epaint::ImageDelta, output::OutputEvent, Context, FullOutput, OpenUrl, RawInput, TextureId, }; -use egui::{Mesh, Vec2}; +use egui::{Mesh, Rounding, Vec2}; use raylib::color::Color; use raylib::drawing::RaylibScissorModeExt; use raylib::ffi::Rectangle; @@ -288,24 +288,32 @@ impl Painter { }; let fill_color = rs.fill.convert(); let stroke_color = rs.stroke.color.convert(); - d.draw_rectangle_rec(rrect2, stroke_color); - if rs.uv == egui::Rect::ZERO { - // No texture here. - d.draw_rectangle_rec(rrect, fill_color); - } else { - // Draw textured rectangle. - if let Some(texture) = self.textures.get(&rs.fill_texture_id) { - let source_rec = Rectangle { - x: rs.uv.min.x * texture.width as f32, - y: rs.uv.max.y * texture.height as f32, - width: rs.uv.width(), - height: rs.uv.height() - }; - d.draw_texture_pro(texture, source_rec, rrect, Vector2::zero(), 0.0, fill_color) + if rs.rounding == Rounding::ZERO { + d.draw_rectangle_rec(rrect2, stroke_color); + if rs.uv == egui::Rect::ZERO { + // No texture here. + d.draw_rectangle_rec(rrect, fill_color); } else { - d.draw_rectangle_rec(rrect, fill_color) + // Draw textured rectangle. + if let Some(texture) = self.textures.get(&rs.fill_texture_id) { + let source_rec = Rectangle { + x: rs.uv.min.x * texture.width as f32, + y: rs.uv.max.y * texture.height as f32, + width: rs.uv.width(), + height: rs.uv.height() + }; + d.draw_texture_pro(texture, source_rec, rrect, Vector2::zero(), 0.0, fill_color) + } else { + d.draw_rectangle_rec(rrect, fill_color) + } } + } else { + // Can't draw textures on rounded rectangles. + // Raylib roundedness is the ratio between the radius and the smallest dimension. + let roundness = rs.rounding.ne.max(rs.rounding.nw).max(rs.rounding.se).max(rs.rounding.sw) * pxpp / rrect.width.min(rrect.height); + d.draw_rectangle_rounded(rrect2, roundness, 4, stroke_color); + d.draw_rectangle_rounded(rrect, roundness, 4, fill_color); } }, diff --git a/src/tests.rs b/src/tests.rs index 090e699..2c04a90 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,4 +1,4 @@ -use egui::{Color32, Context, Label, RichText, Visuals}; +use egui::{Color32, Context, Label, RichText, Rounding, Visuals}; use raylib::prelude::{Color, RaylibDraw}; use crate::{input::InputOptions, RlEgui}; @@ -209,11 +209,12 @@ fn it_works() { ctx.set_visuals(Visuals { override_text_color: Some(Color32::WHITE), hyperlink_color: Color32::BLUE, + window_rounding: Rounding::ZERO, ..Visuals::dark() }); let inopt = InputOptions { - native_pixels_per_point: 1.25, + native_pixels_per_point: 1.3, ..Default::default() };