@@ -200,6 +200,10 @@ impl RenderText for ComplexText {
200200 fn stroke ( self : Pin < & Self > ) -> ( Brush , LogicalLength , TextStrokeStyle ) {
201201 ( self . stroke ( ) , self . stroke_width ( ) , self . stroke_style ( ) )
202202 }
203+
204+ fn is_markdown ( self : Pin < & Self > ) -> bool {
205+ false
206+ }
203207}
204208
205209impl ComplexText {
@@ -215,6 +219,189 @@ impl ComplexText {
215219 }
216220}
217221
222+ /// The implementation of the `Text` element
223+ #[ repr( C ) ]
224+ #[ derive( FieldOffsets , Default , SlintElement ) ]
225+ #[ pin]
226+ pub struct MarkdownText {
227+ pub width : Property < LogicalLength > ,
228+ pub height : Property < LogicalLength > ,
229+ pub text : Property < SharedString > ,
230+ pub font_size : Property < LogicalLength > ,
231+ pub font_weight : Property < i32 > ,
232+ pub color : Property < Brush > ,
233+ pub horizontal_alignment : Property < TextHorizontalAlignment > ,
234+ pub vertical_alignment : Property < TextVerticalAlignment > ,
235+
236+ pub font_family : Property < SharedString > ,
237+ pub font_italic : Property < bool > ,
238+ pub wrap : Property < TextWrap > ,
239+ pub overflow : Property < TextOverflow > ,
240+ pub letter_spacing : Property < LogicalLength > ,
241+ pub stroke : Property < Brush > ,
242+ pub stroke_width : Property < LogicalLength > ,
243+ pub stroke_style : Property < TextStrokeStyle > ,
244+ pub cached_rendering_data : CachedRenderingData ,
245+ }
246+
247+ impl Item for MarkdownText {
248+ fn init ( self : Pin < & Self > , _self_rc : & ItemRc ) { }
249+
250+ fn layout_info (
251+ self : Pin < & Self > ,
252+ orientation : Orientation ,
253+ window_adapter : & Rc < dyn WindowAdapter > ,
254+ self_rc : & ItemRc ,
255+ ) -> LayoutInfo {
256+ text_layout_info (
257+ self ,
258+ & self_rc,
259+ window_adapter,
260+ orientation,
261+ Self :: FIELD_OFFSETS . width . apply_pin ( self ) ,
262+ )
263+ }
264+
265+ fn input_event_filter_before_children (
266+ self : Pin < & Self > ,
267+ _: & MouseEvent ,
268+ _window_adapter : & Rc < dyn WindowAdapter > ,
269+ _self_rc : & ItemRc ,
270+ ) -> InputEventFilterResult {
271+ InputEventFilterResult :: ForwardAndIgnore
272+ }
273+
274+ fn input_event (
275+ self : Pin < & Self > ,
276+ _: & MouseEvent ,
277+ _window_adapter : & Rc < dyn WindowAdapter > ,
278+ _self_rc : & ItemRc ,
279+ ) -> InputEventResult {
280+ InputEventResult :: EventIgnored
281+ }
282+
283+ fn capture_key_event (
284+ self : Pin < & Self > ,
285+ _: & KeyEvent ,
286+ _window_adapter : & Rc < dyn WindowAdapter > ,
287+ _self_rc : & ItemRc ,
288+ ) -> KeyEventResult {
289+ KeyEventResult :: EventIgnored
290+ }
291+
292+ fn key_event (
293+ self : Pin < & Self > ,
294+ _: & KeyEvent ,
295+ _window_adapter : & Rc < dyn WindowAdapter > ,
296+ _self_rc : & ItemRc ,
297+ ) -> KeyEventResult {
298+ KeyEventResult :: EventIgnored
299+ }
300+
301+ fn focus_event (
302+ self : Pin < & Self > ,
303+ _: & FocusEvent ,
304+ _window_adapter : & Rc < dyn WindowAdapter > ,
305+ _self_rc : & ItemRc ,
306+ ) -> FocusEventResult {
307+ FocusEventResult :: FocusIgnored
308+ }
309+
310+ fn render (
311+ self : Pin < & Self > ,
312+ backend : & mut & mut dyn ItemRenderer ,
313+ self_rc : & ItemRc ,
314+ size : LogicalSize ,
315+ ) -> RenderingResult {
316+ ( * backend) . draw_text ( self , self_rc, size, & self . cached_rendering_data ) ;
317+ RenderingResult :: ContinueRenderingChildren
318+ }
319+
320+ fn bounding_rect (
321+ self : core:: pin:: Pin < & Self > ,
322+ _window_adapter : & Rc < dyn WindowAdapter > ,
323+ _self_rc : & ItemRc ,
324+ geometry : LogicalRect ,
325+ ) -> LogicalRect {
326+ geometry
327+ }
328+
329+ fn clips_children ( self : Pin < & Self > ) -> bool {
330+ false
331+ }
332+ }
333+
334+ impl ItemConsts for MarkdownText {
335+ const cached_rendering_data_offset: const_field_offset:: FieldOffset <
336+ MarkdownText ,
337+ CachedRenderingData ,
338+ > = MarkdownText :: FIELD_OFFSETS . cached_rendering_data . as_unpinned_projection ( ) ;
339+ }
340+
341+ impl RenderText for MarkdownText {
342+ fn target_size ( self : Pin < & Self > ) -> LogicalSize {
343+ LogicalSize :: from_lengths ( self . width ( ) , self . height ( ) )
344+ }
345+
346+ fn text ( self : Pin < & Self > ) -> SharedString {
347+ self . text ( )
348+ }
349+
350+ fn font_request ( self : Pin < & Self > , self_rc : & ItemRc ) -> FontRequest {
351+ WindowItem :: resolved_font_request (
352+ self_rc,
353+ self . font_family ( ) ,
354+ self . font_weight ( ) ,
355+ self . font_size ( ) ,
356+ self . letter_spacing ( ) ,
357+ self . font_italic ( ) ,
358+ )
359+ }
360+
361+ fn color ( self : Pin < & Self > ) -> Brush {
362+ self . color ( )
363+ }
364+
365+ fn alignment (
366+ self : Pin < & Self > ,
367+ ) -> ( super :: TextHorizontalAlignment , super :: TextVerticalAlignment ) {
368+ ( self . horizontal_alignment ( ) , self . vertical_alignment ( ) )
369+ }
370+
371+ fn wrap ( self : Pin < & Self > ) -> TextWrap {
372+ self . wrap ( )
373+ }
374+
375+ fn overflow ( self : Pin < & Self > ) -> TextOverflow {
376+ self . overflow ( )
377+ }
378+
379+ fn letter_spacing ( self : Pin < & Self > ) -> LogicalLength {
380+ self . letter_spacing ( )
381+ }
382+
383+ fn stroke ( self : Pin < & Self > ) -> ( Brush , LogicalLength , TextStrokeStyle ) {
384+ ( self . stroke ( ) , self . stroke_width ( ) , self . stroke_style ( ) )
385+ }
386+
387+ fn is_markdown ( self : Pin < & Self > ) -> bool {
388+ true
389+ }
390+ }
391+
392+ impl MarkdownText {
393+ pub fn font_metrics (
394+ self : Pin < & Self > ,
395+ window_adapter : & Rc < dyn WindowAdapter > ,
396+ self_rc : & ItemRc ,
397+ ) -> FontMetrics {
398+ let window_inner = WindowInner :: from_pub ( window_adapter. window ( ) ) ;
399+ let scale_factor = ScaleFactor :: new ( window_inner. scale_factor ( ) ) ;
400+ let font_request = self . font_request ( self_rc) ;
401+ window_adapter. renderer ( ) . font_metrics ( font_request, scale_factor)
402+ }
403+ }
404+
218405/// The implementation of the `Text` element
219406#[ repr( C ) ]
220407#[ derive( FieldOffsets , Default , SlintElement ) ]
@@ -371,6 +558,10 @@ impl RenderText for SimpleText {
371558 fn stroke ( self : Pin < & Self > ) -> ( Brush , LogicalLength , TextStrokeStyle ) {
372559 Default :: default ( )
373560 }
561+
562+ fn is_markdown ( self : Pin < & Self > ) -> bool {
563+ false
564+ }
374565}
375566
376567impl SimpleText {
0 commit comments