macro for text_edit which applies the right text color

This commit is contained in:
Mike Dilger 2023-03-07 07:51:16 +13:00
parent 6d424064a4
commit c3d2932b97
8 changed files with 45 additions and 102 deletions

View File

@ -5,7 +5,7 @@ use crate::tags::{keys_from_text, notes_from_text};
use crate::ui::{GossipUi, HighlightType, Page, Theme};
use eframe::egui;
use eframe::epaint::text::LayoutJob;
use egui::{Align, Context, Layout, RichText, ScrollArea, TextEdit, Ui, Vec2};
use egui::{Align, Context, Layout, RichText, ScrollArea, Ui, Vec2};
use memoize::memoize;
use nostr_types::Tag;
@ -120,8 +120,7 @@ fn real_posting_area(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
ui.horizontal(|ui| {
ui.label("Subject: ");
ui.add(
TextEdit::singleline(&mut app.subject)
.text_color(app.settings.theme.input_text_color())
text_edit_line!(app, app.subject)
.hint_text("Type subject here")
.desired_width(f32::INFINITY),
);
@ -132,8 +131,7 @@ fn real_posting_area(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
ui.horizontal(|ui| {
ui.label("Content Warning: ");
ui.add(
TextEdit::singleline(&mut app.content_warning)
.text_color(app.settings.theme.input_text_color())
text_edit_line!(app, app.content_warning)
.hint_text("Type content warning here")
.desired_width(f32::INFINITY),
);
@ -141,8 +139,7 @@ fn real_posting_area(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
}
ui.add(
TextEdit::multiline(&mut app.draft)
.text_color(app.settings.theme.input_text_color())
text_edit_multiline!(app, app.draft)
.hint_text("Type your message here")
.desired_width(f32::INFINITY)
.lock_focus(true)
@ -188,8 +185,7 @@ fn real_posting_area(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
}
ui.add(
TextEdit::singleline(&mut app.tag_someone)
.text_color(app.settings.theme.input_text_color())
text_edit_line!(app, app.tag_someone)
.desired_width(100.0)
.hint_text("@username"),
);

View File

@ -1,3 +1,17 @@
macro_rules! text_edit_line {
($app:ident, $var:expr) => {
egui::widgets::TextEdit::singleline(&mut $var)
.text_color($app.settings.theme.input_text_color())
};
}
macro_rules! text_edit_multiline {
($app:ident, $var:expr) => {
egui::widgets::TextEdit::multiline(&mut $var)
.text_color($app.settings.theme.input_text_color())
};
}
mod components;
mod feed;
mod help;

View File

@ -2,7 +2,7 @@ use super::GossipUi;
use crate::comms::ToOverlordMessage;
use crate::globals::GLOBALS;
use eframe::egui;
use egui::{Context, TextEdit, Ui};
use egui::{Context, Ui};
use nostr_types::RelayUrl;
pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
@ -24,11 +24,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
ui.horizontal(|ui| {
ui.label("Enter");
ui.add(
TextEdit::singleline(&mut app.nprofile_follow)
.text_color(app.settings.theme.input_text_color())
.hint_text("nprofile1..."),
);
ui.add(text_edit_line!(app, app.nprofile_follow).hint_text("nprofile1..."));
});
if ui.button("follow").clicked() {
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::FollowNprofile(
@ -45,11 +41,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
ui.horizontal(|ui| {
ui.label("Enter user@domain");
ui.add(
TextEdit::singleline(&mut app.nip05follow)
.text_color(app.settings.theme.input_text_color())
.hint_text("user@domain"),
);
ui.add(text_edit_line!(app, app.nip05follow).hint_text("user@domain"));
});
if ui.button("follow").clicked() {
let _ = GLOBALS
@ -66,19 +58,11 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
ui.horizontal(|ui| {
ui.label("Enter public key");
ui.add(
TextEdit::singleline(&mut app.follow_pubkey)
.text_color(app.settings.theme.input_text_color())
.hint_text("npub1 or hex"),
);
ui.add(text_edit_line!(app, app.follow_pubkey).hint_text("npub1 or hex"));
});
ui.horizontal(|ui| {
ui.label("Enter a relay URL where we can find them");
ui.add(
TextEdit::singleline(&mut app.follow_pubkey_at_relay)
.text_color(app.settings.theme.input_text_color())
.hint_text("wss://..."),
);
ui.add(text_edit_line!(app, app.follow_pubkey_at_relay).hint_text("wss://..."));
});
if ui.button("follow").clicked() {
if let Ok(url) = RelayUrl::try_from_str(&app.follow_pubkey_at_relay) {

View File

@ -3,7 +3,7 @@ use crate::comms::ToOverlordMessage;
use crate::db::DbRelay;
use crate::globals::GLOBALS;
use eframe::egui;
use egui::{Align, Context, Layout, TextEdit, Ui};
use egui::{Align, Context, Layout, Ui};
use egui_extras::{Column, TableBuilder};
use nostr_types::{RelayUrl, Unixtime};
@ -13,10 +13,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
ui.horizontal(|ui| {
ui.label("Enter a new relay URL:");
ui.add(
TextEdit::singleline(&mut app.new_relay_url)
.text_color(app.settings.theme.input_text_color()),
);
ui.add(text_edit_line!(app, app.new_relay_url));
if ui.button("Add").clicked() {
if let Ok(url) = RelayUrl::try_from_str(&app.new_relay_url) {
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::AddRelay(url));

View File

@ -2,7 +2,7 @@ use super::{GossipUi, Page};
use crate::feed::FeedKind;
use crate::GLOBALS;
use eframe::{egui, Frame};
use egui::{Context, TextEdit, Ui};
use egui::{Context, Ui};
use nostr_types::{Id, PublicKey};
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut Frame, ui: &mut Ui) {
@ -15,7 +15,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut Frame, ui:
ui.horizontal(|ui| {
ui.label("🔎");
let response = ui.add(
TextEdit::singleline(&mut app.search)
text_edit_line!(app, app.search)
.hint_text("npub1 or note1, other kinds of searches not yet implemented")
.desired_width(f32::INFINITY),
);

View File

@ -2,7 +2,7 @@ use super::GossipUi;
use crate::globals::GLOBALS;
use crate::ui::widgets::CopyButton;
use eframe::egui;
use egui::{Context, TextEdit, Ui};
use egui::{Context, Ui};
use tokio::task;
pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
@ -11,8 +11,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
ui.label("Enter NIP-26 delegation tag, to post on the behalf of another indentity (I will be the delegatee)");
ui.add(
TextEdit::multiline(&mut app.delegatee_tag_str)
.text_color(app.settings.theme.input_text_color())
text_edit_multiline!(app, app.delegatee_tag_str)
.hint_text("full delegation tag, JSON")
.desired_width(f32::INFINITY),
);

View File

@ -80,11 +80,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
if app.editing_metadata {
ui.horizontal(|ui| {
ui.label("Add new field: ");
ui.add(
TextEdit::singleline(&mut app.new_metadata_fieldname)
.text_color(app.settings.theme.input_text_color())
.desired_width(120.0),
);
ui.add(text_edit_line!(app, app.new_metadata_fieldname).desired_width(120.0));
if ui.button("ADD").clicked() {
app.metadata.other.insert(
app.new_metadata_fieldname.clone(),

View File

@ -5,7 +5,7 @@ use crate::globals::{Globals, GLOBALS};
use crate::ui::widgets::CopyButton;
use eframe::egui;
use egui::style::Margin;
use egui::{Color32, Context, Frame, ScrollArea, SelectableLabel, Stroke, TextEdit, Ui, Vec2};
use egui::{Color32, Context, Frame, ScrollArea, SelectableLabel, Stroke, Ui, Vec2};
use nostr_types::{KeySecurity, PublicKeyHex};
use zeroize::Zeroize;
@ -218,11 +218,7 @@ fn offer_unlock_priv_key(app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal(|ui| {
ui.label("Passphrase: ");
let response = ui.add(
TextEdit::singleline(&mut app.password)
.text_color(app.settings.theme.input_text_color())
.password(true),
);
let response = ui.add(text_edit_line!(app, app.password).password(true));
if response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)) {
let _ = GLOBALS
.to_overlord
@ -271,31 +267,19 @@ fn offer_change_password(app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.label("Enter Existing Passphrase: ");
ui.add(
TextEdit::singleline(&mut app.password)
.text_color(app.settings.theme.input_text_color())
.password(true),
);
ui.add(text_edit_line!(app, app.password).password(true));
});
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.label("Enter New Passphrase: ");
ui.add(
TextEdit::singleline(&mut app.password2)
.text_color(app.settings.theme.input_text_color())
.password(true),
);
ui.add(text_edit_line!(app, app.password2).password(true));
});
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.label("Repeat New Passphrase: ");
ui.add(
TextEdit::singleline(&mut app.password3)
.text_color(app.settings.theme.input_text_color())
.password(true),
);
ui.add(text_edit_line!(app, app.password3).password(true));
});
if ui.button("Change Passphrase").clicked() {
@ -333,11 +317,7 @@ fn offer_export_priv_key(app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal(|ui| {
ui.add_space(10.0);
ui.label("Enter Passphrase To Export: ");
ui.add(
TextEdit::singleline(&mut app.password)
.text_color(app.settings.theme.input_text_color())
.password(true),
);
ui.add(text_edit_line!(app, app.password).password(true));
});
if ui.button("Export Private Key as bech32").clicked() {
@ -374,8 +354,7 @@ fn offer_import_priv_key(app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal(|ui| {
ui.label("Enter private key");
ui.add(
TextEdit::singleline(&mut app.import_priv)
.text_color(app.settings.theme.input_text_color())
text_edit_line!(app, app.import_priv)
.hint_text("nsec1, or hex")
.desired_width(f32::INFINITY)
.password(true),
@ -383,19 +362,11 @@ fn offer_import_priv_key(app: &mut GossipUi, ui: &mut Ui) {
});
ui.horizontal(|ui| {
ui.label("Enter a passphrase to keep it encrypted under");
ui.add(
TextEdit::singleline(&mut app.password)
.text_color(app.settings.theme.input_text_color())
.password(true),
);
ui.add(text_edit_line!(app, app.password).password(true));
});
ui.horizontal(|ui| {
ui.label("Repeat passphrase to be sure");
ui.add(
TextEdit::singleline(&mut app.password2)
.text_color(app.settings.theme.input_text_color())
.password(true),
);
ui.add(text_edit_line!(app, app.password2).password(true));
});
if ui.button("import").clicked() {
if app.password != app.password2 {
@ -423,8 +394,7 @@ fn offer_import_priv_key(app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal(|ui| {
ui.label("Enter encrypted private key");
ui.add(
TextEdit::singleline(&mut app.import_priv)
.text_color(app.settings.theme.input_text_color())
text_edit_line!(app, app.import_priv)
.hint_text("ncryptsec1")
.desired_width(f32::INFINITY)
.password(true),
@ -432,11 +402,7 @@ fn offer_import_priv_key(app: &mut GossipUi, ui: &mut Ui) {
});
ui.horizontal(|ui| {
ui.label("Enter the passphrase it is encrypted under");
ui.add(
TextEdit::singleline(&mut app.password)
.text_color(app.settings.theme.input_text_color())
.password(true),
);
ui.add(text_edit_line!(app, app.password).password(true));
});
if ui.button("import").clicked() {
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::ImportPriv(
@ -483,8 +449,7 @@ fn offer_delete_or_import_pub_key(app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal_wrapped(|ui| {
ui.label("Enter your public key");
ui.add(
TextEdit::singleline(&mut app.import_pub)
.text_color(app.settings.theme.input_text_color())
text_edit_line!(app, app.import_pub)
.hint_text("npub1 or hex")
.desired_width(f32::INFINITY),
);
@ -521,19 +486,11 @@ fn offer_generate(app: &mut GossipUi, ui: &mut Ui) {
ui.horizontal(|ui| {
ui.label("Enter a passphrase to keep it encrypted under");
ui.add(
TextEdit::singleline(&mut app.password)
.text_color(app.settings.theme.input_text_color())
.password(true),
);
ui.add(text_edit_line!(app, app.password).password(true));
});
ui.horizontal(|ui| {
ui.label("Repeat passphrase to be sure");
ui.add(
TextEdit::singleline(&mut app.password2)
.text_color(app.settings.theme.input_text_color())
.password(true),
);
ui.add(text_edit_line!(app, app.password2).password(true));
});
if ui.button("Generate Now").clicked() {
if app.password != app.password2 {