Clipboard: Don't create a second Clipboard instance, instead use the ViewportCommand::RequestPaste command

This commit is contained in:
Bu5hm4nn 2024-02-12 12:15:17 -06:00
parent f39877204e
commit 3351fabc06
11 changed files with 26 additions and 75 deletions

16
Cargo.lock generated
View File

@ -1377,7 +1377,7 @@ checksum = "cfdf4e52dbbb615cfd30cf5a5265335c217b5fd8d669593cea74a517d9c605af"
[[package]]
name = "ecolor"
version = "0.26.0"
source = "git+https://github.com/bu5hm4nn/egui?rev=31b7c13ce86065531c87e5497308d46ca3a3c13a#31b7c13ce86065531c87e5497308d46ca3a3c13a"
source = "git+https://github.com/bu5hm4nn/egui?rev=f954e98816d4fb760de31eeec4afcd15ae39a687#f954e98816d4fb760de31eeec4afcd15ae39a687"
dependencies = [
"bytemuck",
"serde",
@ -1386,7 +1386,7 @@ dependencies = [
[[package]]
name = "eframe"
version = "0.26.0"
source = "git+https://github.com/bu5hm4nn/egui?rev=31b7c13ce86065531c87e5497308d46ca3a3c13a#31b7c13ce86065531c87e5497308d46ca3a3c13a"
source = "git+https://github.com/bu5hm4nn/egui?rev=f954e98816d4fb760de31eeec4afcd15ae39a687#f954e98816d4fb760de31eeec4afcd15ae39a687"
dependencies = [
"bytemuck",
"cocoa",
@ -1433,7 +1433,7 @@ dependencies = [
[[package]]
name = "egui"
version = "0.26.0"
source = "git+https://github.com/bu5hm4nn/egui?rev=31b7c13ce86065531c87e5497308d46ca3a3c13a#31b7c13ce86065531c87e5497308d46ca3a3c13a"
source = "git+https://github.com/bu5hm4nn/egui?rev=f954e98816d4fb760de31eeec4afcd15ae39a687#f954e98816d4fb760de31eeec4afcd15ae39a687"
dependencies = [
"accesskit",
"ahash 0.8.7",
@ -1464,7 +1464,7 @@ dependencies = [
[[package]]
name = "egui-wgpu"
version = "0.26.0"
source = "git+https://github.com/bu5hm4nn/egui?rev=31b7c13ce86065531c87e5497308d46ca3a3c13a#31b7c13ce86065531c87e5497308d46ca3a3c13a"
source = "git+https://github.com/bu5hm4nn/egui?rev=f954e98816d4fb760de31eeec4afcd15ae39a687#f954e98816d4fb760de31eeec4afcd15ae39a687"
dependencies = [
"bytemuck",
"document-features",
@ -1481,7 +1481,7 @@ dependencies = [
[[package]]
name = "egui-winit"
version = "0.26.0"
source = "git+https://github.com/bu5hm4nn/egui?rev=31b7c13ce86065531c87e5497308d46ca3a3c13a#31b7c13ce86065531c87e5497308d46ca3a3c13a"
source = "git+https://github.com/bu5hm4nn/egui?rev=f954e98816d4fb760de31eeec4afcd15ae39a687#f954e98816d4fb760de31eeec4afcd15ae39a687"
dependencies = [
"accesskit_winit",
"arboard",
@ -1498,7 +1498,7 @@ dependencies = [
[[package]]
name = "egui_glow"
version = "0.26.0"
source = "git+https://github.com/bu5hm4nn/egui?rev=31b7c13ce86065531c87e5497308d46ca3a3c13a#31b7c13ce86065531c87e5497308d46ca3a3c13a"
source = "git+https://github.com/bu5hm4nn/egui?rev=f954e98816d4fb760de31eeec4afcd15ae39a687#f954e98816d4fb760de31eeec4afcd15ae39a687"
dependencies = [
"bytemuck",
"egui 0.26.0",
@ -1526,7 +1526,7 @@ checksum = "1ef2b29de53074e575c18b694167ccbe6e5191f7b25fe65175a0d905a32eeec0"
[[package]]
name = "emath"
version = "0.26.0"
source = "git+https://github.com/bu5hm4nn/egui?rev=31b7c13ce86065531c87e5497308d46ca3a3c13a#31b7c13ce86065531c87e5497308d46ca3a3c13a"
source = "git+https://github.com/bu5hm4nn/egui?rev=f954e98816d4fb760de31eeec4afcd15ae39a687#f954e98816d4fb760de31eeec4afcd15ae39a687"
dependencies = [
"bytemuck",
"serde",
@ -1590,7 +1590,7 @@ dependencies = [
[[package]]
name = "epaint"
version = "0.26.0"
source = "git+https://github.com/bu5hm4nn/egui?rev=31b7c13ce86065531c87e5497308d46ca3a3c13a#31b7c13ce86065531c87e5497308d46ca3a3c13a"
source = "git+https://github.com/bu5hm4nn/egui?rev=f954e98816d4fb760de31eeec4afcd15ae39a687#f954e98816d4fb760de31eeec4afcd15ae39a687"
dependencies = [
"ab_glyph",
"ahash 0.8.7",

View File

@ -13,6 +13,6 @@ overflow-checks = false
[patch.crates-io]
# override egui crate for egui_video dependency
egui = { git = "https://github.com/bu5hm4nn/egui", rev = "31b7c13ce86065531c87e5497308d46ca3a3c13a" }
egui = { git = "https://github.com/bu5hm4nn/egui", rev = "f954e98816d4fb760de31eeec4afcd15ae39a687" }
# Use the master branch of SDL2 to include a fix related to clang (and XCode after 14.2)
sdl2 = { git = "https://github.com/Rust-SDL2/rust-sdl2", rev = "f2f1e29a416bcc22f2faf411866db2c8d9536308" }

View File

@ -19,9 +19,9 @@ rustls-tls-native = [ "gossip-lib/rustls-tls-native" ]
[dependencies]
bech32 = "0.9"
eframe = { git = "https://github.com/bu5hm4nn/egui", rev = "31b7c13ce86065531c87e5497308d46ca3a3c13a", features = [ "persistence", "wayland" ] }
egui-winit = { git = "https://github.com/bu5hm4nn/egui", rev = "31b7c13ce86065531c87e5497308d46ca3a3c13a", features = [ "default" ] }
#egui = { git = "https://github.com/bu5hm4nn/egui", rev = "31b7c13ce86065531c87e5497308d46ca3a3c13a", features = [ "deadlock_detection" ] }
eframe = { git = "https://github.com/bu5hm4nn/egui", rev = "f954e98816d4fb760de31eeec4afcd15ae39a687", features = [ "persistence", "wayland" ] }
egui-winit = { git = "https://github.com/bu5hm4nn/egui", rev = "f954e98816d4fb760de31eeec4afcd15ae39a687", features = [ "default" ] }
#egui = { git = "https://github.com/bu5hm4nn/egui", rev = "f954e98816d4fb760de31eeec4afcd15ae39a687", features = [ "deadlock_detection" ] }
egui-video = { git = "https://github.com/bu5hm4nn/egui-video", rev = "baad84b9bb897004a243166758d149d3387d4811", features = [ "from_bytes" ], optional = true }
gossip-relay-picker = { git = "https://github.com/mikedilger/gossip-relay-picker", rev = "1d13cacb0d7b32d72d0c8c27414461d5389ca2ec" }
gossip-lib = { path = "../gossip-lib" }

View File

@ -388,9 +388,6 @@ struct GossipUi {
current_scroll_offset: f32,
future_scroll_offset: f32,
// clipboard
clipboard: egui_winit::clipboard::Clipboard,
// Ui timers
popups: HashMap<egui::Id, HashMap<egui::Id, Box<dyn widgets::InformationPopup>>>,
@ -646,12 +643,6 @@ impl GossipUi {
let theme = Theme::from_settings();
theme::apply_theme(&theme, &cctx.egui_ctx);
let maybe_raw_display_handle = if let Ok(display_handle) = cctx.display_handle() {
Some(display_handle.as_raw())
} else {
None
};
GossipUi {
#[cfg(feature = "video-ffmpeg")]
audio_device,
@ -664,7 +655,6 @@ impl GossipUi {
original_dpi_value: override_dpi_value,
current_scroll_offset: 0.0,
future_scroll_offset: 0.0,
clipboard: egui_winit::clipboard::Clipboard::new(maybe_raw_display_handle),
popups: HashMap::new(),
qr_codes: HashMap::new(),
notes: Notes::new(),
@ -2077,7 +2067,7 @@ fn force_login(app: &mut GossipUi, ctx: &Context) {
.password(true)
.with_paste()
.desired_width( 400.0)
.show_extended(ui, &mut app.clipboard);
.show(ui);
if app.unlock_needs_focus {
output.response.request_focus();
app.unlock_needs_focus = false;

View File

@ -84,40 +84,6 @@ impl<'t> TextEdit<'t> {
}
pub fn show(self, ui: &mut egui::Ui) -> egui::text_edit::TextEditOutput {
ui.scope(|ui| {
if ui.visuals().dark_mode {
ui.visuals_mut().extreme_bg_color =
self.bg_color.unwrap_or(egui::Color32::from_gray(0x47));
} else {
ui.visuals_mut().extreme_bg_color = self.bg_color.unwrap_or(Color32::WHITE);
}
let mut inner = match self.multiline {
false => egui::widgets::TextEdit::singleline(self.text),
true => egui::widgets::TextEdit::multiline(self.text),
}
.password(self.password)
.hint_text(self.hint_text.clone());
if let Some(width) = self.desired_width {
inner = inner.desired_width(width);
}
if let Some(color) = self.text_color {
inner = inner.text_color(color);
}
// show inner
inner.show(ui)
})
.inner
}
pub fn show_extended(
self,
ui: &mut egui::Ui,
clipboard: &mut egui_winit::clipboard::Clipboard,
) -> egui::text_edit::TextEditOutput {
ui.scope(|ui| {
if ui.visuals().dark_mode {
ui.visuals_mut().extreme_bg_color =
@ -163,14 +129,9 @@ impl<'t> TextEdit<'t> {
)
.clicked()
{
if let Some(paste) = clipboard.get() {
let index = if let Some(cursor) = output.cursor_range {
cursor.primary.ccursor.index
} else {
0
};
self.text.insert_text(paste.as_str(), index);
}
output.response.request_focus();
ui.ctx()
.send_viewport_cmd(egui::ViewportCommand::RequestPaste);
}
}

View File

@ -90,7 +90,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
.hint_text(
"Enter a key (bech32 npub1 or hex), or an nprofile, or a DNS id (user@domain)",
)
.show_extended(ui, &mut app.clipboard)
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;

View File

@ -21,7 +21,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
.desired_width(f32::INFINITY)
.password(true)
.with_paste()
.show_extended(ui, &mut app.clipboard)
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;
@ -47,7 +47,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
let response = text_edit_line!(app, app.password)
.password(true)
.with_paste()
.show_extended(ui, &mut app.clipboard)
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;
@ -61,7 +61,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
let response = text_edit_line!(app, app.password2)
.password(true)
.with_paste()
.show_extended(ui, &mut app.clipboard)
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;

View File

@ -24,7 +24,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
let response = text_edit_line!(app, app.import_pub)
.with_paste()
.desired_width(f32::INFINITY)
.show_extended(ui, &mut app.clipboard)
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;

View File

@ -102,7 +102,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.label("Enter Relay URL");
let response = text_edit_line!(app, app.wizard_state.relay_url)
.with_paste()
.show_extended(ui, &mut app.clipboard)
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;

View File

@ -55,7 +55,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.label("Name:");
let response = text_edit_line!(app, app.wizard_state.metadata_name)
.with_paste()
.show_extended(ui, &mut app.clipboard)
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;
@ -67,7 +67,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.label("About:");
let response = text_edit_line!(app, app.wizard_state.metadata_about)
.with_paste()
.show_extended(ui, &mut app.clipboard)
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;
@ -79,7 +79,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.label("Picture:");
let response = text_edit_line!(app, app.wizard_state.metadata_picture)
.with_paste()
.show_extended(ui, &mut app.clipboard)
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;

View File

@ -149,7 +149,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
ui.label("Enter Relay URL");
let response = text_edit_line!(app, app.wizard_state.relay_url)
.with_paste()
.show_extended(ui, &mut app.clipboard)
.show(ui)
.response;
if response.changed() {
app.wizard_state.error = None;