From 466c4e98c7524c3401ddbbf2b9a347b247280702 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Tue, 24 Nov 2026 17:02:26 -0800 Subject: [PATCH] Graphic Styles: the large tip is a card thumbnail (size.thumb.card) wide and its square picture fills it, in place of a fixed 132 pt square --- crates/ui-egui/src/panels/graphic_styles.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/panels/graphic_styles.rs b/crates/ui-egui/src/panels/graphic_styles.rs index 9d1a522a80..0633f3fbcd 100644 --- a/crates/ui-egui/src/panels/graphic_styles.rs +++ b/crates/ui-egui/src/panels/graphic_styles.rs @@ -20,7 +20,7 @@ use craft::behavior::{EditEvent, GesturePhase, IconId, Selection}; use craft::ui::contract::{ Bind, DropAt, DropPayload, DropPlace, Entry, ListDrag, MemoProps, PopupKind, ReorderMove, SelectMode, Show as _, ShowContainer as _, Trigger, }; -use craft::ui::display::{Divider, Picture}; +use craft::ui::display::{Divider, Picture, PictureSize}; use craft::ui::list::ThumbAspect; use craft::ui::menu::{Menu, MenuItem, PanelRow}; use craft::ui::patterns::presets::{ @@ -30,9 +30,10 @@ use craft::ui::primitives::{ ContentPainterCx, IconSpec, PaintShape, Priority, Revision, ThumbPaint, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails, }; use craft::ui::runtime::commands::{CommandRef, CommandState, CommandStates}; +use craft::ui::runtime::env::Env; use craft::ui::sections::{FooterAction, FooterBar, FooterOutput, Panel}; use craft::ui::style::DataColor; -use egui::{Color32, Rect, Sense, TextureHandle, Ui, pos2, vec2}; +use egui::{Color32, Rect, TextureHandle, Ui, pos2}; use serde_json::{Value, json}; use vectorcraft_color::{BlendMode, Color, Paint}; use vectorcraft_doc::style_libs::STYLE_LIBRARIES; @@ -132,9 +133,6 @@ fn thumbnails(ctx: &egui::Context, salt: &'static str) -> Thumbnails { Thumbnails::in_context(ctx, salt, ThumbnailOptions::new()) } -/// Side of the large preview shown while the pointer rests on a style. -const LARGE: f32 = 132.0; - thread_local! { // PLAN: the sheet drops RENDERER, but `render` and `render_object` need one renderer that outlives a call. static RENDERER: RefCell = RefCell::new(vectorcraft_render::Renderer::new()); @@ -387,10 +385,13 @@ fn render_object(app: &VectorcraftApp, doc: &Document, n: &Node, g: &GraphicStyl /// The tip over a style: it large, on the selected object when there is one, with its name. fn large_tip(app: &VectorcraftApp, thumbs: &StyleThumbs, ui: &mut Ui, key: &StyleKey) { let Some(i) = thumbs.d.graphic_style_index(key) else { return }; - let px = (LARGE * ui.ctx().pixels_per_point()).round() as u32; + // The preview is a card thumbnail (`size.thumb.card`) wide, and as tall: the tip is that wide, and the square + // picture fills it. + let side = Env::of(ui).tokens.size.thumb.card; + let px = (side * ui.ctx().pixels_per_point()).round() as u32; let look = thumbs.looks.get(i).copied().unwrap_or_default(); let tex = object_preview(app, ui.ctx(), &thumbs.d.graphic_styles[i], look, thumbs.look.preview, px); - let (r, _) = ui.allocate_exact_size(vec2(LARGE, LARGE), Sense::hover()); + ui.set_max_width(side); let texture = tex.as_ref().map(TextureHandle::id); // Decorative: the style's name below it says what it shows. Picture::painter("", ThumbAspect::SQUARE, move |cx, rect| { @@ -399,7 +400,8 @@ fn large_tip(app: &VectorcraftApp, thumbs: &StyleThumbs, ui: &mut Ui, key: &Styl None => draw.data_fill(&PaintShape::Rect(rect, egui::CornerRadius::ZERO), DataColor::new(Color32::WHITE)), }) }) - .show_at(ui, r); + .extent(PictureSize::Fill) + .show(ui); ui.label(key); }