mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
Add UI to modify FontTweak live (#5125)
This will make it easier to get nice sizing and vertical alignments of fonts
This commit is contained in:
@@ -4,9 +4,15 @@ use std::{borrow::Cow, cell::RefCell, panic::Location, sync::Arc, time::Duration
|
||||
|
||||
use containers::area::AreaState;
|
||||
use epaint::{
|
||||
emath, emath::TSTransform, mutex::RwLock, pos2, stats::PaintStats, tessellator, text::Fonts,
|
||||
util::OrderedFloat, vec2, ClippedPrimitive, ClippedShape, Color32, ImageData, ImageDelta, Pos2,
|
||||
Rect, TessellationOptions, TextureAtlas, TextureId, Vec2,
|
||||
emath::{self, TSTransform},
|
||||
mutex::RwLock,
|
||||
pos2,
|
||||
stats::PaintStats,
|
||||
tessellator,
|
||||
text::Fonts,
|
||||
util::OrderedFloat,
|
||||
vec2, ClippedPrimitive, ClippedShape, Color32, ImageData, ImageDelta, Pos2, Rect,
|
||||
TessellationOptions, TextureAtlas, TextureId, Vec2,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@@ -2817,6 +2823,10 @@ impl Context {
|
||||
let prev_options = self.options(|o| o.clone());
|
||||
let mut options = prev_options.clone();
|
||||
|
||||
ui.collapsing("🔠 Font tweak", |ui| {
|
||||
self.fonts_tweak_ui(ui);
|
||||
});
|
||||
|
||||
options.ui(ui);
|
||||
|
||||
if options != prev_options {
|
||||
@@ -2824,6 +2834,23 @@ impl Context {
|
||||
}
|
||||
}
|
||||
|
||||
fn fonts_tweak_ui(&self, ui: &mut Ui) {
|
||||
let mut font_definitions = self.write(|ctx| ctx.font_definitions.clone());
|
||||
let mut changed = false;
|
||||
|
||||
for (name, data) in &mut font_definitions.font_data {
|
||||
ui.collapsing(name, |ui| {
|
||||
if data.tweak.ui(ui).changed() {
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if changed {
|
||||
self.set_fonts(font_definitions);
|
||||
}
|
||||
}
|
||||
|
||||
/// Show the state of egui, including its input and output.
|
||||
pub fn inspection_ui(&self, ui: &mut Ui) {
|
||||
use crate::containers::CollapsingHeader;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
use std::{collections::BTreeMap, ops::RangeInclusive, sync::Arc};
|
||||
|
||||
use epaint::{Rounding, Shadow, Stroke};
|
||||
use epaint::{text::FontTweak, Rounding, Shadow, Stroke};
|
||||
|
||||
use crate::{
|
||||
ecolor::Color32,
|
||||
@@ -2498,3 +2498,48 @@ impl Widget for &mut crate::Frame {
|
||||
.response
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for &mut FontTweak {
|
||||
fn ui(self, ui: &mut Ui) -> Response {
|
||||
let original: FontTweak = *self;
|
||||
|
||||
let mut response = Grid::new("font_tweak")
|
||||
.num_columns(2)
|
||||
.show(ui, |ui| {
|
||||
let FontTweak {
|
||||
scale,
|
||||
y_offset_factor,
|
||||
y_offset,
|
||||
baseline_offset_factor,
|
||||
} = self;
|
||||
|
||||
ui.label("Scale");
|
||||
let speed = *scale * 0.01;
|
||||
ui.add(DragValue::new(scale).range(0.01..=10.0).speed(speed));
|
||||
ui.end_row();
|
||||
|
||||
ui.label("y_offset_factor");
|
||||
ui.add(DragValue::new(y_offset_factor).speed(-0.0025));
|
||||
ui.end_row();
|
||||
|
||||
ui.label("y_offset");
|
||||
ui.add(DragValue::new(y_offset).speed(-0.02));
|
||||
ui.end_row();
|
||||
|
||||
ui.label("baseline_offset_factor");
|
||||
ui.add(DragValue::new(baseline_offset_factor).speed(-0.0025));
|
||||
ui.end_row();
|
||||
|
||||
if ui.button("Reset").clicked() {
|
||||
*self = Default::default();
|
||||
}
|
||||
})
|
||||
.response;
|
||||
|
||||
if *self != original {
|
||||
response.mark_changed();
|
||||
}
|
||||
|
||||
response
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1404,7 +1404,7 @@ impl Ui {
|
||||
///
|
||||
/// If this is called multiple times per frame for the same [`crate::ScrollArea`], the deltas will be summed.
|
||||
///
|
||||
/// /// See also: [`Response::scroll_to_me`], [`Ui::scroll_to_rect`], [`Ui::scroll_to_cursor`]
|
||||
/// See also: [`Response::scroll_to_me`], [`Ui::scroll_to_rect`], [`Ui::scroll_to_cursor`]
|
||||
///
|
||||
/// ```
|
||||
/// # use egui::{Align, Vec2};
|
||||
|
||||
Reference in New Issue
Block a user