kas_core/action.rs
1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License in the LICENSE-APACHE file or at:
4// https://www.apache.org/licenses/LICENSE-2.0
5
6//! Action enum
7
8#[allow(unused)]
9use crate::event::{ConfigCx, EventCx, EventState};
10
11bitflags! {
12 /// Action required after processing
13 ///
14 /// Some methods operate directly on a context ([`ConfigCx`] or [`EventCx`])
15 /// while others don't reqiure a context but do require that some *action*
16 /// is performed afterwards. This enum is used to convey that action.
17 ///
18 /// An `Action` produced at run-time should be passed to a context, usually
19 /// via [`EventState::action`] (to associate the `Action` with a widget)
20 /// or [`EventState::window_action`] (if no particular widget is relevant).
21 ///
22 /// An `Action` produced before starting the GUI may be discarded, for
23 /// example: `let _ = runner.config_mut().font.set_size(24.0);`.
24 ///
25 /// Two `Action` values may be combined via bit-or (`a | b`).
26 #[must_use]
27 #[derive(Copy, Clone, Debug, Default)]
28 pub struct Action: u32 {
29 /// The whole window requires redrawing
30 ///
31 /// See also [`EventState::redraw`].
32 const REDRAW = 1 << 0;
33 /// Some widgets within a region moved
34 ///
35 /// Used when a pop-up is closed or a region adjusted (e.g. scroll or switch
36 /// tab) to update which widget is under the mouse cursor / touch events.
37 /// Identifier is that of the parent widget/window encapsulating the region.
38 ///
39 /// Implies window redraw.
40 ///
41 /// See also [`EventState::region_moved`].
42 const REGION_MOVED = 1 << 4;
43 /// A widget was scrolled
44 ///
45 /// This is used for inter-widget communication (see `EditBox`). If not
46 /// handled locally, it is handled identially to [`Self::SET_RECT`].
47 const SCROLLED = 1 << 6;
48 /// Reset size of all widgets without recalculating requirements
49 const SET_RECT = 1 << 8;
50 /// Resize all widgets in the window
51 ///
52 /// See also [`EventState::resize`].
53 const RESIZE = 1 << 9;
54 /// Update [`Dimensions`](crate::theme::dimensions::Dimensions) instances
55 /// and theme configuration.
56 ///
57 /// Implies [`Action::RESIZE`].
58 #[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
59 #[cfg_attr(docsrs, doc(cfg(internal_doc)))]
60 const THEME_UPDATE = 1 << 10;
61 /// Reload per-window cache of event configuration
62 ///
63 /// Implies [`Action::UPDATE`].
64 #[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
65 #[cfg_attr(docsrs, doc(cfg(internal_doc)))]
66 const EVENT_CONFIG = 1 << 11;
67 /// Switch themes, replacing theme-window instances
68 ///
69 /// Implies [`Action::RESIZE`].
70 #[cfg_attr(not(feature = "internal_doc"), doc(hidden))]
71 #[cfg_attr(docsrs, doc(cfg(internal_doc)))]
72 const THEME_SWITCH = 1 << 12;
73 /// Update all widgets
74 ///
75 /// This is a notification that input data has changed.
76 const UPDATE = 1 << 17;
77 /// The current window should be closed
78 ///
79 /// See also [`EventState::exit`] which closes the UI (all windows).
80 const CLOSE = 1 << 30;
81 }
82}