diff --git a/CHANGELOG.md b/CHANGELOG.md index aba28e0df..0f7b6d498 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs new file mode 100644 index 000000000..10c384a5c --- /dev/null +++ b/examples/fullscreen.rs @@ -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::() + .into_rows(), + ) + .into_rows() + .pad() + .vertical_scroll() + .expand() + .into_window() + .fullscreen(fullscreen) + .open(app)?; + Ok(()) +} + +fn monitor_modes( + index: usize, + monitor: &Monitor, + fullscreen: &Dynamic>, +) -> 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() + ), + ) + })) +} diff --git a/src/widget.rs b/src/widget.rs index d7b919834..f559c7b90 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -2210,6 +2210,19 @@ impl Dynamic { } } +impl FromIterator for WidgetList { + fn from_iter>(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 FromIterator for WidgetList where W: MakeWidget, @@ -2235,6 +2248,15 @@ impl DerefMut for WidgetList { } } +impl IntoIterator for WidgetList { + type IntoIter = std::vec::IntoIter; + 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;