#[derive(Debug, Clone)]
pub enum Segment {
Text(String),
Link {
label: String,
url: String,
},
Action {
label: String,
id: String,
},
}
#[must_use]
pub struct Hypertext {
pub(crate) segments: Vec<Segment>,
pub(crate) centered: bool,
pub(crate) size: f32,
pub(crate) text_color: Option<egui::Color32>,
}
impl Default for Hypertext {
fn default() -> Self {
Self::new()
}
}
impl Hypertext {
pub fn new() -> Self {
Self {
segments: Vec::new(),
centered: false,
size: 12.0,
text_color: None,
}
}
pub fn text(mut self, text: impl Into<String>) -> Self {
let txt = text.into();
if !txt.is_empty() {
self.segments.push(Segment::Text(txt));
}
self
}
pub fn link(mut self, label: impl Into<String>, url: impl Into<String>) -> Self {
self.segments.push(Segment::Link {
label: label.into(),
url: url.into(),
});
self
}
pub fn action(mut self, label: impl Into<String>, id: impl Into<String>) -> Self {
self.segments.push(Segment::Action {
label: label.into(),
id: id.into(),
});
self
}
pub fn centered(mut self) -> Self {
self.centered = true;
self
}
pub fn size(mut self, size: f32) -> Self {
self.size = size;
self
}
pub fn text_color(mut self, color: impl Into<egui::Color32>) -> Self {
self.text_color = Some(color.into());
self
}
pub fn show(self, ui: &mut egui::Ui) -> egui::Response {
self.show_action(ui).0
}
pub fn show_action(self, ui: &mut egui::Ui) -> (egui::Response, Option<String>) {
self.show_inner(ui)
}
}