utils/iced: Allow computing minimum widget size
This commit is contained in:
parent
6ac8fd2f90
commit
85771dff5e
1 changed files with 17 additions and 2 deletions
|
|
@ -12,9 +12,9 @@ use cosmic::{
|
||||||
keyboard::{Event as KeyboardEvent, Modifiers as IcedModifiers},
|
keyboard::{Event as KeyboardEvent, Modifiers as IcedModifiers},
|
||||||
mouse::{Button as MouseButton, Cursor, Event as MouseEvent, ScrollDelta},
|
mouse::{Button as MouseButton, Cursor, Event as MouseEvent, ScrollDelta},
|
||||||
window::{Event as WindowEvent, Id},
|
window::{Event as WindowEvent, Id},
|
||||||
Command, Point as IcedPoint, Rectangle as IcedRectangle, Size as IcedSize,
|
Command, Limits, Point as IcedPoint, Rectangle as IcedRectangle, Size as IcedSize,
|
||||||
},
|
},
|
||||||
iced_core::{clipboard::Null as NullClipboard, renderer::Style, Color},
|
iced_core::{clipboard::Null as NullClipboard, renderer::Style, Color, Length},
|
||||||
iced_renderer::{graphics::Renderer as IcedGraphicsRenderer, Renderer as IcedRenderer},
|
iced_renderer::{graphics::Renderer as IcedGraphicsRenderer, Renderer as IcedRenderer},
|
||||||
iced_runtime::{
|
iced_runtime::{
|
||||||
command::Action,
|
command::Action,
|
||||||
|
|
@ -277,6 +277,21 @@ impl<P: Program + Send + 'static> IcedElement<P> {
|
||||||
func(&internal.state.program().0)
|
func(&internal.state.program().0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn minimum_size(&self) -> Size<i32, Logical> {
|
||||||
|
let internal = self.0.lock().unwrap();
|
||||||
|
let element = internal.state.program().0.view();
|
||||||
|
let node = element
|
||||||
|
.as_widget()
|
||||||
|
.layout(
|
||||||
|
&internal.renderer,
|
||||||
|
&Limits::new(IcedSize::ZERO, IcedSize::INFINITY)
|
||||||
|
.width(Length::Shrink)
|
||||||
|
.height(Length::Shrink),
|
||||||
|
)
|
||||||
|
.size();
|
||||||
|
Size::from((node.width.ceil() as i32, node.height.ceil() as i32))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn loop_handle(&self) -> LoopHandle<'static, crate::state::State> {
|
pub fn loop_handle(&self) -> LoopHandle<'static, crate::state::State> {
|
||||||
self.0.lock().unwrap().handle.clone()
|
self.0.lock().unwrap().handle.clone()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue