pub struct ThemeEditor { /* private fields */ }Expand description
The theme editor’s state, shared by its view and its commands.
Implementations§
Source§impl ThemeEditor
impl ThemeEditor
Sourcepub fn sync(&self, app: &AppHandle)
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.
Sourcepub fn switch_variant(&self, app: &AppHandle) -> Result<String, String>
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).
Sourcepub fn editing_dark(&self, app: &AppHandle) -> bool
pub fn editing_dark(&self, app: &AppHandle) -> bool
Whether the variant edited is the dark one.
Sourcepub fn propose_counterpart(&self, app: &AppHandle) -> Option<GeneratedVariant>
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.
Sourcepub fn proposal(&self) -> Option<GeneratedVariant>
pub fn proposal(&self) -> Option<GeneratedVariant>
The proposal shown, if any.
Sourcepub fn drop_proposal(&self)
pub fn drop_proposal(&self)
Drops the proposal shown.
Sourcepub fn apply_counterpart(
&self,
app: &AppHandle,
cause: Cause,
) -> Result<usize, String>
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.
Sourcepub fn preview_only(&self) -> bool
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.
Sourcepub fn set_preview_only(&self, app: &AppHandle, on: bool)
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.
Sourcepub fn pending(&self, app: &AppHandle) -> bool
pub fn pending(&self, app: &AppHandle) -> bool
Whether the draft differs from the theme installed (a preview not applied yet).
Sourcepub fn apply(&self, app: &AppHandle)
pub fn apply(&self, app: &AppHandle)
Installs the draft app-wide: the theme previewed becomes the application’s (in live mode it already is).
Sourcepub fn discard(&self, app: &AppHandle)
pub fn discard(&self, app: &AppHandle)
Drops the draft’s changes not applied: the editor starts again from the theme installed (its history emptied).
Sourcepub fn set_file_dialog(&self, dialog: Option<FileDialog>)
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.
Sourcepub fn set_sampler(&self, sampler: Option<Sampler>)
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).
Sourcepub fn scoped(&self, app: &AppHandle) -> ScopedTheme
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).
Sourcepub fn set_font_dir(&self, dir: Option<PathBuf>)
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).
Sourcepub fn open_file(
&self,
app: &AppHandle,
path: &Path,
) -> Result<Vec<Warning>, String>
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.
Sourcepub fn package(
&self,
app: &AppHandle,
name: &str,
) -> Result<ThemePackage, String>
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.
Sourcepub fn save_file(&self, app: &AppHandle, path: &Path) -> Result<PathBuf, String>
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.
Sourcepub fn draft(&self) -> ThemeDraft
pub fn draft(&self) -> ThemeDraft
The draft as it is.
Sourcepub fn resolved(&self, app: &AppHandle) -> Arc<ResolvedTokens>
pub fn resolved(&self, app: &AppHandle) -> Arc<ResolvedTokens>
The draft’s theme, resolved (cached): the application’s in live mode.
Sourcepub fn set(
&self,
app: &AppHandle,
path: &str,
to: Option<Json>,
cause: Cause,
) -> Result<Option<TokenEdit>, String>
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.
Sourcepub fn undo(
&self,
app: &AppHandle,
cause: Cause,
) -> Result<Option<TokenEdit>, String>
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.
Sourcepub fn redo(
&self,
app: &AppHandle,
cause: Cause,
) -> Result<Option<TokenEdit>, String>
pub fn redo( &self, app: &AppHandle, cause: Cause, ) -> Result<Option<TokenEdit>, String>
Makes the last undone change again.
Sourcepub fn start(&self, app: &AppHandle, base: &str) -> Result<(), String>
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.
Sourcepub fn export(&self, app: &AppHandle, name: &str) -> String
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).
Sourcepub fn import(
&self,
app: &AppHandle,
text: &str,
) -> Result<Vec<Warning>, String>
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.
Sourcepub fn generate(
&self,
app: &AppHandle,
scale: &str,
seed: Color,
cause: Cause,
) -> Result<usize, String>
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.
pub fn set_tab(&self, tab: Tab)
Sourcepub fn font_files(&self) -> Vec<FontFile>
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).
Sourcepub fn set_font_files(&self, ctx: &Context, files: Vec<FontFile>) -> Vec<String>
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.
Sourcepub fn edited_font_files(&self) -> Vec<FontFile>
pub fn edited_font_files(&self) -> Vec<FontFile>
The font files as edited (applied or not).
Sourcepub fn add_font_file(&self, path: &Path) -> Result<FontFile, String>
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.
Sourcepub fn remove_font_file(&self, path: &Path)
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).
Sourcepub fn families(&self, app: &AppHandle, role: Role) -> Vec<String>
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.
Sourcepub fn set_families(&self, role: Role, families: Vec<String>)
pub fn set_families(&self, role: Role, families: Vec<String>)
Sets a role’s families (in priority order), applied with
ThemeEditor::apply_fonts.
Sourcepub fn fonts_pending(&self, app: &AppHandle) -> bool
pub fn fonts_pending(&self, app: &AppHandle) -> bool
Whether the fonts tab has edits not applied.
Sourcepub fn preview_face(&self, role: Role, name: Option<&str>)
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.
Sourcepub fn font_preview(&self, app: &AppHandle, role: Role) -> Option<Vec<String>>
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.
Sourcepub fn installed_families(&self, app: &AppHandle, role: Role) -> Vec<FamilyInfo>
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.
Sourcepub fn set_face_search(&self, search: &str)
pub fn set_face_search(&self, search: &str)
Searches the families installed (ThemeEditor::installed_families).
Sourcepub fn choose_face(&self, app: &AppHandle, role: Role, name: &str)
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.
Sourcepub fn cancel_fonts(&self, app: &AppHandle)
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.
Sourcepub fn apply_fonts(
&self,
app: &AppHandle,
cause: Cause,
) -> Result<Vec<String>, String>
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).
Trait Implementations§
Source§impl Debug for ThemeEditor
impl Debug for ThemeEditor
Source§impl Default for ThemeEditor
impl Default for ThemeEditor
Source§fn default() -> ThemeEditor
fn default() -> ThemeEditor
Auto Trait Implementations§
impl !Freeze for ThemeEditor
impl RefUnwindSafe for ThemeEditor
impl Send for ThemeEditor
impl Sync for ThemeEditor
impl Unpin for ThemeEditor
impl UnsafeUnpin for ThemeEditor
impl UnwindSafe for ThemeEditor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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