Skip to content

Commit

Permalink
optional_bg_fill -> weak_bg_fill
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 24, 2023
1 parent 221b7c7 commit ce67d73
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion crates/egui/src/containers/collapsing_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl CollapsingHeader {
ui.painter().add(epaint::RectShape {
rect: header_response.rect.expand(visuals.expansion),
rounding: visuals.rounding,
fill: visuals.optional_bg_fill,
fill: visuals.weak_bg_fill,
stroke: visuals.bg_stroke,
// stroke: Default::default(),
});
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/containers/combo_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ fn button_frame(
epaint::RectShape {
rect: outer_rect.expand(visuals.expansion),
rounding: visuals.rounding,
fill: visuals.optional_bg_fill,
fill: visuals.weak_bg_fill,
stroke: visuals.bg_stroke,
},
);
Expand Down
6 changes: 3 additions & 3 deletions crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn set_menu_style(style: &mut Style) {
style.spacing.button_padding = vec2(2.0, 0.0);
style.visuals.widgets.active.bg_stroke = Stroke::NONE;
style.visuals.widgets.hovered.bg_stroke = Stroke::NONE;
style.visuals.widgets.inactive.optional_bg_fill = Color32::TRANSPARENT;
style.visuals.widgets.inactive.weak_bg_fill = Color32::TRANSPARENT;
style.visuals.widgets.inactive.bg_stroke = Stroke::NONE;
}

Expand Down Expand Up @@ -180,7 +180,7 @@ fn stationary_menu_impl<'c, R>(
let mut button = Button::new(title);

if bar_state.open_menu.is_menu_open(menu_id) {
button = button.fill(ui.visuals().widgets.open.optional_bg_fill);
button = button.fill(ui.visuals().widgets.open.weak_bg_fill);
button = button.stroke(ui.visuals().widgets.open.bg_stroke);
}

Expand Down Expand Up @@ -493,7 +493,7 @@ impl SubMenuButton {
ui.painter().rect_filled(
rect.expand(visuals.expansion),
visuals.rounding,
visuals.optional_bg_fill,
visuals.weak_bg_fill,
);
}

Expand Down
43 changes: 21 additions & 22 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl Style {
pub fn interact_selectable(&self, response: &Response, selected: bool) -> WidgetVisuals {
let mut visuals = *self.visuals.widgets.style(response);
if selected {
visuals.optional_bg_fill = self.visuals.selection.bg_fill;
visuals.weak_bg_fill = self.visuals.selection.bg_fill;
visuals.bg_fill = self.visuals.selection.bg_fill;
// visuals.bg_stroke = self.visuals.selection.stroke;
visuals.fg_stroke = self.visuals.selection.stroke;
Expand Down Expand Up @@ -537,7 +537,7 @@ impl Visuals {
// TODO(emilk): replace with an alpha
#[inline(always)]
pub fn fade_out_to_color(&self) -> Color32 {
self.widgets.noninteractive.optional_bg_fill
self.widgets.noninteractive.weak_bg_fill
}

/// Returned a "grayed out" version of the given color.
Expand Down Expand Up @@ -598,17 +598,16 @@ impl Widgets {
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct WidgetVisuals {
/// Background color of widget that must have a background fill,
/// such as the slider background or a checkbox background.
/// Background color of widgets that must have a background fill,
/// such as the slider background, a checkbox background, or a radio button background.
///
/// Must never be [`Color32::TRANSPARENT`].
pub bg_fill: Color32,

/// Background color of widget that can _optionally_ have a background fill,
/// such as buttons.
/// Background color of widgets that can _optionally_ have a background fill, such as buttons.
///
/// May be [`Color32::TRANSPARENT`].
pub optional_bg_fill: Color32,
pub weak_bg_fill: Color32,

/// For surrounding rectangle of things that need it,
/// like buttons, the box of the checkbox, etc.
Expand Down Expand Up @@ -815,39 +814,39 @@ impl Widgets {
pub fn dark() -> Self {
Self {
noninteractive: WidgetVisuals {
optional_bg_fill: Color32::from_gray(27),
weak_bg_fill: Color32::from_gray(27),
bg_fill: Color32::from_gray(27),
bg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // separators, indentation lines
fg_stroke: Stroke::new(1.0, Color32::from_gray(140)), // normal text color
rounding: Rounding::same(2.0),
expansion: 0.0,
},
inactive: WidgetVisuals {
optional_bg_fill: Color32::from_gray(60), // button background
bg_fill: Color32::from_gray(60), // checkbox background
weak_bg_fill: Color32::from_gray(60), // button background
bg_fill: Color32::from_gray(60), // checkbox background
bg_stroke: Default::default(),
fg_stroke: Stroke::new(1.0, Color32::from_gray(180)), // button text
rounding: Rounding::same(2.0),
expansion: 0.0,
},
hovered: WidgetVisuals {
optional_bg_fill: Color32::from_gray(70),
weak_bg_fill: Color32::from_gray(70),
bg_fill: Color32::from_gray(70),
bg_stroke: Stroke::new(1.0, Color32::from_gray(150)), // e.g. hover over window edge or button
fg_stroke: Stroke::new(1.5, Color32::from_gray(240)),
rounding: Rounding::same(3.0),
expansion: 1.0,
},
active: WidgetVisuals {
optional_bg_fill: Color32::from_gray(55),
weak_bg_fill: Color32::from_gray(55),
bg_fill: Color32::from_gray(55),
bg_stroke: Stroke::new(1.0, Color32::WHITE),
fg_stroke: Stroke::new(2.0, Color32::WHITE),
rounding: Rounding::same(2.0),
expansion: 1.0,
},
open: WidgetVisuals {
optional_bg_fill: Color32::from_gray(27),
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(210)),
Expand All @@ -860,39 +859,39 @@ impl Widgets {
pub fn light() -> Self {
Self {
noninteractive: WidgetVisuals {
optional_bg_fill: Color32::from_gray(248),
weak_bg_fill: Color32::from_gray(248),
bg_fill: Color32::from_gray(248),
bg_stroke: Stroke::new(1.0, Color32::from_gray(190)), // separators, indentation lines
fg_stroke: Stroke::new(1.0, Color32::from_gray(80)), // normal text color
rounding: Rounding::same(2.0),
expansion: 0.0,
},
inactive: WidgetVisuals {
optional_bg_fill: Color32::from_gray(230), // button background
bg_fill: Color32::from_gray(230), // checkbox background
weak_bg_fill: Color32::from_gray(230), // button background
bg_fill: Color32::from_gray(230), // checkbox background
bg_stroke: Default::default(),
fg_stroke: Stroke::new(1.0, Color32::from_gray(60)), // button text
rounding: Rounding::same(2.0),
expansion: 0.0,
},
hovered: WidgetVisuals {
optional_bg_fill: Color32::from_gray(220),
weak_bg_fill: Color32::from_gray(220),
bg_fill: Color32::from_gray(220),
bg_stroke: Stroke::new(1.0, Color32::from_gray(105)), // e.g. hover over window edge or button
fg_stroke: Stroke::new(1.5, Color32::BLACK),
rounding: Rounding::same(3.0),
expansion: 1.0,
},
active: WidgetVisuals {
optional_bg_fill: Color32::from_gray(165),
weak_bg_fill: Color32::from_gray(165),
bg_fill: Color32::from_gray(165),
bg_stroke: Stroke::new(1.0, Color32::BLACK),
fg_stroke: Stroke::new(2.0, Color32::BLACK),
rounding: Rounding::same(2.0),
expansion: 1.0,
},
open: WidgetVisuals {
optional_bg_fill: Color32::from_gray(220),
weak_bg_fill: Color32::from_gray(220),
bg_fill: Color32::from_gray(220),
bg_stroke: Stroke::new(1.0, Color32::from_gray(160)),
fg_stroke: Stroke::new(1.0, Color32::BLACK),
Expand Down Expand Up @@ -1214,14 +1213,14 @@ impl Selection {
impl WidgetVisuals {
pub fn ui(&mut self, ui: &mut crate::Ui) {
let Self {
optional_bg_fill,
weak_bg_fill,
bg_fill: mandatory_bg_fill,
bg_stroke,
rounding,
fg_stroke,
expansion,
} = self;
ui_color(ui, optional_bg_fill, "optional background fill")
ui_color(ui, weak_bg_fill, "optional background fill")
.on_hover_text("For buttons, combo-boxes, etc");
ui_color(ui, mandatory_bg_fill, "mandatory background fill")
.on_hover_text("For checkboxes, sliders, etc");
Expand Down Expand Up @@ -1303,7 +1302,7 @@ impl Visuals {
} = self;

ui.collapsing("Background Colors", |ui| {
ui_color(ui, &mut widgets.inactive.optional_bg_fill, "Buttons");
ui_color(ui, &mut widgets.inactive.weak_bg_fill, "Buttons");
ui_color(ui, window_fill, "Windows");
ui_color(ui, panel_fill, "Panels");
ui_color(ui, faint_bg_color, "Faint accent").on_hover_text(
Expand Down
4 changes: 2 additions & 2 deletions crates/egui/src/widgets/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl Widget for Button {
let visuals = ui.style().interact(&response);

if frame {
let fill = fill.unwrap_or(visuals.optional_bg_fill);
let fill = fill.unwrap_or(visuals.weak_bg_fill);
let stroke = stroke.unwrap_or(visuals.bg_stroke);
let rounding = rounding.unwrap_or(visuals.rounding);
ui.painter()
Expand Down Expand Up @@ -540,7 +540,7 @@ impl Widget for ImageButton {
(
expansion,
visuals.rounding,
visuals.optional_bg_fill,
visuals.weak_bg_fill,
visuals.bg_stroke,
)
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/egui/src/widgets/selected_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Widget for SelectableLabel {
ui.painter().rect(
rect,
visuals.rounding,
visuals.optional_bg_fill,
visuals.weak_bg_fill,
visuals.bg_stroke,
);
}
Expand Down
4 changes: 1 addition & 3 deletions crates/egui_extras/src/datepicker/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ impl<'a> Widget for DatePickerButton<'a> {
}
let mut button = Button::new(text);
if button_state.picker_visible {
button = button
.fill(visuals.optional_bg_fill)
.stroke(visuals.bg_stroke);
button = button.fill(visuals.weak_bg_fill).stroke(visuals.bg_stroke);
}
let mut button_response = ui.add(button);
if button_response.clicked() {
Expand Down

0 comments on commit ce67d73

Please sign in to comment.