Files
Ely-GPUI-Components/src/typography/copy.rs
T
ZacharyZhang-NY 931e0ed6f5 Maps · View: host tiles, pins and a popup, a picker, coordinates
maps::MapView lays the host's tile for each zoom, column and row in Web
Mercator, the nearest cut scaled past the zooms it serves, on whole
pixels. gpui packs pictures in its atlas without padding and samples
them linearly, so each tile draws with a one-pixel rim copied from its
own edge, one of its pixels larger each side and clipped, and no seam
shows. A drag, the wheel or the arrows pan; Command-wheel, + and - or
its buttons zoom about the pointer or the center; the owner keeps the
viewport. MapMarker pins take a press and Enter when the map hears
them; MapPopup opens toward the map's larger half and stays inside it,
closing by its button or Escape. LocationPicker picks the place under a
center crosshair; CoordinateDisplay writes degrees or degrees, minutes
and seconds with tabular figures and a copy button. The gallery's tiles
are Natural Earth's countries, cut z0 to z3 by scripts/tiles.py.
2026-09-27 21:22:50 -04:00

54 lines
1.3 KiB
Rust

use gpui::{
App, ElementId, InteractiveElement, IntoElement, ParentElement, RenderOnce, SharedString,
Styled, Window, div, prelude::*,
};
use super::tabular;
use crate::{buttons::CopyButton, theme::ActiveTheme};
/// Text with a copy button that confirms with a check.
#[derive(IntoElement)]
pub struct CopyableText {
id: ElementId,
text: SharedString,
mono: bool,
tabular: bool,
}
impl CopyableText {
pub fn new(id: impl Into<ElementId>, text: impl Into<SharedString>) -> Self {
Self {
id: id.into(),
text: text.into(),
mono: false,
tabular: false,
}
}
pub fn mono(mut self) -> Self {
self.mono = true;
self
}
/// Figures of one width, so text that changes holds still.
pub fn tabular(mut self) -> Self {
self.tabular = true;
self
}
}
impl RenderOnce for CopyableText {
fn render(self, _: &mut Window, cx: &mut App) -> impl IntoElement {
let mono = cx.theme().mono_family.clone();
div()
.id(self.id)
.flex()
.items_center()
.gap_1()
.when(self.mono, |row| row.font_family(mono))
.when(self.tabular, tabular)
.child(self.text.clone())
.child(CopyButton::new("copy-slot", self.text))
}
}