Skip to content

Commit

Permalink
Merge pull request #7 from shartrec/4-Add_menus_in_place_of_popup
Browse files Browse the repository at this point in the history
4 add menus in place of popup
  • Loading branch information
shartrec authored Jul 20, 2024
2 parents 44cf3e5 + 7800582 commit 1616c58
Show file tree
Hide file tree
Showing 15 changed files with 498 additions and 629 deletions.
144 changes: 144 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ strum_macros = "0.26.4"
git = "https://github.com/iced-rs/iced.git"
version = "0.13.0-dev"
features = ["advanced", "multi-window"]

[dependencies.iced_aw]
git = "https://github.com/iced-rs/iced_aw.git"
rev = "b06b22c6755149545c09f7c2d75e8bf2567415f7"
features = ["menu", "icons"]
36 changes: 2 additions & 34 deletions src/conversions/mass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,41 +63,14 @@ pub static MICROGRAM: Unit = Unit {
from_system_base: None,
};
pub static TONNE: Unit = Unit {
name: "Ton (metric)",
name: "Tonne",
dimension: Dimension::Mass,
system: System::Metric,
to_base: Some(Unit::from_kilo),
from_base: Some(Unit::to_kilo),
to_system_base: None,
from_system_base: None,
};
pub static KILOTONNE: Unit = Unit {
name: "Kiloton (metric)",
dimension: Dimension::Mass,
system: System::Metric,
to_base: Some(|v| TONNE.to_base.unwrap()(Unit::from_kilo(v))),
from_base: Some(|v| Unit::to_kilo(TONNE.from_base.unwrap()(v))),
to_system_base: None,
from_system_base: None,
};
pub static MEGATONNE: Unit = Unit {
name: "Megaton (metric)",
dimension: Dimension::Mass,
system: System::Metric,
to_base: Some(|v| TONNE.to_base.unwrap()(Unit::from_mega(v))),
from_base: Some(|v| Unit::to_mega(TONNE.from_base.unwrap()(v))),
to_system_base: None,
from_system_base: None,
};
pub static GIGATONNE: Unit = Unit {
name: "Gigaton (metric)",
dimension: Dimension::Mass,
system: System::Metric,
to_base: Some(|v| TONNE.to_base.unwrap()(Unit::from_giga(v))),
from_base: Some(|v| Unit::to_giga(TONNE.from_base.unwrap()(v))),
to_system_base: None,
from_system_base: None,
};

// Imperial

Expand Down Expand Up @@ -140,8 +113,7 @@ pub static TON_SHORT: Unit = Unit {
};

pub(crate) fn get_all() -> Vec<&'static Unit> {
vec![&KILOGRAM, &GRAM, &MILLIGRAM, &MICROGRAM,
&TONNE, &KILOTONNE, &MEGATONNE, &GIGATONNE,
vec![&KILOGRAM, &GRAM, &MILLIGRAM, &MICROGRAM, &TONNE,
&OUNCE, &POUND, &TON, &TON_SHORT
]
}
Expand All @@ -158,11 +130,7 @@ mod tests {
assert_eq!(convert(&23.66, &MILLIGRAM, &GRAM), 0.02366);
assert_eq!(convert(&23.66, &GRAM, &KILOGRAM), 0.02366);
assert_eq!(convert(&23.66, &KILOGRAM, &TONNE), 0.02366);
assert_eq!(convert(&23.66, &TONNE, &KILOTONNE), 0.02366);
assert_eq!(convert(&23.66, &KILOTONNE, &MEGATONNE), 0.02366);
// and back
assert_eq!(convert(&23.66, &MEGATONNE, &KILOTONNE), 23660.0);
assert_eq!(convert(&23.66, &KILOTONNE, &TONNE), 23660.0);
assert_eq!(convert(&23.66, &TONNE, &KILOGRAM), 23660.0);
assert_eq!(convert(&23.66, &KILOGRAM, &GRAM), 23660.0);
assert_eq!(convert(&23.66, &GRAM, &MILLIGRAM), 23660.0);
Expand Down
27 changes: 11 additions & 16 deletions src/conversions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub(crate) enum Dimension {
Area,
Mass,
Volume,
Temperature,
Temp,
Power,
Torque,
Force,
Expand Down Expand Up @@ -188,39 +188,35 @@ pub(crate) fn convert(value: &f64, from: &Unit, to: &Unit) -> f64 {
result
}

pub(crate) fn get_units(dimension: &Option<Dimension>) -> Vec<&'static Unit> {
pub(crate) fn get_units(dimension: &Dimension) -> Vec<&'static Unit> {
match dimension {
Some(Dimension::Length) => {
Dimension::Length => {
length::get_all()
}
Some(Dimension::Area) => {
Dimension::Area => {
area::get_all()
}
Some(Dimension::Mass) => {
Dimension::Mass => {
mass::get_all()
}
Some(Dimension::Volume) => {
Dimension::Volume => {
volume::get_all()
}
Some(Dimension::Temperature) => {
Dimension::Temp => {
temperature::get_all()
}
Some(Dimension::Power) => {
Dimension::Power => {
power::get_all()
}
Some(Dimension::Torque) => {
Dimension::Torque => {
torque::get_all()
}
Some(Dimension::Force) => {
Dimension::Force => {
force::get_all()
}
Some(Dimension::Energy) => {
Dimension::Energy => {
energy::get_all()
}
None => {
warn!("Trying to convert, but no dimension set");
vec![]
}
}
}

Expand All @@ -238,7 +234,6 @@ mod tests {
#[test]
fn test_base_units() {
assert_eq!(convert(&1.0, &KILOGRAM, &GRAM), 1000.0);
assert_eq!(convert(&2.0, &KILOTONNE, &KILOGRAM), 2000000.0);
}
#[test]
fn test_mixed_units() {
Expand Down
Loading

0 comments on commit 1616c58

Please sign in to comment.