Skip to content

Commit

Permalink
improvement: Uses collapsible version of author widget
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomaz-Vieira committed Jun 11, 2024
1 parent 1085d37 commit 86fcf21
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bioimg_gui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use bioimg_spec::rdf::non_empty_list::NonEmptyList;
use crate::result::{GuiError, Result, VecResultExt};
use crate::widgets::attachments_widget::AttachmentsWidget;

use crate::widgets::collapsible_widget::CollapsibleWidget;
use crate::widgets::cover_image_widget::CoverImageItemConf;
// use crate::widgets::cover_image_widget::CoverImageWidget;
use crate::widgets::icon_widget::IconWidgetValue;
Expand Down Expand Up @@ -48,7 +49,7 @@ pub struct BioimgGui {
pub staging_description: StagingString<BoundedString<1, 1023>>,
pub cover_images: StagingVec<SpecialImageWidget<rt::CoverImage>, CoverImageItemConf>,
// id?
pub staging_authors: StagingVec<StagingAuthor2>,
pub staging_authors: StagingVec<CollapsibleWidget<StagingAuthor2>>,
pub attachments_widget: StagingVec<AttachmentsWidget>,
pub staging_citations: StagingVec<StagingCiteEntry2>,
//config
Expand Down
23 changes: 22 additions & 1 deletion bioimg_gui/src/widgets/author_widget.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bioimg_spec::rdf::{author::Author2, bounded_string::BoundedString, orcid::Orcid};

use super::{staging_opt::StagingOpt, staging_string::StagingString, staging_vec::ItemWidgetConf, StatefulWidget, ValueWidget};
use super::{collapsible_widget::{CollapsibleWidget, SummarizableWidget}, staging_opt::StagingOpt, staging_string::StagingString, staging_vec::ItemWidgetConf, StatefulWidget, ValueWidget};
use crate::result::Result;

pub type ConfString = BoundedString<1, 1023>;
Expand Down Expand Up @@ -29,6 +29,26 @@ impl ItemWidgetConf for StagingAuthor2{
const MIN_NUM_ITEMS: usize = 1;
}

impl ItemWidgetConf for CollapsibleWidget<StagingAuthor2>{
const ITEM_NAME: &'static str = "Author";
const MIN_NUM_ITEMS: usize = 1;
const GROUP_FRAME: bool = false;
}

impl SummarizableWidget for StagingAuthor2{
fn summarize(&mut self, ui: &mut egui::Ui, _id: egui::Id) {
match self.state(){
Ok(author) => {
ui.label(author.to_string());
},
Err(err) => {
let rich_text = egui::RichText::new(err.to_string()).color(egui::Color32::RED);
ui.label(rich_text);
}
}
}
}

impl Default for StagingAuthor2 {
fn default() -> Self {
Self {
Expand All @@ -41,6 +61,7 @@ impl Default for StagingAuthor2 {
}
}


impl StatefulWidget for StagingAuthor2 {
type Value<'p> = Result<Author2>;

Expand Down
15 changes: 15 additions & 0 deletions bioimg_spec/src/rdf/author.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::Display;

use serde::{Deserialize, Serialize};

use crate::rdf::BoundedString;
Expand All @@ -22,6 +24,19 @@ pub struct Author2 {
pub orcid: Option<Orcid>,
}

impl Display for Author2{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.name)?;
if let Some(email) = &self.email{
write!(f, " 📧{email}")?;
}
if let Some(github_user) = &self.github_user{
write!(f, " github: {github_user}")?;
}
Ok(())
}
}

impl From<Author> for Author2 {
fn from(value: Author) -> Self {
Author2 {
Expand Down

0 comments on commit 86fcf21

Please sign in to comment.