mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Small refinements
This commit is contained in:
@@ -617,10 +617,7 @@ impl Focus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccessKit names the widget by the node id it read from the last tree we sent, so the
|
// Handle accesskit focus requests
|
||||||
// widget has been here before and is in the cache. Handing the focus out here, instead of
|
|
||||||
// waiting for the widget to ask for it, means everything that reads the focus before the
|
|
||||||
// widget runs — styling it, for one — already sees the new focus.
|
|
||||||
let newly_focused = focus_requested_by_accesskit.and_then(|node_id| {
|
let newly_focused = focus_requested_by_accesskit.and_then(|node_id| {
|
||||||
self.focus_widgets_cache
|
self.focus_widgets_cache
|
||||||
.keys()
|
.keys()
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::{
|
|||||||
Frame, TextStyle,
|
Frame, TextStyle,
|
||||||
theme::StyleProvider,
|
theme::StyleProvider,
|
||||||
widget_style::{
|
widget_style::{
|
||||||
BaseStyle, ButtonStyle, CheckboxStyle, HasClasses as _, LabelStyle, LayoutStyle,
|
BaseStyle, ButtonStyle, CheckboxStyle, HasClasses as _, LabelStyle, AtomLayoutStyle,
|
||||||
READ_ONLY_CLASS, SELECTED_CLASS, SeparatorStyle, StyleArgs, TextEditStyle, TextVisuals,
|
READ_ONLY_CLASS, SELECTED_CLASS, SeparatorStyle, StyleArgs, TextEditStyle, TextVisuals,
|
||||||
WidgetState,
|
WidgetState,
|
||||||
},
|
},
|
||||||
@@ -88,7 +88,7 @@ impl StyleProvider<ButtonStyle> for DefaultStyle {
|
|||||||
.into(),
|
.into(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
layout: LayoutStyle {
|
layout: AtomLayoutStyle {
|
||||||
min_size: Vec2::new(0.0, spacing.interact_size.y),
|
min_size: Vec2::new(0.0, spacing.interact_size.y),
|
||||||
gap: spacing.icon_spacing,
|
gap: spacing.icon_spacing,
|
||||||
},
|
},
|
||||||
@@ -146,7 +146,7 @@ impl StyleProvider<TextEditStyle> for DefaultStyle {
|
|||||||
outer_margin: Margin::same(-(widget_visuals.expansion as i8)),
|
outer_margin: Margin::same(-(widget_visuals.expansion as i8)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
layout: LayoutStyle {
|
layout: AtomLayoutStyle {
|
||||||
// A text edit sizes itself from the rows it holds; egui's own theme adds no floor
|
// A text edit sizes itself from the rows it holds; egui's own theme adds no floor
|
||||||
// of its own.
|
// of its own.
|
||||||
min_size: Vec2::ZERO,
|
min_size: Vec2::ZERO,
|
||||||
|
|||||||
@@ -36,17 +36,14 @@ pub struct TextVisuals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TextVisuals {
|
impl TextVisuals {
|
||||||
/// The undecorated body text of a [`Style`], as a starting point for a widget's own text.
|
/// Resolves the provided [`TextStyle`], unless `style.override_font_id` is set.
|
||||||
///
|
pub fn from_style(style: &Style, text_style: TextStyle) -> Self {
|
||||||
/// The color is the style's ordinary text color; a widget that paints its text in a color of
|
|
||||||
/// its own overrides it.
|
|
||||||
pub fn from_style(style: &Style) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
color: style.visuals.text_color(),
|
color: style.visuals.text_color(),
|
||||||
font_id: style
|
font_id: style
|
||||||
.override_font_id
|
.override_font_id
|
||||||
.clone()
|
.clone()
|
||||||
.unwrap_or_else(|| TextStyle::Body.resolve(style)),
|
.unwrap_or_else(|| text_style.resolve(style)),
|
||||||
underline: Stroke::NONE,
|
underline: Stroke::NONE,
|
||||||
strikethrough: Stroke::NONE,
|
strikethrough: Stroke::NONE,
|
||||||
}
|
}
|
||||||
@@ -71,7 +68,7 @@ impl WidgetStyle for BaseStyle {}
|
|||||||
/// button are one look, not two — so they travel as one struct, shared by every widget style that
|
/// button are one look, not two — so they travel as one struct, shared by every widget style that
|
||||||
/// lays its contents out with an [`crate::AtomLayout`].
|
/// lays its contents out with an [`crate::AtomLayout`].
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct LayoutStyle {
|
pub struct AtomLayoutStyle {
|
||||||
/// How small the widget may get, before its contents are taken into account.
|
/// How small the widget may get, before its contents are taken into account.
|
||||||
///
|
///
|
||||||
/// A floor, not a size: a widget is never smaller than what it holds.
|
/// A floor, not a size: a widget is never smaller than what it holds.
|
||||||
@@ -88,10 +85,10 @@ pub struct ButtonStyle {
|
|||||||
|
|
||||||
/// How the button's contents are laid out.
|
/// How the button's contents are laid out.
|
||||||
///
|
///
|
||||||
/// [`LayoutStyle::min_size`] is ignored by a [`crate::Button::small`] button, which sizes
|
/// [`AtomLayoutStyle::min_size`] is ignored by a [`crate::Button::small`] button, which sizes
|
||||||
/// itself purely from its contents and its own [`crate::Button::min_size`];
|
/// itself purely from its contents and its own [`crate::Button::min_size`];
|
||||||
/// [`LayoutStyle::gap`] is overridden by [`crate::Button::gap`].
|
/// [`AtomLayoutStyle::gap`] is overridden by [`crate::Button::gap`].
|
||||||
pub layout: LayoutStyle,
|
pub layout: AtomLayoutStyle,
|
||||||
|
|
||||||
pub text_style: TextVisuals,
|
pub text_style: TextVisuals,
|
||||||
}
|
}
|
||||||
@@ -106,10 +103,10 @@ pub struct TextEditStyle {
|
|||||||
|
|
||||||
/// How the field's contents are laid out.
|
/// How the field's contents are laid out.
|
||||||
///
|
///
|
||||||
/// [`LayoutStyle::min_size`] is raised by [`crate::TextEdit::min_size`] and by the rows of
|
/// [`AtomLayoutStyle::min_size`] is raised by [`crate::TextEdit::min_size`] and by the rows of
|
||||||
/// text the field holds, so it only ever sets a floor; [`LayoutStyle::gap`] separates the
|
/// text the field holds, so it only ever sets a floor; [`AtomLayoutStyle::gap`] separates the
|
||||||
/// text from a [`crate::TextEdit::prefix`] or [`crate::TextEdit::suffix`].
|
/// text from a [`crate::TextEdit::prefix`] or [`crate::TextEdit::suffix`].
|
||||||
pub layout: LayoutStyle,
|
pub layout: AtomLayoutStyle,
|
||||||
|
|
||||||
/// The text being edited.
|
/// The text being edited.
|
||||||
pub text: TextVisuals,
|
pub text: TextVisuals,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crate::{
|
|||||||
Atom, AtomExt as _, AtomKind, AtomLayout, AtomLayoutResponse, Atoms, Color32, CornerRadius,
|
Atom, AtomExt as _, AtomKind, AtomLayout, AtomLayoutResponse, Atoms, Color32, CornerRadius,
|
||||||
Frame, Image, IntoAtoms, Response, Sense, Stroke, TextStyle, TextWrapMode, Ui, Vec2, Widget,
|
Frame, Image, IntoAtoms, Response, Sense, Stroke, TextStyle, TextWrapMode, Ui, Vec2, Widget,
|
||||||
WidgetInfo, WidgetText, WidgetType,
|
WidgetInfo, WidgetText, WidgetType,
|
||||||
widget_style::{ButtonStyle, Classes, HasClasses, LayoutStyle, SELECTED_CLASS, WidgetState},
|
widget_style::{ButtonStyle, Classes, HasClasses, AtomLayoutStyle, SELECTED_CLASS, WidgetState},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Clickable button with text.
|
/// Clickable button with text.
|
||||||
@@ -331,7 +331,7 @@ impl<'a> Button<'a> {
|
|||||||
let ButtonStyle {
|
let ButtonStyle {
|
||||||
frame,
|
frame,
|
||||||
layout:
|
layout:
|
||||||
LayoutStyle {
|
AtomLayoutStyle {
|
||||||
min_size: style_min_size,
|
min_size: style_min_size,
|
||||||
gap,
|
gap,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use crate::{
|
|||||||
self, CCursorRange, text_cursor_state::cursor_rect, visuals::paint_text_selection,
|
self, CCursorRange, text_cursor_state::cursor_rect, visuals::paint_text_selection,
|
||||||
},
|
},
|
||||||
vec2,
|
vec2,
|
||||||
widget_style::{Classes, HasClasses, LayoutStyle, READ_ONLY_CLASS, TextEditStyle},
|
widget_style::{Classes, HasClasses, AtomLayoutStyle, READ_ONLY_CLASS, TextEditStyle},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{TextEditOutput, TextEditState};
|
use super::{TextEditOutput, TextEditState};
|
||||||
@@ -490,7 +490,7 @@ impl TextEdit<'_> {
|
|||||||
let TextEditStyle {
|
let TextEditStyle {
|
||||||
frame: styled_frame,
|
frame: styled_frame,
|
||||||
layout:
|
layout:
|
||||||
LayoutStyle {
|
AtomLayoutStyle {
|
||||||
min_size: style_min_size,
|
min_size: style_min_size,
|
||||||
gap,
|
gap,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
use eframe::egui::{
|
use eframe::egui::{
|
||||||
self, CentralPanel, Color32, Frame, Panel,
|
self, CentralPanel, Color32, Frame, Panel,
|
||||||
theme::StyleProvider,
|
theme::StyleProvider,
|
||||||
widget_style::{BaseStyle, ButtonStyle, HasClasses as _, LayoutStyle, StyleArgs, WidgetState},
|
widget_style::{BaseStyle, ButtonStyle, HasClasses as _, AtomLayoutStyle, StyleArgs, WidgetState},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Buttons with this class are styled as a destructive action.
|
/// Buttons with this class are styled as a destructive action.
|
||||||
@@ -67,7 +67,7 @@ impl StyleProvider<ButtonStyle> for MyTheme {
|
|||||||
.fill(fill)
|
.fill(fill)
|
||||||
.corner_radius(self.corner_radius)
|
.corner_radius(self.corner_radius)
|
||||||
.inner_margin(8),
|
.inner_margin(8),
|
||||||
layout: LayoutStyle {
|
layout: AtomLayoutStyle {
|
||||||
min_size: args.style.spacing.interact_size,
|
min_size: args.style.spacing.interact_size,
|
||||||
gap: args.style.spacing.icon_spacing,
|
gap: args.style.spacing.icon_spacing,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user