transparency
This commit is contained in:
parent
f452bb14c6
commit
0ff6a2dff8
9 changed files with 293 additions and 68 deletions
64
src/main.rs
64
src/main.rs
|
|
@ -1,5 +1,5 @@
|
|||
use iced::widget::{Column, TextInput, text};
|
||||
use iced::{Color, Element, Event, Task as Command, event};
|
||||
use iced::widget::{Column, Container, Id, TextInput, container, operation, stack, text};
|
||||
use iced::{Color, Element, Event, Task as Command};
|
||||
use iced_layershell::application;
|
||||
use iced_layershell::reexport::Anchor;
|
||||
use iced_layershell::settings::{LayerShellSettings, Settings, StartMode};
|
||||
|
|
@ -38,15 +38,28 @@ pub fn main() -> Result<(), iced_layershell::Error> {
|
|||
.run()
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct State {
|
||||
initialized: bool,
|
||||
current_message: String,
|
||||
history: Vec<String>,
|
||||
input_id: Id,
|
||||
}
|
||||
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
initialized: false,
|
||||
current_message: String::new(),
|
||||
history: Vec::new(),
|
||||
input_id: Id::unique(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[to_layer_message]
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
Init,
|
||||
TextSubmit,
|
||||
TextInput(String),
|
||||
IcedEvent(Event),
|
||||
|
|
@ -56,14 +69,27 @@ fn namespace() -> String {
|
|||
String::from("Iced qalc claculator")
|
||||
}
|
||||
|
||||
fn subscription(_: &State) -> iced::Subscription<Message> {
|
||||
event::listen().map(Message::IcedEvent)
|
||||
fn subscription(state: &State) -> iced::Subscription<Message> {
|
||||
use iced::event;
|
||||
use iced::futures::stream;
|
||||
|
||||
let init = if !state.initialized {
|
||||
iced::Subscription::run_with("init", |_| stream::once(async { Message::Init }))
|
||||
} else {
|
||||
iced::Subscription::none()
|
||||
};
|
||||
|
||||
iced::Subscription::batch([init, event::listen().map(Message::IcedEvent)])
|
||||
}
|
||||
|
||||
fn update(state: &mut State, message: Message) -> Command<Message> {
|
||||
use iced::keyboard::{Event::KeyReleased, Key, key::Named};
|
||||
|
||||
match message {
|
||||
Message::Init => {
|
||||
state.initialized = true;
|
||||
operation::focus(state.input_id.clone())
|
||||
}
|
||||
Message::IcedEvent(event) => {
|
||||
if let Event::Keyboard(KeyReleased {
|
||||
key: Key::Named(Named::Escape),
|
||||
|
|
@ -92,23 +118,39 @@ fn update(state: &mut State, message: Message) -> Command<Message> {
|
|||
}
|
||||
}
|
||||
|
||||
fn view(state: &State) -> Column<'_, Message> {
|
||||
fn view(state: &State) -> Container<'_, Message> {
|
||||
let input: TextInput<'_, Message> =
|
||||
TextInput::new("Type something here...", &state.current_message)
|
||||
.on_input(Message::TextInput)
|
||||
.on_submit(Message::TextSubmit);
|
||||
.on_submit(Message::TextSubmit)
|
||||
.id(state.input_id.clone());
|
||||
|
||||
Column::with_children(
|
||||
let content = Column::with_children(
|
||||
std::iter::once(input.into())
|
||||
.chain(state.history.iter().rev().map(|msg| text!("{msg}").into()))
|
||||
.collect::<Vec<Element<_>>>(),
|
||||
)
|
||||
);
|
||||
|
||||
let bg = container(iced::widget::Space::new())
|
||||
.width(iced::Length::Fill)
|
||||
.height(iced::Length::Fill)
|
||||
.style(|_theme| container::Style {
|
||||
background: Some(iced::Background::Color(Color::from_rgba8(30, 30, 46, 0.75))),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
let layered = stack![bg, content];
|
||||
|
||||
container(layered).style(|_theme| container::Style {
|
||||
text_color: Some(Color::WHITE),
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
|
||||
fn style(_counter: &State, theme: &iced::Theme) -> iced::theme::Style {
|
||||
fn style(_state: &State, theme: &iced::Theme) -> iced::theme::Style {
|
||||
use iced::theme::Style;
|
||||
Style {
|
||||
background_color: Color::WHITE,
|
||||
background_color: Color::TRANSPARENT,
|
||||
text_color: theme.palette().text,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue