Skip to content

Commit

Permalink
updated tababr to newest iced theme layout
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed May 28, 2024
1 parent 72d466e commit fcf3b59
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 462 deletions.
25 changes: 25 additions & 0 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ default = [
"date_picker",
"color_picker",
"grid",
#"tab_bar",
"tab_bar",
#"tabs",
"time_picker",
"slide_bar",
Expand All @@ -52,7 +52,7 @@ default = [
#"quad",
#"context_menu",
"spinner",
#"drop_down",
"drop_down",
#"menu",
]

Expand Down Expand Up @@ -83,16 +83,16 @@ members = [
"examples/date_picker",
"examples/color_picker",
"examples/grid",
#"examples/tab_bar",
"examples/tab_bar",
#"examples/tabs",
"examples/time_picker",
"examples/sliderbar",
"examples/wrap",
"examples/selection_list",
#"examples/context_menu",
"examples/spinner",
#"examples/WidgetIDReturn",
#"examples/drop_down",
"examples/WidgetIDReturn",
"examples/drop_down",
#"examples/menu",
]

Expand Down
133 changes: 39 additions & 94 deletions examples/WidgetIDReturn/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<f32, Message>; 2],
}

#[derive(Debug)]
pub struct State {
value: [NumInput<f32, Message>; 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<f32>)),
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<Message>) {
(
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<Message> {
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<Message> {
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<Message> {
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()
}
}
17 changes: 9 additions & 8 deletions examples/WidgetIDReturn/src/numberinput.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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;
use std::str::FromStr;

#[derive(Debug, Default)]
pub struct NumInput<V, M> {
phantomdata: PhantomData<M>,
pub value: V,
phantomdata: PhantomData<M>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -36,18 +37,18 @@ where
}
}

impl<V, M> NumInput<V, M>
impl<'a, V, M> NumInput<V, M>
where
V: Num + NumAssignOps + PartialOrd + Display + FromStr + Copy + Bounded,
M: Clone,
M: 'a + Clone,
{
pub fn new(value: V) -> NumInput<V, M>
where
V: 'static,
{
NumInput {
phantomdata: PhantomData,
value,
phantomdata: PhantomData,
}
}

Expand All @@ -58,19 +59,19 @@ where
max: V,
step: V,
on_change: F,
style: Option<NumberInputStyles>,
style: Option<Style>,
) -> Element<M>
where
F: 'static + Fn((usize, NumInputMessage<V>)) -> M + Copy,
V: 'static,
M: 'static,
M: 'static + Clone,
{
let mut input = NumberInput::new(self.value, min..max, NumInputMessage::Change)
.step(step)
.width(Length::Shrink);

if let Some(style) = style {
input = input.style(style);
input = input.style(move |_theme, _status| style);
}

Element::new(input).map(move |i| on_change((id, i)))
Expand Down
26 changes: 11 additions & 15 deletions examples/drop_down/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ use std::fmt::Display;

use iced::{
widget::{Button, Column, Row, Text},
Element, Length, Sandbox, Settings,
Element, Length,
};

use iced_aw::{drop_down, DropDown};

fn main() -> iced::Result {
DropDownExample::run(Settings::default())
iced::program(
"ContextMenu example",
DropDownExample::update,
DropDownExample::view,
)
.font(iced_aw::BOOTSTRAP_FONT_BYTES)
.run()
}

#[derive(Clone, Debug, Default)]
Expand Down Expand Up @@ -40,18 +46,8 @@ struct DropDownExample {
expanded: bool,
}

impl Sandbox for DropDownExample {
type Message = Message;

fn new() -> Self {
Self::default()
}

fn title(&self) -> String {
String::from("ContextMenu example")
}

fn update(&mut self, message: Self::Message) {
impl DropDownExample {
fn update(&mut self, message: Message) {
match message {
Message::Select(choice) => {
self.selected = choice;
Expand All @@ -62,7 +58,7 @@ impl Sandbox for DropDownExample {
}
}

fn view(&self) -> Element<'_, Self::Message> {
fn view(&self) -> Element<'_, Message> {
let underlay = Row::new()
.push(Text::new(format!("Selected: {}", self.selected)))
.push(Button::new(Text::new("expand")).on_press(Message::Expand));
Expand Down
Loading

0 comments on commit fcf3b59

Please sign in to comment.