Class: RubyCurses::Label
Overview
the preferred way of printing text on screen, esp if you want to modify it at run time. Use display_length to ensure no spillage. This can use text or text_variable for setting and getting data (inh from Widget).
Constant Summary
Constants included from Io
Io::ERROR_COLOR_PAIR, Io::FOOTER_COLOR_PAIR, Io::LINEONE, Io::MAIN_WINDOW_COLOR_PAIR
Instance Attribute Summary
Attributes inherited from Widget
#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #parent_component, #row_offset, #rows_panned, #state
Instance Method Summary collapse
-
#bind_hotkey ⇒ Object
for a button, fire it when label invoked without changing focus for other widgets, attempt to change focus to that field.
-
#getvalue ⇒ Object
get the value for the label.
-
#initialize(form, config = {}, &block) ⇒ Label
constructor
A new instance of Label.
- #label_for(field) ⇒ Object
-
#repaint ⇒ Object
XXX need to move wrapping etc up and done once.
Methods inherited from Widget
#changed, #click, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue_for_paint, #handle_key, #height, #height=, #hide, #init_vars, #leave, #modified?, #move, #on_enter, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #set_buffer_modified, #set_buffering, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=
Methods included from Io
#askchoice, #askyesno, #askyesnocancel, #clear_error, #clear_this, #get_string, #newaskyesno, #old_print_header, #old_print_top_right, #print_action, #print_error, #print_footer_help, #print_header, #print_headers, #print_help, #print_help_page, #print_in_middle, #print_key_labels, #print_key_labels_row, #print_screen_labels, #print_status, #print_this, #print_top_right, #rbgetstr, #warn
Methods included from Utils
#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #view, #wrap_text
Methods included from ConfigSetup
#cget, #config_setup, #configure, #variable_set
Methods included from EventHandler
#bind, #fire_handler, #fire_property_change
Constructor Details
#initialize(form, config = {}, &block) ⇒ Label
Returns a new instance of Label.
2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 |
# File 'lib/rbcurse/rwidget.rb', line 2175 def initialize form, config={}, &block @row = config.fetch("row",-1) @col = config.fetch("col",-1) @bgcolor = config.fetch("bgcolor", $def_bg_color) @color = config.fetch("color", $def_fg_color) @text = config.fetch("text", "NOTFOUND") @editable = false @focusable = false super @justify ||= :left @name ||= @text @repaint_required = true end |
Instance Method Details
#bind_hotkey ⇒ Object
for a button, fire it when label invoked without changing focus for other widgets, attempt to change focus to that field
2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 |
# File 'lib/rbcurse/rwidget.rb', line 2203 def bind_hotkey if !@mnemonic.nil? ch = @mnemonic.downcase()[0].ord ## 1.9 DONE # meta key mch = ?\M-a.getbyte(0) + (ch - ?a.getbyte(0)) ## 1.9 if @label_for.is_a? RubyCurses::Button and @label_for.respond_to? :fire @form.bind_key(mch, @label_for) { |_form, _butt| _butt.fire } else $log.debug " bind_hotkey label for: #{@label_for}" @form.bind_key(mch, @label_for) { |_form, _field| _field.focus } end end end |
#getvalue ⇒ Object
get the value for the label
2191 2192 2193 |
# File 'lib/rbcurse/rwidget.rb', line 2191 def getvalue @text_variable && @text_variable.value || @text end |
#label_for(field) ⇒ Object
2194 2195 2196 2197 2198 |
# File 'lib/rbcurse/rwidget.rb', line 2194 def label_for field @label_for = field #$log.debug " label for: #{@label_for}" bind_hotkey unless @form.nil? # GRRR! end |
#repaint ⇒ Object
XXX need to move wrapping etc up and done once.
2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 |
# File 'lib/rbcurse/rwidget.rb', line 2219 def repaint return unless @repaint_required r,c = rowcol # value often nil so putting blank, but usually some application error value = getvalue_for_paint || "" lablist = [] if @height && @height > 1 lablist = wrap_text(value, @display_length).split("\n") else # ensure we do not exceed if !@display_length.nil? if value.length > @display_length value = value[0..@display_length-1] end end lablist << value end len = @display_length || value.length acolor = get_color $datacolor #$log.debug "label :#{@text}, #{value}, #{r}, #{c} col= #{@color}, #{@bgcolor} acolor #{acolor} j:#{@justify} dlL: #{@display_length} " firstrow = r _height = @height || 1 str = @justify.to_sym == :right ? "%*s" : "%-*s" # added 2008-12-22 19:05 # loop added for labels that are wrapped. # TODO clear separately since value can change in status like labels @graphic = @form.window if @graphic.nil? ## HACK messagebox givig this in repaint, 423 not working ?? 0.upto(_height-1) { |i| @graphic.printstring r+i, c, " " * len , acolor,@attr } lablist.each_with_index do |_value, ix| break if ix >= _height if @justify.to_sym == :center padding = (@display_length - _value.length)/2 _value = " "*padding + _value + " "*padding # so its cleared if we change it midway end @graphic.printstring r, c, str % [len, _value], acolor,@attr r += 1 end if !@mnemonic.nil? ulindex = value.index(@mnemonic) || value.index(@mnemonic.swapcase) @graphic.mvchgat(y=firstrow, x=c+ulindex, max=1, Ncurses::A_BOLD|Ncurses::A_UNDERLINE, acolor, nil) end #@form.window.mvchgat(y=r, x=c, max=len, Ncurses::A_NORMAL, color, nil) @repaint_required = false end |