Skip to content

Commit

Permalink
chore: mainly finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Aug 6, 2024
1 parent 6675f03 commit 78e8cbc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
9 changes: 7 additions & 2 deletions iced_examples/counter_muti/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use iced_layershell::actions::{
LayershellCustomActions, LayershellCustomActionsWithId, LayershellCustomActionsWithIdAndInfo,
LayershellCustomActionsWithInfo,
};
use iced_runtime::command::Action;
use iced_runtime::window::Action as WindowAction;

use iced_layershell::reexport::{Anchor, Layer, NewLayerShellSettings};
use iced_layershell::settings::{LayerShellSettings, Settings};
use iced_layershell::MultiApplication;
Expand Down Expand Up @@ -48,6 +51,7 @@ enum Message {
DecrementPressed,
NewWindowLeft,
NewWindowRight,
Close(Id),
TextInput(String),
Direction(WindowDirection),
IcedEvent(Event),
Expand Down Expand Up @@ -211,15 +215,16 @@ impl MultiApplication for Counter {
)
.into(),
),
Message::Close(id) => Command::single(Action::Window(WindowAction::Close(id))),
}
}

fn view(&self, id: iced::window::Id) -> Element<Message> {
if let Some(WindowInfo::Left) = self.id_info(id) {
return text("left").into();
return button("close left").on_press(Message::Close(id)).into();
}
if let Some(WindowInfo::Right) = self.id_info(id) {
return text("right").into();
return button("close right").on_press(Message::Close(id)).into();
}
let center = column![
button("Increment").on_press(Message::IncrementPressed),
Expand Down
18 changes: 14 additions & 4 deletions iced_layershell/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,18 @@ pub(crate) fn run_command<A, C, E>(
*ui_caches = uis.drain().map(|(id, ui)| (id, ui.into_cache())).collect();
}
command::Action::Window(action) => match action {
WinowAction::Close(_) => {
*should_exit = true;
WinowAction::Close(id) => {
if id == iced::window::Id::MAIN {
*should_exit = true;
continue;
}
if let Some(layerid) = window_manager.get_layer_id(id) {
customactions.push(LayershellCustomActionsWithIdInner(
layerid,
Some(layerid),
LayershellCustomActionsWithInfo::RemoveLayerShell(id),
))
}
}
WinowAction::Screenshot(id, tag) => {
let Some(window) = window_manager.get_mut(id) else {
Expand Down Expand Up @@ -895,11 +905,11 @@ pub(crate) fn run_command<A, C, E>(
{
let option_id =
if let LayershellCustomActionsWithInfo::RemoveLayerShell(id) = action.1 {
window_manager.get_iced_id(id)
window_manager.get_layer_id(id)
} else {
None
};
if let Some(id) = window_manager.get_iced_id(action.0) {
if let Some(id) = window_manager.get_layer_id(action.0) {
customactions.push(LayershellCustomActionsWithIdInner(
id,
option_id,
Expand Down
2 changes: 1 addition & 1 deletion iced_layershell/src/multi_window/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ where
Some((id, self.get_mut(id)?))
}

pub fn get_iced_id(&self, id: IcedId) -> Option<LayerId> {
pub fn get_layer_id(&self, id: IcedId) -> Option<LayerId> {
self.back_aliases.get(&id).copied()
}

Expand Down

0 comments on commit 78e8cbc

Please sign in to comment.