Skip to content

Commit 9be194f

Browse files
committed
open theme dir
1 parent ce7ca71 commit 9be194f

8 files changed

Lines changed: 122 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 38 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cargo-features = ["profile-rustflags", "trim-paths"]
22

33
[package]
44
name = "bit_flipper"
5-
version = "0.3.5"
5+
version = "0.3.6"
66
edition = "2024"
77
authors = ["_eyewave <89079979+eye-wave@users.noreply.github.com>"]
88
license = "GPL-3.0-or-later"
@@ -28,6 +28,7 @@ nih_plug = { git = "https://github.com/robbert-vdh/nih-plug.git", features = [
2828
"assert_process_allocs",
2929
"standalone",
3030
] }
31+
open = "5.3.2"
3132
pollster = "0.4.0"
3233
raw-window-handle = "0.5"
3334
raw-window-handle-06 = { package = "raw-window-handle", version = "0.6" }
70 Bytes
Loading

src/editor.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::bus::Bus;
2-
use crate::editor::theme::load_textures;
2+
use crate::editor::theme::{load_textures, open_theme_dir};
33
use crate::model::FlipModes;
44
use crate::{BitFlipperParams, UI_SCALE};
55
use core::{CustomWgpuEditor, baseview_window_to_surface_target};
@@ -150,6 +150,7 @@ impl CustomWgpuWindow {
150150
Box::new(ModeButtonBuilder::new(&device, pipe.clone()).mode(FlipModes::Or)),
151151
Box::new(ModeButtonBuilder::new(&device, pipe.clone()).mode(FlipModes::And)),
152152
Box::new(ModeButtonBuilder::new(&device, pipe.clone()).mode(FlipModes::Not)),
153+
Box::new(OpenFolderBtn::new(&device, &UV_btn_open, (182, 2), pipe.clone()).unwrap()),
153154
Box::new(MonitorGroup::new(
154155
&device,
155156
[(20, 155), (105, 155)],
@@ -341,6 +342,14 @@ impl baseview::WindowHandler for CustomWgpuWindow {
341342

342343
continue;
343344
}
345+
346+
if let Some(btn) =
347+
el.as_mut().as_any_mut().downcast_mut::<OpenFolderBtn>()
348+
{
349+
if btn.is_mouse_over(downscale(self.event_store.mouse_pos)) {
350+
open_theme_dir().ok();
351+
}
352+
}
344353
} else if let Some(btn) = el.as_any_mut().downcast_mut::<Warning>() {
345354
let mouse_pos = self.event_store.mouse_pos;
346355

src/editor/theme.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,14 @@ pub fn load_textures() -> (Cow<'static, [u8]>, Cow<'static, [u8]>) {
3232
(Cow::Borrowed(DEFAULT_PALETTE), Cow::Borrowed(DEFAULT_ATLAS))
3333
}
3434
}
35+
36+
pub fn open_theme_dir() -> std::io::Result<()> {
37+
let config_dir = dirs::config_dir();
38+
if let Some(tex_path) = config_dir.map(|p| p.join(env!("CARGO_PKG_NAME"))) {
39+
if tex_path.exists() {
40+
open::that(tex_path)?;
41+
}
42+
}
43+
44+
Ok(())
45+
}

src/editor/ui.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod button;
66
mod color_box;
77
mod digit;
88
mod monitor;
9+
mod open_folder;
910
mod postprocess;
1011
mod slider;
1112
mod static_box;
@@ -20,6 +21,7 @@ pub use button::*;
2021
pub use color_box::*;
2122
pub use digit::*;
2223
pub use monitor::*;
24+
pub use open_folder::*;
2325
pub use postprocess::*;
2426
pub use slider::*;
2527
pub use static_box::*;

src/editor/ui/open_folder.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use crate::editor::texture::{TextureError, UVSegment};
2+
use crate::editor::ui::{StaticBox, StaticBoxPipeline, UiBox, UiElement, UiInteractive};
3+
use std::sync::Arc;
4+
5+
pub struct OpenFolderBtn(StaticBox);
6+
7+
impl OpenFolderBtn {
8+
pub fn new(
9+
device: &wgpu::Device,
10+
uv_segment: &UVSegment,
11+
position: (u16, u16),
12+
pipeline: Arc<StaticBoxPipeline>,
13+
) -> Result<Self, TextureError> {
14+
Ok(Self(StaticBox::new(
15+
device, uv_segment, position, pipeline,
16+
)?))
17+
}
18+
}
19+
20+
impl UiElement for OpenFolderBtn {
21+
fn as_any(&self) -> &dyn std::any::Any {
22+
self
23+
}
24+
25+
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
26+
self
27+
}
28+
29+
fn prerender(
30+
&mut self,
31+
queue: &wgpu::Queue,
32+
params: Arc<crate::BitFlipperParams>,
33+
buffer: &[f32],
34+
) {
35+
self.0.prerender(queue, params, buffer);
36+
}
37+
38+
fn render(&self, render_pass: &mut wgpu::RenderPass) {
39+
self.0.render(render_pass);
40+
}
41+
}
42+
43+
impl UiBox for OpenFolderBtn {
44+
fn width(&self) -> u16 {
45+
self.0.width()
46+
}
47+
48+
fn height(&self) -> u16 {
49+
self.0.height()
50+
}
51+
52+
fn position(&self) -> (u16, u16) {
53+
self.0.position()
54+
}
55+
}
56+
57+
impl UiInteractive for OpenFolderBtn {}

src/editor/ui/texture.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub enum UVSegment {
3434
UV_btn_or,
3535
UV_btn_and,
3636
UV_btn_not,
37+
UV_btn_open,
3738
UV_slider_handle,
3839
UV_digi_1_0,
3940
UV_digi_1_1,
@@ -84,6 +85,7 @@ const UV_MAP: &[(UVSegment, [u16; 4])] = &[
8485
(UVSegment::UV_btn_or, [44, 173, 16, 16]),
8586
(UVSegment::UV_btn_and, [60, 173, 16, 16]),
8687
(UVSegment::UV_btn_not, [76, 173, 16, 16]),
88+
(UVSegment::UV_btn_open, [28, 157, 16, 16]),
8789
(UVSegment::UV_slider_handle, [73, 165, 19, 8]),
8890
//
8991
(UVSegment::UV_digi_1_0, [0, 153, 9, 6]),

0 commit comments

Comments
 (0)