From 4c0286e8acdf0792a9680f6f8212a534a51e3da0 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 12 Jun 2020 22:12:15 +0200 Subject: Add `background_color` to `Application` and `Sandbox` --- src/sandbox.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/sandbox.rs') diff --git a/src/sandbox.rs b/src/sandbox.rs index c6fa45d0..729d9103 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -1,4 +1,6 @@ -use crate::{executor, Application, Command, Element, Settings, Subscription}; +use crate::{ + executor, Application, Color, Command, Element, Settings, Subscription, +}; /// A sandboxed [`Application`]. /// @@ -124,6 +126,16 @@ pub trait Sandbox { /// [`Sandbox`]: trait.Sandbox.html fn view(&mut self) -> Element<'_, Self::Message>; + /// Returns the background color of the [`Sandbox`]. + /// + /// By default, it returns [`Color::WHITE`]. + /// + /// [`Application`]: trait.Application.html + /// [`Color::WHITE`]: struct.Color.html#const.WHITE + fn background_color(&self) -> Color { + Color::WHITE + } + /// Runs the [`Sandbox`]. /// /// On native platforms, this method will take control of the current thread @@ -169,4 +181,8 @@ where fn view(&mut self) -> Element<'_, T::Message> { T::view(self) } + + fn background_color(&self) -> Color { + T::background_color(self) + } } -- cgit From c9696ca687446d78de374a828183de0a5e4bace3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 19 Jun 2020 19:17:05 +0200 Subject: Add `scale_factor` to `Application` and `Sandbox` --- src/sandbox.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/sandbox.rs') diff --git a/src/sandbox.rs b/src/sandbox.rs index 729d9103..6a73eab0 100644 --- a/src/sandbox.rs +++ b/src/sandbox.rs @@ -130,12 +130,27 @@ pub trait Sandbox { /// /// By default, it returns [`Color::WHITE`]. /// - /// [`Application`]: trait.Application.html + /// [`Sandbox`]: trait.Sandbox.html /// [`Color::WHITE`]: struct.Color.html#const.WHITE fn background_color(&self) -> Color { Color::WHITE } + /// Returns the scale factor of the [`Sandbox`]. + /// + /// It can be used to dynamically control the size of the UI at runtime + /// (i.e. zooming). + /// + /// For instance, a scale factor of `2.0` will make widgets twice as big, + /// while a scale factor of `0.5` will shrink them to half their size. + /// + /// By default, it returns `1.0`. + /// + /// [`Sandbox`]: trait.Sandbox.html + fn scale_factor(&self) -> f64 { + 1.0 + } + /// Runs the [`Sandbox`]. /// /// On native platforms, this method will take control of the current thread @@ -185,4 +200,8 @@ where fn background_color(&self) -> Color { T::background_color(self) } + + fn scale_factor(&self) -> f64 { + T::scale_factor(self) + } } -- cgit