-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix text wrapping too late #2791
Draft
bu5hm4nn
wants to merge
2
commits into
emilk:master
Choose a base branch
from
bu5hm4nn:fix-wrapping-issue-2578
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+170
−42
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,23 @@ | ||
[package] | ||
name = "wrapping_layout" | ||
version = "0.1.0" | ||
authors = ["Emil Ernerfeldt <[email protected]>", "Bu5hm4nn <[email protected]>"] | ||
license = "MIT OR Apache-2.0" | ||
edition = "2021" | ||
rust-version = "1.72" | ||
publish = false | ||
|
||
|
||
[dependencies] | ||
eframe = { workspace = true, features = [ | ||
"default", | ||
"__screenshot", # __screenshot is so we can dump a screenshot using EFRAME_SCREENSHOT_TO | ||
] } | ||
|
||
# For image support: | ||
egui_extras = { workspace = true, features = ["default", "image"] } | ||
|
||
env_logger = { version = "0.10", default-features = false, features = [ | ||
"auto-color", | ||
"humantime", | ||
] } |
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,7 @@ | ||
Example showing text wrapping with `ui.horizontal_wrapped()` | ||
|
||
```sh | ||
cargo run -p wrapping_layout | ||
``` | ||
|
||
![](screenshot.png) |
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,55 @@ | ||
use eframe::{ | ||
egui::{self, WidgetText}, | ||
emath::Align, | ||
epaint::Stroke, | ||
}; | ||
|
||
fn main() -> Result<(), eframe::Error> { | ||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`). | ||
let options = eframe::NativeOptions { | ||
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.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.style_mut().visuals.widgets.noninteractive.fg_stroke = Stroke::new( 1.0, eframe::epaint::Color32::RED ); | ||
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_layout_job(ui.style(), egui::FontSelection::Default, Align::LEFT); | ||
job.wrap.break_anywhere = true; | ||
ui.hyperlink_to( job, url ); | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
first_row_indentation == 0.0
then we never want an empty first row. We would rather overflowmax_width
, because otherwise we will just run into the same problem on the next row. For instance ifmax_width == 0.0
we want a layout where we have exactly one glyph per row.If
first_row_indentation > 0.0
however we are fine with having an empty row, because there will be more space available on the next row, and that might be enough to fit the first word or whatever.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does your code handle this case (
max_width == 0.0
) ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just ran this in examples/wrapped_layout and it seems to work as you describe (one glyph per row).