Compare commits
2 Commits
f7b100e00c
...
23ae5b246e
| Author | SHA1 | Date | |
|---|---|---|---|
| 23ae5b246e | |||
| db888416b6 |
20
examples/minimal.rs
Normal file
20
examples/minimal.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
use iris::{prelude::*, winit::*};
|
||||||
|
|
||||||
|
struct State {
|
||||||
|
ui: DefaultUi,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
UiApp::<State>::run();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DefaultUiState for State {
|
||||||
|
fn new(mut ui: DefaultUi, _proxy: Proxy<Self::Event>) -> Self {
|
||||||
|
rect(Color::RED).set_root(&mut ui);
|
||||||
|
Self { ui }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ui(&mut self) -> &mut DefaultUi {
|
||||||
|
&mut self.ui
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#![feature(const_destruct)]
|
#![feature(const_destruct)]
|
||||||
#![feature(portable_simd)]
|
#![feature(portable_simd)]
|
||||||
#![feature(gen_blocks)]
|
#![feature(gen_blocks)]
|
||||||
|
#![feature(associated_type_defaults)]
|
||||||
|
|
||||||
pub mod core;
|
pub mod core;
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use std::sync::Arc;
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use winit::event::{Ime, WindowEvent};
|
use winit::event::{Ime, WindowEvent};
|
||||||
use winit::event_loop::{ActiveEventLoop, EventLoopProxy};
|
use winit::event_loop::{ActiveEventLoop, EventLoopProxy};
|
||||||
use winit::window::Window;
|
use winit::window::{Window, WindowAttributes};
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
pub mod attr;
|
pub mod attr;
|
||||||
@@ -31,7 +31,7 @@ pub struct DefaultUi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait DefaultUiState: 'static {
|
pub trait DefaultUiState: 'static {
|
||||||
type Event: 'static;
|
type Event: 'static = ();
|
||||||
fn new(ui: DefaultUi, proxy: Proxy<Self::Event>) -> Self;
|
fn new(ui: DefaultUi, proxy: Proxy<Self::Event>) -> Self;
|
||||||
fn ui(&mut self) -> &mut DefaultUi;
|
fn ui(&mut self) -> &mut DefaultUi;
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
@@ -39,6 +39,9 @@ pub trait DefaultUiState: 'static {
|
|||||||
fn exit(&mut self) {}
|
fn exit(&mut self) {}
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn window_event(&mut self, event: WindowEvent) {}
|
fn window_event(&mut self, event: WindowEvent) {}
|
||||||
|
fn window_attrs() -> WindowAttributes {
|
||||||
|
WindowAttributes::default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<State: DefaultUiState> UiState for State {
|
impl<State: DefaultUiState> UiState for State {
|
||||||
@@ -47,8 +50,8 @@ impl<State: DefaultUiState> UiState for State {
|
|||||||
fn new(event_loop: &ActiveEventLoop, proxy: EventLoopProxy<Self::Event>) -> Self {
|
fn new(event_loop: &ActiveEventLoop, proxy: EventLoopProxy<Self::Event>) -> Self {
|
||||||
let window = Arc::new(
|
let window = Arc::new(
|
||||||
event_loop
|
event_loop
|
||||||
.create_window(Window::default_attributes().with_title("OPENWORM"))
|
.create_window(Self::window_attrs())
|
||||||
.unwrap(),
|
.expect("failed to create window "),
|
||||||
);
|
);
|
||||||
let ui = DefaultUi {
|
let ui = DefaultUi {
|
||||||
renderer: UiRenderer::new(window.clone()),
|
renderer: UiRenderer::new(window.clone()),
|
||||||
|
|||||||
Reference in New Issue
Block a user