Skip to content

Commit

Permalink
Merge branch 'master' into webp_animation
Browse files Browse the repository at this point in the history
  • Loading branch information
woelper committed Feb 11, 2024
2 parents 8cfb3a4 + 69fd121 commit 74d66b1
Show file tree
Hide file tree
Showing 26 changed files with 472 additions and 763 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ rand = "0.8"
rand_chacha = "0.3"
rayon = "1.7"
resvg = "0.33.0"
rfd = {version = "0.12", optional = true}
rfd = {version = "0.13", optional = true}
rgb = "0.8"
self_update = {version = "0.39", default-features = false, features = ["rustls"], optional = true}
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
strum = {version = "0.25", features = ["derive"]}
strum_macros = "0.25"
strum = {version = "0.26", features = ["derive"]}
strum_macros = "0.26"
tiny-skia = "0.9"
turbojpeg = {version = "0.5", features = ["image"], optional = true}
usvg = "0.33.0"
Expand Down Expand Up @@ -81,7 +81,7 @@ webp-animation = { version = "0.9.0", features = ["static"] }
heif = ["libheif-rs"]
avif_native = ["avif-decode"]
dav1d = ["libavif-image"]
default = ["turbo", "file_open", "avif_native", "update"]
default = ["turbo", "avif_native", "file_open", "update"]
file_open = ["rfd"]
turbo = ["turbojpeg"]
update = ["self_update"]
Expand Down
359 changes: 1 addition & 358 deletions res/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/net.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/oculante.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/premult.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/screenshot_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/screenshot_exif.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub struct OculanteState {
pub redraw: bool,
pub first_start: bool,
pub toasts: Toasts,
pub filebrowser_id: Option<String>,
}

impl OculanteState {
Expand Down Expand Up @@ -147,6 +148,7 @@ impl Default for OculanteState {
redraw: Default::default(),
first_start: true,
toasts: Toasts::default().with_anchor(egui_notify::Anchor::BottomLeft),
filebrowser_id: None,
}
}
}
267 changes: 267 additions & 0 deletions src/filebrowser.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
use anyhow::{Context, Result};
use dirs;
use egui_phosphor::variants::regular::*;
use notan::egui::{self, *};
use std::io::Write;

use std::{
fs::{self, read_to_string, File},
path::{Path, PathBuf},
};

fn load_recent_dir() -> Result<PathBuf> {
Ok(PathBuf::from(read_to_string(
dirs::cache_dir()
.context("Can't get temp dir")?
.join(".efd_history"),
)?))
}

fn save_recent_dir(p: &Path) -> Result<()> {
let p = if p.is_file() {
p.parent().context("Can't get parent")?.to_path_buf()
} else {
p.to_path_buf()
};

let mut f = File::create(
dirs::cache_dir()
.context("Can't get temp dir")?
.join(".efd_history"),
)?;
write!(f, "{}", p.to_string_lossy())?;
Ok(())
}

pub fn browse_modal<F: FnMut(&PathBuf)>(
save: bool,
filter: &[&str],
mut callback: F,
ctx: &egui::Context,
) {
let mut path = ctx
.data(|r| r.get_temp::<PathBuf>(Id::new("FBPATH")))
.unwrap_or(load_recent_dir().unwrap_or_default());

let mut open = true;

egui::Window::new(if save { "Save" } else { "Open" })
.anchor(Align2::CENTER_CENTER, [0.0, 0.0])
.collapsible(false)
.open(&mut open)
.resizable(true)
.default_width(500.)
.default_height(600.)
// .auto_sized()
.show(ctx, |ui| {
browse(
&mut path,
filter,
save,
|p| {
callback(p);
ctx.memory_mut(|w| w.close_popup());
},
ui,
);

if ui.button("Cancel").clicked() {
ui.ctx().memory_mut(|w| w.close_popup());
}

ctx.data_mut(|w| w.insert_temp(Id::new("FBPATH"), path));
});
if !open {
ctx.memory_mut(|w| w.close_popup());
}
}

