From 7eb948d5fef99b6e81accbefbadf62e6ca19b3e7 Mon Sep 17 00:00:00 2001 From: Melody Madeline Lyons Date: Tue, 2 Jul 2024 04:35:34 -0700 Subject: [PATCH] work on the graphic picker a bit --- crates/graphics/src/primitives/sprite/mod.rs | 26 +++++++++++++ crates/modals/src/event_graphic_picker.rs | 2 +- crates/modals/src/graphic_picker/mod.rs | 39 +++++++++++++++++++- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/crates/graphics/src/primitives/sprite/mod.rs b/crates/graphics/src/primitives/sprite/mod.rs index 00cd25fb..c770a8b8 100644 --- a/crates/graphics/src/primitives/sprite/mod.rs +++ b/crates/graphics/src/primitives/sprite/mod.rs @@ -75,6 +75,32 @@ impl Sprite { bind_group: Arc::new(bind_group), } } + + // like basic, but with a hue + pub fn basic_hue( + graphics_state: &GraphicsState, + hue: i32, + texture: &Texture, + viewport: &Viewport, + ) -> Self { + let rect = egui::Rect::from_min_size(egui::Pos2::ZERO, texture.size_vec2()); + let quad = Quad::new(rect, rect); + Self::new( + graphics_state, + quad, + hue, + 255, + luminol_data::BlendMode::Normal, + texture, + viewport, + Transform::unit(graphics_state), + ) + } + + // takes the full size of a texture, has no hue, opacity, or blend mode, and uses the identity transform + pub fn basic(graphics_state: &GraphicsState, texture: &Texture, viewport: &Viewport) -> Self { + Self::basic_hue(graphics_state, 0, texture, viewport) + } } pub struct Prepared { diff --git a/crates/modals/src/event_graphic_picker.rs b/crates/modals/src/event_graphic_picker.rs index 4b7f50ac..18579311 100644 --- a/crates/modals/src/event_graphic_picker.rs +++ b/crates/modals/src/event_graphic_picker.rs @@ -98,7 +98,7 @@ impl Modal { graphic, &atlas, ) - .unwrap(); + .unwrap(); // FIXME Self { state: State::Closed, diff --git a/crates/modals/src/graphic_picker/mod.rs b/crates/modals/src/graphic_picker/mod.rs index fb0ae898..d0708c1d 100644 --- a/crates/modals/src/graphic_picker/mod.rs +++ b/crates/modals/src/graphic_picker/mod.rs @@ -22,12 +22,18 @@ // terms of the Steamworks API by Valve Corporation, the licensors of this // Program grant you additional permission to convey the resulting work. +use color_eyre::eyre::Context; +use egui::Widget; +use luminol_components::UiExt; use luminol_core::prelude::*; pub struct Modal { state: State, id_source: egui::Id, + button_size: egui::Vec2, + directory: camino::Utf8PathBuf, // do we make this &'static Utf8Path? + button_viewport: Viewport, button_sprite: Option, } @@ -37,8 +43,9 @@ enum State { Open { entries: Vec, filtered_entries: Vec, - search_text: String, + + selected: Selected, }, } @@ -64,6 +71,36 @@ struct Entry { invalid: bool, } +impl Modal { + pub fn new( + update_state: &UpdateState<'_>, + directory: camino::Utf8PathBuf, + path: Option<&camino::Utf8Path>, + button_size: egui::Vec2, + id_source: egui::Id, + ) -> Self { + let button_viewport = Viewport::new(&update_state.graphics, Default::default()); + let button_sprite = path.map(|path| { + let texture = update_state + .graphics + .texture_loader + .load_now_dir(update_state.filesystem, &directory, path) + .unwrap(); // FIXME + + Sprite::basic(&update_state.graphics, &texture, &button_viewport) + }); + + Self { + state: State::Closed, + id_source, + button_size, + directory, + button_viewport, + button_sprite, + } + } +} + impl luminol_core::Modal for Modal { type Data = camino::Utf8PathBuf;