This commit is contained in:
Mike Dilger 2022-12-28 16:22:12 +13:00
parent d4b70fd85c
commit cfbcbfd7de
5 changed files with 58 additions and 35 deletions

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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");
});
});
});

View File

@ -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,

View File

@ -1,3 +1,2 @@
mod copy_button;
pub use copy_button::CopyButton;