mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
fix: Smallvec, const string select
This commit is contained in:
@@ -140,7 +140,7 @@ impl Ui {
|
||||
let disabled = disabled || invisible;
|
||||
let style = style.unwrap_or_else(|| ctx.global_style());
|
||||
let sense = sense.unwrap_or_else(Sense::hover);
|
||||
let classes = classes.unwrap_or_default().with_class(ROOT_CLASS);
|
||||
let classes = classes.with_class(ROOT_CLASS);
|
||||
|
||||
let placer = Placer::new(max_rect, layout);
|
||||
let ui_stack = UiStack {
|
||||
@@ -284,7 +284,6 @@ impl Ui {
|
||||
let sizing_pass = self.sizing_pass || sizing_pass;
|
||||
let style = style.unwrap_or_else(|| Arc::clone(&self.style));
|
||||
let sense = sense.unwrap_or_else(Sense::hover);
|
||||
let classes = classes.unwrap_or_default();
|
||||
|
||||
if sizing_pass {
|
||||
// During the sizing pass we want widgets to use up as little space as possible,
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::{hash::Hash, sync::Arc};
|
||||
|
||||
#[expect(unused_imports)] // Used for doclinks
|
||||
use crate::Ui;
|
||||
use crate::widget_style::HasClasses;
|
||||
use crate::{ClosableTag, widget_style::Classes};
|
||||
use crate::{Id, LayerId, Layout, Rect, Sense, Style, UiStackInfo};
|
||||
|
||||
@@ -25,7 +26,7 @@ pub struct UiBuilder {
|
||||
pub style: Option<Arc<Style>>,
|
||||
pub sense: Option<Sense>,
|
||||
pub accessibility_parent: Option<Id>,
|
||||
pub classes: Option<Classes>,
|
||||
pub classes: Classes,
|
||||
}
|
||||
|
||||
impl UiBuilder {
|
||||
@@ -192,11 +193,14 @@ impl UiBuilder {
|
||||
self.accessibility_parent = Some(parent_id);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Set classes for this [`Ui`].
|
||||
#[inline]
|
||||
pub fn classes(mut self, classes: Classes) -> Self {
|
||||
self.classes = Some(classes);
|
||||
self
|
||||
impl HasClasses for UiBuilder {
|
||||
fn classes(&self) -> &Classes {
|
||||
&self.classes
|
||||
}
|
||||
|
||||
fn classes_mut(&mut self) -> &mut Classes {
|
||||
&mut self.classes
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ impl UiTags {
|
||||
/// Note: since [`UiStack`] contains a reference to its parent, it is both a stack, and a node within
|
||||
/// that stack. Most of its methods are about the specific node, but some methods walk up the
|
||||
/// hierarchy to provide information about the entire stack.
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug)]
|
||||
pub struct UiStack {
|
||||
// stuff that `Ui::child_ui` can deal with directly
|
||||
pub id: Id,
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::{borrow::Cow, fmt};
|
||||
|
||||
use emath::Vec2;
|
||||
use epaint::{Color32, FontId, Shadow, Stroke, text::TextWrapMode};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use crate::{
|
||||
Frame, Response, Style, TextBuffer as _, TextStyle,
|
||||
@@ -219,13 +220,14 @@ impl Style {
|
||||
|
||||
/// The root class is present on every top-level ui
|
||||
pub const ROOT_CLASS: &str = "root";
|
||||
pub const SELECTED_CLASS: &str = "selected";
|
||||
|
||||
pub type ClassName = Cow<'static, str>;
|
||||
|
||||
/// The classes assigned to a widget
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Classes {
|
||||
classes: Vec<ClassName>,
|
||||
classes: SmallVec<[ClassName; 5]>,
|
||||
}
|
||||
|
||||
impl Classes {
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::{
|
||||
Atom, AtomExt as _, AtomKind, AtomLayout, AtomLayoutResponse, Color32, CornerRadius, Frame,
|
||||
Image, IntoAtoms, NumExt as _, Response, Sense, Stroke, TextStyle, TextWrapMode, Ui, Vec2,
|
||||
Widget, WidgetInfo, WidgetText, WidgetType,
|
||||
widget_style::{ButtonStyle, Classes, HasClasses, WidgetState},
|
||||
widget_style::{ButtonStyle, Classes, HasClasses, SELECTED_CLASS, WidgetState},
|
||||
};
|
||||
|
||||
/// Clickable button with text.
|
||||
@@ -308,7 +308,7 @@ impl<'a> Button<'a> {
|
||||
let response: Option<Response> = ui.ctx().read_response(id);
|
||||
let state = response.map(|r| r.widget_state()).unwrap_or_default();
|
||||
|
||||
classes.add_class_if("selected", selected);
|
||||
classes.add_class_if(SELECTED_CLASS, selected);
|
||||
|
||||
let ButtonStyle { frame, text_style } = ui.style().button_style(&classes, state);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user