Skip to content

Commit

Permalink
Fullscreen example
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Sep 9, 2024
1 parent 0f86600 commit 448482e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
57 changes: 57 additions & 0 deletions examples/fullscreen.rs
Original file line number Diff line number Diff line change
@@ -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()
),
)
}))
}
22 changes: 22 additions & 0 deletions src/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down

0 comments on commit 448482e

Please sign in to comment.