I prefer URL's breaking with break_anywhere=true. This allows them to line break anywhere in the URL instead of only on "break chars" like "./?" etc

This commit is contained in:
Bu5hm4nn 2023-03-11 14:40:43 -06:00
parent 5dc82ad65b
commit 1e76ad31c4
4 changed files with 27 additions and 3 deletions

View File

@ -18,7 +18,7 @@ pub(super) fn render_content(
for span in LinkFinder::new().kinds(&[LinkKind::Url]).spans(content) {
if span.kind().is_some() {
ui.hyperlink_to(span.as_str(), span.as_str());
crate::ui::widgets::break_anywhere_hyperlink_to(ui, span.as_str(), span.as_str());
} else {
let s = span.as_str();
let mut pos = 0;

View File

@ -108,7 +108,7 @@ fn relay_table(ui: &mut Ui, relays: &mut [DbRelay], id: &'static str) {
body.rows(24.0, relays.len(), |row_index, mut row| {
let relay = relays.get_mut(row_index).unwrap();
row.col(|ui| {
ui.label(&relay.url.0);
crate::ui::widgets::break_anywhere_label(ui,&relay.url.0);
});
row.col(|ui| {
ui.label(&format!("{}", relay.attempts()));

View File

@ -68,7 +68,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
body.rows(24.0, connected_relays.len(), |row_index, mut row| {
let relay_url = &connected_relays[row_index];
row.col(|ui| {
ui.label(&relay_url.0);
crate::ui::widgets::break_anywhere_label(ui, &relay_url.0);
});
row.col(|ui| {
if let Some(ref assignment) =

View File

@ -1,2 +1,26 @@
mod copy_button;
pub use copy_button::CopyButton;
use eframe::egui::{FontSelection, Ui, WidgetText};
pub fn break_anywhere_label(ui: &mut Ui, text: impl Into<WidgetText>) {
let mut job = text.into().into_text_job(
ui.style(),
FontSelection::Default,
ui.layout().vertical_align(),
);
job.job.sections.first_mut().unwrap().format.color =
ui.style().visuals.widgets.noninteractive.fg_stroke.color;
job.job.wrap.break_anywhere = true;
ui.label(job.job);
}
pub fn break_anywhere_hyperlink_to(ui: &mut Ui, text: impl Into<WidgetText>, url: impl ToString) {
let mut job = text.into().into_text_job(
ui.style(),
FontSelection::Default,
ui.layout().vertical_align(),
);
job.job.wrap.break_anywhere = true;
ui.hyperlink_to(job.job, url);
}