make dialog us apply more such that it cleans up code structure
Some checks are pending
/ test (push) Waiting to run

This commit is contained in:
Chris Cochrun 2025-10-22 10:51:18 -05:00
parent 8699a08948
commit b0a33ad0f6

View file

@ -32,7 +32,7 @@ use cosmic::widget::{
}; };
use cosmic::widget::{container, text}; use cosmic::widget::{container, text};
use cosmic::widget::{icon, slider}; use cosmic::widget::{icon, slider};
use cosmic::{Application, ApplicationExt, Element, executor}; use cosmic::{Application, ApplicationExt, Apply, Element, executor};
use cosmic::{cosmic_config, theme}; use cosmic::{cosmic_config, theme};
use crisp::types::Value; use crisp::types::Value;
use lisp::parse_lisp; use lisp::parse_lisp;
@ -718,72 +718,70 @@ impl cosmic::Application for App {
.map(|item| { .map(|item| {
let title = text::title4(item.title().clone()); let title = text::title4(item.title().clone());
let subtitle = text::body(item.to_string()); let subtitle = text::body(item.to_string());
Element::from(Container::new( Element::from(
row![ row![
column![title, subtitle] column![title, subtitle]
.spacing(space_xxs), .spacing(space_xxs),
horizontal_space(), horizontal_space(),
tooltip( tooltip(
button::icon( icon::from_name("add")
icon::from_name("add") .symbolic(true).apply(button::icon)
.symbolic(true) .icon_size(space_l)
) .on_press(
.icon_size(space_l) Message::AppendServiceItemKind(
.on_press( item.clone()
Message::AppendServiceItemKind( )
item.clone() ),
)
),
"Add to service", "Add to service",
TPosition::FollowCursor TPosition::FollowCursor
), ),
tooltip( tooltip(
button::icon( icon::from_name("edit")
icon::from_name("edit") .symbolic(true).apply(button::icon)
.symbolic(true) .icon_size(space_l)
) .on_press(Message::OpenEditorKind(
.icon_size(space_l) item.clone()
.on_press(Message::OpenEditorKind( )),
item.clone()
)),
"Edit Item", "Edit Item",
TPosition::FollowCursor TPosition::FollowCursor
), ),
] ]
.align_y(Vertical::Center), .align_y(Vertical::Center)
)) .apply(container),
)
}) })
.collect(); .collect();
let modal = Container::new( let modal = column![
column![ search_input("Amazing Grace", &self.search_query)
search_input("Amazing Grace", &self.search_query) .id(self.search_id.clone())
.id(self.search_id.clone()) .select_on_focus(true)
.select_on_focus(true) .on_input(Message::Search)
.on_input(Message::Search) .on_submit(Message::Search),
.on_submit(Message::Search), column(items).spacing(space_xxs)
column(items).spacing(space_xxs) ]
] .spacing(space_s)
.spacing(space_s), .apply(container)
)
.padding(space_xl) .padding(space_xl)
.style(nav_bar_style); .style(nav_bar_style);
let modal = Container::new(modal) let modal = mouse_area(modal)
.on_press(Message::None)
.apply(container)
.padding([space_xxl, space_xxxl * 2]) .padding([space_xxl, space_xxxl * 2])
.center_x(Length::Fill) .center_x(Length::Fill)
.align_top(Length::Fill); .align_top(Length::Fill);
let mouse_stack = stack!( let mouse_stack = stack!(
mouse_area( Space::new(Length::Fill, Length::Fill)
container(Space::new(Length::Fill, Length::Fill)) .apply(container)
.style(|_| { .style(|_| {
container::background( container::background(
cosmic::iced::Background::Color( cosmic::iced::Background::Color(
Color::BLACK, Color::BLACK,
)
.scale_alpha(0.3),
) )
}) .scale_alpha(0.3),
) )
.on_press(Message::CloseSearch), })
.apply(mouse_area)
.on_press(Message::CloseSearch),
modal modal
); );
Some(mouse_stack.into()) Some(mouse_stack.into())
@ -801,51 +799,49 @@ impl cosmic::Application for App {
), ),
); );
let settings_column = column![ let settings_column = column![
Container::new( icon::from_name("dialog-close")
button::icon( .symbolic(true)
icon::from_name("dialog-close") .prefer_svg(true)
.symbolic(true) .apply(button::icon)
)
.class(theme::Button::Icon) .class(theme::Button::Icon)
.on_press(Message::CloseSettings) .on_press(Message::CloseSettings)
) .apply(container)
.padding(space_s) .padding(space_s)
.align_right(Length::Fill) .align_right(Length::Fill)
.align_top(60), .align_top(60),
horizontal_space().height(space_xxl), horizontal_space().height(space_xxl),
Container::new( settings::section()
settings::section() .title("Obs Settings")
.title("Obs Settings") .add(obs_socket)
.add(obs_socket) .add(apply_button)
.add(apply_button) .apply(container)
) .center_x(Length::Fill)
.center_x(Length::Fill) .align_top(Length::Fill)
.align_top(Length::Fill) .padding([0, space_xxxl * 2])
.padding([0, space_xxxl * 2])
] ]
.height(Length::Fill); .height(Length::Fill);
let settings_container = Container::new(settings_column) let settings_container = settings_column
.apply(container)
.style(nav_bar_style) .style(nav_bar_style)
.center_x(Length::Fill) .center_x(Length::Fill)
.align_top(Length::Fill); .align_top(Length::Fill);
let modal = Container::new( let modal = mouse_area(settings_container)
mouse_area(settings_container) .on_press(Message::None)
.on_press(Message::None), .apply(container)
) .padding([space_xxl, space_xxxl * 2]);
.padding([space_xxl, space_xxxl * 2]);
let mouse_stack = stack!( let mouse_stack = stack!(
mouse_area( Space::new(Length::Fill, Length::Fill)
container(Space::new(Length::Fill, Length::Fill)) .apply(container)
.style(|_| { .style(|_| {
container::background( container::background(
cosmic::iced::Background::Color( cosmic::iced::Background::Color(
Color::BLACK, Color::BLACK,
)
.scale_alpha(0.3),
) )
}) .scale_alpha(0.3),
) )
.on_press(Message::CloseSettings), })
.apply(mouse_area)
.on_press(Message::CloseSettings),
modal modal
); );
Some(mouse_stack.into()) Some(mouse_stack.into())
@ -1239,6 +1235,7 @@ impl cosmic::Application for App {
Task::none() Task::none()
} }
Message::SearchFocus => { Message::SearchFocus => {
self.settings_open = false;
self.searching = true; self.searching = true;
cosmic::widget::text_input::focus( cosmic::widget::text_input::focus(
self.search_id.clone(), self.search_id.clone(),
@ -1500,6 +1497,7 @@ impl cosmic::Application for App {
}) })
} }
Message::OpenSettings => { Message::OpenSettings => {
self.searching = false;
self.settings_open = true; self.settings_open = true;
Task::none() Task::none()
} }