aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2024-01-24 09:24:59 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2024-01-24 09:24:59 +0100
commit09450176141cda7c074b3a2584d103ca3bad3026 (patch)
tree26764f7bd026813f1149951e77ed09c19cdb0445 /src/main.rs
parent895240accc908009a33b9fc388b18c7288765c9b (diff)
create simple theme
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs95
1 files changed, 86 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs
index 5565edb..458abc3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,11 +2,12 @@ pub mod function_cache;
pub mod math;
pub mod ui;
+use iced::theme::{Button, TextInput};
use iced::widget::{
- button, canvas, container, pane_grid, responsive, text, text_input, Column, PaneGrid, row,
+ button, canvas, container, pane_grid, responsive, row, text, text_input, Column, PaneGrid, Text,
};
-use iced::{executor, Renderer};
-use iced::{Application, Command, Element, Length, Settings, Theme};
+use iced::{alignment, executor, Font, Renderer, Theme};
+use iced::{Application, Command, Element, Length, Settings};
use ui::graph::GraphCanvas;
use ui::pane::{Pane, PaneKind};
use ui::Message;
@@ -95,16 +96,30 @@ impl Application for Graph {
flist = flist.push(
row![
text_input("f(x) = x^2", f)
- .on_input(move |s| Message::InputChanged(s, i))
- .on_submit(Message::UpdateFunction(i)),
+ .style(TextInput::Custom(Box::new(
+ TextInputStyle::default()
+ )))
+ .on_input(move |s| Message::InputChanged(s, i))
+ .on_submit(Message::UpdateFunction(i)),
button("-").on_press(Message::RemoveFunction(i))
- ].padding(5)
+ ]
+ .padding(5),
);
}
flist = flist.push(
- button("+")
- .width(Length::Fill)
- .on_press(Message::AddFunction),
+ button(
+ Text::new("+")
+ .font(Font {
+ weight: iced::font::Weight::Bold,
+ ..Default::default()
+ })
+ .horizontal_alignment(alignment::Horizontal::Center)
+ .vertical_alignment(alignment::Vertical::Center)
+ .width(Length::Fill),
+ )
+ .style(Button::Custom(Box::new(ButtonStyle::default())))
+ .width(Length::Fill)
+ .on_press(Message::AddFunction),
);
flist.into()
}
@@ -133,3 +148,65 @@ impl Application for Graph {
Theme::Dark
}
}
+
+#[derive(Default)]
+struct ButtonStyle {}
+
+impl button::StyleSheet for ButtonStyle {
+ type Style = Theme;
+
+ fn active(&self, style: &Self::Style) -> button::Appearance {
+ button::Appearance {
+ background: Some(iced::Background::Color(style.palette().primary)),
+ border_radius: 10.0.into(),
+ ..Default::default()
+ }
+ }
+}
+
+#[derive(Default)]
+struct TextInputStyle {}
+
+impl text_input::StyleSheet for TextInputStyle {
+ type Style = Theme;
+
+ fn active(&self, style: &Self::Style) -> text_input::Appearance {
+ text_input::Appearance {
+ background: iced::Background::Color(style.palette().background),
+ border_radius: 10.0.into(),
+ border_width: 2.0,
+ border_color: style.palette().primary,
+ icon_color: style.palette().primary,
+ }
+ }
+
+ fn focused(&self, style: &Self::Style) -> text_input::Appearance {
+ self.active(style)
+ }
+
+ fn placeholder_color(&self, style: &Self::Style) -> iced::Color {
+ style.palette().background
+ }
+
+ fn value_color(&self, style: &Self::Style) -> iced::Color {
+ style.palette().success
+ }
+
+ fn disabled_color(&self, style: &Self::Style) -> iced::Color {
+ style.palette().background
+ }
+
+ fn selection_color(&self, style: &Self::Style) -> iced::Color {
+ style.palette().primary
+ }
+
+ fn disabled(&self, style: &Self::Style) -> text_input::Appearance {
+ text_input::Appearance {
+ background: iced::Background::Color(style.palette().background),
+ border_radius: 10.0.into(),
+ border_width: 2.0,
+ border_color: style.palette().primary,
+ icon_color: style.palette().primary,
+ }
+ }
+}