Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unhovered style, For TextEdit used bg_stroke in unhovered. #4120

Closed
wants to merge 12 commits into from
39 changes: 36 additions & 3 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ pub struct Spacing {
/// Default width of a [`Slider`].
pub slider_width: f32,

/// Default rail height of a [`Slider`].
pub slider_rail_height: f32,

/// Default (minimum) width of a [`ComboBox`](crate::ComboBox).
pub combo_width: f32,

Expand Down Expand Up @@ -1051,6 +1054,9 @@ pub struct Widgets {
/// The style of an interactive widget, such as a button, at rest.
pub inactive: WidgetVisuals,

/// The style of a unhovered widget.
pub unhovered: WidgetVisuals,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what inactive means.


/// The style of an interactive widget while you hover it, or when it is highlighted.
///
/// See [`Response::hovered`], [`Response::highlighted`] and [`Response::highlight`].
Expand Down Expand Up @@ -1224,6 +1230,7 @@ impl Default for Spacing {
indent: 18.0, // match checkbox/radio-button with `button_padding.x + icon_width + icon_spacing`
interact_size: vec2(40.0, 18.0),
slider_width: 100.0,
slider_rail_height: 9.6,
combo_width: 100.0,
text_edit_width: 280.0,
icon_width: 14.0,
Expand Down Expand Up @@ -1372,6 +1379,14 @@ impl Widgets {
rounding: Rounding::same(2.0),
expansion: 0.0,
},
unhovered: WidgetVisuals {
weak_bg_fill: Color32::from_gray(27),
bg_fill: Color32::from_gray(27),
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)),
fg_stroke: Stroke::new(1.0, Color32::from_gray(140)),
rounding: Rounding::same(2.0),
expansion: 0.0,
},
hovered: WidgetVisuals {
weak_bg_fill: Color32::from_gray(70),
bg_fill: Color32::from_gray(70),
Expand Down Expand Up @@ -1417,6 +1432,14 @@ impl Widgets {
rounding: Rounding::same(2.0),
expansion: 0.0,
},
unhovered: WidgetVisuals {
weak_bg_fill: Color32::from_gray(248),
bg_fill: Color32::from_gray(248),
bg_stroke: Stroke::new(1.0, Color32::from_gray(190)),
fg_stroke: Stroke::new(1.0, Color32::from_gray(80)),
rounding: Rounding::same(2.0),
expansion: 0.0,
},
hovered: WidgetVisuals {
weak_bg_fill: Color32::from_gray(220),
bg_fill: Color32::from_gray(220),
Expand Down Expand Up @@ -1573,6 +1596,7 @@ impl Spacing {
indent,
interact_size,
slider_width,
slider_rail_height,
combo_width,
text_edit_width,
icon_width,
Expand Down Expand Up @@ -1601,6 +1625,10 @@ impl Spacing {
ui.add(DragValue::new(slider_width).clamp_range(0.0..=1000.0));
ui.label("Slider width");
});
ui.horizontal(|ui| {
ui.add(DragValue::new(slider_rail_height).clamp_range(0.0..=50.0));
ui.label("Slider rail height");
});
ui.horizontal(|ui| {
ui.add(DragValue::new(combo_width).clamp_range(0.0..=1000.0));
ui.label("ComboBox width");
Expand Down Expand Up @@ -1747,10 +1775,11 @@ impl Interaction {
impl Widgets {
pub fn ui(&mut self, ui: &mut crate::Ui) {
let Self {
active,
hovered,
inactive,
noninteractive,
inactive,
unhovered,
hovered,
active,
open,
} = self;

Expand All @@ -1764,6 +1793,10 @@ impl Widgets {
ui.label("The style of an interactive widget, such as a button, at rest.");
inactive.ui(ui);
});
ui.collapsing("Interactive and unhovered", |ui| {
ui.label("The style of an interactive widget while you unhover it.");
unhovered.ui(ui);
});
ui.collapsing("Interactive and hovered", |ui| {
ui.label("The style of an interactive widget while you hover it.");
hovered.ui(ui);
Expand Down
4 changes: 2 additions & 2 deletions crates/egui/src/widgets/text_edit/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,15 @@ impl<'t> TextEdit<'t> {
frame_rect,
visuals.rounding,
ui.visuals().extreme_bg_color,
visuals.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop".
ui.visuals().widgets.unhovered.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop".
)
}
} else {
let visuals = &ui.style().visuals.widgets.inactive;
epaint::RectShape::stroke(
frame_rect,
visuals.rounding,
visuals.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop".
ui.visuals().widgets.unhovered.bg_stroke, // TODO(emilk): we want to show something here, or a text-edit field doesn't "pop".
)
};

Expand Down
Loading