mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Simplify and unify colors of selectable widgets
This commit is contained in:
@@ -39,6 +39,16 @@ impl Style {
|
||||
self.visuals.widgets.style(response)
|
||||
}
|
||||
|
||||
pub fn interact_selectable(&self, response: &Response, selected: bool) -> WidgetVisuals {
|
||||
let mut visuals = *self.visuals.widgets.style(response);
|
||||
if selected {
|
||||
visuals.bg_fill = self.visuals.selection.bg_fill;
|
||||
// visuals.bg_stroke = self.visuals.selection.stroke;
|
||||
visuals.fg_stroke = self.visuals.selection.stroke;
|
||||
}
|
||||
visuals
|
||||
}
|
||||
|
||||
/// Style to use for non-interactive widgets.
|
||||
pub fn noninteractive(&self) -> &WidgetVisuals {
|
||||
&self.visuals.widgets.noninteractive
|
||||
@@ -357,17 +367,14 @@ impl Default for Visuals {
|
||||
impl Selection {
|
||||
fn dark() -> Self {
|
||||
Self {
|
||||
bg_fill: Rgba::from_rgb(0.0, 0.5, 1.0)
|
||||
.additive()
|
||||
.multiply(0.10)
|
||||
.into(),
|
||||
stroke: Stroke::new(1.0, Rgba::from_rgb(0.3, 0.6, 1.0)),
|
||||
bg_fill: Color32::from_rgb(0, 92, 128),
|
||||
stroke: Stroke::new(1.0, Color32::from_rgb(192, 222, 255)),
|
||||
}
|
||||
}
|
||||
fn light() -> Self {
|
||||
Self {
|
||||
bg_fill: Rgba::from_rgb(0.0, 0.5, 1.0).multiply(0.5).into(),
|
||||
stroke: Stroke::new(1.0, Rgba::from_rgb(0.3, 0.6, 1.0)),
|
||||
bg_fill: Color32::from_rgb(144, 209, 255),
|
||||
stroke: Stroke::new(1.0, Color32::from_rgb(0, 83, 125)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,6 +212,7 @@ impl<'a> Widget for Checkbox<'a> {
|
||||
*checked = !*checked;
|
||||
}
|
||||
|
||||
// let visuals = ui.style().interact_selectable(&response, *checked); // too colorful
|
||||
let visuals = ui.style().interact(&response);
|
||||
let text_cursor = pos2(
|
||||
rect.min.x + button_padding.x + icon_width + icon_spacing,
|
||||
@@ -234,7 +235,6 @@ impl<'a> Widget for Checkbox<'a> {
|
||||
pos2(small_icon_rect.right(), small_icon_rect.top()),
|
||||
],
|
||||
visuals.fg_stroke,
|
||||
// ui.visuals().selection.stroke, // too much color
|
||||
));
|
||||
}
|
||||
|
||||
@@ -305,6 +305,7 @@ impl Widget for RadioButton {
|
||||
rect.center().y - 0.5 * galley.size.y,
|
||||
);
|
||||
|
||||
// let visuals = ui.style().interact_selectable(&response, checked); // too colorful
|
||||
let visuals = ui.style().interact(&response);
|
||||
|
||||
let (small_icon_rect, big_icon_rect) = ui.spacing().icon_rectangles(rect);
|
||||
|
||||
@@ -44,25 +44,14 @@ impl Widget for SelectableLabel {
|
||||
.align_size_within_rect(galley.size, rect.shrink2(button_padding))
|
||||
.min;
|
||||
|
||||
let visuals = ui.style().interact(&response);
|
||||
let visuals = ui.style().interact_selectable(&response, selected);
|
||||
|
||||
if selected || response.hovered() {
|
||||
let rect = rect.expand(visuals.expansion);
|
||||
|
||||
let fill = if selected {
|
||||
ui.visuals().selection.bg_fill
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
|
||||
let stroke = if selected {
|
||||
ui.visuals().selection.stroke
|
||||
} else {
|
||||
visuals.bg_stroke
|
||||
};
|
||||
|
||||
let corner_radius = 2.0;
|
||||
ui.painter().rect(rect, corner_radius, fill, stroke);
|
||||
ui.painter()
|
||||
.rect(rect, corner_radius, visuals.bg_fill, visuals.bg_stroke);
|
||||
}
|
||||
|
||||
let text_color = ui
|
||||
|
||||
Reference in New Issue
Block a user