diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 82ade764..8c7a6842 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -6,6 +6,7 @@ mod settings; mod stats; mod style; mod you; +mod widgets; use crate::about::About; use crate::error::Error; diff --git a/src/ui/widgets/copy_button.rs b/src/ui/widgets/copy_button.rs new file mode 100644 index 00000000..bcdecad3 --- /dev/null +++ b/src/ui/widgets/copy_button.rs @@ -0,0 +1,66 @@ +use eframe::{egui, epaint}; +use egui::{Color32, Pos2, Response, Sense, Shape, Ui, Vec2, Widget}; +use epaint::{PathShape, Stroke}; +use tracing::debug; + +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 }, + ], + closed: false, + fill: Color32::TRANSPARENT, + stroke: Stroke { + width: 1.5, + 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 }, + ], + closed: true, + fill: Color32::TRANSPARENT, + stroke: Stroke { + width: 1.5, + color: Color32::from_rgb(0xb1, 0xa2, 0x96) + } + })); + } +} + +impl Widget for CopyButton { + fn ui(self, ui: &mut Ui) -> Response { + let padding = ui.spacing().button_padding; + let space = Vec2 { + x: 12.0 + padding.x * 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 pos = Pos2 { + x: rect.min.x + padding.x + shift, + y: rect.min.y + padding.y + shift, + }; + Self::paint(ui, pos); + + response + } +} diff --git a/src/ui/widgets/mod.rs b/src/ui/widgets/mod.rs new file mode 100644 index 00000000..52063320 --- /dev/null +++ b/src/ui/widgets/mod.rs @@ -0,0 +1,3 @@ + +mod copy_button; +pub use copy_button::CopyButton;