More testing.

This commit is contained in:
Samuel Guerra 2023-04-14 15:34:51 -03:00
parent 1f1cde6f10
commit 834561c452
5 changed files with 39 additions and 34 deletions

View File

@ -1,15 +1,14 @@
# Widget & Property Refactor
* Docs not generated for nested mix-ins.
* Fix widget docs.
- Mix-in parent deref not included in docs.
- Inject JS in the docs of widget/mix-in structs to format the properties.
- They can be identified with the `P` tag.
Also group in the `unset_property` methods.
* (Re)write property/when syntax docs in `widget_set!`.
* Test widget generated macro in crate that does not depend on zero-ui directly.
* Review names of widget items that have the widget prefix on the name.
`ImageErrorArgs` could be `image::ErrorArgs`?
* Refactor `#[widget]`.
- Test build error for parent not a widget.
- Where is `widget_new!` available for the widget macro?
* Review docs.
- No more property rename.
- `#[widget]` docs.
* Test all.
* Merge.

View File

@ -1,7 +1,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use zero_ui::core::task::http;
use zero_ui::widgets::image::{img_error_fn, img_loading_fn, ImageErrorArgs};
use zero_ui::widgets::image::{img_error_fn, img_loading_fn, ImgErrorArgs};
use zero_ui::{
core::image::{ImageLimits, IMAGES},
prelude::*,
@ -261,7 +261,7 @@ fn large_image() -> impl UiNode {
img_limits = Some(ImageLimits::none().with_max_encoded_len(300.megabytes()).with_max_decoded_len(3.gigabytes()));
img_downscale = Px(8000);
on_error = hn!(|args: &ImageErrorArgs| {
on_error = hn!(|args: &ImgErrorArgs| {
tracing::error!(target: "unexpected", "{}", args.error);
});
@ -296,7 +296,7 @@ fn panorama_image() -> impl UiNode {
img_fit = ImageFit::Fill;
source = "https://upload.wikimedia.org/wikipedia/commons/2/2c/Along_the_River_During_the_Qingming_Festival_%28Qing_Court_Version%29.jpg";
img_limits = Some(ImageLimits::none().with_max_encoded_len(130.megabytes()).with_max_decoded_len(1.gigabytes()));
on_error = hn!(|args: &ImageErrorArgs| {
on_error = hn!(|args: &ImgErrorArgs| {
tracing::error!(target: "unexpected", "{}", args.error);
});
};
@ -330,7 +330,7 @@ fn block_window_load_image() -> impl UiNode {
source = "https://upload.wikimedia.org/wikipedia/commons/2/2c/Along_the_River_During_the_Qingming_Festival_%28Qing_Court_Version%29.jpg";
img_limits = Some(ImageLimits::none().with_max_encoded_len(130.megabytes()).with_max_decoded_len(1.gigabytes()));
on_error = hn!(|args: &ImageErrorArgs| {
on_error = hn!(|args: &ImgErrorArgs| {
tracing::error!(target: "unexpected", "{}", args.error);
});
}
@ -406,7 +406,7 @@ impl ImgWindow {
img_loading_fn = wgt_fn!(|_| loading());
// content shown by all images that failed to load.
img_error_fn = wgt_fn!(|args: ImageErrorArgs| {
img_error_fn = wgt_fn!(|args: ImgErrorArgs| {
center_viewport(Text! {
txt = args.error;
margin = 8;

View File

@ -0,0 +1,6 @@
use zero_ui::prelude::new_widget::*;
#[widget($crate::Foo)]
pub struct Foo(f32);
fn main() { }

View File

@ -59,10 +59,10 @@ context_var! {
pub static IMAGE_CACHE_VAR: bool = true;
/// Widget function for the content shown when the image does not load.
pub static IMAGE_ERROR_GEN_VAR: WidgetFn<ImageErrorArgs> = WidgetFn::nil();
pub static IMAGE_ERROR_GEN_VAR: WidgetFn<ImgErrorArgs> = WidgetFn::nil();
/// Widget function for the content shown when the image is still loading.
pub static IMAGE_LOADING_GEN_VAR: WidgetFn<ImageLoadingArgs> = WidgetFn::nil();
pub static IMAGE_LOADING_GEN_VAR: WidgetFn<ImgLoadingArgs> = WidgetFn::nil();
/// Custom image load and decode limits.
///
@ -296,7 +296,7 @@ pub fn is_loaded(child: impl UiNode, state: impl IntoVar<bool>) -> impl UiNode {
///
/// [`wgt_fn!`]: crate::widgets::wgt_fn
#[property(CONTEXT, default(IMAGE_ERROR_GEN_VAR), impl(Image))]
pub fn img_error_fn(child: impl UiNode, wgt_fn: impl IntoVar<WidgetFn<ImageErrorArgs>>) -> impl UiNode {
pub fn img_error_fn(child: impl UiNode, wgt_fn: impl IntoVar<WidgetFn<ImgErrorArgs>>) -> impl UiNode {
with_context_var(child, IMAGE_ERROR_GEN_VAR, wgt_fn)
}
@ -304,7 +304,7 @@ pub fn img_error_fn(child: impl UiNode, wgt_fn: impl IntoVar<WidgetFn<ImageError
///
/// [`wgt_fn!`]: crate::widgets::wgt_fn
#[property(CONTEXT, default(IMAGE_LOADING_GEN_VAR), impl(Image))]
pub fn img_loading_fn(child: impl UiNode, wgt_fn: impl IntoVar<WidgetFn<ImageLoadingArgs>>) -> impl UiNode {
pub fn img_loading_fn(child: impl UiNode, wgt_fn: impl IntoVar<WidgetFn<ImgLoadingArgs>>) -> impl UiNode {
with_context_var(child, IMAGE_LOADING_GEN_VAR, wgt_fn)
}
@ -312,20 +312,20 @@ pub fn img_loading_fn(child: impl UiNode, wgt_fn: impl IntoVar<WidgetFn<ImageLoa
///
/// [`img_loading_fn`]: fn@img_loading_fn
#[derive(Clone, Debug)]
pub struct ImageLoadingArgs {}
pub struct ImgLoadingArgs {}
/// Arguments for [`on_load`].
///
/// [`on_load`]: fn@on_load
#[derive(Clone, Debug)]
pub struct ImageLoadArgs {}
pub struct ImgLoadArgs {}
/// Arguments for [`on_error`] and [`img_error_fn`].
///
/// [`on_error`]: fn@on_error
/// [`img_error_fn`]: fn@img_error_fn
#[derive(Clone, Debug)]
pub struct ImageErrorArgs {
pub struct ImgErrorArgs {
/// Error message.
pub error: Txt,
}
@ -343,10 +343,10 @@ pub struct ImageErrorArgs {
///
/// This property is not routed, it works only inside a widget that loads images. There is also no *preview* event.
#[property(EVENT, impl(Image))]
pub fn on_error(child: impl UiNode, handler: impl WidgetHandler<ImageErrorArgs>) -> impl UiNode {
pub fn on_error(child: impl UiNode, handler: impl WidgetHandler<ImgErrorArgs>) -> impl UiNode {
#[ui_node(struct OnErrorNode {
child: impl UiNode,
handler: impl WidgetHandler<ImageErrorArgs>,
handler: impl WidgetHandler<ImgErrorArgs>,
error: Txt,
})]
impl UiNode for OnErrorNode {
@ -356,7 +356,7 @@ pub fn on_error(child: impl UiNode, handler: impl WidgetHandler<ImageErrorArgs>)
CONTEXT_IMAGE_VAR.with(|i| {
if let Some(error) = i.error() {
self.error = error;
self.handler.event(&ImageErrorArgs { error: self.error.clone() });
self.handler.event(&ImgErrorArgs { error: self.error.clone() });
}
});
self.child.init();
@ -367,7 +367,7 @@ pub fn on_error(child: impl UiNode, handler: impl WidgetHandler<ImageErrorArgs>)
if let Some(error) = new_img.error() {
if self.error != error {
self.error = error;
self.handler.event(&ImageErrorArgs { error: self.error.clone() });
self.handler.event(&ImgErrorArgs { error: self.error.clone() });
}
} else {
self.error = "".into();
@ -398,17 +398,17 @@ pub fn on_error(child: impl UiNode, handler: impl WidgetHandler<ImageErrorArgs>)
///
/// This property is not routed, it works only inside a widget that loads images. There is also no *preview* event.
#[property(EVENT, impl(Image))]
pub fn on_load(child: impl UiNode, handler: impl WidgetHandler<ImageLoadArgs>) -> impl UiNode {
pub fn on_load(child: impl UiNode, handler: impl WidgetHandler<ImgLoadArgs>) -> impl UiNode {
#[ui_node(struct OnLoadNode {
child: impl UiNode,
handler: impl WidgetHandler<ImageLoadArgs>,
handler: impl WidgetHandler<ImgLoadArgs>,
})]
impl UiNode for OnLoadNode {
fn init(&mut self) {
WIDGET.sub_var(&CONTEXT_IMAGE_VAR);
if CONTEXT_IMAGE_VAR.with(Img::is_loaded) {
self.handler.event(&ImageLoadArgs {});
self.handler.event(&ImgLoadArgs {});
}
self.child.init();
}
@ -416,7 +416,7 @@ pub fn on_load(child: impl UiNode, handler: impl WidgetHandler<ImageLoadArgs>) -
fn update(&mut self, updates: &WidgetUpdates) {
if let Some(new_img) = CONTEXT_IMAGE_VAR.get_new() {
if new_img.is_loaded() {
self.handler.event(&ImageLoadArgs {});
self.handler.event(&ImgLoadArgs {});
}
}

View File

@ -3,7 +3,7 @@
use std::mem;
use super::image_properties::{
ImageErrorArgs, ImageFit, ImageLoadingArgs, IMAGE_ALIGN_VAR, IMAGE_CACHE_VAR, IMAGE_CROP_VAR, IMAGE_DOWNSCALE_VAR, IMAGE_ERROR_GEN_VAR,
ImgErrorArgs, ImageFit, ImgLoadingArgs, IMAGE_ALIGN_VAR, IMAGE_CACHE_VAR, IMAGE_CROP_VAR, IMAGE_DOWNSCALE_VAR, IMAGE_ERROR_GEN_VAR,
IMAGE_FIT_VAR, IMAGE_LIMITS_VAR, IMAGE_LOADING_GEN_VAR, IMAGE_OFFSET_VAR, IMAGE_RENDERING_VAR, IMAGE_SCALE_FACTOR_VAR,
IMAGE_SCALE_PPI_VAR, IMAGE_SCALE_VAR,
};
@ -170,14 +170,14 @@ pub fn image_error_presenter(child: impl UiNode) -> impl UiNode {
} else if is_new {
// init or fn changed.
if let Some(e) = CONTEXT_IMAGE_VAR.get().error() {
DataUpdate::Update(ImageErrorArgs { error: e })
DataUpdate::Update(ImgErrorArgs { error: e })
} else {
DataUpdate::None
}
} else if let Some(new) = CONTEXT_IMAGE_VAR.get_new() {
// image var update.
if let Some(e) = new.error() {
DataUpdate::Update(ImageErrorArgs { error: e })
DataUpdate::Update(ImgErrorArgs { error: e })
} else {
DataUpdate::None
}
@ -227,14 +227,14 @@ pub fn image_loading_presenter(child: impl UiNode) -> impl UiNode {
} else if is_new {
// init or fn changed.
if CONTEXT_IMAGE_VAR.with(Img::is_loading) {
DataUpdate::Update(ImageLoadingArgs {})
DataUpdate::Update(ImgLoadingArgs {})
} else {
DataUpdate::None
}
} else if let Some(new) = CONTEXT_IMAGE_VAR.get_new() {
// image var update.
if new.is_loading() {
DataUpdate::Update(ImageLoadingArgs {})
DataUpdate::Update(ImgLoadingArgs {})
} else {
DataUpdate::None
}