Make hovering feel better
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
dcca967932
commit
480bdbbf1d
1 changed files with 37 additions and 17 deletions
54
src/app.rs
54
src/app.rs
|
@ -19,7 +19,7 @@ use encase::ShaderType;
|
|||
use glam::Mat2;
|
||||
use glyphon::{Buffer, FontSystem, Metrics};
|
||||
use keyframe::functions;
|
||||
use range_map::RangeMap;
|
||||
use range_map::{RangeMap, RangeSet};
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
||||
|
@ -68,6 +68,7 @@ pub enum ContextBlock {
|
|||
}
|
||||
|
||||
const CONTEXT_METRICS: Metrics = Metrics::new(16.0, 18.0);
|
||||
const HOVER_TIME: f64 = 0.5;
|
||||
|
||||
const ABOUT_ME: Cow<'static, [Event<'static>]> =
|
||||
include!(concat!(env!("OUT_DIR"), "/about_me.jot"));
|
||||
|
@ -427,7 +428,7 @@ impl Portfolio {
|
|||
from_pos: [0.0, 0.0],
|
||||
to_pos: [0.0, 0.0],
|
||||
from_beamwidth: 2.0,
|
||||
to_beamwidth: 2.0,
|
||||
to_beamwidth: 6.0,
|
||||
font_system,
|
||||
name_buffers,
|
||||
buffer_size,
|
||||
|
@ -456,16 +457,11 @@ impl Portfolio {
|
|||
|
||||
pub fn hover(&mut self, hovered: bool, ui: &egui::Ui) {
|
||||
if self.hovered != hovered {
|
||||
self.hover_time_offset = ui.input(|i| i.time);
|
||||
let time = ui.input(|i| i.time);
|
||||
let change_factor = HOVER_TIME - (time - self.hover_time_offset).clamp(0.0, HOVER_TIME);
|
||||
self.hover_time_offset = time - change_factor;
|
||||
}
|
||||
self.hovered = hovered;
|
||||
if hovered {
|
||||
self.to_beamwidth = 6.0;
|
||||
self.from_beamwidth = 2.0;
|
||||
} else {
|
||||
self.to_beamwidth = 2.0;
|
||||
self.from_beamwidth = 6.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -526,8 +522,12 @@ impl Portfolio {
|
|||
functions::EaseOutCubic,
|
||||
self.from_beamwidth,
|
||||
self.to_beamwidth,
|
||||
ui.input(|i| i.time) - self.hover_time_offset,
|
||||
0.5,
|
||||
if self.hovered {
|
||||
ui.input(|i| i.time) - self.hover_time_offset
|
||||
} else {
|
||||
HOVER_TIME - (ui.input(|i| i.time) - self.hover_time_offset)
|
||||
},
|
||||
HOVER_TIME,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -619,6 +619,7 @@ impl eframe::App for Portfolio {
|
|||
.translate(Vec2::new(0.0, CONTEXT_METRICS.line_height * 4.0))
|
||||
};
|
||||
let mut link_clicked = false;
|
||||
let mut hovered = false;
|
||||
if zoom_view_opacity > 0.0 {
|
||||
ui.painter().rect_filled(
|
||||
Rect::from_min_size(rect.min, self.window.size).expand(25.0),
|
||||
|
@ -634,11 +635,31 @@ impl eframe::App for Portfolio {
|
|||
// ui.painter().debug_rect(text_rect, Color32::GREEN, "");
|
||||
if let Some(url_map) = url_map {
|
||||
let text_response = ui.allocate_rect(text_rect, Sense::click());
|
||||
if text_response.clicked() && !self.image_zoomed {
|
||||
let mut buffer = buffer.write();
|
||||
let mut editor =
|
||||
Editor::new(BufferRef::Borrowed(buffer.deref_mut()));
|
||||
let mut buffer = buffer.write();
|
||||
let mut editor =
|
||||
Editor::new(BufferRef::Borrowed(buffer.deref_mut()));
|
||||
// if text_response.hovered()
|
||||
// && ui.input(|i| i.raw_scroll_delta == Vec2::ZERO)
|
||||
// {
|
||||
// let mouse_pos = ui
|
||||
// .input(|i| i.pointer.latest_pos().unwrap_or_default())
|
||||
// - text_rect.min.to_vec2();
|
||||
|
||||
// editor.action(
|
||||
// self.font_system.lock().deref_mut(),
|
||||
// glyphon::Action::Click {
|
||||
// x: mouse_pos.x as i32,
|
||||
// y: mouse_pos.y as i32 - 3,
|
||||
// },
|
||||
// );
|
||||
|
||||
// let mut location = editor.cursor();
|
||||
// match location.affinity {
|
||||
// glyphon::Affinity::After => location.index += 1,
|
||||
// glyphon::Affinity::Before => {}
|
||||
// }
|
||||
// }
|
||||
if text_response.clicked() && !self.image_zoomed {
|
||||
let mouse_click = ui.input(|i| {
|
||||
i.pointer.interact_pos().unwrap_or_default()
|
||||
}) - text_rect.min.to_vec2();
|
||||
|
@ -792,7 +813,6 @@ impl eframe::App for Portfolio {
|
|||
}
|
||||
});
|
||||
}
|
||||
let mut hovered = false;
|
||||
if self.zoomed {
|
||||
if ui.input(|i| i.pointer.any_click()) && !link_clicked {
|
||||
if self.image_zoomed {
|
||||
|
|
Loading…
Reference in a new issue