Fullscreen example

This commit is contained in:
Jonathan Johnson 2024-09-09 08:12:59 -07:00
parent 0f866009b8
commit 448482e7bf
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
3 changed files with 81 additions and 0 deletions

View file

@ -88,12 +88,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Many new functions have been added to `Window` to expose more functionality
supported by winit:
- `Window::app_name`
- `Window::content_protected`
- `Window::cursor_hittest`
- `Window::cursor_position`
- `Window::cursor_visible`
- `Window::decorated`
- `Window::enabled_buttons`
- `Window::fullscreen`
- `Window::icon`
- `Window::inner_position`
- `Window::maximized`

57
examples/fullscreen.rs Normal file
View file

@ -0,0 +1,57 @@
use cushy::kludgine::app::winit::window::Fullscreen;
use cushy::kludgine::app::Monitor;
use cushy::value::Dynamic;
use cushy::widget::{MakeWidget, WidgetList};
use cushy::{App, Open};
#[cushy::main]
fn main(app: &mut App) -> cushy::Result {
let monitors = app.monitors().expect("monitors api not supported");
let fullscreen = Dynamic::new(None);
fullscreen
.new_radio(None, "Not Fullscreen")
.and(
monitors
.available
.iter()
.enumerate()
.map(|(index, monitor)| monitor_modes(index, monitor, &fullscreen))
.collect::<WidgetList>()
.into_rows(),
)
.into_rows()
.pad()
.vertical_scroll()
.expand()
.into_window()
.fullscreen(fullscreen)
.open(app)?;
Ok(())
}
fn monitor_modes(
index: usize,
monitor: &Monitor,
fullscreen: &Dynamic<Option<Fullscreen>>,
) -> WidgetList {
let name = monitor.name().unwrap_or_else(|| format!("Monitor {index}"));
name.h1()
.and(fullscreen.new_radio(
Some(Fullscreen::Borderless(Some(monitor.handle().clone()))),
"Borderless Fullscreen",
))
.chain(monitor.video_modes().map(|mode| {
fullscreen.new_radio(
Some(Fullscreen::Exclusive(mode.handle().clone())),
format!(
"{}x{} @ {}Hz ({}-bit color)",
mode.size().width,
mode.size().height,
mode.refresh_rate_millihertz() as f32 / 1_000.,
mode.bit_depth()
),
)
}))
}

View file

@ -2210,6 +2210,19 @@ impl Dynamic<WidgetList> {
}
}
impl FromIterator<WidgetList> for WidgetList {
fn from_iter<T: IntoIterator<Item = WidgetList>>(iter: T) -> Self {
let mut iter = iter.into_iter();
let Some(mut dest) = iter.next() else {
return Self::new();
};
for other in iter {
dest.extend(other);
}
dest
}
}
impl<W> FromIterator<W> for WidgetList
where
W: MakeWidget,
@ -2235,6 +2248,15 @@ impl DerefMut for WidgetList {
}
}
impl IntoIterator for WidgetList {
type IntoIter = std::vec::IntoIter<WidgetInstance>;
type Item = WidgetInstance;
fn into_iter(self) -> Self::IntoIter {
self.ordered.into_iter()
}
}
impl<'a> IntoIterator for &'a WidgetList {
type IntoIter = slice::Iter<'a, WidgetInstance>;
type Item = &'a WidgetInstance;