-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There was confusion in the code over how to break when on a non-empty visual row (`first_row_indentation > 0.0`), causing text to be shifted left outside the ui frame. This is the case for example when another label has already been placed in this `ui.horizontal_wrapped()`. This fix will not create an empty row, essentially starting a newline, but rather try to fit as much text as possible on the existing row. IMO this is the desired use of a wrapping layout. I've also added an example that would demonstrate the problem if the line was included, and that is fixed with this commit
- Loading branch information
Bu5hm4nn
committed
Mar 9, 2023
1 parent
f94187a
commit 462f6db
Showing
4 changed files
with
121 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "wrapping-layout" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
eframe = { path = "../../crates/eframe", features = [ | ||
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO | ||
] } | ||
tracing-subscriber = "0.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use eframe::{ | ||
egui::{self, WidgetText}, | ||
emath::Align, | ||
epaint::Stroke, | ||
}; | ||
|
||
fn main() -> Result<(), eframe::Error> { | ||
let options = eframe::NativeOptions { | ||
initial_window_size: Some(egui::vec2(380.0, 440.0)), | ||
..Default::default() | ||
}; | ||
eframe::run_native( | ||
"Horizontal Wrapped Layouts", | ||
options, | ||
Box::new(|cc| Box::new(MyEguiApp::new(cc))), | ||
) | ||
} | ||
|
||
#[derive(Default)] | ||
struct MyEguiApp {} | ||
|
||
impl MyEguiApp { | ||
fn new(_cc: &eframe::CreationContext<'_>) -> Self { | ||
Self::default() | ||
} | ||
} | ||
|
||
impl eframe::App for MyEguiApp { | ||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { | ||
egui::CentralPanel::default().show(ctx, |ui| { | ||
ui.horizontal_wrapped(|ui| { | ||
ui.hyperlink_to("@npub1vdaeclr2mnntmyw...", "whocares"); | ||
let text = " LotsOfTextPrecededByASpace5kgqfqqxwhkrkw60stn8aph4gm2h2053xvwvvlvjm3q9eqdpqxycrqvpqd3hhgar9wfujqarfvd4k2arncqzpgxqzz6sp5vfenc5l4uafsky0w069zs329edf608ggpjjveguwxfl3xlswg5vq9qyyssqj46d5x3gsnljffm79eqwszk4mk47lkxywdp8mxum7un3qm0ztwj9jf46cm4lw2un9hk4gttgtjdrk29h27xu4e3ume20sqsna8q7xwspqqkwq7"; | ||
ui.label(text); | ||
ui.label("More text followed by two newlines\n\n"); | ||
ui.style_mut().visuals.widgets.noninteractive.fg_stroke = Stroke::new( 1.0, eframe::epaint::Color32::GREEN ); | ||
ui.label("more text, no newline"); | ||
ui.reset_style(); | ||
}); | ||
ui.separator(); | ||
ui.horizontal_wrapped(|ui| { | ||
ui.label("Hyperlink no newline:"); | ||
let url = "https://i.nostrimg.com/c72f5e1a2e162fad2625e15651a654465c06016016f7743b496021cafa2a524e/file.jpeg"; | ||
ui.hyperlink_to( url, url ); | ||
ui.end_row(); | ||
ui.label("Hyperlink break_anywhere=true"); | ||
let mut job = WidgetText::from(url).into_text_job(ui.style(), egui::FontSelection::Default, Align::LEFT); | ||
job.job.wrap.break_anywhere = true; | ||
ui.hyperlink_to( job.job, url ); | ||
}); | ||
}); | ||
} | ||
} |