Skip to content

Commit

Permalink
Update style.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
rustbasic authored Jun 29, 2024
1 parent 197bbd1 commit 64996d4
Showing 1 changed file with 62 additions and 44 deletions.
106 changes: 62 additions & 44 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ impl ScrollStyle {
Self {
floating: true,
bar_width: 10.0,
bar_inner_margin: 0.0,
foreground_color: true,
floating_allocated_width: 0.0,
dormant_background_opacity: 0.0,
Expand Down Expand Up @@ -571,26 +572,30 @@ impl ScrollStyle {
});

ui.horizontal(|ui| {
ui.add(DragValue::new(bar_width).range(0.0..=32.0));
ui.add(DragValue::new(bar_width).clamp_range(0.0..=32.0));
ui.label("Full bar width");
});
if *floating {
ui.horizontal(|ui| {
ui.add(DragValue::new(floating_width).range(0.0..=32.0));
ui.add(DragValue::new(floating_width).clamp_range(0.0..=32.0));
ui.label("Thin bar width");
});
ui.horizontal(|ui| {
ui.add(DragValue::new(floating_allocated_width).range(0.0..=32.0));
ui.add(DragValue::new(floating_allocated_width).clamp_range(0.0..=32.0));
ui.label("Allocated width");
});
}

ui.horizontal(|ui| {
ui.add(DragValue::new(handle_min_length).range(0.0..=32.0));
ui.add(DragValue::new(handle_min_length).clamp_range(0.0..=32.0));
ui.label("Minimum handle length");
});
ui.horizontal(|ui| {
ui.add(DragValue::new(bar_outer_margin).range(0.0..=32.0));
ui.add(DragValue::new(bar_inner_margin).clamp_range(0.0..=32.0));
ui.label("Inner margin");
});
ui.horizontal(|ui| {
ui.add(DragValue::new(bar_outer_margin).clamp_range(0.0..=32.0));
ui.label("Outer margin");
});

Expand All @@ -603,7 +608,7 @@ impl ScrollStyle {
if *floating {
crate::Grid::new("opacity").show(ui, |ui| {
fn opacity_ui(ui: &mut Ui, opacity: &mut f32) {
ui.add(DragValue::new(opacity).speed(0.01).range(0.0..=1.0));
ui.add(DragValue::new(opacity).speed(0.01).clamp_range(0.0..=1.0));
}

ui.label("Opacity");
Expand All @@ -624,11 +629,6 @@ impl ScrollStyle {
opacity_ui(ui, interact_handle_opacity);
ui.end_row();
});
} else {
ui.horizontal(|ui| {
ui.add(DragValue::new(bar_inner_margin).range(0.0..=32.0));
ui.label("Inner margin");
});
}
}
}
Expand Down Expand Up @@ -694,6 +694,12 @@ pub struct TextCursorStyle {

/// When blinking, this is how long the cursor is invisible.
pub off_duration: f32,

/// Whether the IME (Input Method Editor) is allowed.
pub ime_allowed: bool,

/// Whether the IME should be visible.
pub ime_visible: bool,
}

impl Default for TextCursorStyle {
Expand All @@ -704,6 +710,8 @@ impl Default for TextCursorStyle {
blink: true,
on_duration: 0.5,
off_duration: 0.5,
ime_allowed: true,
ime_visible: false,
}
}
}
Expand Down Expand Up @@ -1418,7 +1426,7 @@ impl Style {
ui.label("Animation duration");
ui.add(
DragValue::new(animation_time)
.range(0.0..=1.0)
.clamp_range(0.0..=1.0)
.speed(0.02)
.suffix(" s"),
);
Expand Down Expand Up @@ -1515,58 +1523,58 @@ impl Spacing {
ui.end_row();

ui.label("Indent");
ui.add(DragValue::new(indent).range(0.0..=100.0));
ui.add(DragValue::new(indent).clamp_range(0.0..=100.0));
ui.end_row();

ui.label("Slider width");
ui.add(DragValue::new(slider_width).range(0.0..=1000.0));
ui.add(DragValue::new(slider_width).clamp_range(0.0..=1000.0));
ui.end_row();

ui.label("Slider rail height");
ui.add(DragValue::new(slider_rail_height).range(0.0..=50.0));
ui.add(DragValue::new(slider_rail_height).clamp_range(0.0..=50.0));
ui.end_row();

ui.label("ComboBox width");
ui.add(DragValue::new(combo_width).range(0.0..=1000.0));
ui.add(DragValue::new(combo_width).clamp_range(0.0..=1000.0));
ui.end_row();

ui.label("Default area size");
ui.add(two_drag_values(default_area_size, 0.0..=1000.0));
ui.end_row();

ui.label("TextEdit width");
ui.add(DragValue::new(text_edit_width).range(0.0..=1000.0));
ui.add(DragValue::new(text_edit_width).clamp_range(0.0..=1000.0));
ui.end_row();

ui.label("Tooltip wrap width");
ui.add(DragValue::new(tooltip_width).range(0.0..=1000.0));
ui.add(DragValue::new(tooltip_width).clamp_range(0.0..=1000.0));
ui.end_row();

ui.label("Default menu width");
ui.add(DragValue::new(menu_width).range(0.0..=1000.0));
ui.add(DragValue::new(menu_width).clamp_range(0.0..=1000.0));
ui.end_row();

ui.label("Menu spacing")
.on_hover_text("Horizontal spacing between menus");
ui.add(DragValue::new(menu_spacing).range(0.0..=10.0));
ui.add(DragValue::new(menu_spacing).clamp_range(0.0..=10.0));
ui.end_row();

ui.label("Checkboxes etc");
ui.vertical(|ui| {
ui.add(
DragValue::new(icon_width)
.prefix("outer icon width:")
.range(0.0..=60.0),
.clamp_range(0.0..=60.0),
);
ui.add(
DragValue::new(icon_width_inner)
.prefix("inner icon width:")
.range(0.0..=60.0),
.clamp_range(0.0..=60.0),
);
ui.add(
DragValue::new(icon_spacing)
.prefix("spacing:")
.range(0.0..=10.0),
.clamp_range(0.0..=10.0),
);
});
ui.end_row();
Expand All @@ -1579,7 +1587,7 @@ impl Spacing {

ui.horizontal(|ui| {
ui.label("Max height of a combo box");
ui.add(DragValue::new(combo_height).range(0.0..=1000.0));
ui.add(DragValue::new(combo_height).clamp_range(0.0..=1000.0));
});

ui.collapsing("Scroll Area", |ui| {
Expand Down Expand Up @@ -1611,23 +1619,23 @@ impl Interaction {
.show(ui, |ui| {
ui.label("interact_radius")
.on_hover_text("Interact with the closest widget within this radius.");
ui.add(DragValue::new(interact_radius).range(0.0..=20.0));
ui.add(DragValue::new(interact_radius).clamp_range(0.0..=20.0));
ui.end_row();

ui.label("resize_grab_radius_side").on_hover_text("Radius of the interactive area of the side of a window during drag-to-resize");
ui.add(DragValue::new(resize_grab_radius_side).range(0.0..=20.0));
ui.add(DragValue::new(resize_grab_radius_side).clamp_range(0.0..=20.0));
ui.end_row();

ui.label("resize_grab_radius_corner").on_hover_text("Radius of the interactive area of the corner of a window during drag-to-resize.");
ui.add(DragValue::new(resize_grab_radius_corner).range(0.0..=20.0));
ui.add(DragValue::new(resize_grab_radius_corner).clamp_range(0.0..=20.0));
ui.end_row();

ui.label("Tooltip delay").on_hover_text(
"Delay in seconds before showing tooltips after the mouse stops moving",
);
ui.add(
DragValue::new(tooltip_delay)
.range(0.0..=1.0)
.clamp_range(0.0..=1.0)
.speed(0.05)
.suffix(" s"),
);
Expand All @@ -1638,7 +1646,7 @@ impl Interaction {
);
ui.add(
DragValue::new(tooltip_grace_time)
.range(0.0..=1.0)
.clamp_range(0.0..=1.0)
.speed(0.05)
.suffix(" s"),
);
Expand Down Expand Up @@ -1979,6 +1987,8 @@ impl TextCursorStyle {
blink,
on_duration,
off_duration,
ime_allowed,
ime_visible,
} = self;

ui.horizontal(|ui| {
Expand All @@ -1996,7 +2006,7 @@ impl TextCursorStyle {
ui.add(
DragValue::new(on_duration)
.speed(0.1)
.range(0.0..=2.0)
.clamp_range(0.0..=2.0)
.suffix(" s"),
);
ui.end_row();
Expand All @@ -2005,12 +2015,16 @@ impl TextCursorStyle {
ui.add(
DragValue::new(off_duration)
.speed(0.1)
.range(0.0..=2.0)
.clamp_range(0.0..=2.0)
.suffix(" s"),
);
ui.end_row();
});
}

ui.checkbox(ime_allowed, "Whether the IME is allowed");

ui.checkbox(ime_visible, "Whether the IME should be visible");
}
}

Expand Down Expand Up @@ -2065,12 +2079,12 @@ fn two_drag_values(value: &mut Vec2, range: std::ops::RangeInclusive<f32>) -> im
ui.horizontal(|ui| {
ui.add(
DragValue::new(&mut value.x)
.range(range.clone())
.clamp_range(range.clone())
.prefix("x: "),
);
ui.add(
DragValue::new(&mut value.y)
.range(range.clone())
.clamp_range(range.clone())
.prefix("y: "),
);
})
Expand Down Expand Up @@ -2212,7 +2226,7 @@ impl Widget for &mut Rounding {
ui.checkbox(&mut same, "same");

let mut cr = self.nw;
ui.add(DragValue::new(&mut cr).range(0.0..=f32::INFINITY));
ui.add(DragValue::new(&mut cr).clamp_range(0.0..=f32::INFINITY));
*self = Rounding::same(cr);
})
.response
Expand All @@ -2222,19 +2236,19 @@ impl Widget for &mut Rounding {

crate::Grid::new("rounding").num_columns(2).show(ui, |ui| {
ui.label("NW");
ui.add(DragValue::new(&mut self.nw).range(0.0..=f32::INFINITY));
ui.add(DragValue::new(&mut self.nw).clamp_range(0.0..=f32::INFINITY));
ui.end_row();

ui.label("NE");
ui.add(DragValue::new(&mut self.ne).range(0.0..=f32::INFINITY));
ui.add(DragValue::new(&mut self.ne).clamp_range(0.0..=f32::INFINITY));
ui.end_row();

ui.label("SW");
ui.add(DragValue::new(&mut self.sw).range(0.0..=f32::INFINITY));
ui.add(DragValue::new(&mut self.sw).clamp_range(0.0..=f32::INFINITY));
ui.end_row();

ui.label("SE");
ui.add(DragValue::new(&mut self.se).range(0.0..=f32::INFINITY));
ui.add(DragValue::new(&mut self.se).clamp_range(0.0..=f32::INFINITY));
ui.end_row();
});
})
Expand Down Expand Up @@ -2266,28 +2280,28 @@ impl Widget for &mut Shadow {
ui.add(
DragValue::new(&mut offset.x)
.speed(1.0)
.range(-100.0..=100.0)
.clamp_range(-100.0..=100.0)
.prefix("x: "),
);
ui.add(
DragValue::new(&mut offset.y)
.speed(1.0)
.range(-100.0..=100.0)
.clamp_range(-100.0..=100.0)
.prefix("y: "),
);
ui.end_row();

ui.add(
DragValue::new(blur)
.speed(1.0)
.range(0.0..=100.0)
.clamp_range(0.0..=100.0)
.prefix("blur: "),
);

ui.add(
DragValue::new(spread)
.speed(1.0)
.range(0.0..=100.0)
.clamp_range(0.0..=100.0)
.prefix("spread: "),
);
});
Expand All @@ -2302,8 +2316,12 @@ impl Widget for &mut Stroke {
let Stroke { width, color } = self;

ui.horizontal(|ui| {
ui.add(DragValue::new(width).speed(0.1).range(0.0..=f32::INFINITY))
.on_hover_text("Width");
ui.add(
DragValue::new(width)
.speed(0.1)
.clamp_range(0.0..=f32::INFINITY),
)
.on_hover_text("Width");
ui.color_edit_button_srgba(color);

// stroke preview:
Expand Down

0 comments on commit 64996d4

Please sign in to comment.