From cfbcbfd7de816ae3648553e4c6500ecd1220d6d2 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Wed, 28 Dec 2022 16:22:12 +1300 Subject: [PATCH] clean up --- src/ui/feed.rs | 15 +++---- src/ui/mod.rs | 2 +- src/ui/relays.rs | 2 - src/ui/widgets/copy_button.rs | 73 ++++++++++++++++++++++++----------- src/ui/widgets/mod.rs | 1 - 5 files changed, 58 insertions(+), 35 deletions(-) diff --git a/src/ui/feed.rs b/src/ui/feed.rs index 94b9d9e6..bb7557fb 100644 --- a/src/ui/feed.rs +++ b/src/ui/feed.rs @@ -2,11 +2,9 @@ use super::{GossipUi, Page}; use crate::comms::BusMessage; use crate::globals::{Globals, GLOBALS}; use crate::ui::widgets::CopyButton; -use eframe::{egui, epaint}; -use egui::{Align, Color32, Context, Layout, Pos2, RichText, ScrollArea, Shape, TextStyle, Ui, Vec2}; -use epaint::{PathShape, Stroke}; +use eframe::egui; +use egui::{Align, Color32, Context, Layout, RichText, ScrollArea, TextStyle, Ui, Vec2}; use nostr_types::{EventKind, Id}; -use tracing::info; pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Frame, ui: &mut Ui) { let feed = Globals::blocking_get_feed(true); @@ -78,7 +76,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram fn render_post( app: &mut GossipUi, - ctx: &Context, + _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui, id: Id, @@ -160,7 +158,7 @@ fn render_post( ui.label(RichText::new(GossipUi::pubkey_short(&event.pubkey)).weak()); - if ui.add(CopyButton { }).clicked() { + if ui.add(CopyButton {}).clicked() { ui.output().copied_text = GossipUi::pubkey_long(&event.pubkey); } @@ -207,7 +205,7 @@ fn render_post( // Under row ui.horizontal(|ui| { - if ui.add(CopyButton { }).clicked() { + if ui.add(CopyButton {}).clicked() { ui.output().copied_text = event.content.clone(); } }); @@ -218,8 +216,7 @@ fn render_post( if app.settings.view_threaded { for reply_id in replies { - render_post(app, ctx, _frame, ui, reply_id, indent + 1); + render_post(app, _ctx, _frame, ui, reply_id, indent + 1); } } } - diff --git a/src/ui/mod.rs b/src/ui/mod.rs index be6618ea..a718a56b 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -5,8 +5,8 @@ mod relays; mod settings; mod stats; mod style; -mod you; mod widgets; +mod you; use crate::about::About; use crate::error::Error; diff --git a/src/ui/relays.rs b/src/ui/relays.rs index 5d3a6f22..0c400814 100644 --- a/src/ui/relays.rs +++ b/src/ui/relays.rs @@ -37,7 +37,6 @@ pub(super) fn update(_app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::F ui.with_layout(Layout::top_down(Align::Center), |ui| { ScrollArea::vertical().show(ui, |ui| { - ui.label("This is the scroll area top"); for relay in relays.iter_mut() { ui.horizontal(|ui| { ui.label(&relay.url); @@ -65,7 +64,6 @@ pub(super) fn update(_app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::F ui.add_space(12.0); ui.separator(); } - ui.label("This is the scroll area bottom"); }); }); }); diff --git a/src/ui/widgets/copy_button.rs b/src/ui/widgets/copy_button.rs index bcdecad3..3372c064 100644 --- a/src/ui/widgets/copy_button.rs +++ b/src/ui/widgets/copy_button.rs @@ -1,46 +1,71 @@ use eframe::{egui, epaint}; use egui::{Color32, Pos2, Response, Sense, Shape, Ui, Vec2, Widget}; use epaint::{PathShape, Stroke}; -use tracing::debug; -pub struct CopyButton { } +pub struct CopyButton {} impl CopyButton { - pub fn new() -> CopyButton { - CopyButton { } - } - fn paint(ui: &mut Ui, corner: Pos2) { ui.painter().add(Shape::Path(PathShape { points: vec![ - Pos2 { x: corner.x + 2.0, y: corner.y + 8.0 }, - Pos2 { x: corner.x + 0.0, y: corner.y + 8.0 }, - Pos2 { x: corner.x + 0.0, y: corner.y + 0.0 }, - Pos2 { x: corner.x + 8.0, y: corner.y + 0.0 }, - Pos2 { x: corner.x + 8.0, y: corner.y + 2.0 }, + Pos2 { + x: corner.x + 2.0, + y: corner.y + 8.0, + }, + Pos2 { + x: corner.x + 0.0, + y: corner.y + 8.0, + }, + Pos2 { + x: corner.x + 0.0, + y: corner.y + 0.0, + }, + Pos2 { + x: corner.x + 8.0, + y: corner.y + 0.0, + }, + Pos2 { + x: corner.x + 8.0, + y: corner.y + 2.0, + }, ], closed: false, fill: Color32::TRANSPARENT, stroke: Stroke { width: 1.5, - color: Color32::from_rgb(0xb1, 0xa2, 0x96) - } + color: Color32::from_rgb(0xb1, 0xa2, 0x96), + }, })); ui.painter().add(Shape::Path(PathShape { points: vec![ - Pos2 { x: corner.x + 4.0, y: corner.y + 4.0 }, - Pos2 { x: corner.x + 4.0, y: corner.y + 12.0 }, - Pos2 { x: corner.x + 12.0, y: corner.y + 12.0 }, - Pos2 { x: corner.x + 12.0, y: corner.y + 4.0 }, - Pos2 { x: corner.x + 4.0, y: corner.y + 4.0 }, + Pos2 { + x: corner.x + 4.0, + y: corner.y + 4.0, + }, + Pos2 { + x: corner.x + 4.0, + y: corner.y + 12.0, + }, + Pos2 { + x: corner.x + 12.0, + y: corner.y + 12.0, + }, + Pos2 { + x: corner.x + 12.0, + y: corner.y + 4.0, + }, + Pos2 { + x: corner.x + 4.0, + y: corner.y + 4.0, + }, ], closed: true, fill: Color32::TRANSPARENT, stroke: Stroke { width: 1.5, - color: Color32::from_rgb(0xb1, 0xa2, 0x96) - } + color: Color32::from_rgb(0xb1, 0xa2, 0x96), + }, })); } } @@ -50,11 +75,15 @@ impl Widget for CopyButton { let padding = ui.spacing().button_padding; let space = Vec2 { x: 12.0 + padding.x * 2.0, - y: 12.0 + padding.y * 2.0 + y: 12.0 + padding.y * 2.0, }; let (id, rect) = ui.allocate_space(space); let response = ui.interact(rect, id, Sense::click()); - let shift = if response.is_pointer_button_down_on() { 2.0 } else { 0.0 }; + let shift = if response.is_pointer_button_down_on() { + 2.0 + } else { + 0.0 + }; let pos = Pos2 { x: rect.min.x + padding.x + shift, y: rect.min.y + padding.y + shift, diff --git a/src/ui/widgets/mod.rs b/src/ui/widgets/mod.rs index 52063320..34985845 100644 --- a/src/ui/widgets/mod.rs +++ b/src/ui/widgets/mod.rs @@ -1,3 +1,2 @@ - mod copy_button; pub use copy_button::CopyButton;