mirror of
https://github.com/danbulant/cushy
synced 2026-07-05 03:00:43 +00:00
Fullscreen example
This commit is contained in:
parent
0f866009b8
commit
448482e7bf
3 changed files with 81 additions and 0 deletions
|
|
@ -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
|
- Many new functions have been added to `Window` to expose more functionality
|
||||||
supported by winit:
|
supported by winit:
|
||||||
|
|
||||||
|
- `Window::app_name`
|
||||||
- `Window::content_protected`
|
- `Window::content_protected`
|
||||||
- `Window::cursor_hittest`
|
- `Window::cursor_hittest`
|
||||||
- `Window::cursor_position`
|
- `Window::cursor_position`
|
||||||
- `Window::cursor_visible`
|
- `Window::cursor_visible`
|
||||||
- `Window::decorated`
|
- `Window::decorated`
|
||||||
- `Window::enabled_buttons`
|
- `Window::enabled_buttons`
|
||||||
|
- `Window::fullscreen`
|
||||||
- `Window::icon`
|
- `Window::icon`
|
||||||
- `Window::inner_position`
|
- `Window::inner_position`
|
||||||
- `Window::maximized`
|
- `Window::maximized`
|
||||||
|
|
|
||||||
57
examples/fullscreen.rs
Normal file
57
examples/fullscreen.rs
Normal 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()
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
@ -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
|
impl<W> FromIterator<W> for WidgetList
|
||||||
where
|
where
|
||||||
W: MakeWidget,
|
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 {
|
impl<'a> IntoIterator for &'a WidgetList {
|
||||||
type IntoIter = slice::Iter<'a, WidgetInstance>;
|
type IntoIter = slice::Iter<'a, WidgetInstance>;
|
||||||
type Item = &'a WidgetInstance;
|
type Item = &'a WidgetInstance;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue