Skip to content

Commit

Permalink
Merge branch 'main' into feat/toml-config
Browse files Browse the repository at this point in the history
  • Loading branch information
THEGOLDENPRO authored Nov 15, 2024
2 parents 4d09748 + 7e6f6ce commit 4a68de5
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
Binary file added assets/osaka.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
70 changes: 61 additions & 9 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ pub struct Roseate {
toasts: ToastsManager,
magnification_panel: MagnificationPanel,
window_scaling: WindowScaling,
image_loader: ImageLoader,
last_window_rect: Rect,
config: Config
image_loader: ImageLoader,
config: Config,
}

impl Roseate {
Expand All @@ -39,9 +39,9 @@ impl Roseate {
info_box,
magnification_panel,
window_scaling: WindowScaling::new(),
image_loader: image_loader,
last_window_rect: Rect::NOTHING,
config
image_loader: image_loader,
config,
}
}

Expand Down Expand Up @@ -84,6 +84,15 @@ impl Roseate {

ctx.set_style(custom_style);
}

fn draw_dotted_line(&self, ui: &egui::Painter, pos: &[egui::Pos2]) {
ui.add(
egui::Shape::dashed_line(pos, Stroke {
width: 2.0,
color: Color32::from_hex(&self.theme.accent_colour.hex_code).unwrap()
}, 10.0, 10.0)
);
}
}

impl eframe::App for Roseate {
Expand Down Expand Up @@ -111,28 +120,55 @@ impl eframe::App for Roseate {
self.toasts.update(ctx);

if self.image.is_none() {
// Collect dropped files.
ctx.input(|i| {
let dropped_files = &i.raw.dropped_files;

if !dropped_files.is_empty() {
let path = dropped_files.first().unwrap()
.path
.as_ref()
.unwrap(); // gotta love rust ~ ananas

let mut image = Image::from_path(path);

self.image = Some(image.clone());
self.image_loader.load_image(&mut image, true);
}
});

ui.centered_and_justified(|ui| {
let rose_width: f32 = 130.0;
let file_is_hovering = !ctx.input(|i| i.raw.hovered_files.is_empty());

let mut rose_rect = Rect::NOTHING;

egui::Frame::default()
.outer_margin(
// I adjust the margin as it's the only way I know to
// narrow down the interactive part (clickable part) of the rose image.
Margin::symmetric(
// NOTE: width and height of rose are the same.
(window_rect.width() / 2.0) - rose_width / 2.0,
(window_rect.height() / 2.0) - rose_width / 2.0
)
)
.show(ui, |ui| {
let response = ui.add(
let rose_response = ui.add(
egui::Image::new(get_platform_rose_image())
.max_width(rose_width)
.sense(egui::Sense::click())
);

response.clone().on_hover_cursor(CursorIcon::PointingHand);
rose_rect = rose_response.rect;

if file_is_hovering {
ui.label("You're about to drop a file.");
}

rose_response.clone().on_hover_cursor(CursorIcon::PointingHand);

if response.clicked() {
if rose_response.clicked() {
let image_result = files::select_image();

match image_result {
Expand All @@ -149,6 +185,23 @@ impl eframe::App for Roseate {
}
}
);

if file_is_hovering {
let rect = rose_rect.expand2(
Vec2::new(150.0, 100.0)
);
let painter = ui.painter();

let top_right = rect.right_top();
let top_left = rect.left_top();
let bottom_right = rect.right_bottom();
let bottom_left = rect.left_bottom();

self.draw_dotted_line(painter, &[top_left, top_right]);
self.draw_dotted_line(painter, &[top_right, bottom_right]);
self.draw_dotted_line(painter, &[bottom_right, bottom_left]);
self.draw_dotted_line(painter, &[bottom_left, top_left]);
}
});

return; // don't do anything else, you know, like stop right there bitch
Expand Down Expand Up @@ -202,8 +255,6 @@ impl eframe::App for Roseate {
self.zoom_pan.handle_pan_input(ctx, &response, self.info_box.response.as_ref());
});

// TODO:

// We must update the WindowScaling with the window size AFTER
// the image has loaded to maintain that smooth scaling animation.
self.window_scaling.update(&window_rect, &image.image_size);
Expand Down Expand Up @@ -243,6 +294,7 @@ impl eframe::App for Roseate {

}


fn get_platform_rose_image<'a>() -> ImageSource<'a> {
if cfg!(target_os = "windows") {
return egui::include_image!("../assets/rose_emojis/microsoft.png");
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ fn main() -> eframe::Result {
let mut toasts = ToastsManager::new();

let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([800.0, 600.0]),
viewport: egui::ViewportBuilder::default()
.with_inner_size([800.0, 600.0])
.with_drag_and_drop(true),
..Default::default()
};

Expand Down

0 comments on commit 4a68de5

Please sign in to comment.