#![allow(non_snake_case)]
use dioxus_core::{Callback, Element, EventHandler};
use dioxus_core_macro::{Props, component, rsx};
use dioxus_hooks::use_signal;
use dioxus_signals::WritableExt as _;
use crate as dioxus_elements;
use crate::Key;
use crate::drawing::DrawList;
use crate::schema::{
Alignment, Arrangement, ButtonVariant, ColorRole, IconRole, MaterialRole, MotionRole, Paint,
ShapeRole, SlotRole, SpaceRole, TextAlign, TextOverflow, TypeRole,
};
use std::cell::Cell;
use std::rc::Rc;
#[derive(Clone, Debug)]
pub struct KeyEvent {
key: Key,
shift_key: bool,
ctrl_key: bool,
alt_key: bool,
meta_key: bool,
consumed: Rc<Cell<bool>>,
}
impl KeyEvent {
pub(crate) fn new(
key: Key,
shift_key: bool,
ctrl_key: bool,
alt_key: bool,
meta_key: bool,
) -> Self {
Self {
key,
shift_key,
ctrl_key,
alt_key,
meta_key,
consumed: Rc::new(Cell::new(false)),
}
}
pub fn key(&self) -> Key {
self.key
}
pub fn shift_key(&self) -> bool {
self.shift_key
}
pub fn ctrl_key(&self) -> bool {
self.ctrl_key
}
pub fn alt_key(&self) -> bool {
self.alt_key
}
pub fn meta_key(&self) -> bool {
self.meta_key
}
pub fn consume(&self) {
self.consumed.set(true);
}
pub fn consumed(&self) -> bool {
self.consumed.get()
}
}
fn role(value: Option<impl Into<u16>>) -> i64 {
value.map_or(0, |value| i64::from(value.into()))
}
fn opt_dp(value: Option<f32>) -> Option<f64> {
value.map(f64::from)
}
fn opt_role(value: Option<impl Into<u16>>) -> Option<i64> {
value.map(|value| i64::from(value.into()))
}
fn opt_paint(value: Option<Paint>) -> Option<i64> {
value.map(|paint| paint.to_bits() as i64)
}
fn dp(value: Option<f32>) -> f64 {
f64::from(value.unwrap_or(0.0))
}
#[component]
pub fn Column(
#[props(default)]
observe_size: Option<i64>,
#[props(default)]
motion: Option<MotionRole>,
#[props(default)]
material: Option<MaterialRole>,
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] arrangement: Option<Arrangement>,
#[props(default)] spacing: Option<f32>,
#[props(default)] space_role: Option<SpaceRole>,
#[props(default)] alignment: Option<Alignment>,
children: Element,
) -> Element {
rsx! {
column {
observe_size,
motion: opt_role(motion),
material: opt_role(material),
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
arrangement: role(arrangement),
spacing: dp(spacing),
space_role: role(space_role),
alignment: role(alignment),
{children}
}
}
}
#[component]
pub fn Row(
#[props(default)]
observe_size: Option<i64>,
#[props(default)]
motion: Option<MotionRole>,
#[props(default)]
material: Option<MaterialRole>,
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] arrangement: Option<Arrangement>,
#[props(default)] spacing: Option<f32>,
#[props(default)] space_role: Option<SpaceRole>,
#[props(default)] alignment: Option<Alignment>,
children: Element,
) -> Element {
rsx! {
row {
observe_size,
motion: opt_role(motion),
material: opt_role(material),
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
arrangement: role(arrangement),
spacing: dp(spacing),
space_role: role(space_role),
alignment: role(alignment),
{children}
}
}
}
#[component]
pub fn ComposeBox(
#[props(default)]
observe_size: Option<i64>,
#[props(default)]
motion: Option<MotionRole>,
#[props(default)]
material: Option<MaterialRole>,
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] alignment: Option<Alignment>,
children: Element,
) -> Element {
rsx! {
composebox {
observe_size,
motion: opt_role(motion),
material: opt_role(material),
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
alignment: role(alignment),
{children}
}
}
}
#[component]
pub fn ScrollColumn(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
children: Element,
) -> Element {
rsx! {
scrollcolumn {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
{children}
}
}
}
#[component]
pub fn Text(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)]
spans: crate::spans::TextSpans,
#[props(into)] text: String,
#[props(default)] type_role: Option<TypeRole>,
#[props(default)] font_size: Option<f32>,
#[props(default)] font_weight: Option<u16>,
#[props(default)] line_height: Option<f32>,
#[props(default)] letter_spacing: Option<f32>,
#[props(default)] color: Option<Paint>,
#[props(default)] text_align: Option<TextAlign>,
#[props(default)] max_lines: Option<u32>,
#[props(default)] overflow: Option<TextOverflow>,
) -> Element {
rsx! {
text {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
spans: (!spans.is_empty()).then_some(spans),
text,
type_role: role(type_role),
font_size: dp(font_size),
font_weight: i64::from(font_weight.unwrap_or(0)),
line_height: dp(line_height),
letter_spacing: dp(letter_spacing),
color: color.map_or(0, |paint| paint.to_bits() as i64),
text_align: role(text_align),
max_lines: i64::from(max_lines.unwrap_or(0)),
overflow: role(overflow),
}
}
}
#[component]
pub fn TextField(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(into, default)] placeholder: String,
#[props(default = true)] enabled: bool,
#[props(default)] multiline: bool,
#[props(default)]
type_role: Option<TypeRole>,
#[props(default)] on_value_change: EventHandler<String>,
#[props(default)] on_submit: EventHandler<String>,
#[props(default)] on_focus_lost: EventHandler<()>,
#[props(default)] on_key_down: EventHandler<KeyEvent>,
) -> Element {
rsx! {
textfield {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
placeholder,
enabled,
multiline,
type_role: role(type_role),
onvaluechange: move |event| on_value_change.call((*event.data()).clone()),
onsubmit: move |event| on_submit.call((*event.data()).clone()),
onfocuslost: move |_| on_focus_lost.call(()),
onkeydown: move |event| on_key_down.call((*event.data()).clone()),
}
}
}
#[component]
pub fn Button(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(into)] text: String,
#[props(default)]
icon: Option<IconRole>,
#[props(default = true)] enabled: bool,
#[props(default)] variant: Option<ButtonVariant>,
#[props(default)]
color: Option<Paint>,
#[props(default)] on_click: EventHandler<()>,
) -> Element {
rsx! {
button {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
text,
icon: opt_role(icon),
enabled,
variant: role(variant),
color: opt_paint(color),
onclick: move |_| on_click.call(()),
}
}
}
#[component]
pub fn Separator(#[props(default)] color: Option<Paint>) -> Element {
rsx! {
Divider { background: color }
}
}
#[component]
pub fn Spacer(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
) -> Element {
rsx! {
spacer {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct FileDrop {
paths: Vec<String>,
}
impl FileDrop {
pub fn new(joined: &str) -> Self {
Self {
paths: joined
.split('\0')
.filter(|path| !path.is_empty())
.map(str::to_owned)
.collect(),
}
}
pub fn paths(&self) -> &[String] {
&self.paths
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct RangeRequest {
start: u32,
count: u32,
}
impl RangeRequest {
pub(crate) fn new(start: u32, count: u32) -> Self {
Self { start, count }
}
pub fn start(&self) -> usize {
self.start as usize
}
pub fn count(&self) -> usize {
self.count as usize
}
}
#[component]
pub fn LazyColumn(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
item_count: usize,
#[props(default)] key_of: Option<Callback<usize, String>>,
item: Callback<usize, Element>,
) -> Element {
let mut range = use_signal(|| (0_usize, 0_usize));
let (start, count) = range();
let first = start.min(item_count);
let last = first.saturating_add(count).min(item_count);
rsx! {
lazycolumn {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
item_count: item_count as i64,
onrangerequest: move |event: dioxus_core::Event<RangeRequest>| {
let requested = event.data();
range.set((requested.start(), requested.count()));
},
for index in first..last {
{
let item_key = key_of
.map_or_else(|| index.to_string(), |key_of| key_of.call(index));
rsx! {
composebox { key: "{item_key}", item_key, {item.call(index)} }
}
}
}
}
}
}
#[component]
pub fn Card(
#[props(default)]
observe_size: Option<i64>,
#[props(default)]
motion: Option<MotionRole>,
#[props(default)]
material: Option<MaterialRole>,
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
children: Element,
) -> Element {
rsx! {
card {
observe_size,
motion: opt_role(motion),
material: opt_role(material),
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
{children}
}
}
}
#[component]
pub fn Surface(
#[props(default)]
observe_size: Option<i64>,
#[props(default)]
motion: Option<MotionRole>,
#[props(default)]
material: Option<MaterialRole>,
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
children: Element,
) -> Element {
rsx! {
surface {
observe_size,
motion: opt_role(motion),
material: opt_role(material),
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
{children}
}
}
}
#[component]
pub fn Dialog(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] open: bool,
#[props(default)] on_dismiss: EventHandler<()>,
children: Element,
) -> Element {
rsx! {
dialog {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
open,
ondismiss: move |_| on_dismiss.call(()),
{children}
}
}
}
#[component]
pub fn Menu(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] expanded: bool,
#[props(default)] on_dismiss: EventHandler<()>,
anchor: Element,
children: Element,
) -> Element {
rsx! {
menu {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
open: expanded,
ondismiss: move |_| on_dismiss.call(()),
{anchor}
{children}
}
}
}
#[component]
pub fn Tabs(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)]
color: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] selected_index: usize,
children: Element,
) -> Element {
rsx! {
tabs {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
color: opt_paint(color),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
selected_index: selected_index as i64,
{children}
}
}
}
#[component]
pub fn TopAppBar(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)]
title: String,
children: Element,
) -> Element {
rsx! {
topappbar {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
text: title,
{children}
}
}
}
#[component]
pub fn LazyRow(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
item_count: usize,
#[props(default)] key_of: Option<Callback<usize, String>>,
item: Callback<usize, Element>,
) -> Element {
let mut range = use_signal(|| (0_usize, 0_usize));
let (start, count) = range();
let first = start.min(item_count);
let last = first.saturating_add(count).min(item_count);
rsx! {
lazyrow {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
item_count: item_count as i64,
onrangerequest: move |event: dioxus_core::Event<RangeRequest>| {
let requested = event.data();
range.set((requested.start(), requested.count()));
},
for index in first..last {
{
let item_key = key_of
.map_or_else(|| index.to_string(), |key_of| key_of.call(index));
rsx! {
composebox { key: "{item_key}", item_key, {item.call(index)} }
}
}
}
}
}
}
#[component]
pub fn Tooltip(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(into)] text: String,
children: Element,
) -> Element {
rsx! {
tooltip {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
text,
{children}
}
}
}
#[component]
pub fn Canvas(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
commands: DrawList,
) -> Element {
rsx! {
canvas {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
commands,
}
}
}
#[component]
pub fn Image(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
asset_id: u32,
) -> Element {
rsx! {
image {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
asset: i64::from(asset_id),
}
}
}
#[component]
pub fn Icon(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
asset_id: u32,
#[props(default)] color: Option<Paint>,
) -> Element {
rsx! {
icon {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
asset: i64::from(asset_id),
color: color.map_or(0, |paint| paint.to_bits() as i64),
}
}
}
#[component]
pub fn DatePicker(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
value: i64,
#[props(default)] min: Option<i64>,
#[props(default)] max: Option<i64>,
#[props(default = true)] enabled: bool,
#[props(default)] on_change: EventHandler<i64>,
) -> Element {
rsx! {
datepicker {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
value,
min: min.unwrap_or(i64::MIN),
max: max.unwrap_or(i64::MAX),
enabled,
onchange: move |event: dioxus_core::Event<f64>| on_change.call(*event.data() as i64),
}
}
}
#[component]
pub fn TimePicker(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
value: u32,
#[props(default)] min: Option<u32>,
#[props(default)] max: Option<u32>,
#[props(default = true)] enabled: bool,
#[props(default)] on_change: EventHandler<u32>,
) -> Element {
rsx! {
timepicker {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
value: i64::from(value),
min: i64::from(min.unwrap_or(0)),
max: i64::from(max.unwrap_or(MINUTES_IN_A_DAY - 1)),
enabled,
onchange: move |event: dioxus_core::Event<f64>| {
on_change.call((*event.data() as i64).clamp(0, i64::from(MINUTES_IN_A_DAY - 1)) as u32)
},
}
}
}
const MINUTES_IN_A_DAY: u32 = 24 * 60;
#[component]
pub fn Dropdown(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] selected_index: usize,
#[props(default = true)] enabled: bool,
#[props(default)] on_change: EventHandler<usize>,
children: Element,
) -> Element {
rsx! {
dropdown {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
selected_index: selected_index as i64,
enabled,
onchange: move |event: dioxus_core::Event<f64>| {
on_change.call((*event.data() as i64).max(0) as usize)
},
{children}
}
}
}
#[component]
pub fn Checkbox(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] checked: bool,
#[props(default = true)] enabled: bool,
#[props(default)] on_change: EventHandler<bool>,
) -> Element {
rsx! {
checkbox {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
checked,
enabled,
onchange: move |event: dioxus_core::Event<f64>| on_change.call(is_on(*event.data())),
}
}
}
#[component]
pub fn RadioButton(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] selected: bool,
#[props(default = true)] enabled: bool,
#[props(default)] on_change: EventHandler<bool>,
) -> Element {
rsx! {
radiobutton {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
checked: selected,
enabled,
onchange: move |event: dioxus_core::Event<f64>| on_change.call(is_on(*event.data())),
}
}
}
#[component]
pub fn Switch(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] checked: bool,
#[props(default = true)] enabled: bool,
#[props(default)] on_change: EventHandler<bool>,
) -> Element {
rsx! {
switch {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
checked,
enabled,
onchange: move |event: dioxus_core::Event<f64>| on_change.call(is_on(*event.data())),
}
}
}
#[component]
pub fn Slider(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)]
color: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] value: f32,
#[props(default = 0.0)] min: f32,
#[props(default = 1.0)] max: f32,
#[props(default)] steps: u32,
#[props(default = true)] enabled: bool,
#[props(default)] on_change: EventHandler<f32>,
) -> Element {
rsx! {
slider {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
color: opt_paint(color),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
value: f64::from(value),
min: f64::from(min),
max: f64::from(max),
steps: i64::from(steps),
enabled,
onchange: move |event: dioxus_core::Event<f64>| on_change.call(*event.data() as f32),
}
}
}
#[component]
pub fn ProgressIndicator(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] value: f32,
#[props(default = true)] determinate: bool,
#[props(default)] circular: bool,
) -> Element {
rsx! {
progressindicator {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
value: f64::from(value),
determinate,
circular,
}
}
}
#[component]
pub fn Divider(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] vertical: bool,
) -> Element {
rsx! {
divider {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
vertical,
}
}
}
fn is_on(value: f64) -> bool {
value != 0.0
}
#[component]
pub fn Navigation(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] selected_index: usize,
#[props(default)]
head: Option<Element>,
#[props(default)]
foot: Option<Element>,
children: Element,
) -> Element {
rsx! {
navigation {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
selected_index: selected_index as i64,
if let Some(head) = head {
scaffoldslot { slot: i64::from(u16::from(SlotRole::TopBar)), {head} }
}
if let Some(foot) = foot {
scaffoldslot { slot: i64::from(u16::from(SlotRole::BottomBar)), {foot} }
}
{children}
}
}
}
#[component]
pub fn NavigationItem(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] text: String,
#[props(default)] icon: Option<IconRole>,
#[props(default)]
color: Option<Paint>,
#[props(default = true)] enabled: bool,
#[props(default)]
section: Option<String>,
#[props(default)] on_click: EventHandler<()>,
) -> Element {
rsx! {
navigationitem {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
text,
icon: opt_role(icon),
color: opt_paint(color),
enabled,
section,
onclick: move |_| on_click.call(()),
}
}
}
#[component]
pub fn Sheet(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] open: bool,
#[props(default)] on_dismiss: EventHandler<()>,
children: Element,
) -> Element {
rsx! {
sheet {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
open,
ondismiss: move |_| on_dismiss.call(()),
{children}
}
}
}
#[component]
pub fn Scaffold(
#[props(default)]
background: Option<Paint>,
#[props(default)]
material: Option<MaterialRole>,
#[props(default)]
top_bar: Option<Element>,
#[props(default)]
bottom_bar: Option<Element>,
#[props(default)]
floating_action: Option<Element>,
children: Element,
) -> Element {
rsx! {
scaffold {
background: opt_paint(background),
material: opt_role(material),
if let Some(bar) = top_bar {
scaffoldslot { slot: i64::from(u16::from(SlotRole::TopBar)), {bar} }
}
if let Some(bar) = bottom_bar {
scaffoldslot { slot: i64::from(u16::from(SlotRole::BottomBar)), {bar} }
}
if let Some(action) = floating_action {
scaffoldslot {
slot: i64::from(u16::from(SlotRole::FloatingAction)),
{action}
}
}
scaffoldslot { slot: i64::from(u16::from(SlotRole::Content)), {children} }
}
}
}
#[component]
pub fn LazyGrid(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)]
columns: Option<u32>,
#[props(default)]
min_column_width: Option<f32>,
item_count: usize,
#[props(default)] key_of: Option<Callback<usize, String>>,
item: Callback<usize, Element>,
) -> Element {
let mut range = use_signal(|| (0_usize, 0_usize));
let (start, count) = range();
let first = start.min(item_count);
let last = first.saturating_add(count).min(item_count);
rsx! {
lazygrid {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
item_count: item_count as i64,
columns: columns.map(i64::from),
min_column_width: min_column_width.map(f64::from),
onrangerequest: move |event: dioxus_core::Event<RangeRequest>| {
let requested = event.data();
range.set((requested.start(), requested.count()));
},
for index in first..last {
{
let item_key = key_of
.map_or_else(|| index.to_string(), |key_of| key_of.call(index));
rsx! {
composebox { key: "{item_key}", item_key, {item.call(index)} }
}
}
}
}
}
}
#[component]
pub fn FileDropTarget(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)] alignment: Option<Alignment>,
#[props(default)]
on_files_entered: EventHandler<()>,
#[props(default)]
on_files_dropped: EventHandler<FileDrop>,
children: Element,
) -> Element {
rsx! {
filedroptarget {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
alignment: opt_role(alignment),
onfilesentered: move |_: dioxus_core::Event<()>| on_files_entered.call(()),
onfilesdropped: move |event: dioxus_core::Event<FileDrop>| {
on_files_dropped.call(event.data().as_ref().clone());
},
{children}
}
}
}
#[component]
pub fn Badge(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
#[props(default)]
value: Option<u32>,
#[props(default)]
text: Option<String>,
#[props(default)]
color: Option<ColorRole>,
#[props(default)] children: Element,
) -> Element {
rsx! {
badge {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
count: value.map(i64::from),
text,
color: opt_paint(color.map(Paint::Role)),
{children}
}
}
}
#[component]
pub fn SelectionContainer(
#[props(default)] weight: Option<f32>,
#[props(default)] width: Option<f32>,
#[props(default)] height: Option<f32>,
#[props(default)] padding: Option<f32>,
#[props(default)] padding_role: Option<SpaceRole>,
#[props(default)] background: Option<Paint>,
#[props(default)] shape_role: Option<ShapeRole>,
#[props(default)] corner_radius: Option<f32>,
#[props(default)] border_width: Option<f32>,
#[props(default)] border_color: Option<Paint>,
#[props(default)] elevation: Option<f32>,
#[props(default)] fill_max_width: bool,
#[props(default)] fill_max_height: bool,
children: Element,
) -> Element {
rsx! {
selectioncontainer {
weight: opt_dp(weight),
width: opt_dp(width),
height: opt_dp(height),
padding: opt_dp(padding),
padding_role: opt_role(padding_role),
background: opt_paint(background),
shape_role: opt_role(shape_role),
corner_radius: opt_dp(corner_radius),
border_width: opt_dp(border_width),
border_color: opt_paint(border_color),
elevation: opt_dp(elevation),
fill_max_width,
fill_max_height,
{children}
}
}
}