pub struct LayoutCtx<'a, 'b> { /* private fields */ }Expand description
A context provided to layout-handling methods of widgets.
As of now, the main service provided is access to a factory for creating text layout objects, which are likely to be useful during widget layout.
Implementations§
Source§impl LayoutCtx<'_, '_>
impl LayoutCtx<'_, '_>
Sourcepub fn window(&self) -> &WindowHandle
pub fn window(&self) -> &WindowHandle
Returns a reference to the current WindowHandle.
Examples found in repository?
120 fn layout(
121 &mut self,
122 ctx: &mut druid::LayoutCtx,
123 bc: &druid::BoxConstraints,
124 data: &AppState,
125 env: &druid::Env,
126 ) -> druid::Size {
127 let mut interactable_area = Region::EMPTY;
128 let smaller_bc = BoxConstraints::new(
129 Size::new(0.0, 0.0),
130 Size::new(bc.max().width - 100.0, bc.max().height - 100.0),
131 );
132 let full_bc = BoxConstraints::new(Size::new(0.0, 0.0), bc.max());
133 let _label_size = self.info_label.layout(ctx, &smaller_bc, data, env);
134 let controls_size = self.controls.layout(ctx, &full_bc, data, env);
135
136 let text_origin_point = Point::new(50.0, 50.0 + controls_size.height);
137 self.info_label.set_origin(ctx, text_origin_point);
138 let controls_origin_point = Point::new(EXAMPLE_BORDER_SIZE, EXAMPLE_BORDER_SIZE);
139 self.controls.set_origin(ctx, controls_origin_point);
140
141 // Add side rects to clarify the dimensions of the window.
142 let left_rect = Rect::new(0.0, 0.0, EXAMPLE_BORDER_SIZE, bc.max().height);
143 let right_rect = Rect::new(
144 bc.max().width - EXAMPLE_BORDER_SIZE,
145 0.0,
146 bc.max().width,
147 bc.max().height,
148 );
149 let bottom_rect = Rect::new(
150 0.0,
151 bc.max().height - EXAMPLE_BORDER_SIZE,
152 bc.max().width,
153 bc.max().height,
154 );
155 interactable_area.add_rect(left_rect);
156 interactable_area.add_rect(right_rect);
157 interactable_area.add_rect(bottom_rect);
158 interactable_area.add_rect(self.info_label.layout_rect());
159 interactable_area.add_rect(self.controls.layout_rect());
160
161 if data.limit_input_region {
162 ctx.window().set_input_region(Some(interactable_area));
163 } else {
164 ctx.window().set_input_region(None);
165 }
166
167 bc.max()
168 }Source§impl LayoutCtx<'_, '_>
impl LayoutCtx<'_, '_>
Sourcepub fn view_context_changed(&mut self)
pub fn view_context_changed(&mut self)
Indicate that your ViewContext has changed.
This event is sent after layout is done and before paint is called. Note that you can still receive this event even if there was no prior call to layout.
Widgets must call this method after changing the clip region of their children.
Changes to the other parts of ViewContext (cursor position and global origin) are tracked
internally.
Source§impl LayoutCtx<'_, '_>
impl LayoutCtx<'_, '_>
Sourcepub fn submit_command(&mut self, cmd: impl Into<Command>)
pub fn submit_command(&mut self, cmd: impl Into<Command>)
Submit a Command to be run after this event is handled.
Commands are run in the order they are submitted; all commands
submitted during the handling of an event are executed before
the update method is called; events submitted during update
are handled after painting.
Target::Auto commands will be sent to the window containing the widget.
Sourcepub fn get_external_handle(&self) -> ExtEventSink
pub fn get_external_handle(&self) -> ExtEventSink
Returns an ExtEventSink that can be moved between threads,
and can be used to submit commands back to the application.
Sourcepub fn request_timer(&mut self, deadline: Duration) -> TimerToken
pub fn request_timer(&mut self, deadline: Duration) -> TimerToken
Request a timer event.
The return value is a token, which can be used to associate the request with the event.
Source§impl<'a, 'b> LayoutCtx<'a, 'b>
impl<'a, 'b> LayoutCtx<'a, 'b>
Sourcepub fn set_paint_insets(&mut self, insets: impl Into<Insets>)
pub fn set_paint_insets(&mut self, insets: impl Into<Insets>)
Set explicit paint Insets for this widget.
You are not required to set explicit paint bounds unless you need
to paint outside of your layout bounds. In this case, the argument
should be an Insets struct that indicates where your widget
needs to overpaint, relative to its bounds.
For more information, see WidgetPod::paint_insets.
Sourcepub fn set_baseline_offset(&mut self, baseline: f64)
pub fn set_baseline_offset(&mut self, baseline: f64)
Set an explicit baseline position for this widget.
The baseline position is used to align widgets that contain text, such as buttons, labels, and other controls. It may also be used by other widgets that are opinionated about how they are aligned relative to neighbouring text, such as switches or checkboxes.
The provided value should be the distance from the bottom of the widget to the baseline.