pub struct Appearance { /* private fields */ }Expand description
The appearance section of a settings page or a setup wizard: language, theme and icons as the
family shares them, reduced motion and the pillar, as rows of a
SettingsList; and, where the application asks for its updates, the
family’s update notice with updates.
Each shared row has a box under it, “In every Quvyta application”, checked while the
application follows the family: a change then goes to the family’s shared file and every
application that follows it changes too. Cleared, the change stays in the application’s own
file. Reduced motion and the pillar are the application’s own. The update notice is one switch
for the whole family, kept in the shared file; see Family::update_notice. A change is applied at once
and saved at once, each file read again right before it is written; see
Family::set. When the QUVYTA_REDUCED_MOTION environment variable decides, the reduced
motion row is disabled and says why. Texts come from the framework’s language files.
use qframe::i18n::I18n;
use qframe::prelude::*;
use qframe::storage::{Family, Settings};
use qframe::widgets::{Appearance, AppearanceChange, SettingsList};
struct Code {
settings: Settings,
appearance: Appearance,
}
#[derive(Debug, Clone)]
enum Msg {
Appearance(AppearanceChange),
}
impl App for Code {
type Msg = Msg;
fn update(&mut self, msg: Msg) -> Command<Msg> {
match msg {
Msg::Appearance(change) => self.appearance.update(change, &mut self.settings),
}
}
fn view(&self, ui: &mut View<'_, Msg>) {
SettingsList::show(ui, |list| self.appearance.section(list, Msg::Appearance));
}
}
let family = Family::QUVYTA;
// An application passes `family.preferences("code", &i18n)`; the example stays in a folder of its own.
let preferences = family.preferences_in(&folder, "code", &I18n::builtin());
let appearance = Appearance::new(family, "code", preferences).in_folder(&folder);
let settings = Settings::open(folder.join("code.conf")).member_of(&family);
let mut app = Harness::new(Code { settings, appearance }, 60, 20);
assert!(app.screen().contains("In every Quvyta application"));Implementations§
Source§impl Appearance
impl Appearance
Sourcepub fn new(
family: Family,
app: impl Into<String>,
preferences: Preferences,
) -> Self
pub fn new( family: Family, app: impl Into<String>, preferences: Preferences, ) -> Self
The appearance of application app of family, starting from the preferences
Family::preferences resolved for it. Changes are saved in the family’s folder.
Sourcepub fn in_folder(self, folder: impl Into<PathBuf>) -> Self
pub fn in_folder(self, folder: impl Into<PathBuf>) -> Self
Saves changes in folder as the family’s folder instead of this platform’s, for a test
or a demo that must leave the user’s own files alone; see Family::set_in.
Sourcepub fn without_saving(self) -> Self
pub fn without_saving(self) -> Self
Applies every change without writing a file: the shared preferences
and the settings given to update take it, the screen shows it, and the
files are left to whoever writes them later.
For the first step of a setup wizard, which writes both files only when the wizard finishes, so a wizard closed half-way leaves nothing behind.
Sourcepub fn preferences(&self) -> &Preferences
pub fn preferences(&self) -> &Preferences
The shared preferences as they stand after the changes made so far.
Sourcepub fn section<Msg: Clone + 'static>(
&self,
list: &mut SettingsRows<'_, Msg>,
message: impl Fn(AppearanceChange) -> Msg + Clone + 'static,
)
pub fn section<Msg: Clone + 'static>( &self, list: &mut SettingsRows<'_, Msg>, message: impl Fn(AppearanceChange) -> Msg + Clone + 'static, )
Adds an “Appearance” heading, the three shared rows and the application’s own
rows, reduced motion and the pillar, to list.
Sourcepub fn updates<Msg: Clone + 'static>(
&self,
list: &mut SettingsRows<'_, Msg>,
message: impl Fn(AppearanceChange) -> Msg + Clone + 'static,
)
pub fn updates<Msg: Clone + 'static>( &self, list: &mut SettingsRows<'_, Msg>, message: impl Fn(AppearanceChange) -> Msg + Clone + 'static, )
Adds the family’s update notice switch to list, with the text saying what it asks and
what it never sends: for an application that asks whether a newer version of itself is out
(Command::check_for_update), right after
section. The switch is the family’s, one for every application, kept in
the shared file; see Family::update_notice. An application that never asks leaves the
row out, so its settings offer nothing that does nothing there.
Sourcepub fn rows<Msg: Clone + 'static>(
&self,
list: &mut SettingsRows<'_, Msg>,
message: impl Fn(AppearanceChange) -> Msg + Clone + 'static,
)
pub fn rows<Msg: Clone + 'static>( &self, list: &mut SettingsRows<'_, Msg>, message: impl Fn(AppearanceChange) -> Msg + Clone + 'static, )
Adds the three rows the family shares, language, theme and icons, each with its box, to
list, without a heading and without the application’s own rows: what the first step of a
setup wizard asks, on a page that names the section itself. Every change is
sent as message.
Sourcepub fn update<Msg: Send + 'static>(
&mut self,
change: AppearanceChange,
settings: &mut Settings,
) -> Command<Msg>
pub fn update<Msg: Send + 'static>( &mut self, change: AppearanceChange, settings: &mut Settings, ) -> Command<Msg>
Saves change and returns the command that shows it at once. settings are the
application’s own settings as it holds them in memory; they take the change too, so a
later Settings::save writes what the file now says instead of what it said before.
A change that cannot be saved is still applied, and the row it was made on says why it was not saved until the next change.
Trait Implementations§
Source§impl Clone for Appearance
impl Clone for Appearance
Auto Trait Implementations§
impl Freeze for Appearance
impl RefUnwindSafe for Appearance
impl Send for Appearance
impl Sync for Appearance
impl Unpin for Appearance
impl UnsafeUnpin for Appearance
impl UnwindSafe for Appearance
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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