pub struct App<AppData: 'static + PartialEq, O: FnPersist<AppData, HashMap<Arc<SourceID>, Option<Window>>>> {
pub instance: Instance,
pub driver: Weak<Driver>,
/* private fields */
}
Fields§
§instance: Instance
§driver: Weak<Driver>
Implementations§
Source§impl<AppData: PartialEq, O: FnPersist<AppData, HashMap<Arc<SourceID>, Option<Window>>>> App<AppData, O>
impl<AppData: PartialEq, O: FnPersist<AppData, HashMap<Arc<SourceID>, Option<Window>>>> App<AppData, O>
Sourcepub fn new<T: 'static>(
app_state: AppData,
inputs: Vec<AppEvent<AppData>>,
outline: O,
driver_init: impl FnOnce(Weak<Driver>) + 'static,
) -> Result<(Self, EventLoop<T>)>
pub fn new<T: 'static>( app_state: AppData, inputs: Vec<AppEvent<AppData>>, outline: O, driver_init: impl FnOnce(Weak<Driver>) + 'static, ) -> Result<(Self, EventLoop<T>)>
Examples found in repository?
examples/paragraph-rs.rs (lines 184-191)
182fn main() {
183 let (mut app, event_loop): (App<Blocker, BasicApp>, winit::event_loop::EventLoop<()>) =
184 App::new(
185 Blocker {
186 area: AbsRect::new(-1.0, -1.0, -1.0, -1.0),
187 },
188 vec![],
189 BasicApp {},
190 |_| (),
191 )
192 .unwrap();
193
194 event_loop.run_app(&mut app).unwrap();
195}
More examples
examples/textbox-rs.rs (lines 122-129)
120fn main() {
121 let (mut app, event_loop): (App<TextState, BasicApp>, winit::event_loop::EventLoop<()>) =
122 App::new(
123 TextState {
124 text: EditBuffer::new("new text", (0, 0)).into(),
125 },
126 vec![],
127 BasicApp {},
128 |_| (),
129 )
130 .unwrap();
131
132 event_loop.run_app(&mut app).unwrap();
133}
examples/basic-rs.rs (lines 217-222)
201fn main() {
202 let onclick = Box::new(
203 |_: mouse_area::MouseAreaEvent,
204 mut appdata: CounterState|
205 -> Result<CounterState, CounterState> {
206 {
207 appdata.count += 1;
208 Ok(appdata)
209 }
210 }
211 .wrap(),
212 );
213
214 let (mut app, event_loop): (
215 App<CounterState, BasicApp>,
216 winit::event_loop::EventLoop<()>,
217 ) = App::new(
218 CounterState { count: 0 },
219 vec![onclick],
220 BasicApp {},
221 |_| (),
222 )
223 .unwrap();
224
225 event_loop.run_app(&mut app).unwrap();
226}
examples/grid-rs.rs (lines 275-280)
259fn main() {
260 let onclick = Box::new(
261 |_: mouse_area::MouseAreaEvent,
262 mut appdata: CounterState|
263 -> Result<CounterState, CounterState> {
264 {
265 appdata.count += 1;
266 Ok(appdata)
267 }
268 }
269 .wrap(),
270 );
271
272 let (mut app, event_loop): (
273 App<CounterState, BasicApp>,
274 winit::event_loop::EventLoop<()>,
275 ) = App::new(
276 CounterState { count: 0 },
277 vec![onclick],
278 BasicApp {},
279 |_| (),
280 )
281 .unwrap();
282
283 event_loop.run_app(&mut app).unwrap();
284}
examples/list-rs.rs (lines 318-323)
302fn main() {
303 let onclick = Box::new(
304 |_: mouse_area::MouseAreaEvent,
305 mut appdata: CounterState|
306 -> Result<CounterState, CounterState> {
307 {
308 appdata.count += 1;
309 Ok(appdata)
310 }
311 }
312 .wrap(),
313 );
314
315 let (mut app, event_loop): (
316 App<CounterState, BasicApp>,
317 feather_ui::winit::event_loop::EventLoop<()>,
318 ) = App::new(
319 CounterState { count: 0 },
320 vec![onclick],
321 BasicApp {},
322 |_| (),
323 )
324 .unwrap();
325
326 event_loop.run_app(&mut app).unwrap();
327}
examples/graph-rs.rs (lines 242-252)
185fn main() {
186 let handle_input = Box::new(
187 |e: mouse_area::MouseAreaEvent,
188 mut appdata: GraphState|
189 -> Result<GraphState, GraphState> {
190 match e {
191 mouse_area::MouseAreaEvent::OnClick(MouseButton::Left, pos) => {
192 if let Some(selected) = appdata.selected {
193 for i in 0..appdata.nodes.len() {
194 let diff = appdata.nodes[i] - pos + appdata.offset;
195 if diff.dot(diff) < NODE_RADIUS * NODE_RADIUS {
196 if appdata.edges.contains(&(selected, i)) {
197 appdata.edges.remove(&(i, selected));
198 appdata.edges.remove(&(selected, i));
199 } else {
200 appdata.edges.insert((selected, i));
201 appdata.edges.insert((i, selected));
202 }
203 break;
204 }
205 }
206
207 appdata.selected = None;
208 } else {
209 // Check to see if we're anywhere near a node (yes this is inefficient but we don't care right now)
210 for i in 0..appdata.nodes.len() {
211 let diff = appdata.nodes[i] - pos + appdata.offset;
212 if diff.dot(diff) < NODE_RADIUS * NODE_RADIUS {
213 appdata.selected = Some(i);
214 return Ok(appdata);
215 }
216 }
217
218 // TODO: maybe make this require shift click
219 appdata.nodes.push(pos - appdata.offset);
220 }
221
222 Ok(appdata)
223 }
224 mouse_area::MouseAreaEvent::OnDblClick(MouseButton::Left, pos) => {
225 // TODO: winit currently doesn't capture double clicks
226 appdata.nodes.push(pos - appdata.offset);
227 Ok(appdata)
228 }
229 mouse_area::MouseAreaEvent::OnDrag(MouseButton::Left, diff) => {
230 appdata.offset += diff;
231 Ok(appdata)
232 }
233 _ => Ok(appdata),
234 }
235 }
236 .wrap(),
237 );
238
239 let (mut app, event_loop): (
240 App<GraphState, BasicApp>,
241 feather_ui::winit::event_loop::EventLoop<()>,
242 ) = App::new(
243 GraphState {
244 nodes: vec![],
245 edges: HashSet::new(),
246 offset: Vec2::new(-5000.0, -5000.0),
247 selected: None,
248 },
249 vec![handle_input],
250 BasicApp {},
251 |_| (),
252 )
253 .unwrap();
254
255 event_loop.run_app(&mut app).unwrap();
256}
pub fn new_any_thread<T: 'static>( app_state: AppData, inputs: Vec<AppEvent<AppData>>, outline: O, any_thread: bool, driver_init: impl FnOnce(Weak<Driver>) + 'static, ) -> Result<(Self, EventLoop<T>)>
Trait Implementations§
Source§impl<AppData: PartialEq, T: 'static, O: FnPersist<AppData, HashMap<Arc<SourceID>, Option<Window>>>> ApplicationHandler<T> for App<AppData, O>
impl<AppData: PartialEq, T: 'static, O: FnPersist<AppData, HashMap<Arc<SourceID>, Option<Window>>>> ApplicationHandler<T> for App<AppData, O>
Source§fn resumed(&mut self, event_loop: &ActiveEventLoop)
fn resumed(&mut self, event_loop: &ActiveEventLoop)
Emitted when the application has been resumed. Read more
Source§fn window_event(
&mut self,
event_loop: &ActiveEventLoop,
window_id: WindowId,
event: WindowEvent,
)
fn window_event( &mut self, event_loop: &ActiveEventLoop, window_id: WindowId, event: WindowEvent, )
Emitted when the OS sends an event to a winit window.
Source§fn device_event(
&mut self,
event_loop: &ActiveEventLoop,
device_id: DeviceId,
event: DeviceEvent,
)
fn device_event( &mut self, event_loop: &ActiveEventLoop, device_id: DeviceId, event: DeviceEvent, )
Emitted when the OS sends an event to a device.
Source§fn user_event(&mut self, event_loop: &ActiveEventLoop, _: T)
fn user_event(&mut self, event_loop: &ActiveEventLoop, _: T)
Emitted when an event is sent from
EventLoopProxy::send_event
.Source§fn suspended(&mut self, event_loop: &ActiveEventLoop)
fn suspended(&mut self, event_loop: &ActiveEventLoop)
Emitted when the application has been suspended. Read more
Source§fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause)
fn new_events(&mut self, event_loop: &ActiveEventLoop, cause: StartCause)
Emitted when new events arrive from the OS to be processed. Read more
Source§fn about_to_wait(&mut self, event_loop: &ActiveEventLoop)
fn about_to_wait(&mut self, event_loop: &ActiveEventLoop)
Emitted when the event loop is about to block and wait for new events. Read more
Source§fn exiting(&mut self, event_loop: &ActiveEventLoop)
fn exiting(&mut self, event_loop: &ActiveEventLoop)
Emitted when the event loop is being shut down. Read more
Source§fn memory_warning(&mut self, event_loop: &ActiveEventLoop)
fn memory_warning(&mut self, event_loop: &ActiveEventLoop)
Emitted when the application has received a memory warning. Read more
Auto Trait Implementations§
impl<AppData, O> Freeze for App<AppData, O>
impl<AppData, O> !RefUnwindSafe for App<AppData, O>
impl<AppData, O> !Send for App<AppData, O>
impl<AppData, O> !Sync for App<AppData, O>
impl<AppData, O> Unpin for App<AppData, O>
impl<AppData, O> !UnwindSafe for App<AppData, O>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more