Merge pull request #415 from hecrj/feature/configurable-scale-factor
Add `scale_factor` to `Application` and `Sandbox`
This commit is contained in:
commit
eec65a055f
4 changed files with 93 additions and 5 deletions
|
|
@ -186,6 +186,21 @@ pub trait Application: Sized {
|
|||
Color::WHITE
|
||||
}
|
||||
|
||||
/// Returns the scale factor of the [`Application`].
|
||||
///
|
||||
/// 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`.
|
||||
///
|
||||
/// [`Application`]: trait.Application.html
|
||||
fn scale_factor(&self) -> f64 {
|
||||
1.0
|
||||
}
|
||||
|
||||
/// Runs the [`Application`].
|
||||
///
|
||||
/// On native platforms, this method will take control of the current thread
|
||||
|
|
@ -273,6 +288,10 @@ where
|
|||
fn background_color(&self) -> Color {
|
||||
self.0.background_color()
|
||||
}
|
||||
|
||||
fn scale_factor(&self) -> f64 {
|
||||
self.0.scale_factor()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue