Shape refactor (#705)

* More introspection stats about vertices/indices etc

* more serde derive

* #[inline] to Shape constructors

* Introduce RectShape

* Introduce CircleShape

* Introduce PathShape

* More serde derive

* impl Copy for RectShape and CircleShape

* Simplify some code

* More serde derive

* Add helpers for appending more input or output

* Serde derives for RawInput

* Rename Fonts::from_definitions to Fonts::new

* Add Output::take

* refactor EguiGlium slightly

* Derive PartialEq for RawInput

* Improve egui::util::History interface

* tweaks

* Improve History filter: add minimum length

* Calculate galley bounding rect

* tessellator: cull line segments and paths

* tessellator: cull meshes

* Fix bug in History bandwidth estimator
This commit is contained in:
Emil Ernerfeldt
2021-09-20 21:36:56 +02:00
committed by GitHub
parent 93c2fde1fc
commit e7cfda4941
36 changed files with 578 additions and 313 deletions
+1 -1
View File
@@ -305,7 +305,7 @@ impl CollapsingHeader {
.unwrap_or_else(|| visuals.text_color());
if ui.visuals().collapsing_header_frame || self.show_background {
ui.painter().add(Shape::Rect {
ui.painter().add(epaint::RectShape {
rect: header_response.rect.expand(visuals.expansion),
corner_radius: visuals.corner_radius,
fill: visuals.bg_fill,
+1 -1
View File
@@ -238,7 +238,7 @@ fn button_frame(
ui.painter().set(
where_to_put_background,
Shape::Rect {
epaint::RectShape {
rect: outer_rect.expand(visuals.expansion),
corner_radius: visuals.corner_radius,
fill: visuals.bg_fill,
+2 -2
View File
@@ -178,12 +178,12 @@ impl Frame {
stroke,
} = *self;
let frame_shape = Shape::Rect {
let frame_shape = Shape::Rect(epaint::RectShape {
rect: outer_rect,
corner_radius,
fill,
stroke,
};
});
if shadow == Default::default() {
frame_shape
+4 -5
View File
@@ -282,12 +282,11 @@ impl Resize {
if self.with_stroke && corner_response.is_some() {
let rect = Rect::from_min_size(content_ui.min_rect().left_top(), state.desired_size);
let rect = rect.expand(2.0); // breathing room for content
ui.painter().add(epaint::Shape::Rect {
ui.painter().add(Shape::rect_stroke(
rect,
corner_radius: 3.0,
fill: Default::default(),
stroke: ui.visuals().widgets.noninteractive.bg_stroke,
});
3.0,
ui.visuals().widgets.noninteractive.bg_stroke,
));
}
if let Some(corner_response) = corner_response {
+1 -1
View File
@@ -569,7 +569,7 @@ impl Context {
};
if self.fonts.is_none() || new_font_definitions.is_some() || pixels_per_point_changed {
self.fonts = Some(Arc::new(Fonts::from_definitions(
self.fonts = Some(Arc::new(Fonts::new(
pixels_per_point,
new_font_definitions.unwrap_or_else(|| {
self.fonts
+39 -3
View File
@@ -10,7 +10,8 @@ use crate::emath::*;
/// [`crate::Context::wants_pointer_input`] and [`crate::Context::wants_keyboard_input`].
///
/// All coordinates are in points (logical pixels) with origin (0, 0) in the top left corner.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct RawInput {
/// How many points (logical pixels) the user scrolled
pub scroll_delta: Vec2,
@@ -100,10 +101,38 @@ impl RawInput {
dropped_files: std::mem::take(&mut self.dropped_files),
}
}
/// Add on new input.
pub fn append(&mut self, newer: Self) {
let Self {
scroll_delta,
zoom_delta,
screen_rect,
pixels_per_point,
time,
predicted_dt,
modifiers,
mut events,
mut hovered_files,
mut dropped_files,
} = newer;
self.scroll_delta += scroll_delta;
self.zoom_delta *= zoom_delta;
self.screen_rect = screen_rect.or(self.screen_rect);
self.pixels_per_point = pixels_per_point.or(self.pixels_per_point);
self.time = time; // use latest time
self.predicted_dt = predicted_dt; // use latest dt
self.modifiers = modifiers; // use latest
self.events.append(&mut events);
self.hovered_files.append(&mut hovered_files);
self.dropped_files.append(&mut dropped_files);
}
}
/// A file about to be dropped into egui.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct HoveredFile {
/// Set by the `egui_glium` backend.
pub path: Option<std::path::PathBuf>,
@@ -112,7 +141,8 @@ pub struct HoveredFile {
}
/// A file dropped into egui.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct DroppedFile {
/// Set by the `egui_glium` backend.
pub path: Option<std::path::PathBuf>,
@@ -128,6 +158,7 @@ pub struct DroppedFile {
///
/// This only covers events that egui cares about.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub enum Event {
/// The integration detected a "copy" event (e.g. Cmd+C).
Copy,
@@ -186,6 +217,7 @@ pub enum Event {
/// Mouse button (or similar for touch input)
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub enum PointerButton {
/// The primary mouse button is usually the left one.
Primary = 0,
@@ -201,6 +233,7 @@ pub const NUM_POINTER_BUTTONS: usize = 3;
/// State of the modifier keys. These must be fed to egui.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct Modifiers {
/// Either of the alt keys are down (option ⌥ on Mac).
pub alt: bool,
@@ -350,16 +383,19 @@ impl RawInput {
/// this is a `u64` as values of this kind can always be obtained by hashing
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct TouchDeviceId(pub u64);
/// Unique identification of a touch occurrence (finger or pen or ...).
/// A Touch ID is valid until the finger is lifted.
/// A new ID is used for the next touch.
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct TouchId(pub u64);
/// In what phase a touch event is in.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub enum TouchPhase {
/// User just placed a touch point on the touch surface
Start,
+38 -1
View File
@@ -5,6 +5,7 @@ use crate::WidgetType;
/// What egui emits each frame.
/// The backend should use this.
#[derive(Clone, Default, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct Output {
/// Set the cursor to this icon.
pub cursor_icon: CursorIcon,
@@ -12,7 +13,9 @@ pub struct Output {
/// If set, open this url.
pub open_url: Option<OpenUrl>,
/// Response to [`crate::Event::Copy`] or [`crate::Event::Cut`]. Ignore if empty.
/// If set, put this text in the system clipboard. Ignore if empty.
///
/// This is often a response to [`crate::Event::Copy`] or [`crate::Event::Cut`].
pub copied_text: String,
/// If `true`, egui is requesting immediate repaint (i.e. on the next frame).
@@ -53,9 +56,40 @@ impl Output {
}
Default::default()
}
/// Add on new output.
pub fn append(&mut self, newer: Self) {
let Self {
cursor_icon,
open_url,
copied_text,
needs_repaint,
mut events,
text_cursor_pos,
} = newer;
self.cursor_icon = cursor_icon;
if open_url.is_some() {
self.open_url = open_url;
}
if !copied_text.is_empty() {
self.copied_text = copied_text;
}
self.needs_repaint = needs_repaint; // if the last frame doesn't need a repaint, then we don't need to repaint
self.events.append(&mut events);
self.text_cursor_pos = text_cursor_pos.or(self.text_cursor_pos);
}
/// Take everything ephemeral (everything except `cursor_icon` currently)
pub fn take(&mut self) -> Self {
let taken = std::mem::take(self);
self.cursor_icon = taken.cursor_icon; // eveything else is ephemeral
taken
}
}
#[derive(Clone, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct OpenUrl {
pub url: String,
/// If `true`, open the url in a new tab.
@@ -88,6 +122,7 @@ impl OpenUrl {
///
/// Loosely based on <https://developer.mozilla.org/en-US/docs/Web/CSS/cursor>.
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub enum CursorIcon {
/// Normal cursor icon, whatever that is.
Default,
@@ -209,6 +244,7 @@ impl Default for CursorIcon {
///
/// In particular, these events may be useful for accessability, i.e. for screen readers.
#[derive(Clone, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub enum OutputEvent {
// A widget was clicked.
Clicked(WidgetInfo),
@@ -236,6 +272,7 @@ impl std::fmt::Debug for OutputEvent {
/// Describes a widget such as a [`crate::Button`] or a [`crate::TextEdit`].
#[derive(Clone, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct WidgetInfo {
/// The type of widget this is.
pub typ: WidgetType,
+1 -1
View File
@@ -378,7 +378,7 @@ impl Default for PointerState {
interact_pos: None,
delta: Vec2::ZERO,
velocity: Vec2::ZERO,
pos_history: History::new(1000, 0.1),
pos_history: History::new(0..1000, 0.1),
down: Default::default(),
press_origin: None,
press_start_time: None,
+10 -2
View File
@@ -89,6 +89,8 @@ impl Widget for &epaint::stats::PaintStats {
shape_path,
shape_mesh,
shape_vec,
text_shape_vertices,
text_shape_indices,
clipped_meshes,
vertices,
indices,
@@ -96,13 +98,19 @@ impl Widget for &epaint::stats::PaintStats {
ui.label("Intermediate:");
label(ui, shapes, "shapes").on_hover_text("Boxes, circles, etc");
label(ui, shape_text, "text");
label(ui, shape_text, "text (mostly cached)");
label(ui, shape_path, "paths");
label(ui, shape_mesh, "nested meshes");
label(ui, shape_vec, "nested shapes");
ui.add_space(10.0);
ui.label("Tessellated:");
ui.label("Text shapes:");
label(ui, text_shape_vertices, "vertices");
label(ui, text_shape_indices, "indices")
.on_hover_text("Three 32-bit indices per triangles");
ui.add_space(10.0);
ui.label("Tessellated (and culled):");
label(ui, clipped_meshes, "clipped_meshes")
.on_hover_text("Number of separate clip rectangles");
label(ui, vertices, "vertices");
+2 -1
View File
@@ -397,7 +397,7 @@ pub use {
};
pub mod text {
pub use epaint::text::{Galley, LayoutJob, LayoutSection, TextFormat, TAB_SIZE};
pub use epaint::text::{Fonts, Galley, LayoutJob, LayoutSection, TextFormat, TAB_SIZE};
}
// ----------------------------------------------------------------------------
@@ -527,6 +527,7 @@ pub mod special_emojis {
/// The different types of built-in widgets in egui
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub enum WidgetType {
Label, // TODO: emit Label events
Hyperlink,
+14 -15
View File
@@ -6,7 +6,7 @@ use crate::{
use epaint::{
mutex::Mutex,
text::{Fonts, Galley, TextStyle},
Shape, Stroke, TextShape,
CircleShape, RectShape, Shape, Stroke, TextShape,
};
/// Helper to paint shapes and text to a specific region on a specific layer.
@@ -183,10 +183,11 @@ impl Painter {
}
/// Modify an existing [`Shape`].
pub fn set(&self, idx: ShapeIdx, mut shape: Shape) {
pub fn set(&self, idx: ShapeIdx, shape: impl Into<Shape>) {
if self.fade_to_color == Some(Color32::TRANSPARENT) {
return;
}
let mut shape = shape.into();
self.transform_shape(&mut shape);
self.paint_list.lock().set(idx, self.clip_rect, shape)
}
@@ -223,13 +224,11 @@ impl Painter {
let galley = self.layout_no_wrap(text.to_string(), TextStyle::Monospace, color);
let rect = anchor.anchor_rect(Rect::from_min_size(pos, galley.size()));
let frame_rect = rect.expand(2.0);
self.add(Shape::Rect {
rect: frame_rect,
corner_radius: 0.0,
fill: Color32::from_black_alpha(240),
// stroke: Stroke::new(1.0, color),
stroke: Default::default(),
});
self.add(Shape::rect_filled(
frame_rect,
0.0,
Color32::from_black_alpha(240),
));
self.galley(rect.min, galley);
frame_rect
}
@@ -251,7 +250,7 @@ impl Painter {
fill_color: impl Into<Color32>,
stroke: impl Into<Stroke>,
) {
self.add(Shape::Circle {
self.add(CircleShape {
center,
radius,
fill: fill_color.into(),
@@ -260,7 +259,7 @@ impl Painter {
}
pub fn circle_filled(&self, center: Pos2, radius: f32, fill_color: impl Into<Color32>) {
self.add(Shape::Circle {
self.add(CircleShape {
center,
radius,
fill: fill_color.into(),
@@ -269,7 +268,7 @@ impl Painter {
}
pub fn circle_stroke(&self, center: Pos2, radius: f32, stroke: impl Into<Stroke>) {
self.add(Shape::Circle {
self.add(CircleShape {
center,
radius,
fill: Default::default(),
@@ -284,7 +283,7 @@ impl Painter {
fill_color: impl Into<Color32>,
stroke: impl Into<Stroke>,
) {
self.add(Shape::Rect {
self.add(RectShape {
rect,
corner_radius,
fill: fill_color.into(),
@@ -293,7 +292,7 @@ impl Painter {
}
pub fn rect_filled(&self, rect: Rect, corner_radius: f32, fill_color: impl Into<Color32>) {
self.add(Shape::Rect {
self.add(RectShape {
rect,
corner_radius,
fill: fill_color.into(),
@@ -302,7 +301,7 @@ impl Painter {
}
pub fn rect_stroke(&self, rect: Rect, corner_radius: f32, stroke: impl Into<Stroke>) {
self.add(Shape::Rect {
self.add(RectShape {
rect,
corner_radius,
fill: Default::default(),
+56 -17
View File
@@ -2,11 +2,13 @@ use std::collections::VecDeque;
/// This struct tracks recent values of some time series.
///
/// One use is to show a log of recent events,
/// or show a graph over recent events.
/// It can be used as a smoothing filter for e.g. latency, fps etc,
/// or to show a log or graph of recent events.
///
/// It has both a maximum length and a maximum storage time.
/// Elements are dropped when either max length or max age is reached.
/// It has a minimum and maximum length, as well as a maximum storage time.
/// * The minimum length is to ensure you have enough data for an estimate.
/// * The maximum length is to make sure the history doesn't take up too much space.
/// * The maximum age is to make sure the estimate isn't outdated.
///
/// Time difference between values can be zero, but never negative.
///
@@ -15,11 +17,15 @@ use std::collections::VecDeque;
/// All times are in seconds.
#[derive(Clone, Debug)]
pub struct History<T> {
/// In elements, i.e. of `values.len()`
/// In elements, i.e. of `values.len()`.
/// The length is initially zero, but once past `min_len` will not shrink below it.
min_len: usize,
/// In elements, i.e. of `values.len()`.
max_len: usize,
/// In seconds
max_age: f64, // TODO: f32
/// In seconds.
max_age: f32,
/// Total number of elements seen ever
total_count: u64,
@@ -33,13 +39,22 @@ impl<T> History<T>
where
T: Copy,
{
pub fn new(max_len: usize, max_age: f64) -> Self {
Self::from_max_len_age(max_len, max_age)
}
pub fn from_max_len_age(max_len: usize, max_age: f64) -> Self {
/// Example:
/// ```
/// # use egui::util::History;
/// # fn now() -> f64 { 0.0 }
/// // Drop events that are older than one second,
/// // as long we keep at least two events. Never keep more than a hundred events.
/// let mut history = History::new(2..100, 1.0);
/// assert_eq!(history.average(), None);
/// history.add(now(), 40.0_f32);
/// history.add(now(), 44.0_f32);
/// assert_eq!(history.average(), Some(42.0));
/// ```
pub fn new(length_range: std::ops::Range<usize>, max_age: f32) -> Self {
Self {
max_len,
min_len: length_range.start,
max_len: length_range.end,
max_age,
total_count: 0,
values: Default::default(),
@@ -51,7 +66,7 @@ where
}
pub fn max_age(&self) -> f32 {
self.max_age as f32
self.max_age
}
pub fn is_empty(&self) -> bool {
@@ -125,14 +140,23 @@ where
}
}
// Mean number of events per second.
pub fn rate(&self) -> Option<f32> {
self.mean_time_interval().map(|time| 1.0 / time)
}
/// Remove samples that are too old
pub fn flush(&mut self, now: f64) {
while self.values.len() > self.max_len {
self.values.pop_front();
}
while let Some((front_time, _)) = self.values.front() {
if *front_time < now - self.max_age {
self.values.pop_front();
while self.values.len() > self.min_len {
if let Some((front_time, _)) = self.values.front() {
if *front_time < now - (self.max_age as f64) {
self.values.pop_front();
} else {
break;
}
} else {
break;
}
@@ -160,6 +184,21 @@ where
}
}
impl<T> History<T>
where
T: Copy,
T: std::iter::Sum,
T: std::ops::Div<f32, Output = T>,
T: std::ops::Mul<f32, Output = T>,
{
/// Average times rate.
/// If you are keeping track of individual sizes of things (e.g. bytes),
/// this will estimate the bandwidth (bytes per second).
pub fn bandwidth(&self) -> Option<T> {
Some(self.average()? * self.rate()?)
}
}
impl<T, Vel> History<T>
where
T: Copy,
+3 -3
View File
@@ -309,7 +309,7 @@ impl<'a> Widget for Checkbox<'a> {
rect.center().y - 0.5 * galley.size().y,
);
let (small_icon_rect, big_icon_rect) = ui.spacing().icon_rectangles(rect);
ui.painter().add(Shape::Rect {
ui.painter().add(epaint::RectShape {
rect: big_icon_rect.expand(visuals.expansion),
corner_radius: visuals.corner_radius,
fill: visuals.bg_fill,
@@ -433,7 +433,7 @@ impl Widget for RadioButton {
let painter = ui.painter();
painter.add(Shape::Circle {
painter.add(epaint::CircleShape {
center: big_icon_rect.center(),
radius: big_icon_rect.width() / 2.0 + visuals.expansion,
fill: visuals.bg_fill,
@@ -441,7 +441,7 @@ impl Widget for RadioButton {
});
if checked {
painter.add(Shape::Circle {
painter.add(epaint::CircleShape {
center: small_icon_rect.center(),
radius: small_icon_rect.width() / 3.0,
fill: visuals.fg_stroke.color, // Intentional to use stroke and not fill
+2 -2
View File
@@ -57,7 +57,7 @@ fn show_hsva(ui: &mut Ui, color: Hsva, desired_size: Vec2) -> Response {
ui.painter().rect_filled(left, 0.0, color);
ui.painter().rect_filled(right, 0.0, color.to_opaque());
} else {
ui.painter().add(Shape::Rect {
ui.painter().add(RectShape {
rect,
corner_radius: 2.0,
fill: color.into(),
@@ -190,7 +190,7 @@ fn color_slider_2d(
let x = lerp(rect.left()..=rect.right(), *x_value);
let y = lerp(rect.bottom()..=rect.top(), *y_value);
let picked_color = color_at(*x_value, *y_value);
ui.painter().add(Shape::Circle {
ui.painter().add(epaint::CircleShape {
center: pos2(x, y),
radius: rect.width() / 12.0,
fill: picked_color,
+9 -44
View File
@@ -800,12 +800,7 @@ impl PlotItem for Polygon {
let fill = Rgba::from(stroke.color).to_opaque().multiply(fill_alpha);
let shape = Shape::Path {
points: values_tf.clone(),
closed: true,
fill: fill.into(),
stroke: Stroke::none(),
};
let shape = Shape::convex_polygon(values_tf.clone(), fill, Stroke::none());
shapes.push(shape);
values_tf.push(*values_tf.first().unwrap());
style.style_line(values_tf, *stroke, *highlight, shapes);
@@ -1081,21 +1076,16 @@ impl PlotItem for Points {
match shape {
MarkerShape::Circle => {
shapes.push(Shape::Circle {
shapes.push(Shape::Circle(epaint::CircleShape {
center,
radius,
fill,
stroke,
});
}));
}
MarkerShape::Diamond => {
let points = vec![tf(1.0, 0.0), tf(0.0, -1.0), tf(-1.0, 0.0), tf(0.0, 1.0)];
shapes.push(Shape::Path {
points,
closed: true,
fill,
stroke,
});
shapes.push(Shape::convex_polygon(points, fill, stroke));
}
MarkerShape::Square => {
let points = vec![
@@ -1104,12 +1094,7 @@ impl PlotItem for Points {
tf(-frac_1_sqrt_2, -frac_1_sqrt_2),
tf(-frac_1_sqrt_2, frac_1_sqrt_2),
];
shapes.push(Shape::Path {
points,
closed: true,
fill,
stroke,
});
shapes.push(Shape::convex_polygon(points, fill, stroke));
}
MarkerShape::Cross => {
let diagonal1 = [
@@ -1132,12 +1117,7 @@ impl PlotItem for Points {
MarkerShape::Up => {
let points =
vec![tf(0.0, -1.0), tf(-0.5 * sqrt_3, 0.5), tf(0.5 * sqrt_3, 0.5)];
shapes.push(Shape::Path {
points,
closed: true,
fill,
stroke,
});
shapes.push(Shape::convex_polygon(points, fill, stroke));
}
MarkerShape::Down => {
let points = vec![
@@ -1145,22 +1125,12 @@ impl PlotItem for Points {
tf(-0.5 * sqrt_3, -0.5),
tf(0.5 * sqrt_3, -0.5),
];
shapes.push(Shape::Path {
points,
closed: true,
fill,
stroke,
});
shapes.push(Shape::convex_polygon(points, fill, stroke));
}
MarkerShape::Left => {
let points =
vec![tf(-1.0, 0.0), tf(0.5, -0.5 * sqrt_3), tf(0.5, 0.5 * sqrt_3)];
shapes.push(Shape::Path {
points,
closed: true,
fill,
stroke,
});
shapes.push(Shape::convex_polygon(points, fill, stroke));
}
MarkerShape::Right => {
let points = vec![
@@ -1168,12 +1138,7 @@ impl PlotItem for Points {
tf(-0.5, -0.5 * sqrt_3),
tf(-0.5, 0.5 * sqrt_3),
];
shapes.push(Shape::Path {
points,
closed: true,
fill,
stroke,
});
shapes.push(Shape::convex_polygon(points, fill, stroke));
}
MarkerShape::Asterisk => {
let vertical = [tf(0.0, -1.0), tf(0.0, 1.0)];
+5 -6
View File
@@ -117,7 +117,7 @@ impl LegendEntry {
let painter = ui.painter();
painter.add(Shape::Circle {
painter.add(epaint::CircleShape {
center: icon_rect.center(),
radius: icon_size * 0.5,
fill: visuals.bg_fill,
@@ -130,12 +130,11 @@ impl LegendEntry {
} else {
*color
};
painter.add(Shape::Circle {
center: icon_rect.center(),
radius: icon_size * 0.4,
painter.add(epaint::Shape::circle_filled(
icon_rect.center(),
icon_size * 0.4,
fill,
stroke: Default::default(),
});
));
}
let text_position_x = if label_on_the_left {
+1 -1
View File
@@ -404,7 +404,7 @@ impl Widget for Plot {
// Background
if show_background {
plot_painter.add(Shape::Rect {
plot_painter.add(epaint::RectShape {
rect,
corner_radius: 2.0,
fill: ui.visuals().extreme_bg_color,
+3 -5
View File
@@ -116,12 +116,10 @@ impl Widget for ProgressBar {
+ vec2(-corner_radius, 0.0)
})
.collect();
ui.painter().add(Shape::Path {
ui.painter().add(Shape::line(
points,
closed: false,
fill: Color32::TRANSPARENT,
stroke: Stroke::new(2.0, visuals.faint_bg_color),
});
Stroke::new(2.0, visuals.faint_bg_color),
));
}
if let Some(text_kind) = text {
+2 -2
View File
@@ -333,7 +333,7 @@ impl<'a> Slider<'a> {
let marker_center_x = self.x_from_value(value, x_range);
let visuals = ui.style().interact(response);
ui.painter().add(Shape::Rect {
ui.painter().add(epaint::RectShape {
rect: rail_rect,
corner_radius: ui.visuals().widgets.inactive.corner_radius,
fill: ui.visuals().widgets.inactive.bg_fill,
@@ -344,7 +344,7 @@ impl<'a> Slider<'a> {
// stroke: ui.visuals().widgets.inactive.bg_stroke,
});
ui.painter().add(Shape::Circle {
ui.painter().add(epaint::CircleShape {
center: pos2(marker_center_x, rail_rect.center().y),
radius: handle_radius(rect) + visuals.expansion,
fill: visuals.bg_fill,
+2 -2
View File
@@ -425,7 +425,7 @@ impl<'t, S: TextBuffer> Widget for TextEdit<'t, S> {
let visuals = ui.style().interact(&response);
let frame_rect = response.rect.expand(visuals.expansion);
let shape = if response.has_focus() {
Shape::Rect {
epaint::RectShape {
rect: frame_rect,
corner_radius: visuals.corner_radius,
// fill: ui.visuals().selection.bg_fill,
@@ -433,7 +433,7 @@ impl<'t, S: TextBuffer> Widget for TextEdit<'t, S> {
stroke: ui.visuals().selection.stroke,
}
} else {
Shape::Rect {
epaint::RectShape {
rect: frame_rect,
corner_radius: visuals.corner_radius,
fill: ui.visuals().extreme_bg_color,