feat: native layer code

feat: login kinds (nsec)
feat: write chat messages
This commit is contained in:
2024-10-31 15:56:29 +00:00
parent a98eb6f4ce
commit 58132d2cf5
21 changed files with 1396 additions and 180 deletions

46
src/widgets/text_input.rs Normal file
View File

@ -0,0 +1,46 @@
use crate::route::{RouteAction, RouteServices};
use crate::theme::{MARGIN_DEFAULT, NEUTRAL_500, NEUTRAL_800, ROUNDING_DEFAULT};
use crate::widgets::NostrWidget;
use egui::{Frame, Response, TextEdit, Ui};
/// Wrap the [TextEdit] widget to handle native keyboard
pub struct NativeTextInput<'a> {
pub text: &'a mut String,
hint_text: Option<&'a str>,
}
impl<'a> NativeTextInput<'a> {
pub fn new(text: &'a mut String) -> Self {
Self {
text,
hint_text: None,
}
}
pub fn with_hint_text(mut self, hint_text: &'a str) -> Self {
self.hint_text = Some(hint_text);
self
}
}
impl<'a> NostrWidget for NativeTextInput<'a> {
fn render(&mut self, ui: &mut Ui, services: &mut RouteServices<'_>) -> Response {
let mut editor = TextEdit::singleline(self.text).frame(false);
if let Some(hint_text) = self.hint_text {
editor = editor.hint_text(egui::RichText::new(hint_text).color(NEUTRAL_500));
}
let response = Frame::none()
.inner_margin(MARGIN_DEFAULT)
.fill(NEUTRAL_800)
.rounding(ROUNDING_DEFAULT)
.show(ui, |ui| ui.add(editor))
.inner;
if response.lost_focus() {
services.action(RouteAction::HideKeyboard);
}
if response.gained_focus() {
services.action(RouteAction::ShowKeyboard);
}
response
}
}