Skip to content

Commit

Permalink
working theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Redhawk18 committed Jul 15, 2023
1 parent bfca09c commit 6508f6b
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 47 deletions.
3 changes: 1 addition & 2 deletions src/gui/elements.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use iced::widget::{button, row};
use iced::Element;
use iced_aw::menu::{MenuBar, MenuTree};
use iced_aw::{TabBar, TabLabel};

use crate::gui::theme::Renderer;
use crate::gui::theme::{Element, Renderer};

pub fn menu_bar<'a>() -> MenuBar<'a, super::Message, Renderer> {
MenuBar::new(vec![file()])
Expand Down
54 changes: 26 additions & 28 deletions src/gui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::path::PathBuf;

//use iced::widget::text_input;
//use iced::widget::Column;
use iced::widget::button;
use iced::widget::text_input;
use iced::widget::Column;
use iced::{Application, Command, Subscription};
mod theme;
mod elements;
mod file_dialog;
mod theme;

pub use elements::menu_bar;
use theme::mywidget::{Element, Column, Button};
use theme::Theme;
use theme::{Theme, Element};

#[derive(Debug, Clone)]
pub enum Message {
Expand Down Expand Up @@ -38,7 +38,7 @@ pub struct FileTab {
pub struct State {
active_tab: Option<usize>,
tabs: Vec<FileTab>,
theme: Theme
theme: Theme,
}

impl Application for State {
Expand All @@ -52,7 +52,7 @@ impl Application for State {
State {
active_tab: None,
tabs: Vec::new(),
theme: Theme::Dark
theme: Theme::Dark,
},
Command::none(),
)
Expand All @@ -75,7 +75,7 @@ impl Application for State {
path: PathBuf::default(),
}))
}
}
},

Message::NewFile => {
return self.update(Message::TabNew(FileTab {
Expand Down Expand Up @@ -110,15 +110,15 @@ impl Application for State {
file_dialog::save_file(tab.text.as_str(), tab.path.as_path()).unwrap();
}
None => return Command::none(),
}
},

Message::SaveAs => match self.active_tab {
Some(index) => {
let tab = self.tabs.get(index).unwrap();
file_dialog::save_as(tab.text.as_str(), tab.path.as_path()).unwrap();
}
None => return Command::none(),
}
},

Message::Quit => std::process::exit(0),

Expand Down Expand Up @@ -151,24 +151,22 @@ impl Application for State {
}

fn view(&self) -> Element<Message> {
//let open_file = Button::new("Open File").on_press(Message::OpenFile);
let c = Column::new();
// let mut c = Column::new().push(menu_bar());

// if !self.tabs.is_empty() {
// c = c.push(elements::tab_header(&self.tabs, self.active_tab.unwrap()));
// c = c.push(
// text_input(
// "",
// self.tabs
// .get(self.active_tab.unwrap())
// .unwrap()
// .text
// .as_str(),
// )
// .on_input(Message::TextUpdate),
// );
// }
let mut c = Column::new().push(menu_bar());

if !self.tabs.is_empty() {
c = c.push(elements::tab_header(&self.tabs, self.active_tab.unwrap()));
c = c.push(
text_input(
"",
self.tabs
.get(self.active_tab.unwrap())
.unwrap()
.text
.as_str(),
)
.on_input(Message::TextUpdate),
);
}

c.into()
}
Expand Down
105 changes: 88 additions & 17 deletions src/gui/theme.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
use iced::{application, color};

// pub mod mywidget {
// use super::Theme;
// pub type Renderer = iced::Renderer<Theme>;
// pub type Element<'a, Message> = iced::Element<'a, Message, Renderer>;
// pub type Container<'a, Message> = iced::widget::Container<'a, Message, Renderer>;
// pub type Button<'a, Message> = iced::widget::Button<'a, Message, Renderer>;
// pub type Text<'a> = iced::widget::Text<'a, Renderer>;
// pub type Row<'a, Message> = iced::widget::Row<'a, Message, Renderer>;
// pub type Column<'a, Message> = iced::widget::Column<'a, Message, Renderer>;
// pub type Scrollable<'a, Message> = iced::widget::Scrollable<'a, Message, Renderer>;
// }
use iced::widget::{button, text, text_input};
use iced::{application, color, Color, Background};
use iced_aw::menu;
use iced_aw::style::tab_bar; //lib bug


pub type Renderer = iced::Renderer<Theme>;
pub type Element<'msg, Message> = iced::Element<'msg, Message, Renderer>;

#[derive(Debug, Clone, Copy, Default)]
pub enum Theme {
#[default]
Dark,
Light,
#[default]
Dark,
Light,
}

impl application::StyleSheet for Theme {
type Style = Theme; // ModernTheme in this case is an enum
type Style = Theme;

fn appearance(&self, _style: &Self::Style) -> application::Appearance {
application::Appearance {
Expand All @@ -31,3 +24,81 @@ impl application::StyleSheet for Theme {
}
}
}

impl button::StyleSheet for Theme {
type Style = Theme;

fn active(&self, style: &Self::Style) -> button::Appearance {
button::Appearance {
..Default::default()
}
}
}

impl menu::StyleSheet for Theme {
type Style = Theme;

fn appearance(&self, style: &Self::Style) -> menu::Appearance {
Default::default()
}
}

impl tab_bar::StyleSheet for Theme {
type Style = Theme;

fn active(&self, style: Self::Style, is_active: bool) -> tab_bar::Appearance {
Default::default()
}

fn hovered(&self, style: Self::Style, is_active: bool) -> tab_bar::Appearance {
Default::default()
}

}

impl text::StyleSheet for Theme {
type Style = Theme;

fn appearance(&self, style: Self::Style) -> text::Appearance {
Default::default()
}
}

impl text_input::StyleSheet for Theme {
type Style = Theme;

fn active(&self, style: &Self::Style) -> text_input::Appearance {
text_input::Appearance {
background: Background::Color(color!(0, 0, 0)),
border_radius: 4.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
// XXX Not currently displayed in application.
icon_color: color!(0, 0, 0),
}
}

fn focused(&self, style: &Self::Style) -> text_input::Appearance {
self.active(style)
}

fn placeholder_color(&self, style: &Self::Style) -> Color {
Default::default()
}

fn value_color(&self, style: &Self::Style) -> Color {
Default::default()
}

fn disabled_color(&self, style: &Self::Style) -> Color {
Default::default()
}

fn selection_color(&self, style: &Self::Style) -> Color {
Default::default()
}

fn disabled(&self, style: &Self::Style) -> text_input::Appearance {
self.active(style)
}
}

0 comments on commit 6508f6b

Please sign in to comment.