Struct App

Source
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>

Source

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
Hide additional 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}
Source

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>

Source§

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, )

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, )

Emitted when the OS sends an event to a device.
Source§

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)

Emitted when the application has been suspended. Read more
Source§

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)

Emitted when the event loop is about to block and wait for new events. Read more
Source§

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)

Emitted when the application has received a memory warning. Read more

Auto Trait Implementations§

§

impl<AppData, O> Freeze for App<AppData, O>
where O: Freeze, <O as FnPersist<AppData, HashMap<Arc<SourceID>, Option<Window>>>>::Store: Freeze,

§

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>
where O: Unpin, <O as FnPersist<AppData, HashMap<Arc<SourceID>, Option<Window>>>>::Store: Unpin,

§

impl<AppData, O> !UnwindSafe for App<AppData, O>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

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>

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)

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)

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> MaybeSend for T