diff --git a/Cargo.lock b/Cargo.lock index 7d7cff0e..e9054b80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -893,6 +893,14 @@ dependencies = [ "linux-raw-sys 0.6.4", ] +[[package]] +name = "drop_down" +version = "0.1.0" +dependencies = [ + "iced", + "iced_aw", +] + [[package]] name = "either" version = "1.12.0" @@ -2926,6 +2934,14 @@ dependencies = [ "libc", ] +[[package]] +name = "tab_bar" +version = "0.1.0" +dependencies = [ + "iced", + "iced_aw", +] + [[package]] name = "tempfile" version = "3.10.1" @@ -3537,6 +3553,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311" +[[package]] +name = "widget_id" +version = "0.1.0" +dependencies = [ + "iced", + "iced_aw", + "num-traits", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 47cd17d7..33ff7617 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ default = [ "date_picker", "color_picker", "grid", - #"tab_bar", + "tab_bar", #"tabs", "time_picker", "slide_bar", @@ -52,7 +52,7 @@ default = [ #"quad", #"context_menu", "spinner", - #"drop_down", + "drop_down", #"menu", ] @@ -83,7 +83,7 @@ members = [ "examples/date_picker", "examples/color_picker", "examples/grid", - #"examples/tab_bar", + "examples/tab_bar", #"examples/tabs", "examples/time_picker", "examples/sliderbar", @@ -91,8 +91,8 @@ members = [ "examples/selection_list", #"examples/context_menu", "examples/spinner", - #"examples/WidgetIDReturn", - #"examples/drop_down", + "examples/WidgetIDReturn", + "examples/drop_down", #"examples/menu", ] diff --git a/examples/WidgetIDReturn/src/main.rs b/examples/WidgetIDReturn/src/main.rs index dd49d118..6adb98af 100644 --- a/examples/WidgetIDReturn/src/main.rs +++ b/examples/WidgetIDReturn/src/main.rs @@ -1,121 +1,66 @@ use iced::{ - alignment, font, - theme::Theme, - widget::{container, text, Column, Container, Row, Text}, - window, Alignment, Application, Command, Element, Length, Settings, Size, + widget::{Column, Container, Row, Text}, + Alignment, Element, Length, }; #[derive(Debug)] -enum NumberInputDemo { - Loading, - Loaded(State), +pub struct NumberInputDemo { + value: [NumInput; 2], } -#[derive(Debug)] -pub struct State { - value: [NumInput; 2], +impl Default for NumberInputDemo { + fn default() -> Self { + Self { + value: [NumInput::new(32.0), NumInput::new(12.0)], + } + } } #[derive(Debug, Clone)] pub enum Message { - Loaded(Result<(), String>), GenericF32Input((usize, NumInputMessage)), - FontLoaded(Result<(), font::Error>), } fn main() -> iced::Result { - NumberInputDemo::run(Settings { - default_text_size: iced::Pixels(12.0), - window: window::Settings { - size: Size::new(500.0, 400.0), - ..Default::default() - }, - ..Settings::default() - }) + iced::program( + "NumberInput example", + NumberInputDemo::update, + NumberInputDemo::view, + ) + .font(iced_aw::BOOTSTRAP_FONT_BYTES) + .run() } mod numberinput; - use numberinput::*; -async fn load() -> Result<(), String> { - Ok(()) -} - -impl Application for NumberInputDemo { - type Message = Message; - type Theme = Theme; - type Executor = iced::executor::Default; - type Flags = (); - - fn new(_flags: ()) -> (NumberInputDemo, Command) { - ( - NumberInputDemo::Loading, - Command::batch(vec![ - font::load(iced_aw::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded), - Command::perform(load(), Message::Loaded), - ]), - ) +impl NumberInputDemo { + fn update(&mut self, message: self::Message) { + let Message::GenericF32Input((id, val)) = message; + self.value[id].value = val.get_data(); } - fn title(&self) -> String { - String::from("Number Input Demo") - } - - fn update(&mut self, message: self::Message) -> Command { - match self { - NumberInputDemo::Loading => { - if let Message::Loaded(_) = message { - *self = NumberInputDemo::Loaded(State { - value: [NumInput::new(27.0), NumInput::new(5.0)], - }) - } - } - NumberInputDemo::Loaded(State { value }) => { - if let Message::GenericF32Input((id, val)) = message { - value[id].value = val.get_data(); - } - } + fn view(&self) -> Element { + let mut column1 = Column::new(); + + for (id, val) in self.value.iter().enumerate() { + let lb_minute = Text::new(format!("Number Input {}:", id)); + let txt_minute = val.view(id, 1.0, 255.0, 0.5, Message::GenericF32Input, None); + + column1 = column1.push( + Row::new() + .spacing(10) + .align_items(Alignment::Center) + .push(lb_minute) + .push(txt_minute), + ); } - Command::none() - } - - fn view(&self) -> Element { - match self { - NumberInputDemo::Loading => container( - text("Loading...") - .horizontal_alignment(alignment::Horizontal::Center) - .size(50), - ) + Container::new(column1) .width(Length::Fill) .height(Length::Fill) - .center_y() - .center_x() - .into(), - NumberInputDemo::Loaded(State { value }) => { - let mut column1 = Column::new(); - - for (id, val) in value.iter().enumerate() { - let lb_minute = Text::new(format!("Number Input {}:", id)); - let txt_minute = val.view(id, 1.0, 255.0, 0.5, Message::GenericF32Input, None); - - column1 = column1.push( - Row::new() - .spacing(10) - .align_items(Alignment::Center) - .push(lb_minute) - .push(txt_minute), - ); - } - - Container::new(column1) - .width(Length::Fill) - .height(Length::Fill) - .center_x() - .center_y() - .into() - } - } + .center_x(Length::Fill) + .center_y(Length::Fill) + .into() } } diff --git a/examples/WidgetIDReturn/src/numberinput.rs b/examples/WidgetIDReturn/src/numberinput.rs index fdf920a9..6308a681 100644 --- a/examples/WidgetIDReturn/src/numberinput.rs +++ b/examples/WidgetIDReturn/src/numberinput.rs @@ -1,5 +1,6 @@ use iced::{Element, Length}; -use iced_aw::{NumberInput, NumberInputStyles}; +use iced_aw::style::number_input::Style; +use iced_aw::NumberInput; use num_traits::{bounds::Bounded, Num, NumAssignOps}; use std::fmt::Display; use std::marker::PhantomData; @@ -7,8 +8,8 @@ use std::str::FromStr; #[derive(Debug, Default)] pub struct NumInput { - phantomdata: PhantomData, pub value: V, + phantomdata: PhantomData, } #[derive(Debug, Clone, PartialEq, Eq)] @@ -36,18 +37,18 @@ where } } -impl NumInput +impl<'a, V, M> NumInput where V: Num + NumAssignOps + PartialOrd + Display + FromStr + Copy + Bounded, - M: Clone, + M: 'a + Clone, { pub fn new(value: V) -> NumInput where V: 'static, { NumInput { - phantomdata: PhantomData, value, + phantomdata: PhantomData, } } @@ -58,19 +59,19 @@ where max: V, step: V, on_change: F, - style: Option, + style: Option