edit profile button

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-01-02 14:57:23 -05:00
parent 45d07cc432
commit a1520fec7e
2 changed files with 80 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

View File

@@ -6,7 +6,7 @@ use crate::ui::note::NoteOptions;
use crate::{colors, images}; use crate::{colors, images};
use crate::{notes_holder::NotesHolder, NostrName}; use crate::{notes_holder::NotesHolder, NostrName};
use egui::load::TexturePoll; use egui::load::TexturePoll;
use egui::{Label, RichText, Rounding, ScrollArea, Sense, Stroke}; use egui::{vec2, Color32, Label, Layout, Rect, RichText, Rounding, ScrollArea, Sense, Stroke};
use enostr::Pubkey; use enostr::Pubkey;
use nostrdb::{Ndb, ProfileRecord, Transaction}; use nostrdb::{Ndb, ProfileRecord, Transaction};
pub use picture::ProfilePic; pub use picture::ProfilePic;
@@ -108,6 +108,7 @@ impl<'a> ProfileView<'a> {
pfp_rect.set_height(size); pfp_rect.set_height(size);
let pfp_rect = pfp_rect.translate(egui::vec2(0.0, -(padding + 2.0 + (size / 2.0)))); let pfp_rect = pfp_rect.translate(egui::vec2(0.0, -(padding + 2.0 + (size / 2.0))));
ui.horizontal(|ui| {
ui.put( ui.put(
pfp_rect, pfp_rect,
ProfilePic::new(self.img_cache, get_profile_url(Some(&profile))).size(size), ProfilePic::new(self.img_cache, get_profile_url(Some(&profile))).size(size),
@@ -124,6 +125,11 @@ impl<'a> ProfileView<'a> {
}); });
} }
ui.with_layout(Layout::right_to_left(egui::Align::Max), |ui| {
ui.add(edit_profile_button())
});
});
ui.add_space(18.0); ui.add_space(18.0);
ui.add(display_name_widget(get_display_name(Some(&profile)), false)); ui.add(display_name_widget(get_display_name(Some(&profile)), false));
@@ -222,6 +228,66 @@ fn copy_key_widget(pfp_rect: &egui::Rect) -> impl egui::Widget + '_ {
} }
} }
fn edit_profile_button() -> impl egui::Widget + 'static {
|ui: &mut egui::Ui| -> egui::Response {
let (rect, resp) = ui.allocate_exact_size(vec2(124.0, 32.0), Sense::click());
let painter = ui.painter_at(rect);
let rect = painter.round_rect_to_pixels(rect);
painter.rect_filled(
rect,
Rounding::same(8.0),
if resp.hovered() {
ui.visuals().widgets.active.bg_fill
} else {
ui.visuals().widgets.inactive.bg_fill
},
);
painter.rect_stroke(
rect.shrink(1.0),
Rounding::same(8.0),
if resp.hovered() {
ui.visuals().widgets.active.bg_stroke
} else {
ui.visuals().widgets.inactive.bg_stroke
},
);
let edit_icon_size = vec2(16.0, 16.0);
let galley = painter.layout(
"Edit Profile".to_owned(),
NotedeckTextStyle::Button.get_font_id(ui.ctx()),
ui.visuals().text_color(),
rect.width(),
);
let space_between_icon_galley = 8.0;
let half_icon_size = edit_icon_size.x / 2.0;
let galley_rect = {
let galley_rect = Rect::from_center_size(rect.center(), galley.rect.size());
galley_rect.translate(vec2(half_icon_size + space_between_icon_galley / 2.0, 0.0))
};
let edit_icon_rect = {
let mut center = galley_rect.left_center();
center.x -= half_icon_size + space_between_icon_galley;
painter.round_rect_to_pixels(Rect::from_center_size(
painter.round_pos_to_pixel_center(center),
edit_icon_size,
))
};
painter.galley(galley_rect.left_top(), galley, Color32::WHITE);
egui::Image::new(egui::include_image!(
"../../../../../assets/icons/edit_icon_4x_dark.png"
))
.paint_at(ui, edit_icon_rect);
resp
}
}
fn display_name_widget(name: NostrName<'_>, add_placeholder_space: bool) -> impl egui::Widget + '_ { fn display_name_widget(name: NostrName<'_>, add_placeholder_space: bool) -> impl egui::Widget + '_ {
move |ui: &mut egui::Ui| -> egui::Response { move |ui: &mut egui::Ui| -> egui::Response {
let disp_resp = name.display_name.map(|disp_name| { let disp_resp = name.display_name.map(|disp_name| {