rr-ribbon-w6: red round 2 (lead commit)

This commit is contained in:
Martin Ball committed 2026-11-18 21:36:08 +00:00
1 parent 799b873ea5
commit a4b331d3fa
3 files changed
+37 -12

No files matched your search

@@ -40,18 +40,6 @@ fn picture_rendered(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
Picture::rendered("Rendered", 1, &thumbnails, &source).extent(PictureSize::Thumb(ThumbSize::Large)).show(ui).into()
}
/// The gradient at its own size in device pixels, beside it at the icon side: the first keeps one texel to a pixel
/// at every display scale.
#[story(Picture<'static>, covers = [], drive = Drive::Never)]
fn picture_device_pixels(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
ui.horizontal(|ui| {
Picture::new("Gradient", 6, &gradient).extent(PictureSize::Icon).show(ui);
Picture::new("Gradient", 7, &gradient).extent(PictureSize::DevicePixels).show(ui)
})
.inner
.into()
}
#[story(Picture<'static>, covers = [], drive = Drive::Never)]
fn picture_painter(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
Picture::painter("Swatch", ThumbAspect::new(4, 1), |cx, rect| cx.checker(rect)).extent(PictureSize::Thumb(ThumbSize::Large)).show(ui).into()
+1
View File
@@ -22,6 +22,7 @@ mod notices;
mod overlay;
mod pickers;
mod picture;
mod popover;
mod runtime;
+36
View File
@@ -0,0 +1,36 @@
//! `Picture` sized in device pixels.
use craft_ui::contract::Show as _;
use craft_ui::display::{Picture, PictureSize};
use craft_ui::runtime::env::Scale;
use craft_ui::testing::{Fixture, trial};
use egui::{Color32, ColorImage, Vec2};
use std::cell::Cell;
use std::rc::Rc;
/// The side, in texels, of the picture's image.
const SIDE: usize = 32;
fn image() -> ColorImage {
ColorImage::new([SIDE, SIDE], vec![Color32::from_rgb(40, 120, 200); SIDE * SIDE])
}
/// A `DevicePixels` picture keeps one texel to a device pixel at every display scale: its size in points times the
/// scale is its texel size.
#[trial]
fn a_device_pixel_picture_keeps_one_texel_to_a_pixel_at_every_scale() {
for scale in [1.0_f32, 2.0] {
let size = Rc::new(Cell::new(Vec2::ZERO));
let seen = size.clone();
let mut fixture = Fixture::new(move |ui| {
seen.set(Picture::new("Gradient", 1, &image).extent(PictureSize::DevicePixels).show(ui).response.rect.size());
});
fixture.scale(Scale(scale));
fixture.settle();
let device = size.get() * scale;
assert!(
(device.x - SIDE as f32).abs() < 0.01 && (device.y - SIDE as f32).abs() < 0.01,
"at scale {scale} the picture is {device:?} device pixels, not {SIDE} square"
);
}
}