1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

Polish image API (#3338)

* Imoprove docs for callback shapes

* Improve docs for loader traits

* Use snake_case for feature `all_loaders`

* Make loaders publix

* Slightly better error message on image load failure

* Improve image loading error messages

* Use `bytes://` schema for included bytes loader

* Try user loaders first

* Move `image_loading_spinners` to `Visuals`

* Unify and simplify code

* Make the main text of `Button` optional

This largely makes ImageButton obsolete

* Fix docstrings

* Better docs

* typos

* Use the more explicit `egui_extras::install_image_loaders`

* Simplify `Image::paint_at` function
This commit is contained in:
Emil Ernerfeldt
2023-09-14 16:33:10 +02:00
committed by GitHub
parent e367c20779
commit d7d222d3f6
25 changed files with 406 additions and 279 deletions

View File

@@ -787,6 +787,8 @@ pub struct PaintCallbackInfo {
/// Rect is the [-1, +1] of the Normalized Device Coordinates.
///
/// Note than only a portion of this may be visible due to [`Self::clip_rect`].
///
/// This comes from [`PaintCallback::rect`].
pub viewport: Rect,
/// Clip rectangle in points.
@@ -819,7 +821,7 @@ pub struct ViewportInPixels {
}
impl PaintCallbackInfo {
fn points_to_pixels(&self, rect: &Rect) -> ViewportInPixels {
fn pixels_from_points(&self, rect: &Rect) -> ViewportInPixels {
ViewportInPixels {
left_px: rect.min.x * self.pixels_per_point,
top_px: rect.min.y * self.pixels_per_point,
@@ -831,12 +833,12 @@ impl PaintCallbackInfo {
/// The viewport rectangle. This is what you would use in e.g. `glViewport`.
pub fn viewport_in_pixels(&self) -> ViewportInPixels {
self.points_to_pixels(&self.viewport)
self.pixels_from_points(&self.viewport)
}
/// The "scissor" or "clip" rectangle. This is what you would use in e.g. `glScissor`.
pub fn clip_rect_in_pixels(&self) -> ViewportInPixels {
self.points_to_pixels(&self.clip_rect)
self.pixels_from_points(&self.clip_rect)
}
}
@@ -846,6 +848,8 @@ impl PaintCallbackInfo {
#[derive(Clone)]
pub struct PaintCallback {
/// Where to paint.
///
/// This will become [`PaintCallbackInfo::viewport`].
pub rect: Rect,
/// Paint something custom (e.g. 3D stuff).

View File

@@ -1063,7 +1063,7 @@ fn mul_color(color: Color32, factor: f32) -> Color32 {
///
/// For performance reasons it is smart to reuse the same [`Tessellator`].
///
/// Se also [`tessellate_shapes`], a convenient wrapper around [`Tessellator`].
/// See also [`tessellate_shapes`], a convenient wrapper around [`Tessellator`].
pub struct Tessellator {
pixels_per_point: f32,
options: TessellationOptions,