From 09450176141cda7c074b3a2584d103ca3bad3026 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 24 Jan 2024 09:24:59 +0100 Subject: create simple theme --- src/main.rs | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file 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, + } + } +} -- cgit v1.2.3-70-g09d2