Skip to content

Commit 778bcc1

Browse files
authored
Style tweaks (#450)
* Tweak style More compact, less round, less noisy * Button text is now same size as body text * The rounder corners are now less rounded * Collapsing headers no longer have a frame around them * Combo-boxes looks better when opened * Slightly more muted colors * Remove extra line spacing after `\n` (i.e. between paragraphs) * Thinner scrollbars * Tweak light mode * Tweak shadows * Fix broken doc link * Add style tweak to CHANGELOG
1 parent a50ddc2 commit 778bcc1

18 files changed

+367
-168
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ NOTE: [`eframe`](eframe/CHANGELOG.md), [`egui_web`](egui_web/CHANGELOG.md) and [
2424
* Add `ScrollArea::enable_scrolling` to allow freezing scrolling when editing TextEdit widgets within it
2525

2626
### Changed 🔧
27+
* [Tweaked the default visuals style](https://github.com/emilk/egui/pull/450).
2728
* Plot: Changed `Curve` to `Line`.
2829
* `TopPanel::top` is now `TopBottomPanel::top`.
2930
* `SidePanel::left` no longet takes the default width by argument, but by a builder call.

egui/src/containers/collapsing_header.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,16 @@ impl CollapsingHeader {
246246

247247
let visuals = ui.style().interact(&header_response);
248248
let text_color = visuals.text_color();
249-
ui.painter().add(Shape::Rect {
250-
rect: header_response.rect.expand(visuals.expansion),
251-
corner_radius: visuals.corner_radius,
252-
fill: visuals.bg_fill,
253-
stroke: visuals.bg_stroke,
254-
// stroke: Default::default(),
255-
});
249+
250+
if ui.visuals().collapsing_header_frame {
251+
ui.painter().add(Shape::Rect {
252+
rect: header_response.rect.expand(visuals.expansion),
253+
corner_radius: visuals.corner_radius,
254+
fill: visuals.bg_fill,
255+
stroke: visuals.bg_stroke,
256+
// stroke: Default::default(),
257+
});
258+
}
256259

257260
{
258261
let (mut icon_rect, _) = ui.spacing().icon_rectangles(header_response.rect);

egui/src/containers/combo_box.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ fn combo_box(
176176
) -> Response {
177177
let popup_id = button_id.with("popup");
178178

179-
let button_active = ui.memory().is_popup_open(popup_id);
180-
let button_response = button_frame(ui, button_id, button_active, Sense::click(), |ui| {
179+
let is_popup_open = ui.memory().is_popup_open(popup_id);
180+
let button_response = button_frame(ui, button_id, is_popup_open, Sense::click(), |ui| {
181181
// We don't want to change width when user selects something new
182182
let full_minimum_width = ui.spacing().slider_width;
183183
let icon_size = Vec2::splat(ui.spacing().icon_width);
@@ -193,10 +193,14 @@ fn combo_box(
193193
let (_, rect) = ui.allocate_space(Vec2::new(width, height));
194194
let button_rect = ui.min_rect().expand2(ui.spacing().button_padding);
195195
let response = ui.interact(button_rect, button_id, Sense::click());
196-
// response.active |= button_active;
196+
// response.active |= is_popup_open;
197197

198198
let icon_rect = Align2::RIGHT_CENTER.align_size_within_rect(icon_size, rect);
199-
let visuals = ui.style().interact(&response);
199+
let visuals = if is_popup_open {
200+
&ui.visuals().widgets.open
201+
} else {
202+
ui.style().interact(&response)
203+
};
200204
paint_icon(ui.painter(), icon_rect.expand(visuals.expansion), visuals);
201205

202206
let text_rect = Align2::LEFT_CENTER.align_size_within_rect(galley.size, rect);
@@ -207,9 +211,8 @@ fn combo_box(
207211
if button_response.clicked() {
208212
ui.memory().toggle_popup(popup_id);
209213
}
210-
const MAX_COMBO_HEIGHT: f32 = 128.0;
211214
crate::popup::popup_below_widget(ui, popup_id, &button_response, |ui| {
212-
ScrollArea::from_max_height(MAX_COMBO_HEIGHT).show(ui, menu_contents)
215+
ScrollArea::from_max_height(ui.spacing().combo_height).show(ui, menu_contents)
213216
});
214217

215218
button_response
@@ -218,7 +221,7 @@ fn combo_box(
218221
fn button_frame(
219222
ui: &mut Ui,
220223
id: Id,
221-
button_active: bool,
224+
is_popup_open: bool,
222225
sense: Sense,
223226
add_contents: impl FnOnce(&mut Ui),
224227
) -> Response {
@@ -237,9 +240,12 @@ fn button_frame(
237240
let mut outer_rect = content_ui.min_rect().expand2(margin);
238241
outer_rect.set_height(outer_rect.height().at_least(interact_size.y));
239242

240-
let mut response = ui.interact(outer_rect, id, sense);
241-
response.is_pointer_button_down_on |= button_active;
242-
let visuals = ui.style().interact(&response);
243+
let response = ui.interact(outer_rect, id, sense);
244+
let visuals = if is_popup_open {
245+
&ui.visuals().widgets.open
246+
} else {
247+
ui.style().interact(&response)
248+
};
243249

244250
ui.painter().set(
245251
where_to_put_background,

egui/src/containers/frame.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ impl Frame {
2424
pub fn group(style: &Style) -> Self {
2525
Self {
2626
margin: Vec2::new(8.0, 6.0),
27-
corner_radius: 4.0,
28-
stroke: style.visuals.window_stroke(),
27+
corner_radius: style.visuals.widgets.noninteractive.corner_radius,
28+
stroke: style.visuals.widgets.noninteractive.bg_stroke,
2929
..Default::default()
3030
}
3131
}
@@ -63,8 +63,8 @@ impl Frame {
6363
pub fn menu(style: &Style) -> Self {
6464
Self {
6565
margin: Vec2::splat(1.0),
66-
corner_radius: 2.0,
67-
shadow: Shadow::small(),
66+
corner_radius: style.visuals.widgets.noninteractive.corner_radius,
67+
shadow: style.visuals.popup_shadow,
6868
fill: style.visuals.window_fill(),
6969
stroke: style.visuals.window_stroke(),
7070
}
@@ -73,8 +73,8 @@ impl Frame {
7373
pub fn popup(style: &Style) -> Self {
7474
Self {
7575
margin: style.spacing.window_padding,
76-
corner_radius: 5.0,
77-
shadow: Shadow::small(),
76+
corner_radius: style.visuals.widgets.noninteractive.corner_radius,
77+
shadow: style.visuals.popup_shadow,
7878
fill: style.visuals.window_fill(),
7979
stroke: style.visuals.window_stroke(),
8080
}
@@ -84,7 +84,7 @@ impl Frame {
8484
pub fn dark_canvas(style: &Style) -> Self {
8585
Self {
8686
margin: Vec2::new(10.0, 10.0),
87-
corner_radius: 5.0,
87+
corner_radius: style.visuals.widgets.noninteractive.corner_radius,
8888
fill: Color32::from_black_alpha(250),
8989
stroke: style.visuals.window_stroke(),
9090
..Default::default()

egui/src/containers/scroll_area.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ impl Prepared {
357357
let margin = animation_t * ui.spacing().item_spacing.x;
358358
let left = inner_rect.right() + margin;
359359
let right = outer_rect.right();
360-
let corner_radius = (right - left) / 2.0;
361360
let top = inner_rect.top();
362361
let bottom = inner_rect.bottom();
363362

@@ -415,7 +414,7 @@ impl Prepared {
415414
pos2(left, from_content(state.offset.y)),
416415
pos2(right, from_content(state.offset.y + inner_rect.height())),
417416
);
418-
let min_handle_height = (2.0 * corner_radius).max(8.0);
417+
let min_handle_height = ui.spacing().scroll_bar_width;
419418
if handle_rect.size().y < min_handle_height {
420419
handle_rect = Rect::from_center_size(
421420
handle_rect.center(),
@@ -429,21 +428,17 @@ impl Prepared {
429428
&ui.style().visuals.widgets.inactive
430429
};
431430

432-
ui.painter().add(epaint::Shape::Rect {
433-
rect: outer_scroll_rect,
434-
corner_radius,
435-
fill: ui.visuals().extreme_bg_color,
436-
stroke: Default::default(),
437-
// fill: visuals.bg_fill,
438-
// stroke: visuals.bg_stroke,
439-
});
440-
441-
ui.painter().add(epaint::Shape::Rect {
442-
rect: handle_rect.expand(-2.0),
443-
corner_radius,
444-
fill: visuals.bg_fill,
445-
stroke: visuals.bg_stroke,
446-
});
431+
ui.painter().add(epaint::Shape::rect_filled(
432+
outer_scroll_rect,
433+
visuals.corner_radius,
434+
ui.visuals().extreme_bg_color,
435+
));
436+
437+
ui.painter().add(epaint::Shape::rect_filled(
438+
handle_rect,
439+
visuals.corner_radius,
440+
visuals.bg_fill,
441+
));
447442
}
448443

449444
let size = vec2(
@@ -465,5 +460,5 @@ impl Prepared {
465460
}
466461

467462
fn max_scroll_bar_width_with_margin(ui: &Ui) -> f32 {
468-
ui.spacing().item_spacing.x + 16.0
463+
ui.spacing().item_spacing.x + ui.spacing().scroll_bar_width
469464
}

egui/src/grid.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,7 @@ impl GridLayout {
198198
let rect = rect.expand2(0.5 * self.spacing.y * Vec2::Y);
199199
let rect = rect.expand2(2.0 * Vec2::X); // HACK: just looks better with some spacing on the sides
200200

201-
let color = if self.style.visuals.dark_mode {
202-
Rgba::from_white_alpha(0.0075)
203-
} else {
204-
Rgba::from_black_alpha(0.075)
205-
};
206-
painter.rect_filled(rect, 2.0, color);
201+
painter.rect_filled(rect, 2.0, self.style.visuals.faint_bg_color);
207202
}
208203
}
209204
}

egui/src/introspection.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,17 @@ impl Widget for &mut epaint::TessellationOptions {
132132
debug_paint_text_rects,
133133
debug_ignore_clip_rects,
134134
} = self;
135-
ui.checkbox(anti_alias, "Antialias");
136-
ui.checkbox(
137-
coarse_tessellation_culling,
138-
"Do coarse culling in the tessellator",
139-
);
140-
ui.checkbox(debug_ignore_clip_rects, "Ignore clip rectangles (debug)");
141-
ui.checkbox(debug_paint_clip_rects, "Paint clip rectangles (debug)");
142-
ui.checkbox(debug_paint_text_rects, "Paint text bounds (debug)");
135+
ui.checkbox(anti_alias, "Antialias")
136+
.on_hover_text("Turn off for small performance gain.");
137+
ui.collapsing("debug", |ui| {
138+
ui.checkbox(
139+
coarse_tessellation_culling,
140+
"Do coarse culling in the tessellator)",
141+
);
142+
ui.checkbox(debug_ignore_clip_rects, "Ignore clip rectangles");
143+
ui.checkbox(debug_paint_clip_rects, "Paint clip rectangles");
144+
ui.checkbox(debug_paint_text_rects, "Paint text bounds");
145+
});
143146
})
144147
.response
145148
}

egui/src/menu.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ fn menu_impl<'c>(ui: &mut Ui, title: impl ToString, add_contents: Box<dyn FnOnce
7575
let mut button = Button::new(title);
7676

7777
if bar_state.open_menu == Some(menu_id) {
78-
button = button.fill(Some(ui.visuals().selection.bg_fill));
78+
button = button.fill(ui.visuals().widgets.open.bg_fill);
79+
button = button.stroke(ui.visuals().widgets.open.bg_stroke);
7980
}
8081

8182
let button_response = ui.add(button);

0 commit comments

Comments
 (0)