pub struct FrusApp { /* private fields */ }Expand description
An application: a root component, and how it is dressed.
use frus_shell::FrusApp;
use frus_widgets::{text, Theme, ThemeMode};
let app = FrusApp::from_fn(|_| Box::new(text("hello")))
.title("Hello")
.theme(Theme::light())
.dark_theme(Theme::dark())
.theme_mode(ThemeMode::System);How it is dressed — its title, themes, language, zoom — is kept where a component can reach
it too, in host::app: what the builders here set, a component changes with the same
names (host::app().set_theme_mode(..)), and the shell reads it every frame.
Implementations§
Source§impl FrusApp
impl FrusApp
Sourcepub fn new(root: impl StatelessWidget) -> Self
pub fn new(root: impl StatelessWidget) -> Self
An application whose interface is the StatelessWidget root.
Sourcepub fn from_fn(
root: impl Fn(&BuildContext<'_>) -> Box<dyn Widget> + 'static,
) -> Self
pub fn from_fn( root: impl Fn(&BuildContext<'_>) -> Box<dyn Widget> + 'static, ) -> Self
An application whose interface is a function of the build context — hooks may be called in it.
Sourcepub fn stateful<W: StatefulWidget + Clone>(root: W) -> Self
pub fn stateful<W: StatefulWidget + Clone>(root: W) -> Self
An application whose root is a StatefulWidget. It is configuration, made again
on every rebuild — hence Clone.
Sourcepub fn router(router: GoRouter) -> Self
pub fn router(router: GoRouter) -> Self
An application whose pages are the routes of router: the router builds the interface,
moves it when told a location, and answers the back gesture.
use frus_shell::FrusApp;
use frus_widgets::{text, GoRoute, GoRouter};
let router = GoRouter::new(vec![
GoRoute::new("/", |_, _| text("home")),
GoRoute::new("/about", |_, _| text("about")),
]);
let app = FrusApp::router(router).title("Pages");Sourcepub fn builder(
self,
builder: impl Fn(&BuildContext<'_>, Box<dyn Widget>) -> Box<dyn Widget> + 'static,
) -> Self
pub fn builder( self, builder: impl Fn(&BuildContext<'_>, Box<dyn Widget>) -> Box<dyn Widget> + 'static, ) -> Self
What goes around the application’s pages: builder is handed them, as child, and
returns what the window shows. The place for what belongs to the window rather than to
a page — what must stay put while the pages change under it, and stay there whichever
page is on show: a WindowMenuBar, a banner across every
page.
use frus_shell::FrusApp;
use frus_widgets::{
text, Callback, GoRoute, GoRouter, MenuBar, MenuPath, SubmenuButton, WindowMenuBar,
};
let router = GoRouter::new(vec![GoRoute::new("/", |_, _| text("home"))]);
let app = FrusApp::router(router).builder(|cx, pages| {
// Which menu is open: the window's to keep, as the bar is.
let menus = cx.use_state(MenuPath::closed);
let set = menus.clone();
let bar = MenuBar::new(&menus.get(), move |path: MenuPath| {
let set = set.clone();
Callback::new(move || set.set(path.clone()))
})
.menu(SubmenuButton::new("File"));
Box::new(WindowMenuBar::new(bar, pages))
});child is built where builder puts it, so what it reads of the window there — a
MediaQuery a wrapper narrowed — is what its pages are built
for. builder may call hooks, and reach the router with
BuildContext::router.
Keep the shape of what it returns: the pages are kept under their place in the tree,
and a child that moves loses their state. A wrapper that is sometimes not needed is
told so — WindowMenuBar::new(None, child) — rather than left out.
Sourcepub fn single_instance(self, id: impl Into<String>) -> Self
pub fn single_instance(self, id: impl Into<String>) -> Self
Makes the application one window on a desktop, named id — a reverse domain such as
com.example.myapp. A second process started with a link (myapp://orders/42, how a
desktop opens a registered scheme) hands it to the first, which opens the location it
names, and ends. See Application::instance_id.
Sourcepub fn location_strategy(self, strategy: LocationStrategy) -> Self
pub fn location_strategy(self, strategy: LocationStrategy) -> Self
How the router’s location is written in a browser’s address bar: after a # (the
default, which any static host serves) or as a path (which needs the server to answer
every address with the page). Only the web has an address bar to show it in. See
LocationStrategy.
Sourcepub fn theme(self, theme: Theme) -> Self
pub fn theme(self, theme: Theme) -> Self
The application’s theme — its light one, where it has two.
Sourcepub fn dark_theme(self, theme: Theme) -> Self
pub fn dark_theme(self, theme: Theme) -> Self
The theme for a dark interface. With one, the application follows the system’s
brightness, or theme_mode.
Sourcepub fn theme_mode(self, mode: ThemeMode) -> Self
pub fn theme_mode(self, mode: ThemeMode) -> Self
Which of the two themes is on display: the system’s choice by default.
Sourcepub fn supported_locales(self, locales: Vec<Locale>) -> Self
pub fn supported_locales(self, locales: Vec<Locale>) -> Self
The languages the application has, best first. The framework resolves the device’s list against them.
Sourcepub fn localizations(self, table: Rc<dyn Localizations>) -> Self
pub fn localizations(self, table: Rc<dyn Localizations>) -> Self
The words the framework says on the application’s behalf, where they are not English.
Sourcepub fn on_start(self, start: impl FnOnce() + 'static) -> Self
pub fn on_start(self, start: impl FnOnce() + 'static) -> Self
Runs start once, when the application starts and before anything is drawn: the place
for what has to be true from the first frame — registering data, opening a store.
Sourcepub fn persist(
self,
save: impl Fn() -> Option<Vec<u8>> + 'static,
restore: impl Fn(&[u8]) + 'static,
) -> Self
pub fn persist( self, save: impl Fn() -> Option<Vec<u8>> + 'static, restore: impl Fn(&[u8]) + 'static, ) -> Self
Keeps what save returns across a live reload, and hands it to restore afterwards.
A development convenience: the state of an application survives a recompilation.
Sourcepub fn icon(self, icon: AppIcon) -> Self
pub fn icon(self, icon: AppIcon) -> Self
The application’s icon. The frus logo is the default — an application has it without
writing a line — and this is how to change it: .icon(AppIcon::from_png(include_bytes!( "../assets/icon.png"))), or .icon(AppIcon::none()) for none of the framework’s. On
Android the launcher icon is the manifest’s instead; see AppIcon.
Sourcepub fn window_size(self, width: f32, height: f32) -> Self
pub fn window_size(self, width: f32, height: f32) -> Self
The window’s initial size, in logical pixels.
Trait Implementations§
Source§impl Application for FrusApp
impl Application for FrusApp
Source§fn go_back(&mut self)
fn go_back(&mut self)
The router pops: the page leaves with its transition, as it does for a back button in the reference, and not as a swipe let go (milestone 622).
Source§type Message = Callback
type Message = Callback
Application::update consumes. Read moreSource§fn update(&mut self, callback: Callback) -> Command<Callback>
fn update(&mut self, callback: Callback) -> Command<Callback>
Command::none for none.Source§fn init(&mut self) -> Command<Callback>
fn init(&mut self) -> Command<Callback>
Source§fn effects(&mut self) -> Command<Callback>
fn effects(&mut self) -> Command<Callback>
update — from
a build, say, or from a component that has no message to return them with. The shell
asks after every frame and after every message, and runs what comes back like any
other command. An application that returns its effects from update never needs it.Source§fn save_state(&self) -> Option<Vec<u8>>
fn save_state(&self) -> Option<Vec<u8>>
FRUS_WATCH=1).
None, the default, means the app opts out, and a reload then starts from a
fresh state. The byte format belongs to the app.Source§fn restore_state(&mut self, bytes: &[u8])
fn restore_state(&mut self, bytes: &[u8])
Application::save_state snapshot taken by the
previous binary; called before Application::init. The bytes come from
another version of the code, so tolerate unexpected formats — ignoring beats
panicking.Source§fn view(&self, _theme: &Theme) -> Box<dyn Widget<Callback>>
fn view(&self, _theme: &Theme) -> Box<dyn Widget<Callback>>
Source§fn subscription(&self) -> Subscription<Callback>
fn subscription(&self) -> Subscription<Callback>
Source§fn tick(&mut self, dt: f32) -> bool
fn tick(&mut self, dt: f32) -> bool
dt seconds. Returns true while something is still moving, in which case the
framework asks for another frame. Read moreSource§fn location(&self) -> Option<String>
fn location(&self) -> Option<String>
/users/42?tab=posts. None — the
default — for an application with no addresses, which the shell then leaves alone. Read moreSource§fn location_replaces(&self) -> bool
fn location_replaces(&self) -> bool
location swapped the page — a
router’s replace — rather than adding one. The browser’s entry is then swapped too,
instead of a new one being added behind it. false by default.Source§fn location_stack(&self) -> Vec<String>
fn location_stack(&self) -> Vec<String>
location last. Used once, when the page is opened at an address
deep in the application: the browser’s history is made to hold the pages beneath too,
so that going back — the application’s own or the browser’s — has somewhere to land
inside the application. The default is the location alone.Source§fn open_location(&mut self, location: &str) -> Command<Callback>
fn open_location(&mut self, location: &str) -> Command<Callback>
Source§fn location_strategy(&self) -> LocationStrategy
fn location_strategy(&self) -> LocationStrategy
location is written in the address bar. See
LocationStrategy.Source§fn instance_id(&self) -> Option<String>
fn instance_id(&self) -> Option<String>
myapp://orders/42 — hands
the link to the first and ends, instead of opening a second window. None, the default,
lets every process be its own. Read moreSource§fn can_go_back(&self) -> bool
fn can_go_back(&self) -> bool
Source§fn back_gesture(&mut self, progress: f32)
fn back_gesture(&mut self, progress: f32)
0 → 1), so view can preview it.Source§fn back_gesture_end(&mut self, velocity: f32)
fn back_gesture_end(&mut self, velocity: f32)
tick.Source§fn theme(&self) -> Theme
fn theme(&self) -> Theme
app.dart:425). Read moreSource§fn dark_theme(&self) -> Option<Theme>
fn dark_theme(&self) -> Option<Theme>
app.dart:447). Read moreSource§fn theme_mode(&self) -> ThemeMode
fn theme_mode(&self) -> ThemeMode
app.dart:502): the platform’s choice
by default, or one of them pinned. Read moreSource§fn supported_locales(&self) -> Vec<Locale>
fn supported_locales(&self) -> Vec<Locale>
app.dart’s supportedLocales), best
first — the answer to what can I actually show this reader? Read moreSource§fn locale(&self) -> Option<Locale>
fn locale(&self) -> Option<Locale>
app.dart’s
locale); None — the default — follows the device. Read moreSource§fn localizations(&self) -> Option<Rc<dyn Localizations>>
fn localizations(&self) -> Option<Rc<dyn Localizations>>
Source§fn window_size(&self) -> Option<(f32, f32)>
fn window_size(&self) -> Option<(f32, f32)>
None for the system default. Ignored on
the Web, where the page decides how big the canvas is.Source§fn icon(&self) -> AppIcon
fn icon(&self) -> AppIcon
AppIcon for what it does on each platform, and
for how to change or remove it.Source§fn density(&self) -> f32
fn density(&self) -> f32
1.0 by
default, applied on top of the system DPI scale. 1.2 grows the whole UI by
20%, 0.9 tightens it. It can change at runtime through the state.Source§fn high_contrast_theme(&self) -> Option<Theme>
fn high_contrast_theme(&self) -> Option<Theme>
app.dart:460);
None falls back to Application::theme. Read moreSource§fn high_contrast_dark_theme(&self) -> Option<Theme>
fn high_contrast_dark_theme(&self) -> Option<Theme>
app.dart:476); None falls
back to Application::dark_theme, then to Application::high_contrast_theme,
then to Application::theme — the reference’s own order, rung for rung.Source§fn resolved_theme(&self, brightness: Brightness, high_contrast: bool) -> Theme
fn resolved_theme(&self, brightness: Brightness, high_contrast: bool) -> Theme
_themeBuilder (app.dart:995), rung for rung. Read moreSource§fn theme_animation_duration(&self) -> f32
fn theme_animation_duration(&self) -> f32
app.dart:516); 0 switches at once. The default is the reference’s 200 ms. Read moreSource§fn theme_animation_curve(&self) -> Curve
fn theme_animation_curve(&self) -> Curve
app.dart:526); linear by default, as in the
reference. Ignored when Application::theme_animation_duration is 0.Source§fn accessibility(&self) -> AccessibilityOverrides
fn accessibility(&self) -> AccessibilityOverrides
Source§fn scroll_behavior(&self) -> ScrollBehavior
fn scroll_behavior(&self) -> ScrollBehavior
frus_widgets::ScrollBehavior put in force at the root of the tree. Read moreSource§fn resolved_locale(&self, preferred: &[Locale]) -> Locale
fn resolved_locale(&self, preferred: &[Locale]) -> Locale
Source§fn on_resize(&mut self, _width: f32, _height: f32)
fn on_resize(&mut self, _width: f32, _height: f32)
Source§fn on_lifecycle(&mut self, _state: Lifecycle)
fn on_lifecycle(&mut self, _state: Lifecycle)
Lifecycle): Resumed in the
foreground, Inactive when the window loses focus, Paused in the background
with the surface lost, Detached just before closing. The default does
nothing. This is where an app suspends and resumes its work — timers, sensors —
or persists its state.Source§fn on_insets(&mut self, _insets: WindowInsets)
fn on_insets(&mut self, _insets: WindowInsets)
padding is the
system bars and the notch, which are static, while view_insets is the
software keyboard, which is dynamic — avoiding the keyboard means pushing the
content away by insets.safe(). In logical px. Always zero on desktop.Auto Trait Implementations§
impl !RefUnwindSafe for FrusApp
impl !Send for FrusApp
impl !Sync for FrusApp
impl !UnwindSafe for FrusApp
impl Freeze for FrusApp
impl Unpin for FrusApp
impl UnsafeUnpin for FrusApp
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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.Source§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.Source§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.Source§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.