actionbar: remove border on reply button, add expand animation

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-06-13 09:36:53 -07:00
parent db1642bc31
commit c4e0c710c9
3 changed files with 29 additions and 17 deletions

View File

@@ -4,16 +4,16 @@ pub fn hover_expand(
size: f32, size: f32,
expand_size: f32, expand_size: f32,
anim_speed: f32, anim_speed: f32,
) -> (egui::Rect, f32) { ) -> (egui::Rect, f32, egui::Response) {
// Allocate space for the profile picture with a fixed size // Allocate space for the profile picture with a fixed size
let default_size = size + expand_size; let default_size = size + expand_size;
let (rect, response) = let (rect, response) =
ui.allocate_exact_size(egui::vec2(default_size, default_size), egui::Sense::hover()); ui.allocate_exact_size(egui::vec2(default_size, default_size), egui::Sense::click());
let val = ui let val = ui
.ctx() .ctx()
.animate_bool_with_time(id, response.hovered(), anim_speed); .animate_bool_with_time(id, response.hovered(), anim_speed);
let size = size + val * expand_size; let size = size + val * expand_size;
(rect, size) (rect, size, response)
} }

View File

@@ -207,7 +207,7 @@ impl<'a> Note<'a> {
if self.app.is_mobile() { if self.app.is_mobile() {
ui.add(ui::ProfilePic::new(&mut self.app.img_cache, pic)); ui.add(ui::ProfilePic::new(&mut self.app.img_cache, pic));
} else { } else {
let (rect, size) = ui::anim::hover_expand( let (rect, size, _resp) = ui::anim::hover_expand(
ui, ui,
egui::Id::new((profile_key, note_key)), egui::Id::new((profile_key, note_key)),
pfp_size, pfp_size,
@@ -295,7 +295,7 @@ impl<'a> Note<'a> {
)); ));
if self.options().has_actionbar() { if self.options().has_actionbar() {
note_action = render_note_actionbar(ui).inner; note_action = render_note_actionbar(ui, note_key).inner;
} }
}); });
}) })
@@ -313,7 +313,10 @@ pub enum BarAction {
Reply, Reply,
} }
fn render_note_actionbar(ui: &mut egui::Ui) -> egui::InnerResponse<Option<BarAction>> { fn render_note_actionbar(
ui: &mut egui::Ui,
note_key: NoteKey,
) -> egui::InnerResponse<Option<BarAction>> {
ui.horizontal(|ui| { ui.horizontal(|ui| {
let img_data = if ui.style().visuals.dark_mode { let img_data = if ui.style().visuals.dark_mode {
egui::include_image!("../../../assets/icons/reply.png") egui::include_image!("../../../assets/icons/reply.png")
@@ -322,16 +325,25 @@ fn render_note_actionbar(ui: &mut egui::Ui) -> egui::InnerResponse<Option<BarAct
}; };
ui.spacing_mut().button_padding = egui::vec2(0.0, 0.0); ui.spacing_mut().button_padding = egui::vec2(0.0, 0.0);
if ui
.add( let button_size = 10.0;
egui::Button::image(egui::Image::new(img_data).max_width(10.0)) let expand_size = 5.0;
//.stroke(egui::Stroke::NONE) let anim_speed = 0.05;
.frame(false)
.stroke(egui::Stroke::NONE) let (rect, size, resp) = ui::anim::hover_expand(
.fill(ui.style().visuals.panel_fill), ui,
) ui.id().with(("reply_anim", note_key)),
.clicked() button_size,
{ expand_size,
anim_speed,
);
// align rect to note contents
let rect = rect.translate(egui::vec2(-(expand_size / 2.0), 0.0));
ui.put(rect, egui::Image::new(img_data).max_width(size));
if resp.clicked() {
Some(BarAction::Reply) Some(BarAction::Reply)
} else { } else {
None None

View File

@@ -164,7 +164,7 @@ mod preview {
let expand_size = 10.0; let expand_size = 10.0;
let anim_speed = 0.05; let anim_speed = 0.05;
let (rect, size) = ui::anim::hover_expand( let (rect, size, _resp) = ui::anim::hover_expand(
ui, ui,
egui::Id::new(profile.key().unwrap()), egui::Id::new(profile.key().unwrap()),
ui::ProfilePic::default_size(), ui::ProfilePic::default_size(),