mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20:04 -04:00
Rename classes, more button options via StyleProvider (#8464)
Moves global classnames to e.g. `egui::class::ROOT`. Widget specific classes live on the widgets struct. Adds some more classes for our buttons styling options (`CLASS_SMALL` etc), so that custom `StyleProvider`s can choose to implement them differently or ignore them altogether. Also removes some styleproviders that were partly or completely unused (e.g. basestyle / labelstyle). We can add them back once we actually implement styling for those. --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,9 +4,10 @@
|
||||
//! based on the _classes_ set on it, and that can be edited live.
|
||||
|
||||
use eframe::egui::{
|
||||
self, CentralPanel, Color32, Frame, Panel,
|
||||
self, CentralPanel, Color32, Frame, Panel, TextStyle,
|
||||
class::HasClasses as _,
|
||||
theme::StyleProvider,
|
||||
widget_style::{BaseStyle, ButtonStyle, HasClasses as _, StyleArgs, WidgetState},
|
||||
widget_style::{ButtonStyle, StyleArgs, TextVisuals, WidgetState},
|
||||
};
|
||||
|
||||
/// Buttons with this class are styled as a destructive action.
|
||||
@@ -42,14 +43,11 @@ impl StyleProvider<ButtonStyle> for MyTheme {
|
||||
let StyleArgs {
|
||||
classes,
|
||||
state,
|
||||
ctx,
|
||||
style,
|
||||
..
|
||||
} = args;
|
||||
|
||||
// Start from the style egui computed for a generic widget, so we inherit e.g. the font:
|
||||
let base: BaseStyle = ctx.get_widget_style(args);
|
||||
|
||||
let fill = if classes.has(DANGER) {
|
||||
let fill = if classes.has_class(DANGER) {
|
||||
self.danger
|
||||
} else {
|
||||
self.normal
|
||||
@@ -63,11 +61,13 @@ impl StyleProvider<ButtonStyle> for MyTheme {
|
||||
};
|
||||
|
||||
ButtonStyle {
|
||||
min_size: egui::vec2(0.0, style.spacing.interact_size.y),
|
||||
frame: Frame::new()
|
||||
.fill(fill)
|
||||
.corner_radius(self.corner_radius)
|
||||
.inner_margin(8),
|
||||
text_style: base.text,
|
||||
// Resolve the font from the style, so we follow the user's font sizes:
|
||||
text_style: TextVisuals::new(style, TextStyle::Button, Color32::WHITE),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user