Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Syntax Highlighting with StyledText via Glimmer DSL for SWT(Shortest StyledText Syntax Highlighting Implementation with Glimmer Ruby DSL)
Syntax Highlighting with StyledText via Glimmer DSL for SWT [message #1833678] Wed, 21 October 2020 09:07 Go to next message
Andy Maleh is currently offline Andy MalehFriend
Messages: 22
Registered: March 2020
Junior Member
Glimmer DSL for SWT v4.17.4.0 ships with a number of changes, such as the new code_text syntax highlighting custom widget based on StyledText, the Glimmer Meta-Sample (The Sample of Samples), and the Hello, Sash Form! Sample. One noteworthy thing to mention about implementing `code_text` is that with Glimmer Ruby syntax, it was the shortest Syntax Highlighting implementation of SWT StyledText I have ever seen compared to various resources online.

https://andymaleh.blogspot.com/2020/10/glimmer-syntax-highlighting-text-widget.html

Here is the entire Glimmer view code for StyledText:

# From https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/lib/glimmer/swt/custom/code_text.rb
styled_text(swt_style) {
  font name: 'Consolas', height: 15
  foreground rgb(75, 75, 75)
  left_margin 5
  top_margin 5
  right_margin 5
  bottom_margin 5

  on_line_get_style { |line_style_event|
    styles = []
    line_style_event.lineOffset
    syntax_highlighting.each do |token_hash|
      if token_hash[:token_index] >= line_style_event.lineOffset && token_hash[:token_index] < (line_style_event.lineOffset + line_style_event.lineText.size)
        start_index = token_hash[:token_index]
        size = token_hash[:token_text].size
        token_color = SYNTAX_COLOR_MAP[token_hash[:token_type].name] || [:black]
        token_color = color(*token_color).swt_color
        styles << StyleRange.new(start_index, size, token_color, nil)
      end
    end
    line_style_event.styles = styles.to_java(StyleRange) unless styles.empty?
  }            
}


Of course, to use it, developers can now just use the `code_text` keyword (no more need for complicated custom implementations of syntax highlighting via StyledText as the work has been automated):

code_text {
  # ... properties go here, e.g. `text bind(model, :property)`
}


Result:

https://raw.githubusercontent.com/AndyObtiva/glimmer-dsl-swt/master/images/glimmer-meta-sample.png


OSS Author of Glimmer (GUI DSL for SWT)
https://github.com/AndyObtiva/glimmer

[Updated on: Thu, 22 October 2020 06:05]

Report message to a moderator

Re: Syntax Highlighting with StyledText via Glimmer DSL for SWT [message #1833796 is a reply to message #1833678] Fri, 23 October 2020 20:49 Go to previous message
Andy Maleh is currently offline Andy MalehFriend
Messages: 22
Registered: March 2020
Junior Member
Gladiator (Glimmer Editor) has been upgraded to take advantage of the new `code_text` custom widget in Glimmer DSL for SWT.

https://raw.githubusercontent.com/AndyObtiva/glimmer-cs-gladiator/master/images/glimmer-gladiator.png


OSS Author of Glimmer (GUI DSL for SWT)
https://github.com/AndyObtiva/glimmer
Previous Topic:How to change SWT Table Item selection background color
Next Topic:ImageData loader with 1bpp images
Goto Forum:
  


Current Time: Sun Apr 11 19:31:45 GMT 2021

Powered by FUDForum. Page generated in 0.01759 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top