@@ -10,12 +10,14 @@ use dpi::LogicalPosition;
1010use parley:: { FontContext , LayoutContext } ;
1111use tracing:: { trace, warn} ;
1212use vello:: kurbo:: Vec2 ;
13+ use vello:: peniko:: Color ;
1314use winit:: window:: ResizeDirection ;
1415
1516use crate :: action:: Action ;
1617use crate :: passes:: layout:: run_layout_on;
1718use crate :: render_root:: { MutateCallback , RenderRootSignal , RenderRootState } ;
1819use crate :: text:: TextBrush ;
20+ use crate :: theme:: get_debug_color;
1921use crate :: tree_arena:: { ArenaMutChildren , ArenaRefChildren } ;
2022use crate :: widget:: { WidgetMut , WidgetRef , WidgetState } ;
2123use crate :: { AllowRawMut , BoxConstraints , Insets , Point , Rect , Size , Widget , WidgetId , WidgetPod } ;
@@ -226,6 +228,11 @@ impl_context_method!(
226228 self . widget_state. layout_rect( )
227229 }
228230
231+ /// The offset of the baseline relative to the bottom of the widget.
232+ pub fn baseline_offset( & self ) -> f64 {
233+ self . widget_state. baseline_offset
234+ }
235+
229236 /// The origin of the widget in window coordinates, relative to the top left corner of the
230237 /// content area.
231238 pub fn window_origin( & self ) -> Point {
@@ -1123,6 +1130,29 @@ impl_context_method!(LayoutCtx<'_>, PaintCtx<'_>, {
11231130 }
11241131} ) ;
11251132
1133+ impl PaintCtx < ' _ > {
1134+ /// Whether debug paint is enabled.
1135+ ///
1136+ /// If this property is set, your widget may draw additional debug information
1137+ /// (such as the position of the text baseline).
1138+ /// These should normally use the [debug color][Self::debug_color] for this widget.
1139+ /// Please note that when debug painting is enabled, each widget's layout boundaries are
1140+ /// outlined by Masonry, so you should avoid duplicating that.
1141+ ///
1142+ /// Debug paint can be enabled by setting the environment variable `MASONRY_DEBUG_PAINT`.
1143+ pub fn debug_paint_enabled ( & self ) -> bool {
1144+ self . debug_paint
1145+ }
1146+
1147+ /// A color used for debug painting in this widget.
1148+ ///
1149+ /// This is normally used to paint additional debugging information
1150+ /// when debug paint is enabled, see [`Self::debug_paint_enabled`].
1151+ pub fn debug_color ( & self ) -> Color {
1152+ get_debug_color ( self . widget_id ( ) . to_raw ( ) )
1153+ }
1154+ }
1155+
11261156// --- MARK: RAW WRAPPERS ---
11271157macro_rules! impl_get_raw {
11281158 ( $SomeCtx: tt) => {
0 commit comments