This commit is contained in:
Ashley Wulber 2024-10-17 09:58:45 -04:00 committed by Ashley Wulber
parent 478f3ead75
commit 7b9cad4d2c
5 changed files with 22 additions and 20 deletions

View file

@ -4,7 +4,7 @@ use cosmic::{
app::Core,
iced::{self, event, window},
iced_core::{id, Alignment, Length, Point},
iced_widget::{column, container, scrollable, text, text_input},
iced_widget::{column, container, scrollable, text},
widget::{button, header_bar},
ApplicationExt, Task,
};
@ -45,7 +45,7 @@ impl cosmic::Application for MultiWindow {
fn init(core: Core, _input: Self::Flags) -> (Self, cosmic::app::Task<Self::Message>) {
let windows = MultiWindow {
windows: HashMap::from([(
self.core.main_window_id().unwrap(),
core.main_window_id().unwrap(),
Window {
input_id: id::Id::new("main"),
input_value: String::new(),
@ -86,7 +86,7 @@ impl cosmic::Application for MultiWindow {
}
Message::WindowOpened(id, ..) => {
if let Some(window) = self.windows.get(&id) {
text_input::focus(window.input_id.clone())
cosmic::widget::text_input::focus(window.input_id.clone())
} else {
Task::none()
}
@ -94,7 +94,7 @@ impl cosmic::Application for MultiWindow {
Message::NewWindow => {
let count = self.windows.len() + 1;
let (id, spawn_window) = window::spawn(window::Settings {
let (id, spawn_window) = window::open(window::Settings {
position: Default::default(),
exit_on_close_request: count % 2 == 0,
decorations: false,
@ -110,13 +110,11 @@ impl cosmic::Application for MultiWindow {
);
_ = self.set_window_title(format!("window_{}", count), id);
spawn_window
spawn_window.map(|id| cosmic::app::Message::App(Message::WindowOpened(id, None)))
}
Message::Input(id, value) => {
if let Some(w) = self.windows.get_mut(&self.core.main_window_id().unwrap()) {
if id == w.input_id {
w.input_value = value;
}
if let Some((_, w)) = self.windows.iter_mut().find(|e| e.1.input_id == id) {
w.input_value = value;
}
Task::none()
@ -128,7 +126,7 @@ impl cosmic::Application for MultiWindow {
let w = self.windows.get(&id).unwrap();
let input_id = w.input_id.clone();
let input = text_input("something", &w.input_value)
let input = cosmic::widget::text_input::text_input("something", &w.input_value)
.on_input(move |msg| Message::Input(input_id.clone(), msg))
.id(w.input_id.clone());
let focused = self
@ -136,7 +134,7 @@ impl cosmic::Application for MultiWindow {
.focused_window()
.map(|i| i == id)
.unwrap_or_default();
let new_window_button = button(text("New Window")).on_press(Message::NewWindow);
let new_window_button = button::custom(text("New Window")).on_press(Message::NewWindow);
let content = scrollable(
column![input, new_window_button]
@ -146,7 +144,7 @@ impl cosmic::Application for MultiWindow {
);
let window_content = container(container(content).center_x(Length::Fixed(200.)))
.style(cosmic::style::Container::Background)
.class(cosmic::style::Container::Background)
.center_x(Length::Fill)
.center_y(Length::Fill);