Skip to main content

ThemeEditor

Struct ThemeEditor 

Source
pub struct ThemeEditor { /* private fields */ }
Expand description

The theme editor’s state, shared by its view and its commands.

Implementations§

Source§

impl ThemeEditor

Source

pub fn sync(&self, app: &AppHandle)

Follows the application’s theme: when the theme installed (its base, its counterpart and their overrides) is not what the editor wrote last, the editor starts again from it, a pair as a pair, editing the variant shown. When the variant shown changes (the light or dark preference, or the system’s mode), the pair’s variant of that mode is edited.

Source

pub fn switch_variant(&self, app: &AppHandle) -> Result<String, String>

Edits the pair’s other variant, and shows it: the light or dark preference becomes its mode, as the application’s toggle does. Each variant keeps its changes and history. The theme now edited, or why nothing changed (a theme alone).

Source

pub fn editing_dark(&self, app: &AppHandle) -> bool

Whether the variant edited is the dark one.

Source

pub fn propose_counterpart(&self, app: &AppHandle) -> Option<GeneratedVariant>

The other variant generated from the one edited (ThemeDraft::generate_counterpart), kept to be shown (the preview pane draws it) until applied or dropped. None for a theme alone.

Source

pub fn proposal(&self) -> Option<GeneratedVariant>

The proposal shown, if any.

Source

pub fn drop_proposal(&self)

Drops the proposal shown.

Source

pub fn apply_counterpart( &self, app: &AppHandle, cause: Cause, ) -> Result<usize, String>

Writes the other variant generated from the one edited: its edits through the theme.token step, recorded on it as one change (one undo there takes them back), and its seeds. The variant edited stays the same. The number of tokens changed.

Source

pub fn preview_only(&self) -> bool

Whether changes stay in the draft, drawn in the preview pane only, until ThemeEditor::apply; off (live) by default, each change installed at once.

Source

pub fn set_preview_only(&self, app: &AppHandle, on: bool)

Switches between live editing and the preview only. Going back to live installs the draft.

Source

pub fn pending(&self, app: &AppHandle) -> bool

Whether the draft differs from the theme installed (a preview not applied yet).

Source

pub fn apply(&self, app: &AppHandle)

Installs the draft app-wide: the theme previewed becomes the application’s (in live mode it already is).

Source

pub fn discard(&self, app: &AppHandle)

Drops the draft’s changes not applied: the editor starts again from the theme installed (its history emptied).

Source

pub fn set_file_dialog(&self, dialog: Option<FileDialog>)

The file chooser the editor opens and saves files with: the host’s, so the editor needs no file-dialog dependency. Without one, the files plugin’s chooser (files::FILES) when it is connected; without either, files are pasted as text only.

Source

pub fn set_sampler(&self, sampler: Option<Sampler>)

What the preview pane draws in the draft’s theme; a few of egui’s and egui-pop’s widgets by default (sample).

Source

pub fn scoped(&self, app: &AppHandle) -> ScopedTheme

The draft’s theme as the preview pane draws it (built once per draft): the variant edited, or the other variant proposed while a proposal is shown (ThemeEditor::propose_counterpart).

Source

pub fn set_font_dir(&self, dir: Option<PathBuf>)

Where the faces of a theme package opened in the editor are copied, so they are kept as the user’s own font files (paths, ThemeEditor::font_files): a folder of the host’s, such as one under its data directory. Without one, the faces of a folder are used where they are, and those of an archive are registered for this run only (a warning says so).

Source

pub fn open_file( &self, app: &AppHandle, path: &Path, ) -> Result<Vec<Warning>, String>

Opens a theme from disk (what “Open” does once a file is chosen): a token file, the folder of a theme package, or its .zip archive (with the theme-zip feature; package). The token file is imported (ThemeEditor::import); the faces it lists become the user’s font files, registered and installed at once (ThemeEditor::set_font_dir). What it loaded with, the faces not read included.

Source

pub fn package( &self, app: &AppHandle, name: &str, ) -> Result<ThemePackage, String>

The draft as a theme package named name: its token file (ThemeEditor::export) and the user’s font files (applied) of the families its font.family.ui and font.family.mono name.

Source

pub fn save_file(&self, app: &AppHandle, path: &Path) -> Result<PathBuf, String>

Writes the draft (what “Save as” does once a file is chosen), named after the file: a token file, or, when the theme names font files of the user’s (ThemeEditor::package), a folder beside it holding the token file and the faces; a path ending in .zip is an archive of the same (theme-zip feature). Where the token file, or the archive, was written.

Source

pub fn select(&self, path: &str)

Shows a token in the editor (as a click in its list does).

Source

pub fn selected(&self) -> Option<String>

The token shown in the editor.

Source

pub fn draft(&self) -> ThemeDraft

The draft as it is.

Source

pub fn resolved(&self, app: &AppHandle) -> Arc<ResolvedTokens>

The draft’s theme, resolved (cached): the application’s in live mode.

Source

pub fn set( &self, app: &AppHandle, path: &str, to: Option<Json>, cause: Cause, ) -> Result<Option<TokenEdit>, String>

Sets a token (None: the base theme’s value) through the theme.token step, recorded for undo and written to the theme. Ok(None): nothing changed.

Source

pub fn undo( &self, app: &AppHandle, cause: Cause, ) -> Result<Option<TokenEdit>, String>

Takes the last change back, through the theme.token step. Ok(None): nothing to undo.

Source

