Basic theming with system/light/dark selection

This commit is contained in:
Squid committed 2026-10-29 22:29:31 +01:00
1 parent 995a5fbc1d
commit c265841334
2 files changed
+192 -20

No files matched your search

+57 -20
View File
@@ -1,28 +1,48 @@
use iced::widget::{button, column, container, row, stack, text};
use iced::{Alignment, Border, Element, Length, Padding, Task};
use iced::widget::{button, column, container, pick_list, row, stack, text};
use iced::{Alignment, Element, Length, Padding, Task};
#[allow(dead_code)]
mod terminal;
mod theme;
const MENUBAR_HEIGHT: f32 = 21.0;
fn main() -> iced::Result {
iced::application(Moorly::default, update, view)
.title("Moorly")
.theme(|state: &Moorly| state.theme.iced())
.run()
}
#[derive(Default)]
struct Moorly {
menu_open: bool,
theme: theme::Preference,
}
impl Default for Moorly {
fn default() -> Self {
Self {
menu_open: false,
theme: theme::load(),
}
}
}
#[derive(Debug, Clone)]
enum Message {
ToggleMenu,
SetTheme(theme::Preference),
Quit,
}
fn update(state: &mut Moorly, message: Message) -> Task<Message> {
match message {
Message::ToggleMenu => state.menu_open = !state.menu_open,
Message::SetTheme(preference) => {
state.theme = preference;
state.menu_open = false;
theme::save(preference);
}
Message::Quit => std::process::exit(0),
}
@@ -48,18 +68,7 @@ fn view(state: &Moorly) -> Element<'_, Message> {
.align_x(Alignment::End)
.align_y(Alignment::Center)
.padding([0, 8])
.style(|theme| {
let palette = theme.extended_palette();
container::Style {
background: Some(palette.background.weak.color.into()),
border: Border {
color: palette.background.strong.color,
width: 1.0,
radius: 0.0.into(),
},
..container::Style::default()
}
});
.style(theme::menubar);
let main_area = container(column![]).width(Length::Fill).height(Length::Fill);
@@ -69,19 +78,47 @@ fn view(state: &Moorly) -> Element<'_, Message> {
return base.into();
}
let theme_field = stack![
container(
pick_list(
theme::Preference::ALL,
Some(state.theme),
Message::SetTheme
)
.width(Length::Fill),
)
.width(Length::Fill)
.padding(Padding::ZERO.top(6.0)),
container(
container(text("Theme").size(11))
.padding([0, 4])
.style(theme::field_label),
)
.padding(Padding::ZERO.left(8.0)),
]
.width(Length::Fill);
let menu_items = column![theme_field].spacing(4);
let menu_items = menu_items.push(
button("Quit")
.on_press(Message::Quit)
.width(Length::Fill)
.style(button::text),
);
let menu = container(
column![
container(hamburger()).width(Length::Fill).align_x(Alignment::End),
button("Quit")
.on_press(Message::Quit)
container(hamburger())
.width(Length::Fill)
.style(button::text),
.align_x(Alignment::End),
menu_items,
]
.spacing(2),
)
.width(160)
.padding(4)
.style(container::rounded_box);
.style(theme::menu);
let dropdown = container(menu)
.width(Length::Fill)