Skip to main content

uzor_framework/widgets/
composites.rs

1//! The composite half of the `lm` set. Each call registers the composite
2//! with the hook's coordinator and paints it with the library draw
3//! function. Opening an overlay is still an [`crate::OverlayCmd`] issued
4//! by the app; these functions draw a frame the kernel (or the hook) asks
5//! for. Blackbox panels are not here (design ยง7.2: the app `panel` hook
6//! replaces that slot).
7
8use uzor::ui::widgets::composite::chrome::{
9    draw_chrome, register_input_coordinator_chrome, ChromeRenderKind, ChromeSettings, ChromeState,
10    ChromeView,
11};
12use uzor::ui::widgets::composite::context_menu::{
13    draw_context_menu, register_input_coordinator_context_menu, ContextMenuRenderKind,
14    ContextMenuSettings, ContextMenuState, ContextMenuView,
15};
16use uzor::ui::widgets::composite::dropdown::{
17    draw_dropdown, register_input_coordinator_dropdown, DropdownRenderKind, DropdownSettings,
18    DropdownState, DropdownView,
19};
20use uzor::ui::widgets::composite::modal::render::draw_modal;
21use uzor::ui::widgets::composite::modal::{
22    register_input_coordinator_modal, ModalRenderKind, ModalSettings, ModalState, ModalView,
23};
24use uzor::ui::widgets::composite::panel::{
25    draw_panel, register_input_coordinator_panel, PanelRenderKind, PanelSettings, PanelState,
26    PanelView,
27};
28use uzor::ui::widgets::composite::popup::render::draw_popup;
29use uzor::ui::widgets::composite::popup::{
30    register_input_coordinator_popup, PopupRenderKind, PopupSettings, PopupState, PopupView,
31};
32use uzor::ui::widgets::composite::sidebar::{
33    draw_sidebar, register_input_coordinator_sidebar, SidebarRenderKind, SidebarSettings,
34    SidebarState, SidebarView,
35};
36use uzor::ui::widgets::composite::toolbar::render::draw_toolbar;
37use uzor::ui::widgets::composite::toolbar::{
38    register_input_coordinator_toolbar, ToolbarRenderKind, ToolbarSettings, ToolbarState,
39    ToolbarView,
40};
41use uzor::Rect;
42use uzor::WidgetId;
43
44use super::host::ContentCx;
45
46/// Register and draw a window chrome strip.
47pub fn chrome<'a, C: ContentCx<'a>>(
48    cx: &mut C,
49    id: impl Into<WidgetId>,
50    rect: Rect,
51    state: &ChromeState,
52    view: &ChromeView<'_>,
53    settings: &ChromeSettings,
54    kind: &ChromeRenderKind,
55) {
56    let id = id.into();
57    cx.with_paint(|render, widgets, _visual, _tokens| {
58        chrome_paint(render, widgets, id, rect, state, view, settings, kind);
59    });
60}
61
62pub(crate) fn chrome_paint(
63    render: &mut dyn uzor::render::RenderContext,
64    widgets: &mut crate::handle::Widgets<'_>,
65    id: WidgetId,
66    rect: Rect,
67    state: &ChromeState,
68    view: &ChromeView<'_>,
69    settings: &ChromeSettings,
70    kind: &ChromeRenderKind,
71) {
72    let _cid = register_input_coordinator_chrome(
73        widgets.coord,
74        id,
75        rect,
76        state,
77        view,
78        settings,
79        kind,
80        &widgets.layer,
81    );
82    draw_chrome(render, rect, state, view, settings, kind);
83}
84
85/// Register and draw a modal frame. `state.position == (0, 0)` keeps `rect`.
86pub fn modal<'a, C: ContentCx<'a>>(
87    cx: &mut C,
88    id: impl Into<WidgetId>,
89    rect: Rect,
90    state: &mut ModalState,
91    view: &mut ModalView<'_>,
92    settings: &ModalSettings,
93    kind: &ModalRenderKind,
94) {
95    let id = id.into();
96    cx.with_paint(|render, widgets, _visual, _tokens| {
97        let _cid = register_input_coordinator_modal(
98            widgets.coord,
99            id,
100            rect,
101            state,
102            view,
103            settings,
104            kind,
105            &widgets.layer,
106        );
107        draw_modal(render, rect, state, view, settings, kind);
108    });
109}
110
111/// Register and draw a dropdown panel.
112pub fn dropdown<'a, C: ContentCx<'a>>(
113    cx: &mut C,
114    id: impl Into<WidgetId>,
115    rect: Rect,
116    state: &DropdownState,
117    view: &DropdownView<'_>,
118    settings: &DropdownSettings,
119    kind: DropdownRenderKind,
120) {
121    let id = id.into();
122    cx.with_paint(|render, widgets, _visual, _tokens| {
123        let _cid = register_input_coordinator_dropdown(
124            widgets.coord,
125            id,
126            rect,
127            state,
128            view,
129            settings,
130            kind,
131            &widgets.layer,
132        );
133        draw_dropdown(render, rect, state, view, settings, kind);
134    });
135}
136
137/// Register and draw a context menu. The frame origin is `state.x/y`.
138pub fn context_menu<'a, C: ContentCx<'a>>(
139    cx: &mut C,
140    id: impl Into<WidgetId>,
141    state: &ContextMenuState,
142    view: &ContextMenuView<'_>,
143    settings: &ContextMenuSettings,
144    kind: &ContextMenuRenderKind<'_>,
145) {
146    let id = id.into();
147    cx.with_paint(|render, widgets, _visual, _tokens| {
148        let _cid = register_input_coordinator_context_menu(
149            widgets.coord,
150            id,
151            state,
152            view,
153            settings,
154            kind,
155            &widgets.layer,
156        );
157        draw_context_menu(render, state, view, settings, kind);
158    });
159}
160
161/// Register and draw a popup frame.
162pub fn popup<'a, C: ContentCx<'a>>(
163    cx: &mut C,
164    id: impl Into<WidgetId>,
165    rect: Rect,
166    state: &mut PopupState,
167    view: &mut PopupView<'_>,
168    settings: &PopupSettings,
169    kind: PopupRenderKind,
170) {
171    let id = id.into();
172    cx.with_paint(|render, widgets, _visual, _tokens| {
173        let _cid = register_input_coordinator_popup(
174            widgets.coord,
175            id,
176            rect,
177            state,
178            view,
179            settings,
180            kind,
181            &widgets.layer,
182        );
183        draw_popup(render, rect, state, view, settings, kind);
184    });
185}
186
187/// Register and draw a panel frame (header / columns / body / footer per
188/// `kind`). `state` is the caller's persistent scroll and sort.
189pub fn panel<'a, C: ContentCx<'a>>(
190    cx: &mut C,
191    id: impl Into<WidgetId>,
192    rect: Rect,
193    state: &mut PanelState,
194    view: &mut PanelView<'_>,
195    settings: &PanelSettings,
196    kind: &PanelRenderKind,
197) {
198    let id = id.into();
199    cx.with_paint(|render, widgets, _visual, _tokens| {
200        let cid = {
201            register_input_coordinator_panel(
202                widgets.coord,
203                id,
204                rect,
205                state,
206                view,
207                settings,
208                kind,
209                &widgets.layer,
210            )
211        };
212        draw_panel(
213            render,
214            rect,
215            widgets.coord,
216            &cid,
217            state,
218            view,
219            settings,
220            kind,
221        );
222    });
223}
224
225/// Register and draw an edge sidebar.
226pub fn sidebar<'a, C: ContentCx<'a>>(
227    cx: &mut C,
228    id: impl Into<WidgetId>,
229    rect: Rect,
230    state: &mut SidebarState,
231    view: &mut SidebarView<'_>,
232    settings: &SidebarSettings,
233    kind: &SidebarRenderKind,
234) {
235    let id = id.into();
236    cx.with_paint(|render, widgets, _visual, _tokens| {
237        let _cid = register_input_coordinator_sidebar(
238            widgets.coord,
239            id,
240            rect,
241            state,
242            view,
243            settings,
244            kind,
245            &widgets.layer,
246        );
247        draw_sidebar(render, rect, state, view, settings, kind);
248    });
249}
250
251/// Register and draw a toolbar strip.
252pub fn toolbar<'a, C: ContentCx<'a>>(
253    cx: &mut C,
254    id: impl Into<WidgetId>,
255    rect: Rect,
256    state: &ToolbarState,
257    view: &ToolbarView<'_>,
258    settings: &ToolbarSettings,
259    kind: &ToolbarRenderKind,
260) {
261    let id = id.into();
262    cx.with_paint(|render, widgets, _visual, _tokens| {
263        let _cid = register_input_coordinator_toolbar(
264            widgets.coord,
265            id,
266            rect,
267            state,
268            view,
269            settings,
270            kind,
271            &widgets.layer,
272        );
273        draw_toolbar(render, rect, state, view, settings, kind);
274    });
275}