Skip to content

Commit

Permalink
Add form to fancy example
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed May 4, 2024
1 parent 2ffa46d commit c44b710
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ async = ["egui_suspense/async", "egui_infinite_scroll/async"]
tokio = ["egui_suspense/tokio", "egui_infinite_scroll/tokio"]

[dependencies]
egui_animation = { workspace = true, optional = true }
egui_dnd = { workspace = true, optional = true }
egui_inbox = { workspace = true, optional = true }
egui_form = { workspace = true, optional = true }
egui_infinite_scroll = { workspace = true, optional = true }
egui_pull_to_refresh = { workspace = true, optional = true }
egui_animation = { workspace = true, optional = true }
egui_suspense = { workspace = true, optional = true }
egui_virtual_list = { workspace = true, optional = true }
egui_infinite_scroll = { workspace = true, optional = true }
egui_thumbhash = { workspace = true, optional = true }
egui_virtual_list = { workspace = true, optional = true }


[workspace]
Expand All @@ -46,6 +47,7 @@ resolver = "2"
egui_dnd = { path = "./crates/egui_dnd", version = "0.8.0" }
egui_animation = { path = "./crates/egui_animation", version = "0.4.0" }
hello_egui_utils = { path = "./crates/hello_egui_utils", version = "0.4.0" }
egui_form = { path = "./crates/egui_form", version = "0.1.0" }
egui_inbox = { path = "./crates/egui_inbox", version = "0.4.0" }
egui_pull_to_refresh = { path = "./crates/egui_pull_to_refresh", version = "0.4.0" }
egui_suspense = { path = "./crates/egui_suspense", version = "0.4.0" }
Expand Down
Empty file added crates/egui_form/README.md
Empty file.
8 changes: 8 additions & 0 deletions crates/egui_form/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::EguiValidationErrors;
use std::borrow::Cow;

use std::hash::Hash;
pub use validator;
use validator::{Validate, ValidationError, ValidationErrors, ValidationErrorsKind};

#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
Expand Down Expand Up @@ -116,6 +117,13 @@ impl EguiValidationErrors for ValidatorReport {
None
};

if let Some(message) = error
.and_then(|errors| errors.first())
.and_then(|e| e.message.as_ref())
{
return Some(message.clone());
}

error.and_then(|errors| errors.first()).map(|error| {
if let Some(get_t) = &self.get_t {
get_t(error)
Expand Down
11 changes: 7 additions & 4 deletions fancy-example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ publish = false
release = false

[dependencies]
egui_animation.workspace = true
egui_dnd.workspace = true
egui_infinite_scroll.workspace = true
hello_egui_utils.workspace = true
egui_form = { workspace = true, features = ["validator_validator"] }
egui_inbox.workspace = true
egui_animation.workspace = true
egui_thumbhash.workspace = true
egui_infinite_scroll.workspace = true
egui_pull_to_refresh.workspace = true
egui_taffy = { path = "../crates/egui_taffy" }
egui_thumbhash.workspace = true
hello_egui_utils.workspace = true

egui = { workspace = true, features = ["color-hex"] }
eframe = { workspace = true, default-features = true }
Expand All @@ -36,6 +37,8 @@ casey = "0.4.0"

egui_commonmark = { version = "0.14.0", features = [] }

validator = { version = "0.18.1", features = ["derive"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["time", "rt", "macros"] }
ureq = "2"
Expand Down
19 changes: 11 additions & 8 deletions fancy-example/src/crate_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub const README_CONTENT_SEPARATOR: &str = "[content]:<>";
pub enum Crate {
EguiAnimation,
EguiDnd,
EguiForm,
EguiInbox,
EguiInfiniteScroll,
EguiPullToRefresh,
Expand Down Expand Up @@ -64,6 +65,7 @@ macro_rules! crate_impl {
crate_impl!(
EguiAnimation,
EguiDnd,
EguiForm,
EguiInbox,
EguiInfiniteScroll,
EguiPullToRefresh,
Expand All @@ -83,16 +85,17 @@ impl Crate {

pub fn short_description(&self) -> &'static str {
match self {
Self::EguiAnimation => "Animation utilities for egui",
Self::EguiDnd => "Drag and drop sorting for egui",
Self::EguiInbox => "Channel with ergonomics optimized for egui",
Self::EguiInfiniteScroll => "Infinite scroll widget for egui",
Self::EguiVirtualList => {
EguiAnimation => "Animation utilities for egui",
EguiDnd => "Drag and drop sorting for egui",
EguiForm => "Form validation for egui",
EguiInbox => "Channel with ergonomics optimized for egui",
EguiInfiniteScroll => "Infinite scroll widget for egui",
EguiVirtualList => {
"Virtual list widget for egui with support for varying heights and custom layouts"
}
Self::EguiPullToRefresh => "Pull to refresh widget for egui",
Self::EguiSuspense => "Suspense widget for egui for ergonomic data fetching",
Self::EguiThumbhash => "Image loading and caching for egui",
EguiPullToRefresh => "Pull to refresh widget for egui",
EguiSuspense => "Suspense widget for egui for ergonomic data fetching",
EguiThumbhash => "Image loading and caching for egui",
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions fancy-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod futures;
mod gallery;
mod shared_state;
mod sidebar;
mod signup_form;
mod stargazers;

pub enum FancyMessage {
Expand Down Expand Up @@ -63,6 +64,10 @@ impl App {
Box::new(gallery::Gallery::new()),
],
},
Category {
name: "Form Validation".to_string(),
examples: vec![Box::new(signup_form::SignupForm::new())],
},
]),
shared_state: SharedState::new(tx),
sidebar_expanded: false,
Expand Down
Loading

0 comments on commit c44b710

Please sign in to comment.