Tweak and organize devtools crate

This commit is contained in:
Héctor Ramón Jiménez 2025-04-28 22:31:13 +02:00
parent 267583c2a9
commit ef16ea3b2a
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
8 changed files with 239 additions and 132 deletions

View file

@ -31,6 +31,7 @@ impl text::Renderer for () {
type Paragraph = ();
type Editor = ();
const MONOSPACE_FONT: Font = Font::MONOSPACE;
const ICON_FONT: Font = Font::DEFAULT;
const CHECKMARK_ICON: char = '0';
const ARROW_DOWN_ICON: char = '0';

View file

@ -232,6 +232,11 @@ pub trait Renderer: crate::Renderer {
/// The [`Editor`] of this [`Renderer`].
type Editor: Editor<Font = Self::Font> + 'static;
/// A monospace font.
///
/// It may be used by devtools.
const MONOSPACE_FONT: Self::Font;
/// The icon font of the backend.
const ICON_FONT: Self::Font;

View file

@ -5,6 +5,7 @@ pub use palette::Palette;
use crate::Color;
use std::borrow::Cow;
use std::fmt;
use std::sync::Arc;
@ -87,14 +88,17 @@ impl Theme {
];
/// Creates a new custom [`Theme`] from the given [`Palette`].
pub fn custom(name: String, palette: Palette) -> Self {
pub fn custom(
name: impl Into<Cow<'static, str>>,
palette: Palette,
) -> Self {
Self::custom_with_fn(name, palette, palette::Extended::generate)
}
/// Creates a new custom [`Theme`] from the given [`Palette`], with
/// a custom generator of a [`palette::Extended`].
pub fn custom_with_fn(
name: String,
name: impl Into<Cow<'static, str>>,
palette: Palette,
generate: impl FnOnce(Palette) -> palette::Extended,
) -> Self {
@ -220,7 +224,7 @@ impl fmt::Display for Theme {
/// A [`Theme`] with a customized [`Palette`].
#[derive(Debug, Clone, PartialEq)]
pub struct Custom {
name: String,
name: Cow<'static, str>,
palette: Palette,
extended: palette::Extended,
}
@ -234,12 +238,12 @@ impl Custom {
/// Creates a [`Custom`] theme from the given [`Palette`] with
/// a custom generator of a [`palette::Extended`].
pub fn with_fn(
name: String,
name: impl Into<Cow<'static, str>>,
palette: Palette,
generate: impl FnOnce(Palette) -> palette::Extended,
) -> Self {
Self {
name,
name: name.into(),
palette,
extended: generate(palette),
}