Skip to content

Commit

Permalink
Merge hide nsec in account panel
Browse files Browse the repository at this point in the history
jglad (2):
      fix compilation
      hide nsec in account panel
  • Loading branch information
jb55 committed Feb 21, 2025
2 parents dfa4b24 + 030e76c commit 32c7f83
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 5 deletions.
Binary file added assets/icons/eye-dark.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 added assets/icons/eye-light.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 added assets/icons/eye-slash-dark.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 added assets/icons/eye-slash-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions crates/notedeck_columns/src/login_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct AcquireKeyState {
error: Option<AcquireKeyError>,
key_on_error: Option<String>,
should_create_new: bool,
show_password: bool,
}

impl<'a> AcquireKeyState {
Expand Down Expand Up @@ -115,6 +116,14 @@ impl<'a> AcquireKeyState {

ui.add_space(8.0);
}

pub fn toggle_password_visibility(&mut self) {
self.show_password = !self.show_password;
}

pub fn password_visible(&self) -> bool {
self.show_password
}
}

fn show_error(ui: &mut egui::Ui, err: &AcquireKeyError) {
Expand Down
40 changes: 36 additions & 4 deletions crates/notedeck_columns/src/ui/account_login_view.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::login_manager::AcquireKeyState;
use crate::ui::{Preview, PreviewConfig};
use egui::{Align, Button, Color32, Frame, InnerResponse, Margin, RichText, Vec2};
use egui::{
Align, Button, Color32, Frame, Image, InnerResponse, Margin, RichText, TextBuffer, Vec2,
};
use egui::{Layout, TextEdit};
use enostr::Keypair;
use notedeck::fonts::get_font_size;
Expand Down Expand Up @@ -38,7 +40,16 @@ impl<'a> AccountLoginView<'a> {
});

ui.vertical_centered_justified(|ui| {
ui.add(login_textedit(self.manager));
ui.horizontal(|ui| {
let available_width = ui.available_width();
let button_width = 32.0;
let text_edit_width = available_width - button_width;

ui.add_sized([text_edit_width, 40.0], login_textedit(self.manager));
if eye_button(ui, self.manager.password_visible()).clicked() {
self.manager.toggle_password_visibility();
}
});
ui.with_layout(Layout::left_to_right(Align::TOP), |ui| {
let help_text_style = NotedeckTextStyle::Small;
ui.add(egui::Label::new(
Expand Down Expand Up @@ -105,15 +116,36 @@ fn login_button() -> Button<'static> {
}

fn login_textedit(manager: &mut AcquireKeyState) -> TextEdit {
manager.get_acquire_textedit(|text| {
let create_textedit: fn(&mut dyn TextBuffer) -> TextEdit = |text| {
egui::TextEdit::singleline(text)
.hint_text(
RichText::new("Your key here...").text_style(NotedeckTextStyle::Body.text_style()),
)
.vertical_align(Align::Center)
.min_size(Vec2::new(0.0, 40.0))
.margin(Margin::same(12.0))
})
};

let is_visible = manager.password_visible();
let mut text_edit = manager.get_acquire_textedit(create_textedit);
if !is_visible {
text_edit = text_edit.password(true);
}
text_edit
}

fn eye_button(ui: &mut egui::Ui, is_visible: bool) -> egui::Response {
let is_dark_mode = ui.visuals().dark_mode;
let icon = Image::new(if is_visible && is_dark_mode {
egui::include_image!("../../../../assets/icons/eye-dark.png")
} else if is_visible {
egui::include_image!("../../../../assets/icons/eye-light.png")
} else if is_dark_mode {
egui::include_image!("../../../../assets/icons/eye-slash-dark.png")
} else {
egui::include_image!("../../../../assets/icons/eye-slash-light.png")
});
ui.add(Button::image(icon).frame(false))
}

mod preview {
Expand Down
2 changes: 1 addition & 1 deletion crates/notedeck_columns/src/ui/search_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn user_result<'a>(
cache: &'a mut ImageCache,
index: usize,
width: f32,
) -> impl egui::Widget + use<'a> {
) -> impl egui::Widget + 'a {
move |ui: &mut egui::Ui| -> egui::Response {
let min_img_size = 48.0;
let max_image = min_img_size * ICON_EXPANSION_MULTIPLE;
Expand Down

0 comments on commit 32c7f83

Please sign in to comment.