Browse Source

Add ui.set_row_height

pull/249/head
Emil Ernerfeldt 4 years ago
parent
commit
953d2bb39b
  1. 5
      egui/src/experimental/easy_mark_viewer.rs
  2. 7
      egui/src/layout.rs
  3. 5
      egui/src/placer.rs
  4. 5
      egui/src/ui.rs
  5. 6
      egui_demo_lib/src/apps/http_app.rs

5
egui/src/experimental/easy_mark_viewer.rs

@ -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) => {

7
egui/src/layout.rs

@ -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;
}
}
}
// ----------------------------------------------------------------------------

5
egui/src/placer.rs

@ -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 {

5
egui/src/ui.rs

@ -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.
///
/// ```

6
egui_demo_lib/src/apps/http_app.rs

@ -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…
Cancel
Save