refactor fonts: put TextStyle in Galley instead of in Shape::Text
This commit is contained in:
@@ -262,12 +262,7 @@ impl CollapsingHeader {
|
||||
paint_icon(ui, openness, &icon_response);
|
||||
}
|
||||
|
||||
ui.painter().galley(
|
||||
text_pos,
|
||||
galley,
|
||||
label.text_style_or_default(ui.style()),
|
||||
text_color,
|
||||
);
|
||||
ui.painter().galley(text_pos, galley, text_color);
|
||||
|
||||
Prepared {
|
||||
id,
|
||||
|
||||
@@ -179,8 +179,9 @@ fn combo_box(
|
||||
let full_minimum_width = ui.spacing().slider_width;
|
||||
let icon_size = Vec2::splat(ui.spacing().icon_width);
|
||||
|
||||
let text_style = TextStyle::Button;
|
||||
let galley = ui.fonts().layout_no_wrap(text_style, selected.into());
|
||||
let galley = ui
|
||||
.fonts()
|
||||
.layout_no_wrap(TextStyle::Button, selected.into());
|
||||
|
||||
let width = galley.size.x + ui.spacing().item_spacing.x + icon_size.x;
|
||||
let width = width.at_least(full_minimum_width);
|
||||
@@ -197,7 +198,7 @@ fn combo_box(
|
||||
|
||||
let text_rect = Align2::LEFT_CENTER.align_size_within_rect(galley.size, rect);
|
||||
ui.painter()
|
||||
.galley(text_rect.min, galley, text_style, visuals.text_color());
|
||||
.galley(text_rect.min, galley, visuals.text_color());
|
||||
});
|
||||
|
||||
if button_response.clicked() {
|
||||
|
||||
+9
-10
@@ -172,10 +172,11 @@ impl Painter {
|
||||
}
|
||||
|
||||
pub fn error(&self, pos: Pos2, text: impl std::fmt::Display) -> Rect {
|
||||
let text_style = TextStyle::Monospace;
|
||||
let galley =
|
||||
self.fonts()
|
||||
.layout_multiline(text_style, format!("🔥 {}", text), f32::INFINITY);
|
||||
let galley = self.fonts().layout_multiline(
|
||||
TextStyle::Monospace,
|
||||
format!("🔥 {}", text),
|
||||
f32::INFINITY,
|
||||
);
|
||||
let rect = Align2::LEFT_TOP.anchor_rect(Rect::from_min_size(pos, galley.size));
|
||||
let frame_rect = rect.expand(2.0);
|
||||
self.add(Shape::Rect {
|
||||
@@ -184,7 +185,7 @@ impl Painter {
|
||||
fill: Color32::from_black_alpha(240),
|
||||
stroke: Stroke::new(1.0, Color32::RED),
|
||||
});
|
||||
self.galley(rect.min, galley, text_style, Color32::RED);
|
||||
self.galley(rect.min, galley, Color32::RED);
|
||||
frame_rect
|
||||
}
|
||||
}
|
||||
@@ -296,27 +297,25 @@ impl Painter {
|
||||
.fonts()
|
||||
.layout_multiline(text_style, text.into(), f32::INFINITY);
|
||||
let rect = anchor.anchor_rect(Rect::from_min_size(pos, galley.size));
|
||||
self.galley(rect.min, galley, text_style, text_color);
|
||||
self.galley(rect.min, galley, text_color);
|
||||
rect
|
||||
}
|
||||
|
||||
/// Paint text that has already been layed out in a `Galley`.
|
||||
pub fn galley(&self, pos: Pos2, galley: Galley, text_style: TextStyle, color: Color32) {
|
||||
self.galley_with_italics(pos, galley, text_style, color, false)
|
||||
pub fn galley(&self, pos: Pos2, galley: Galley, color: Color32) {
|
||||
self.galley_with_italics(pos, galley, color, false)
|
||||
}
|
||||
|
||||
pub fn galley_with_italics(
|
||||
&self,
|
||||
pos: Pos2,
|
||||
galley: Galley,
|
||||
text_style: TextStyle,
|
||||
color: Color32,
|
||||
fake_italics: bool,
|
||||
) {
|
||||
self.add(Shape::Text {
|
||||
pos,
|
||||
galley,
|
||||
text_style,
|
||||
color,
|
||||
fake_italics,
|
||||
});
|
||||
|
||||
@@ -141,8 +141,7 @@ impl Button {
|
||||
let text_color = text_color
|
||||
.or(ui.visuals().override_text_color)
|
||||
.unwrap_or_else(|| visuals.text_color());
|
||||
ui.painter()
|
||||
.galley(text_cursor, galley, text_style, text_color);
|
||||
ui.painter().galley(text_cursor, galley, text_color);
|
||||
}
|
||||
|
||||
response
|
||||
@@ -264,8 +263,7 @@ impl<'a> Widget for Checkbox<'a> {
|
||||
let text_color = text_color
|
||||
.or(ui.visuals().override_text_color)
|
||||
.unwrap_or_else(|| visuals.text_color());
|
||||
ui.painter()
|
||||
.galley(text_cursor, galley, text_style, text_color);
|
||||
ui.painter().galley(text_cursor, galley, text_color);
|
||||
response
|
||||
}
|
||||
}
|
||||
@@ -373,7 +371,7 @@ impl Widget for RadioButton {
|
||||
let text_color = text_color
|
||||
.or(ui.visuals().override_text_color)
|
||||
.unwrap_or_else(|| visuals.text_color());
|
||||
painter.galley(text_cursor, galley, text_style, text_color);
|
||||
painter.galley(text_cursor, galley, text_color);
|
||||
response
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ impl Label {
|
||||
|
||||
pub fn font_height(&self, fonts: &epaint::text::Fonts, style: &Style) -> f32 {
|
||||
let text_style = self.text_style_or_default(style);
|
||||
fonts[text_style].row_height()
|
||||
fonts.row_height(text_style)
|
||||
}
|
||||
|
||||
// TODO: this should return a LabelLayout which has a paint method.
|
||||
@@ -234,9 +234,8 @@ impl Label {
|
||||
}
|
||||
}
|
||||
|
||||
let text_style = self.text_style_or_default(ui.style());
|
||||
ui.painter()
|
||||
.galley_with_italics(pos, galley, text_style, text_color, italics);
|
||||
.galley_with_italics(pos, galley, text_color, italics);
|
||||
|
||||
ui.painter().extend(lines);
|
||||
}
|
||||
|
||||
@@ -661,7 +661,6 @@ impl Prepared {
|
||||
shapes.push(Shape::Text {
|
||||
pos: text_pos,
|
||||
galley,
|
||||
text_style,
|
||||
color: ui.visuals().text_color(),
|
||||
fake_italics: false,
|
||||
});
|
||||
|
||||
@@ -78,8 +78,7 @@ impl Widget for SelectableLabel {
|
||||
.visuals
|
||||
.override_text_color
|
||||
.unwrap_or_else(|| visuals.text_color());
|
||||
ui.painter()
|
||||
.galley(text_cursor, galley, text_style, text_color);
|
||||
ui.painter().galley(text_cursor, galley, text_color);
|
||||
response
|
||||
}
|
||||
}
|
||||
|
||||
@@ -513,8 +513,7 @@ impl<'t> TextEdit<'t> {
|
||||
.or(ui.visuals().override_text_color)
|
||||
// .unwrap_or_else(|| ui.style().interact(&response).text_color()); // too bright
|
||||
.unwrap_or_else(|| ui.visuals().widgets.inactive.text_color());
|
||||
ui.painter()
|
||||
.galley(response.rect.min, galley, text_style, text_color);
|
||||
ui.painter().galley(response.rect.min, galley, text_color);
|
||||
|
||||
if text.is_empty() && !hint_text.is_empty() {
|
||||
let galley = if multiline {
|
||||
@@ -525,7 +524,7 @@ impl<'t> TextEdit<'t> {
|
||||
};
|
||||
let hint_text_color = ui.visuals().weak_text_color();
|
||||
ui.painter()
|
||||
.galley(response.rect.min, galley, text_style, hint_text_color);
|
||||
.galley(response.rect.min, galley, hint_text_color);
|
||||
}
|
||||
|
||||
ui.memory().text_edit.insert(id, state);
|
||||
|
||||
Reference in New Issue
Block a user