pub fn browse<F: FnMut(&PathBuf)>(
path: &mut PathBuf,
filter: &[&str],
save: bool,
mut callback: F,
ui: &mut Ui,
) {
let mut filename = ui
.ctx()
.data(|r| r.get_temp::<String>(Id::new("FBFILENAME")))
.unwrap_or(String::from("unnamed.png"));

let d = fs::read_dir(&path).ok();
ui.horizontal(|ui| {
ui.allocate_ui_with_layout(
Vec2::new(120., ui.available_height()),
Layout::top_down_justified(Align::LEFT),
|ui| {
if let Some(d) = dirs::desktop_dir() {
if ui.button(format!("{DESKTOP} Desktop")).clicked() {
*path = d;
}
}
if let Some(d) = dirs::home_dir() {
if ui.button(format!("{HOUSE} Home")).clicked() {
*path = d;
}
}
if let Some(d) = dirs::document_dir() {
if ui.button(format!("{FILE} Documents")).clicked() {
*path = d;
}
}
if let Some(d) = dirs::download_dir() {
if ui.button(format!("{DOWNLOAD} Downloads")).clicked() {
*path = d;
}
}
if let Some(d) = dirs::picture_dir() {
if ui.button(format!("{IMAGES} Pictures")).clicked() {
*path = d;
}
}
},
);
ui.separator();

ui.vertical(|ui| {
if ui.button(ARROW_BEND_LEFT_UP).clicked() {
if let Some(d) = path.parent() {
let p = d.to_path_buf();
*path = p;
}
}

ui.separator();

egui::ScrollArea::new([false, true])
.max_width(100.)
.min_scrolled_height(400.)
.auto_shrink([true, false])
.show(ui, |ui| match d {
Some(contents) => {
egui::Grid::new("browser")
.striped(true)
.num_columns(0)
.min_col_width(ui.available_width())
.show(ui, |ui| {
let mut entries = contents
.into_iter()
.flat_map(|x| x)
.filter(|de| !de.file_name().to_string_lossy().starts_with("."))
.filter(|de| {
de.path().is_dir()
|| filter.contains(
&de.path()
.extension()
.map(|ext| ext.to_string_lossy().to_string())
.unwrap_or_default()
.to_lowercase()
.as_str(),
)
})
.collect::<Vec<_>>();

entries.sort_by(|a, b| {
a.file_name()
.to_string_lossy()
.to_lowercase()
.cmp(&b.file_name().to_string_lossy().to_lowercase())
});

for de in entries {
if de.path().is_dir() {
if ui
.add(
egui::Button::new(format!(
"{FOLDER} {}",
de.file_name()
.to_string_lossy()
.chars()
.take(50)
.collect::<String>()
))
.frame(false),
)
.clicked()
{
*path = de.path();
}
} else {
if ui
.add(
egui::Button::new(format!(
"{IMAGE_SQUARE} {}",
de.file_name()
.to_string_lossy()
.chars()
.take(50)
.collect::<String>()
))
.frame(false),
)
.clicked()
{
_ = save_recent_dir(&de.path());
if !save {
callback(&de.path());
} else {
filename = de
.path()
.to_path_buf()
.file_name()
.map(|f| f.to_string_lossy().to_string())
.unwrap_or_default();
ui.ctx().data_mut(|w| {
w.insert_temp(
Id::new("FBFILENAME"),
filename.clone(),
)
});
}
// self.result = Some(de.path().to_path_buf());
}
}
ui.end_row();
}
});
}
None => {
ui.label("no contents");
}
});
ui.spacing();
ui.separator();

if save {
ui.horizontal(|ui| {
ui.label("Filename");
ui.add(
egui::TextEdit::singleline(&mut filename)
.desired_width(ui.available_width() - 10.),
);
});

ui.horizontal(|ui| {
let ext = Path::new(&filename)
.extension()
.map(|e| e.to_string_lossy().to_string())
.unwrap_or_default();
for f in filter {
if ui.selectable_label(&ext == f, f.to_string()).clicked() {
filename = Path::new(&filename)
.with_extension(f)
.to_string_lossy()
.to_string();
}
}
});

ui.ctx()
.data_mut(|w| w.insert_temp(Id::new("FBFILENAME"), filename.clone()));
if ui.button("Save").clicked() {
callback(&path.join(filename));
}
}
});
});
}
Loading

0 comments on commit 74d66b1

Please sign in to comment.