1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Merge branch 'master' of https://github.com/emilk/egui into multiples_viewports

This commit is contained in:
Konkitoman
2023-09-25 23:15:51 +03:00
25 changed files with 437 additions and 160 deletions

View File

@@ -93,7 +93,7 @@ impl super::View for FontBook {
};
if ui.add(button).on_hover_ui(tooltip_ui).clicked() {
ui.output_mut(|o| o.copied_text = chr.to_string());
ui.ctx().copy_text(chr.to_string());
}
}
}

View File

@@ -7,16 +7,18 @@ pub struct TextLayoutDemo {
overflow_character: Option<char>,
extra_letter_spacing_pixels: i32,
line_height_pixels: u32,
lorem_ipsum: bool,
}
impl Default for TextLayoutDemo {
fn default() -> Self {
Self {
max_rows: 3,
max_rows: 6,
break_anywhere: true,
overflow_character: Some('…'),
extra_letter_spacing_pixels: 0,
line_height_pixels: 0,
lorem_ipsum: true,
}
}
}
@@ -45,6 +47,7 @@ impl super::View for TextLayoutDemo {
overflow_character,
extra_letter_spacing_pixels,
line_height_pixels,
lorem_ipsum,
} = self;
use egui::text::LayoutJob;
@@ -104,32 +107,55 @@ impl super::View for TextLayoutDemo {
}
});
ui.end_row();
ui.label("Text:");
ui.horizontal(|ui| {
ui.selectable_value(lorem_ipsum, true, "Lorem Ipsum");
ui.selectable_value(lorem_ipsum, false, "La Pasionaria");
});
});
ui.add_space(12.0);
egui::ScrollArea::vertical().show(ui, |ui| {
let extra_letter_spacing = points_per_pixel * *extra_letter_spacing_pixels as f32;
let line_height =
(*line_height_pixels != 0).then_some(points_per_pixel * *line_height_pixels as f32);
let text = if *lorem_ipsum {
crate::LOREM_IPSUM_LONG
} else {
TO_BE_OR_NOT_TO_BE
};
let mut job = LayoutJob::single_section(
crate::LOREM_IPSUM_LONG.to_owned(),
egui::TextFormat {
extra_letter_spacing,
line_height,
egui::ScrollArea::vertical()
.auto_shrink([false; 2])
.show(ui, |ui| {
let extra_letter_spacing = points_per_pixel * *extra_letter_spacing_pixels as f32;
let line_height = (*line_height_pixels != 0)
.then_some(points_per_pixel * *line_height_pixels as f32);
let mut job = LayoutJob::single_section(
text.to_owned(),
egui::TextFormat {
extra_letter_spacing,
line_height,
..Default::default()
},
);
job.wrap = egui::text::TextWrapping {
max_rows: *max_rows,
break_anywhere: *break_anywhere,
overflow_character: *overflow_character,
..Default::default()
},
);
job.wrap = egui::text::TextWrapping {
max_rows: *max_rows,
break_anywhere: *break_anywhere,
overflow_character: *overflow_character,
..Default::default()
};
};
// NOTE: `Label` overrides some of the wrapping settings, e.g. wrap width
ui.label(job);
});
// NOTE: `Label` overrides some of the wrapping settings, e.g. wrap width
ui.label(job);
});
}
}
/// Excerpt from Dolores Ibárruri's farwel speech to the International Brigades:
const TO_BE_OR_NOT_TO_BE: &str = "Mothers! Women!\n
When the years pass by and the wounds of war are stanched; when the memory of the sad and bloody days dissipates in a present of liberty, of peace and of wellbeing; when the rancor have died out and pride in a free country is felt equally by all Spaniards, speak to your children. Tell them of these men of the International Brigades.\n\
\n\
Recount for them how, coming over seas and mountains, crossing frontiers bristling with bayonets, sought by raving dogs thirsting to tear their flesh, these men reached our country as crusaders for freedom, to fight and die for Spains liberty and independence threatened by German and Italian fascism. \
They gave up everything — their loves, their countries, home and fortune, fathers, mothers, wives, brothers, sisters and children — and they came and said to us: “We are here. Your cause, Spains cause, is ours. It is the cause of all advanced and progressive mankind.”\n\
\n\
- Dolores Ibárruri, 1938";