mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Make TextStyle !Copy
This commit is contained in:
@@ -71,7 +71,7 @@ impl super::View for CodeEditor {
|
||||
ui.collapsing("Theme", |ui| {
|
||||
ui.group(|ui| {
|
||||
theme.ui(ui);
|
||||
theme.store_in_memory(ui.ctx());
|
||||
theme.clone().store_in_memory(ui.ctx());
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ impl CodeExample {
|
||||
);
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
let indentation = 8.0 * ui.fonts().glyph_width(egui::TextStyle::Monospace, ' ');
|
||||
let indentation = 8.0 * ui.fonts().glyph_width(&egui::TextStyle::Monospace, ' ');
|
||||
let item_spacing = ui.spacing_mut().item_spacing;
|
||||
ui.add_space(indentation - item_spacing.x);
|
||||
|
||||
|
||||
@@ -55,7 +55,11 @@ impl super::View for FontBook {
|
||||
.selected_text(format!("{:?}", self.text_style))
|
||||
.show_ui(ui, |ui| {
|
||||
for style in egui::TextStyle::all() {
|
||||
ui.selectable_value(&mut self.text_style, style, format!("{:?}", style));
|
||||
ui.selectable_value(
|
||||
&mut self.text_style,
|
||||
style.clone(),
|
||||
format!("{:?}", style),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -68,19 +72,22 @@ impl super::View for FontBook {
|
||||
}
|
||||
});
|
||||
|
||||
let text_style = self.text_style;
|
||||
let text_style = self.text_style.clone();
|
||||
let filter = &self.filter;
|
||||
let named_chars = self.named_chars.entry(text_style).or_insert_with(|| {
|
||||
ui.fonts()
|
||||
.lock()
|
||||
.fonts
|
||||
.font_mut(text_style)
|
||||
.characters()
|
||||
.iter()
|
||||
.filter(|chr| !chr.is_whitespace() && !chr.is_ascii_control())
|
||||
.map(|&chr| (chr, char_name(chr)))
|
||||
.collect()
|
||||
});
|
||||
let named_chars = self
|
||||
.named_chars
|
||||
.entry(text_style.clone())
|
||||
.or_insert_with(|| {
|
||||
ui.fonts()
|
||||
.lock()
|
||||
.fonts
|
||||
.font_mut(&text_style)
|
||||
.characters()
|
||||
.iter()
|
||||
.filter(|chr| !chr.is_whitespace() && !chr.is_ascii_control())
|
||||
.map(|&chr| (chr, char_name(chr)))
|
||||
.collect()
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
||||
@@ -91,12 +98,14 @@ impl super::View for FontBook {
|
||||
for (&chr, name) in named_chars {
|
||||
if filter.is_empty() || name.contains(filter) || *filter == chr.to_string() {
|
||||
let button = egui::Button::new(
|
||||
egui::RichText::new(chr.to_string()).text_style(text_style),
|
||||
egui::RichText::new(chr.to_string()).text_style(text_style.clone()),
|
||||
)
|
||||
.frame(false);
|
||||
|
||||
let tooltip_ui = |ui: &mut egui::Ui| {
|
||||
ui.label(egui::RichText::new(chr.to_string()).text_style(text_style));
|
||||
ui.label(
|
||||
egui::RichText::new(chr.to_string()).text_style(text_style.clone()),
|
||||
);
|
||||
ui.label(format!("{}\nU+{:X}\n\nClick to copy", name, chr as u32));
|
||||
};
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ impl Widgets {
|
||||
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
// Trick so we don't have to add spaces in the text below:
|
||||
let width = ui.fonts().glyph_width(TextStyle::Body, ' ');
|
||||
let width = ui.fonts().glyph_width(&TextStyle::Body, ' ');
|
||||
ui.spacing_mut().item_spacing.x = width;
|
||||
|
||||
ui.label(RichText::new("Text can have").color(Color32::from_rgb(110, 255, 110)));
|
||||
|
||||
@@ -262,7 +262,11 @@ impl Widget for &mut LegendDemo {
|
||||
ui.label("Text style:");
|
||||
ui.horizontal(|ui| {
|
||||
TextStyle::all().for_each(|style| {
|
||||
ui.selectable_value(&mut config.text_style, style, format!("{:?}", style));
|
||||
ui.selectable_value(
|
||||
&mut config.text_style,
|
||||
style.clone(),
|
||||
format!("{:?}", style),
|
||||
);
|
||||
});
|
||||
});
|
||||
ui.end_row();
|
||||
@@ -284,7 +288,9 @@ impl Widget for &mut LegendDemo {
|
||||
ui.end_row();
|
||||
});
|
||||
|
||||
let legend_plot = Plot::new("legend_demo").legend(*config).data_aspect(1.0);
|
||||
let legend_plot = Plot::new("legend_demo")
|
||||
.legend(config.clone())
|
||||
.data_aspect(1.0);
|
||||
legend_plot
|
||||
.show(ui, |plot_ui| {
|
||||
plot_ui.line(LegendDemo::line_with_slope(0.5).name("lines"));
|
||||
|
||||
@@ -81,7 +81,7 @@ fn huge_content_lines(ui: &mut egui::Ui) {
|
||||
ui.add_space(4.0);
|
||||
|
||||
let text_style = TextStyle::Body;
|
||||
let row_height = ui.fonts().row_height(text_style);
|
||||
let row_height = ui.fonts().row_height(&text_style);
|
||||
let num_rows = 10_000;
|
||||
ScrollArea::vertical().auto_shrink([false; 2]).show_rows(
|
||||
ui,
|
||||
@@ -102,7 +102,7 @@ fn huge_content_painter(ui: &mut egui::Ui) {
|
||||
ui.add_space(4.0);
|
||||
|
||||
let text_style = TextStyle::Body;
|
||||
let row_height = ui.fonts().row_height(text_style) + ui.spacing().item_spacing.y;
|
||||
let row_height = ui.fonts().row_height(&text_style) + ui.spacing().item_spacing.y;
|
||||
let num_rows = 10_000;
|
||||
|
||||
ScrollArea::vertical()
|
||||
@@ -130,7 +130,7 @@ fn huge_content_painter(ui: &mut egui::Ui) {
|
||||
pos2(x, y),
|
||||
Align2::LEFT_TOP,
|
||||
text,
|
||||
text_style,
|
||||
text_style.clone(),
|
||||
ui.visuals().text_color(),
|
||||
);
|
||||
used_rect = used_rect.union(text_rect);
|
||||
@@ -265,7 +265,7 @@ impl super::View for ScrollStickTo {
|
||||
ui.add_space(4.0);
|
||||
|
||||
let text_style = TextStyle::Body;
|
||||
let row_height = ui.fonts().row_height(text_style);
|
||||
let row_height = ui.fonts().row_height(&text_style);
|
||||
ScrollArea::vertical().stick_to_bottom().show_rows(
|
||||
ui,
|
||||
row_height,
|
||||
|
||||
Reference in New Issue
Block a user