fix: designs

This commit is contained in:
2024-11-05 13:24:10 +00:00
parent ce5f206f6a
commit e718b8e322
7 changed files with 117 additions and 89 deletions

View File

@ -1,5 +1,5 @@
use crate::route::{RouteAction, RouteServices};
use crate::theme::{MARGIN_DEFAULT, NEUTRAL_500, NEUTRAL_800, ROUNDING_DEFAULT};
use crate::theme::{MARGIN_DEFAULT, NEUTRAL_500, NEUTRAL_900, ROUNDING_DEFAULT};
use crate::widgets::NostrWidget;
use egui::{Frame, Response, TextEdit, Ui};
@ -7,6 +7,7 @@ use egui::{Frame, Response, TextEdit, Ui};
pub struct NativeTextInput<'a> {
pub text: &'a mut String,
hint_text: Option<&'a str>,
frame: bool,
}
impl<'a> NativeTextInput<'a> {
@ -14,6 +15,7 @@ impl<'a> NativeTextInput<'a> {
Self {
text,
hint_text: None,
frame: false,
}
}
@ -21,20 +23,31 @@ impl<'a> NativeTextInput<'a> {
self.hint_text = Some(hint_text);
self
}
pub fn with_frame(mut self, frame: bool) -> Self {
self.frame = frame;
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);
let mut editor = TextEdit::singleline(self.text)
.frame(false)
.desired_width(f32::INFINITY);
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;
let response = if self.frame {
Frame::none()
.inner_margin(MARGIN_DEFAULT)
.fill(NEUTRAL_900)
.rounding(ROUNDING_DEFAULT)
.show(ui, |ui| ui.add(editor))
.inner
} else {
ui.add(editor)
};
if response.lost_focus() {
services.action(RouteAction::HideKeyboard);
}