various fixes

This commit is contained in:
Ashley Wulber 2024-01-31 23:17:16 -05:00 committed by Ashley Wulber
parent a6785de7ba
commit dbcd927d4b
7 changed files with 110 additions and 110 deletions

View file

@ -8,7 +8,7 @@ publish = false
[dependencies] [dependencies]
apply = "0.3.0" apply = "0.3.0"
fraction = "0.14.0" fraction = "0.14.0"
libcosmic = { path = "../..", features = ["debug", "winit", "tokio", "single-instance", "dbus-config", "wgpu"] } libcosmic = { path = "../..", features = ["debug", "winit", "tokio", "single-instance", "dbus-config", ] }
once_cell = "1.18" once_cell = "1.18"
slotmap = "1.0.6" slotmap = "1.0.6"
env_logger = "0.10" env_logger = "0.10"
@ -17,5 +17,5 @@ log = "0.4.17"
[dependencies.cosmic-time] [dependencies.cosmic-time]
git = "https://github.com/pop-os/cosmic-time" git = "https://github.com/pop-os/cosmic-time"
default-features = false default-features = false
branch = "update-0.12" branch = "wip-iced-update"
features = ["libcosmic", "once_cell"] features = ["libcosmic", "once_cell"]

View file

@ -14,7 +14,14 @@ pub fn main() -> cosmic::iced::Result {
env_logger::init_from_env(env); env_logger::init_from_env(env);
cosmic::icon_theme::set_default("Pop"); cosmic::icon_theme::set_default("Pop");
let mut settings = Settings::default(); #[allow(clippy::field_reassign_with_default)]
settings.window.min_size = Some(cosmic::iced::Size::new(600., 300.)); let settings = Settings {
default_font: cosmic::font::FONT,
window: cosmic::iced::window::Settings {
min_size: Some(cosmic::iced::Size::new(600., 300.)),
..cosmic::iced::window::Settings::default()
},
..Settings::default()
};
Window::run(settings) Window::run(settings)
} }

View file

@ -288,6 +288,7 @@ impl Window {
) )
.padding([20, 24]), .padding([20, 24]),
) )
.width(Length::Fill)
.padding(0) .padding(0)
.style(theme::iced::Button::Transparent) .style(theme::iced::Button::Transparent)
.on_press(Message::from(sub_page.into_page())) .on_press(Message::from(sub_page.into_page()))
@ -565,11 +566,11 @@ impl Application for Window {
}; };
widgets.push( widgets.push(
scrollable(row![ scrollable(
horizontal_space(Length::Fill), container(content.debug(self.debug))
content.debug(self.debug), .align_x(iced::alignment::Horizontal::Center),
horizontal_space(Length::Fill), )
]) .width(Length::Fill)
.into(), .into(),
); );
} }

View file

@ -3,7 +3,7 @@ use std::{cell::RefCell, rc::Rc};
use apply::Apply; use apply::Apply;
use cosmic::{ use cosmic::{
cosmic_theme, cosmic_theme,
iced::widget::{checkbox, column, progress_bar, radio, slider, text, text_input}, iced::widget::{checkbox, column, progress_bar, radio, slider, text},
iced::{Alignment, Length}, iced::{Alignment, Length},
iced_core::id, iced_core::id,
theme::ThemeType, theme::ThemeType,
@ -488,6 +488,7 @@ impl State {
.into(), .into(),
cosmic::widget::text_input("", &self.entry_value) cosmic::widget::text_input("", &self.entry_value)
.label("Test Input") .label("Test Input")
.helper_text("test helper text")
.on_input(Message::InputChanged) .on_input(Message::InputChanged)
.size(20) .size(20)
.id(INPUT_ID.clone()) .id(INPUT_ID.clone())

View file

@ -135,6 +135,7 @@ impl State {
.spacing(16) .spacing(16)
.into(), .into(),
]) ])
.width(Length::Fill)
.into(), .into(),
Some(DesktopPage::DesktopOptions) => self.view_desktop_options(window), Some(DesktopPage::DesktopOptions) => self.view_desktop_options(window),
Some(DesktopPage::Wallpaper) => self.view_desktop_wallpaper(window), Some(DesktopPage::Wallpaper) => self.view_desktop_wallpaper(window),

View file

