rust_widgets 2.4.0

Pure Rust cross-platform native GUI library with hardware-adaptive rendering, 60+ widgets, touch/gesture support, i18n, and SVG-pipeline-accurate output
// SPDX-FileCopyrightText: Copyright (c) 2026 Mike Li/Mikewolfli/Wei Li(mikewolfli@163.com)
// SPDX-License-Identifier: MIT

macro_rules! impl_other_widgets {
    () => {
        #[cfg(not(alloc_frugal))]
        fn create_canvas(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            self.mount_widget_of_kind(WidgetKind::Canvas, parent, "", x, y, width, height)
        }
        #[cfg(not(alloc_frugal))]
        fn create_grid(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            self.mount_widget_of_kind(WidgetKind::Grid, parent, "", x, y, width, height)
        }
        #[cfg(not(alloc_frugal))]
        fn create_chart(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            self.mount_widget_of_kind(WidgetKind::Chart, parent, "", x, y, width, height)
        }
        #[cfg(not(alloc_frugal))]
        fn create_radar_chart(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            self.mount_widget_of_kind(WidgetKind::RadarChart, parent, "", x, y, width, height)
        }
        #[cfg(not(alloc_frugal))]
        fn create_kanban_board(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            self.mount_widget_of_kind(WidgetKind::KanbanBoard, parent, "", x, y, width, height)
        }
        #[cfg(not(alloc_frugal))]
        fn create_cascader(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            self.mount_widget_of_kind(WidgetKind::Cascader, parent, "", x, y, width, height)
        }
        #[cfg(not(alloc_frugal))]
        fn create_query_builder(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            self.mount_widget_of_kind(WidgetKind::QueryBuilder, parent, "", x, y, width, height)
        }
        #[cfg(not(alloc_frugal))]
        fn create_emoji_picker(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            self.mount_widget_of_kind(WidgetKind::EmojiPicker, parent, "", x, y, width, height)
        }
        #[cfg(not(alloc_frugal))]
        fn create_mention(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            self.mount_widget_of_kind(WidgetKind::Mention, parent, "", x, y, width, height)
        }
        #[cfg(not(alloc_frugal))]
        fn create_web_view(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            // Mounted by **name**, not by kind. `WidgetKind::WebEngineView` is shared
            // with `MediaPlayer`, and while `capability_by_kind` now resolves the kind
            // to its own capability, going through the name says directly which
            // control is wanted — the same rule `create_web_engine_page` and
            // `mount_named_widget`'s own documentation lay out for shared kinds.
            #[cfg(full_widgets)]
            {
                self.mount_named_widget("web_engine_view", parent, "", x, y, width, height)
            }
            #[cfg(not(full_widgets))]
            {
                self.mount_widget_of_kind(WidgetKind::WebEngineView, parent, "", x, y, width, height)
            }
        }
        #[cfg(not(alloc_frugal))]
        fn create_activity_indicator(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            self.mount_widget_of_kind(
                WidgetKind::ActivityIndicator,
                parent,
                "",
                x,
                y,
                width,
                height,
            )
        }
        #[cfg(not(alloc_frugal))]
        fn create_lcd_number(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            self.mount_widget_of_kind(WidgetKind::LCDNumber, parent, "", x, y, width, height)
        }
        #[cfg(not(alloc_frugal))]
        fn create_web_engine_view(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            // By name: see `create_web_view` above for why a shared kind is not
            // sufficient to identify the control.
            #[cfg(full_widgets)]
            {
                self.mount_named_widget("web_engine_view", parent, "", x, y, width, height)
            }
            #[cfg(not(full_widgets))]
            {
                self.mount_widget_of_kind(WidgetKind::WebEngineView, parent, "", x, y, width, height)
            }
        }
        #[cfg(full_widgets)]
        fn create_web_engine_page(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            // The web engine's page/settings/download/… names address one view, so
            // they all mount the view named `web_engine_view`. They are deliberately
            // not `WidgetKind` variants: those named nothing any code path could
            // produce, so a kind lookup resolved to the empty constructor name and
            // returned `0`.
            #[cfg(full_widgets)]
            {
                self.mount_named_widget("web_engine_view", parent, "", x, y, width, height)
            }
            #[cfg(not(full_widgets))]
            {
                self.mount_widget_of_kind(WidgetKind::WebEngineView, parent, "", x, y, width, height)
            }
        }
        #[cfg(full_widgets)]
        fn create_web_engine_settings(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            #[cfg(full_widgets)]
            {
                self.mount_named_widget("web_engine_view", parent, "", x, y, width, height)
            }
            #[cfg(not(full_widgets))]
            {
                self.mount_widget_of_kind(WidgetKind::WebEngineView, parent, "", x, y, width, height)
            }
        }
        #[cfg(full_widgets)]
        fn create_web_engine_download_item(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            #[cfg(full_widgets)]
            {
                self.mount_named_widget("web_engine_view", parent, "", x, y, width, height)
            }
            #[cfg(not(full_widgets))]
            {
                self.mount_widget_of_kind(WidgetKind::WebEngineView, parent, "", x, y, width, height)
            }
        }
        #[cfg(full_widgets)]
        fn create_web_engine_cookie_store(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            #[cfg(full_widgets)]
            {
                self.mount_named_widget("web_engine_view", parent, "", x, y, width, height)
            }
            #[cfg(not(full_widgets))]
            {
                self.mount_widget_of_kind(WidgetKind::WebEngineView, parent, "", x, y, width, height)
            }
        }
        #[cfg(full_widgets)]
        fn create_web_engine_web_channel(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            #[cfg(full_widgets)]
            {
                self.mount_named_widget("web_engine_view", parent, "", x, y, width, height)
            }
            #[cfg(not(full_widgets))]
            {
                self.mount_widget_of_kind(WidgetKind::WebEngineView, parent, "", x, y, width, height)
            }
        }
        #[cfg(full_widgets)]
        fn create_web_engine_find_text_result(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            #[cfg(full_widgets)]
            {
                self.mount_named_widget("web_engine_view", parent, "", x, y, width, height)
            }
            #[cfg(not(full_widgets))]
            {
                self.mount_widget_of_kind(WidgetKind::WebEngineView, parent, "", x, y, width, height)
            }
        }
        #[cfg(full_widgets)]
        fn create_web_engine_notification(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            #[cfg(full_widgets)]
            {
                self.mount_named_widget("web_engine_view", parent, "", x, y, width, height)
            }
            #[cfg(not(full_widgets))]
            {
                self.mount_widget_of_kind(WidgetKind::WebEngineView, parent, "", x, y, width, height)
            }
        }
        #[cfg(full_widgets)]
        fn create_web_engine_script_dialog(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            #[cfg(full_widgets)]
            {
                self.mount_named_widget("web_engine_view", parent, "", x, y, width, height)
            }
            #[cfg(not(full_widgets))]
            {
                self.mount_widget_of_kind(WidgetKind::WebEngineView, parent, "", x, y, width, height)
            }
        }
        #[cfg(full_widgets)]
        fn create_web_engine_context_menu_request(
            &self,
            parent: ObjectId,
            x: i32,
            y: i32,
            width: u32,
            height: u32,
        ) -> ObjectId {
            #[cfg(full_widgets)]
            {
                self.mount_named_widget("web_engine_view", parent, "", x, y, width, height)
            }
            #[cfg(not(full_widgets))]
            {
                self.mount_widget_of_kind(WidgetKind::WebEngineView, parent, "", x, y, width, height)
            }
        }
    };
}