mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 07:10:04 -04:00
Make has_class take &str
This commit is contained in:
@@ -38,7 +38,7 @@ impl StyleProvider<ButtonStyle> for DefaultStyle {
|
|||||||
let spacing = &style.spacing;
|
let spacing = &style.spacing;
|
||||||
let mut widget_visuals = *style.visuals.widgets.state(*state);
|
let mut widget_visuals = *style.visuals.widgets.state(*state);
|
||||||
|
|
||||||
if classes.has_class(Button::CLASS_SELECTED) {
|
if classes.has_class(&Button::CLASS_SELECTED) {
|
||||||
let visuals = &style.visuals;
|
let visuals = &style.visuals;
|
||||||
widget_visuals.weak_bg_fill = visuals.selection.bg_fill;
|
widget_visuals.weak_bg_fill = visuals.selection.bg_fill;
|
||||||
widget_visuals.bg_fill = visuals.selection.bg_fill;
|
widget_visuals.bg_fill = visuals.selection.bg_fill;
|
||||||
@@ -48,7 +48,7 @@ impl StyleProvider<ButtonStyle> for DefaultStyle {
|
|||||||
let mut inner_margin: Margin = spacing.button_padding.into();
|
let mut inner_margin: Margin = spacing.button_padding.into();
|
||||||
|
|
||||||
// A small button as high as regular text
|
// A small button as high as regular text
|
||||||
if classes.has_class(Button::CLASS_SMALL) {
|
if classes.has_class(&Button::CLASS_SMALL) {
|
||||||
inner_margin.top = 0;
|
inner_margin.top = 0;
|
||||||
inner_margin.bottom = 0;
|
inner_margin.bottom = 0;
|
||||||
}
|
}
|
||||||
@@ -63,13 +63,13 @@ impl StyleProvider<ButtonStyle> for DefaultStyle {
|
|||||||
// Ensure changing expansion and stroke don't affect layout:
|
// Ensure changing expansion and stroke don't affect layout:
|
||||||
.expand_in_place(widget_visuals.expansion);
|
.expand_in_place(widget_visuals.expansion);
|
||||||
|
|
||||||
let has_frame = classes.has_class(Button::CLASS_FRAME)
|
let has_frame = classes.has_class(&Button::CLASS_FRAME)
|
||||||
|| (!classes.has_class(Button::CLASS_NO_FRAME) && style.visuals.button_frame);
|
|| (!classes.has_class(&Button::CLASS_NO_FRAME) && style.visuals.button_frame);
|
||||||
|
|
||||||
let frame = if !has_frame {
|
let frame = if !has_frame {
|
||||||
// No frame at all: the button takes up no more room than its contents.
|
// No frame at all: the button takes up no more room than its contents.
|
||||||
Frame::new()
|
Frame::new()
|
||||||
} else if classes.has_class(Button::CLASS_HIDE_FRAME_WHEN_INACTIVE)
|
} else if classes.has_class(&Button::CLASS_HIDE_FRAME_WHEN_INACTIVE)
|
||||||
&& *state == WidgetState::Inactive
|
&& *state == WidgetState::Inactive
|
||||||
{
|
{
|
||||||
// Hide the frame, but keep its spacing
|
// Hide the frame, but keep its spacing
|
||||||
@@ -79,7 +79,7 @@ impl StyleProvider<ButtonStyle> for DefaultStyle {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ButtonStyle {
|
ButtonStyle {
|
||||||
min_size: if classes.has_class(Button::CLASS_SMALL) {
|
min_size: if classes.has_class(&Button::CLASS_SMALL) {
|
||||||
Vec2::ZERO
|
Vec2::ZERO
|
||||||
} else {
|
} else {
|
||||||
Vec2::new(0.0, spacing.interact_size.y)
|
Vec2::new(0.0, spacing.interact_size.y)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use core::{any::Any, iter::FusedIterator};
|
use core::{any::Any, iter::FusedIterator};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::widget_style::{ClassName, Classes, HasClasses as _};
|
use crate::widget_style::{Classes, HasClasses as _};
|
||||||
use epaint::Color32;
|
use epaint::Color32;
|
||||||
|
|
||||||
use crate::{Direction, Frame, Id, Rect};
|
use crate::{Direction, Frame, Id, Rect};
|
||||||
@@ -292,10 +292,8 @@ impl UiStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Does this node, or any [`crate::Ui`] up the stack, carry this class?
|
/// Does this node, or any [`crate::Ui`] up the stack, carry this class?
|
||||||
pub fn has_class(&self, class: impl Into<ClassName>) -> bool {
|
pub fn has_class(&self, class: &str) -> bool {
|
||||||
let class = class.into();
|
self.iter().any(|node| node.classes.has_class(class))
|
||||||
self.iter()
|
|
||||||
.any(|node| node.classes.has_class(class.clone()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -289,8 +289,11 @@ pub trait HasClasses {
|
|||||||
|
|
||||||
/// True if the class is present.
|
/// True if the class is present.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn has_class(&self, class: impl Into<ClassName>) -> bool {
|
fn has_class(&self, class: &str) -> bool {
|
||||||
self.classes().classes.contains(&class.into())
|
self.classes()
|
||||||
|
.classes
|
||||||
|
.iter()
|
||||||
|
.any(|existing| existing.as_str() == class)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The list of class.
|
/// The list of class.
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ pub mod class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
|
|
||||||
use epaint::{Color32, FontId, Stroke, Vec2};
|
use epaint::{Color32, FontId, Stroke, Vec2};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -158,8 +157,7 @@ impl StyleArgs<'_> {
|
|||||||
/// See also:
|
/// See also:
|
||||||
/// - [`Classes::has_class`]
|
/// - [`Classes::has_class`]
|
||||||
/// - [`UiStack::has_class`]
|
/// - [`UiStack::has_class`]
|
||||||
pub fn has_class(&self, class: impl Into<ClassName>) -> bool {
|
pub fn has_class(&self, class: &str) -> bool {
|
||||||
let class = class.into();
|
self.classes.has_class(class) || self.stack.has_class(class)
|
||||||
self.classes.has_class(class.clone()) || self.stack.has_class(class)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user