Skip to content

Commit

Permalink
work on the graphic picker a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
melody-rs committed Jul 2, 2024
1 parent 6603a13 commit 7eb948d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
26 changes: 26 additions & 0 deletions crates/graphics/src/primitives/sprite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/modals/src/event_graphic_picker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Modal {
graphic,
&atlas,
)
.unwrap();
.unwrap(); // FIXME

Self {
state: State::Closed,
Expand Down
39 changes: 38 additions & 1 deletion crates/modals/src/graphic_picker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Sprite>,
}
Expand All @@ -37,8 +43,9 @@ enum State {
Open {
entries: Vec<Entry>,
filtered_entries: Vec<Entry>,

search_text: String,

selected: Selected,
},
}

Expand All @@ -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;

Expand Down

0 comments on commit 7eb948d

Please sign in to comment.