@ -756,7 +756,7 @@ where
height: bounds.height, height: bounds.height,
}, },
border: Border { border: Border {
radius: appearance.focus.first.border_radius, radius: theme.cosmic().radius_s().into(),
..Default::default() ..Default::default()
}, },
shadow: Shadow::default(), shadow: Shadow::default(),
@ -808,7 +808,7 @@ where
height: bounds.height, height: bounds.height,
}, },
border: Border { border: Border {
radius: appearance.focus.last.border_radius, radius: theme.cosmic().radius_s().into(),
..Default::default() ..Default::default()
}, },
shadow: Shadow::default(), shadow: Shadow::default(),

View file

@ -227,7 +227,7 @@ where
padding: [spacing, spacing, spacing, spacing].into(), padding: [spacing, spacing, spacing, spacing].into(),
size: None, size: None,
helper_size: 10.0, helper_size: 10.0,
helper_line_height: text::LineHeight::from(14.0), helper_line_height: text::LineHeight::Absolute(14.0.into()),
on_input: None, on_input: None,
on_paste: None, on_paste: None,
on_submit: None, on_submit: None,
@ -907,7 +907,7 @@ pub fn layout<Message>(
let mut nodes = Vec::with_capacity(3); let mut nodes = Vec::with_capacity(3);
let text_pos = if let Some(label) = label { let text_pos = if let Some(label) = label {
let text_bounds = limits.resolve(Length::Shrink, Length::Shrink, Size::ZERO); let text_bounds = limits.resolve(width, Length::Shrink, Size::INFINITY);
let state = tree.state.downcast_mut::<State>(); let state = tree.state.downcast_mut::<State>();
let label_paragraph = &mut state.label; let label_paragraph = &mut state.label;
label_paragraph.update(Text { label_paragraph.update(Text {
@ -929,7 +929,7 @@ pub fn layout<Message>(
}; };
let text_size = size.unwrap_or_else(|| renderer.default_size().0); let text_size = size.unwrap_or_else(|| renderer.default_size().0);
let mut text_input_height = text_size * 1.2; let mut text_input_height = line_height.to_absolute(text_size.into()).0;
let padding = padding.fit(Size::ZERO, limits.max()); let padding = padding.fit(Size::ZERO, limits.max());
let helper_pos = if leading_icon.is_some() || trailing_icon.is_some() { let helper_pos = if leading_icon.is_some() || trailing_icon.is_some() {
@ -968,16 +968,20 @@ pub fn layout<Message>(
} else { } else {
(0.0, None) (0.0, None)
}; };
let text_limits = limits.width(width).height(text_size * 1.2); let text_limits = limits
.width(width)
.height(line_height.to_absolute(text_size.into()));
let text_bounds = text_limits.resolve(Length::Shrink, Length::Shrink, Size::ZERO); let text_bounds = text_limits.resolve(width, Length::Shrink, Size::INFINITY);
let text_node = layout::Node::new( let text_node = layout::Node::new(
text_bounds - Size::new(leading_icon_width + trailing_icon_width, 0.0), text_bounds - Size::new(leading_icon_width + trailing_icon_width, 0.0),
) )
.move_to(Point::new( .move_to(Point::new(
padding.left + leading_icon_width, padding.left + leading_icon_width,
padding.top + (text_size.mul_add(-1.2, text_input_height) / 2.0).max(0.0), padding.top
+ ((text_input_height - line_height.to_absolute(text_size.into()).0) / 2.0)
.max(0.0),
)); ));
let mut node_list: Vec<_> = Vec::with_capacity(3); let mut node_list: Vec<_> = Vec::with_capacity(3);
@ -991,20 +995,17 @@ pub fn layout<Message>(
))); )));
} }
if let Some(trailing_icon) = trailing_icon.take() { if let Some(trailing_icon) = trailing_icon.take() {
node_list.push(trailing_icon.clone().move_to(Point::new( let trailing_icon = trailing_icon.clone().move_to(Point::new(
text_node_bounds.x + text_node_bounds.width + f32::from(spacing), text_node_bounds.x + text_node_bounds.width + f32::from(spacing),
padding.top + ((text_input_height - trailing_icon.bounds().height) / 2.0).max(0.0), padding.top + ((text_input_height - trailing_icon.bounds().height) / 2.0).max(0.0),
))); ));
node_list.push(trailing_icon);
} }
let text_input_size = Size::new( let text_input_size = Size::new(
text_node_bounds.x + text_node_bounds.width + trailing_icon_width, text_node_bounds.x + text_node_bounds.width + trailing_icon_width,
text_input_height, text_input_height,
) )
.expand(Size {
height: -padding.top - padding.bottom,
width: -padding.left - padding.right,
})
.expand(padding); .expand(padding);
let input_limits = limits_copy let input_limits = limits_copy
@ -1026,13 +1027,14 @@ pub fn layout<Message>(
.width(width) .width(width)
.height(text_input_height + padding.vertical()) .height(text_input_height + padding.vertical())
.shrink(padding); .shrink(padding);
let text_bounds = limits.resolve(Length::Shrink, Length::Shrink, Size::ZERO); let text_bounds = limits.resolve(width, Length::Shrink, Size::INFINITY);
let text = layout::Node::new(text_bounds).move_to(Point::new(padding.left, padding.top)); let text = layout::Node::new(text_bounds).move_to(Point::new(padding.left, padding.top));
let node = layout::Node::with_children(text_bounds.expand(padding), vec![text]) let node = layout::Node::with_children(text_bounds.expand(padding), vec![text])
.translate(text_pos); .translate(text_pos);
let y_pos = node.bounds().y + node.bounds().height + f32::from(spacing); let y_pos = node.bounds().y + node.bounds().height + f32::from(spacing);
nodes.push(node); nodes.push(node);
Vector::new(0.0, y_pos) Vector::new(0.0, y_pos)
@ -1042,15 +1044,15 @@ pub fn layout<Message>(
let limits = limits let limits = limits
.width(width) .width(width)
.shrink(padding) .shrink(padding)
.height(helper_text_size * 1.2); .height(helper_text_line_height.to_absolute(helper_text_size.into()));
let text_bounds = limits.resolve(Length::Shrink, Length::Shrink, Size::ZERO); let text_bounds = limits.resolve(width, Length::Shrink, Size::INFINITY);
dbg!(text_bounds);
let state = tree.state.downcast_mut::<State>(); let state = tree.state.downcast_mut::<State>();
let helper_text_paragraph = &mut state.label; let helper_text_paragraph = &mut state.helper_text;
helper_text_paragraph.update(Text { helper_text_paragraph.update(Text {
content: helper_text, content: helper_text,
font, font,
bounds: text_bounds, bounds: Size::INFINITY,
size: iced::Pixels(helper_text_size), size: iced::Pixels(helper_text_size),
horizontal_alignment: alignment::Horizontal::Left, horizontal_alignment: alignment::Horizontal::Left,
vertical_alignment: alignment::Vertical::Center, vertical_alignment: alignment::Vertical::Center,
@ -1058,8 +1060,9 @@ pub fn layout<Message>(
shaping: text::Shaping::Advanced, shaping: text::Shaping::Advanced,
}); });
let helper_text_size = helper_text_paragraph.min_bounds(); let helper_text_size = helper_text_paragraph.min_bounds();
let helper_text_node = layout::Node::new(helper_text_size).translate(helper_pos);
nodes.push(layout::Node::new(helper_text_size).translate(helper_pos)); dbg!(helper_text_node.bounds());
nodes.push(helper_text_node);
}; };
let mut size = nodes.iter().fold(Size::ZERO, |size, node| { let mut size = nodes.iter().fold(Size::ZERO, |size, node| {
@ -1310,43 +1313,6 @@ where
return event::Status::Captured; return event::Status::Captured;
} }
} }
Event::Keyboard(keyboard::Event::KeyReleased {
key: keyboard::Key::Character(c),
modifiers,
..
}) => {
let state = state();
if let Some(focus) = &mut state.is_focused {
let Some(on_input) = on_input else {
return event::Status::Ignored;
};
if state.is_pasting.is_none()
&& !state.keyboard_modifiers.command()
&& !modifiers.control()
{
let mut editor = Editor::new(unsecured_value, &mut state.cursor);
editor.insert(c.chars().next().unwrap_or_default());
let contents = editor.contents();
let unsecured_value = Value::new(&contents);
let message = (on_input)(contents);
shell.publish(message);
focus.updated_at = Instant::now();
let value = if is_secure {
unsecured_value.secure()
} else {
unsecured_value
};
update_cache(state, &value);
return event::Status::Captured;
}
}
}
Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => { Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => {
let state = state(); let state = state();
@ -1486,46 +1452,44 @@ where
shell.publish(message); shell.publish(message);
} }
} }
keyboard::Key::Character(c) if "v" == c => { keyboard::Key::Character(c)
if state.keyboard_modifiers.command() { if "v" == c && state.keyboard_modifiers.command() =>
let content = if let Some(content) = state.is_pasting.take() { {
content let content = if let Some(content) = state.is_pasting.take() {
} else { content
let content: String = clipboard
.read()
.unwrap_or_default()
.chars()
.filter(|c| !c.is_control())
.collect();
Value::new(&content)
};
let mut editor = Editor::new(unsecured_value, &mut state.cursor);
editor.paste(content.clone());
let contents = editor.contents();
let unsecured_value = Value::new(&contents);
let message = if let Some(paste) = &on_paste {
(paste)(contents)
} else {
(on_input)(contents)
};
shell.publish(message);
state.is_pasting = Some(content);
let value = if is_secure {
unsecured_value.secure()
} else {
unsecured_value
};
update_cache(state, &value);
} else { } else {
state.is_pasting = None; let content: String = clipboard
} .read()
.unwrap_or_default()
.chars()
.filter(|c| !c.is_control())
.collect();
Value::new(&content)
};
let mut editor = Editor::new(unsecured_value, &mut state.cursor);
editor.paste(content.clone());
let contents = editor.contents();
let unsecured_value = Value::new(&contents);
let message = if let Some(paste) = &on_paste {
(paste)(contents)
} else {
(on_input)(contents)
};
shell.publish(message);
state.is_pasting = Some(content);
let value = if is_secure {
unsecured_value.secure()
} else {
unsecured_value
};
update_cache(state, &value);
} }
keyboard::Key::Character(c) keyboard::Key::Character(c)
if "a" == c && state.keyboard_modifiers.command() => if "a" == c && state.keyboard_modifiers.command() =>
@ -1544,6 +1508,31 @@ where
| keyboard::Key::Named(keyboard::key::Named::ArrowDown) => { | keyboard::Key::Named(keyboard::key::Named::ArrowDown) => {
return event::Status::Ignored; return event::Status::Ignored;
} }
keyboard::Key::Character(c) => {
if state.is_pasting.is_none()
&& !state.keyboard_modifiers.command()
&& !modifiers.control()
{
let mut editor = Editor::new(unsecured_value, &mut state.cursor);
editor.insert(c.chars().next().unwrap_or_default());
let contents = editor.contents();
let unsecured_value = Value::new(&contents);
let message = (on_input)(contents);
shell.publish(message);
focus.updated_at = Instant::now();
let value = if is_secure {
unsecured_value.secure()
} else {
unsecured_value
};
update_cache(state, &value);
return event::Status::Captured;
}
}
_ => {} _ => {}
} }
@ -1926,8 +1915,7 @@ pub fn draw<'a, Message>(
bounds, bounds,
border: Border { border: Border {
width: appearance.border_width, width: appearance.border_width,
color: appearance.border_color, ..Default::default()
radius: appearance.border_radius,
}, },
shadow: Shadow { shadow: Shadow {
offset: Vector::new(0.0, 1.0), offset: Vector::new(0.0, 1.0),
@ -2256,6 +2244,7 @@ pub struct State {
pub value: crate::Paragraph, pub value: crate::Paragraph,
pub placeholder: crate::Paragraph, pub placeholder: crate::Paragraph,
pub label: crate::Paragraph, pub label: crate::Paragraph,
pub helper_text: crate::Paragraph,
pub dirty: bool, pub dirty: bool,
pub is_secure: bool, pub is_secure: bool,
is_focused: Option<Focus>, is_focused: Option<Focus>,
@ -2315,6 +2304,7 @@ impl State {
value: crate::Paragraph::new(), value: crate::Paragraph::new(),
placeholder: crate::Paragraph::new(), placeholder: crate::Paragraph::new(),
label: crate::Paragraph::new(), label: crate::Paragraph::new(),
helper_text: crate::Paragraph::new(),
is_focused: None, is_focused: None,
dragging_state: None, dragging_state: None,