pub fn redo( &self, app: &AppHandle, cause: Cause, ) -> Result<Option<TokenEdit>, String>

Makes the last undone change again.

Source

pub fn start(&self, app: &AppHandle, base: &str) -> Result<(), String>

Starts again from a theme the application knows (its tokens as they are, the history emptied), through the theme.load step: with its counterpart of the other mode, if it has one, as a pair, the theme picked edited and shown.

Source

pub fn export(&self, app: &AppHandle, name: &str) -> String

The draft as the text of a .tokens.json file named name: a pair as one file, the theme named first’s carrying its counterpart (named name and its mode, my-theme-light).

Source

pub fn import( &self, app: &AppHandle, text: &str, ) -> Result<Vec<Warning>, String>

Loads a token file through the theme.load step, over its base as any theme file (ThemeDraft::import), a file carrying its counterpart as a pair; what it loaded with: the tokens left out (unknown to its base, or with a value that does not check), renamed, or a file newer than this egui-pop.

Source

pub fn generate( &self, app: &AppHandle, scale: &str, seed: Color, cause: Cause, ) -> Result<usize, String>

Writes a scale generated from a seed colour over one of the theme’s colour scales (blue, gray): its steps 1 to 12 and its contrast (palette::Ramp), for the scheme of the variant edited, fitted to its surfaces and text (ThemeDraft::seeded_ramp). Each token goes through the theme.token step; together they undo as one change. The seed is recorded (ThemeDraft::set_seed): the exported file gives the scale as its seed, regenerated when loaded, rather than twelve values. The number of tokens changed.

The variant edited only: a pair’s other variant keeps its own scale (switch to it and generate it there, or generate the other variant, ThemeEditor::apply_counterpart). An accent for both is ThemeService::set_accent_color.

Source

pub fn tab(&self) -> Tab

The tab shown.

Source

pub fn set_tab(&self, tab: Tab)

Source

pub fn font_files(&self) -> Vec<FontFile>

The user’s font files as applied: paths, family and weight, what the host saves in its settings (never the bytes) and gives back at the next start (ThemeEditor::set_font_files).

Source

pub fn set_font_files(&self, ctx: &Context, files: Vec<FontFile>) -> Vec<String>

The font files saved by the host, at start: registered (each read again from its path), installed with the next theme install. What could not be read, by file.

Source

pub fn edited_font_files(&self) -> Vec<FontFile>

The font files as edited (applied or not).

Source

pub fn add_font_file(&self, path: &Path) -> Result<FontFile, String>

Adds a font file (read to check it and to take its family and weight), applied with ThemeEditor::apply_fonts. A file of the same path replaces it.

Source

pub fn remove_font_file(&self, path: &Path)

Removes a font file, applied with ThemeEditor::apply_fonts (its face stays registered until the application starts again).

Source

pub fn families(&self, app: &AppHandle, role: Role) -> Vec<String>

A role’s families as edited, in priority order: the first found draws, the others are its fallbacks.

Source

pub fn set_families(&self, role: Role, families: Vec<String>)

Sets a role’s families (in priority order), applied with ThemeEditor::apply_fonts.

Source

pub fn fonts_pending(&self, app: &AppHandle) -> bool

Whether the fonts tab has edits not applied.

Source

pub fn preview_face(&self, role: Role, name: Option<&str>)

Previews a face in a role without applying it (what resting the pointer on a face does): the fonts tab’s preview draws it first, before the role’s families as edited. None stops it.

Source

pub fn font_preview(&self, app: &AppHandle, role: Role) -> Option<Vec<String>>

What the fonts tab’s preview draws for a role: the face previewed (ThemeEditor::preview_face) before the role’s families as edited, or the families as edited when they are not applied; None when it draws the fonts installed.

Source

pub fn installed_families(&self, app: &AppHandle, role: Role) -> Vec<FamilyInfo>

The families installed a role may pick (monospace ones only for Role::Mono), matching the fonts tab’s search (a part of the name, any case): egui’s, the application’s, the user’s files, then the system’s.

Searches the families installed (ThemeEditor::installed_families).

Source

pub fn choose_face(&self, app: &AppHandle, role: Role, name: &str)

Picks a family for a role, as clicking it among the families installed does: put first in the role’s families as edited (moved there when it is already in them), the others kept as its fallbacks, and a generic family added at the end when there is none (sans-serif, monospace), so a theme naming a face missing on another machine still draws there. Previewed, applied with ThemeEditor::apply_fonts.

Source

pub fn cancel_fonts(&self, app: &AppHandle)

Drops the fonts tab’s edits (families, files, the face previewed): the fonts installed stay as they are.

Source

pub fn apply_fonts( &self, app: &AppHandle, cause: Cause, ) -> Result<Vec<String>, String>

Applies the fonts tab, once (the atlas is rebuilt, a slow frame): registers the font files (read again from their paths; one that cannot be read is reported and the face it had stays), writes the families into the draft as one change through the theme.token step, and applies the draft app-wide (fonts are global: the fonts tab’s pane previews them through the preview families, ThemeEditor::font_preview). What could not be done, by file; saving the files is the host’s (ThemeEditor::font_files).

Source

pub fn read(&self, app: &AppHandle, path: Option<&str>) -> Result<Json, String>

The draft, or one token, as agents read it.

Trait Implementations§

Source§

impl Debug for ThemeEditor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ThemeEditor

Source§

fn default() -> ThemeEditor

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,