Add ui.set_row_height
This commit is contained in:
parent
e20e3baa98
commit
953d2bb39b
5 changed files with 25 additions and 3 deletions
|
@ -8,7 +8,9 @@ pub fn easy_mark(ui: &mut Ui, easy_mark: &str) {
|
|||
|
||||
pub fn easy_mark_it<'em>(ui: &mut Ui, items: impl Iterator<Item = easy_mark::Item<'em>>) {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing = Vec2::ZERO;
|
||||
ui.spacing_mut().item_spacing = Vec2::new(0.0, 0.0);
|
||||
ui.set_row_height(ui.fonts()[TextStyle::Body].row_height());
|
||||
|
||||
for item in items {
|
||||
item_ui(ui, item);
|
||||
}
|
||||
|
@ -24,6 +26,7 @@ pub fn item_ui(ui: &mut Ui, item: easy_mark::Item<'_>) {
|
|||
// ui.label("\n"); // too much spacing (paragraph spacing)
|
||||
ui.allocate_exact_size(vec2(0.0, row_height), Sense::hover()); // make sure we take up some height
|
||||
ui.end_row();
|
||||
ui.set_row_height(row_height);
|
||||
}
|
||||
|
||||
easy_mark::Item::Text(style, text) => {
|
||||
|
|
|
@ -698,6 +698,13 @@ impl Layout {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Set row height in horizontal wrapping layout.
|
||||
pub(crate) fn set_row_height(&mut self, region: &mut Region, height: f32) {
|
||||
if self.main_wrap && self.is_horizontal() {
|
||||
region.cursor.max.y = region.cursor.min.y + height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
|
@ -177,6 +177,11 @@ impl Placer {
|
|||
self.layout.end_row(&mut self.region, item_spacing)
|
||||
}
|
||||
}
|
||||
|
||||
/// Set row height in horizontal wrapping layout.
|
||||
pub(crate) fn set_row_height(&mut self, height: f32) {
|
||||
self.layout.set_row_height(&mut self.region, height);
|
||||
}
|
||||
}
|
||||
|
||||
impl Placer {
|
||||
|
|
|
@ -1386,6 +1386,11 @@ impl Ui {
|
|||
.end_row(self.spacing().item_spacing, &self.painter().clone());
|
||||
}
|
||||
|
||||
/// Set row height in horizontal wrapping layout.
|
||||
pub fn set_row_height(&mut self, height: f32) {
|
||||
self.placer.set_row_height(height);
|
||||
}
|
||||
|
||||
/// Temporarily split split an Ui into several columns.
|
||||
///
|
||||
/// ```
|
||||
|
|
|
@ -238,8 +238,10 @@ impl ColoredText {
|
|||
|
||||
pub fn ui(&self, ui: &mut egui::Ui) {
|
||||
for line in &self.0 {
|
||||
ui.horizontal_wrapped_for_text(egui::TextStyle::Monospace, |ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
ui.spacing_mut().item_spacing = egui::Vec2::ZERO;
|
||||
ui.set_row_height(ui.fonts()[egui::TextStyle::Body].row_height());
|
||||
|
||||
for (style, range) in line {
|
||||
let fg = style.foreground;
|
||||
let text_color = egui::Color32::from_rgb(fg.r, fg.g, fg.b);
|
||||
|
|
Loading…
Reference in a new issue