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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
fn layout(
&mut self,
ctx: &mut druid::LayoutCtx,
bc: &druid::BoxConstraints,
data: &AppState,
env: &druid::Env,
) -> druid::Size {
let mut interactable_area = Region::EMPTY;
let smaller_bc = BoxConstraints::new(
Size::new(0.0, 0.0),
Size::new(bc.max().width - 100.0, bc.max().height - 100.0),
);
let full_bc = BoxConstraints::new(Size::new(0.0, 0.0), bc.max());
let _label_size = self.info_label.layout(ctx, &smaller_bc, data, env);
let controls_size = self.controls.layout(ctx, &full_bc, data, env);
let text_origin_point = Point::new(50.0, 50.0 + controls_size.height);
self.info_label.set_origin(ctx, text_origin_point);
let controls_origin_point = Point::new(EXAMPLE_BORDER_SIZE, EXAMPLE_BORDER_SIZE);
self.controls.set_origin(ctx, controls_origin_point);
// Add side rects to clarify the dimensions of the window.
let left_rect = Rect::new(0.0, 0.0, EXAMPLE_BORDER_SIZE, bc.max().height);
let right_rect = Rect::new(
bc.max().width - EXAMPLE_BORDER_SIZE,
0.0,
bc.max().width,
bc.max().height,
);
let bottom_rect = Rect::new(
0.0,
bc.max().height - EXAMPLE_BORDER_SIZE,
bc.max().width,
bc.max().height,
);
interactable_area.add_rect(left_rect);
interactable_area.add_rect(right_rect);
interactable_area.add_rect(bottom_rect);
interactable_area.add_rect(self.info_label.layout_rect());
interactable_area.add_rect(self.controls.layout_rect());
if data.limit_input_region {
ctx.window().set_input_region(Some(interactable_area));
} else {
ctx.window().set_input_region(None);
}
bc.max()
}
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.