1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

Add Ui::spacing() and Ui::spacing_mut() as shortcuts

This commit is contained in:
Emil Ernerfeldt
2021-02-01 16:55:40 +01:00
parent c687671a9f
commit 01fca2f31c
24 changed files with 96 additions and 85 deletions

View File

@@ -71,7 +71,7 @@ impl ColorTest {
ui.heading("sRGB color test");
ui.label("Use a color picker to ensure this color is (255, 165, 0) / #ffa500");
ui.wrap(|ui| {
ui.style_mut().spacing.item_spacing.y = 0.0; // No spacing between gradients
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
let g = Gradient::one_color(Color32::from_rgb(255, 165, 0));
self.vertex_gradient(ui, "orange rgb(255, 165, 0) - vertex", WHITE, &g);
self.tex_gradient(
@@ -87,13 +87,13 @@ impl ColorTest {
ui.label("Test that vertex color times texture color is done in linear space:");
ui.wrap(|ui| {
ui.style_mut().spacing.item_spacing.y = 0.0; // No spacing between gradients
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
let tex_color = Rgba::from_rgb(1.0, 0.25, 0.25);
let vertex_color = Rgba::from_rgb(0.5, 0.75, 0.75);
ui.horizontal(|ui| {
let color_size = ui.style().spacing.interact_size;
let color_size = ui.spacing().interact_size;
ui.label("texture");
show_color(ui, tex_color, color_size);
ui.label(" * ");
@@ -174,7 +174,7 @@ impl ColorTest {
let is_opaque = left.is_opaque() && right.is_opaque();
ui.horizontal(|ui| {
let color_size = ui.style().spacing.interact_size;
let color_size = ui.spacing().interact_size;
if !is_opaque {
ui.label("Background:");
show_color(ui, bg_fill, color_size);
@@ -186,7 +186,7 @@ impl ColorTest {
});
ui.wrap(|ui| {
ui.style_mut().spacing.item_spacing.y = 0.0; // No spacing between gradients
ui.spacing_mut().item_spacing.y = 0.0; // No spacing between gradients
if is_opaque {
let g = Gradient::ground_truth_linear_gradient(left, right);
self.vertex_gradient(ui, "Ground Truth (CPU gradient) - vertices", bg_fill, &g);

View File

@@ -90,7 +90,7 @@ impl super::View for FontBook {
egui::ScrollArea::auto_sized().show(ui, |ui| {
ui.horizontal_wrapped(|ui| {
ui.style_mut().spacing.item_spacing = egui::Vec2::splat(2.0);
ui.spacing_mut().item_spacing = egui::Vec2::splat(2.0);
if self.standard {
self.characters_ui(ui, UBUNTU_FONT_CHARACTERS);

View File

@@ -19,7 +19,7 @@ pub fn toggle(ui: &mut egui::Ui, on: &mut bool) -> egui::Response {
// 1. Deciding widget size:
// You can query the `ui` how much space is available,
// but in this example we have a fixed size widget of the default size for a button:
let desired_size = ui.style().spacing.interact_size;
let desired_size = ui.spacing().interact_size;
// 2. Allocating space:
// This is where we get a region of the screen assigned.
@@ -61,7 +61,7 @@ pub fn toggle(ui: &mut egui::Ui, on: &mut bool) -> egui::Response {
/// Here is the same code again, but a bit more compact:
#[allow(dead_code)]
fn toggle_compact(ui: &mut egui::Ui, on: &mut bool) -> egui::Response {
let desired_size = ui.style().spacing.interact_size;
let desired_size = ui.spacing().interact_size;
let (rect, response) = ui.allocate_exact_size(desired_size, egui::Sense::click());
*on ^= response.clicked(); // toggle if clicked

View File

@@ -239,7 +239,7 @@ impl ColoredText {
pub fn ui(&self, ui: &mut egui::Ui) {
for line in &self.0 {
ui.horizontal_wrapped_for_text(egui::TextStyle::Monospace, |ui| {
ui.style_mut().spacing.item_spacing.x = 0.0;
ui.spacing_mut().item_spacing.x = 0.0;
for (style, range) in line {
let fg = style.foreground;
let text_color = egui::Color32::from_rgb(fg.r, fg.g, fg.b);

View File

@@ -64,7 +64,7 @@ impl FrameHistory {
let history = &self.frame_times;
// TODO: we should not use `slider_width` as default graph width.
let height = ui.style().spacing.slider_width;
let height = ui.spacing().slider_width;
let size = vec2(ui.available_size_before_wrap_finite().x, height);
let (rect, response) = ui.allocate_at_least(size, Sense::hover());
let style = ui.style().noninteractive();

View File

@@ -261,7 +261,7 @@ impl BackendPanel {
let pixels_per_point = self.pixels_per_point.as_mut()?;
ui.horizontal(|ui| {
ui.style_mut().spacing.slider_width = 90.0;
ui.spacing_mut().slider_width = 90.0;
ui.add(
egui::Slider::f32(pixels_per_point, 0.5..=5.0)
.logarithmic(true)