Skip to main content

Appearance

Struct Appearance 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn preferences(&self) -> &Preferences

The shared preferences as they stand after the changes made so far.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Appearance

Source§

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

Formats the value using the given formatter. 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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.