Class: Canis::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). 2011-11-12 making it simpler, and single line only. The original multiline label
has moved to extras/multilinelabel.rb
Instance Attribute Summary
Attributes inherited from Widget
#_object_created, #col_offset, #config, #curpos, #focussed, #form, #handler, #id, #key_label, #parent_component, #row_offset, #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
dsl_property :display_length #please give this to ensure the we only print this much for consistency with others 2011-11-5 alias :width :display_length alias :width= :display_length=.
- #label_for(field) ⇒ Object
-
#on_enter ⇒ Object
Added 2011-10-22 to prevent some naive components from putting focus here.
- #on_leave ⇒ Object
-
#repaint ⇒ Object
label’s repaint - I am removing wrapping and Array stuff and making it simple 2011-11-12.
Methods inherited from Widget
#action_manager, #bgcolor, #color, #color_pair, #command, #destroy, #focus, #focusable, #focusable?, #getvalue_for_paint, #handle_key, #hide, #init_vars, #modified?, #move, #override_graphic, #process_key, #property_set, #remove, #repaint_all, #repaint_required, #rowcol, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #unbind_key
Methods included from Io
#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rb_getstr, #warn
Methods included from Utils
#ORIG_process_key, #ORIGbind_key, #ORIGkeycode_tos, #_process_key, #bind_composite_mapping, #bind_key, #bind_keys, #check_composite_mapping, #create_logger, #define_key, #define_prefix_command, #execute_mapping, #get_attrib, #get_color, #key, #key_tos, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #xxxbind_composite_mapping
Methods included from ConfigSetup
Methods included from EventHandler
#bind, #event?, #event_list, #fire_handler, #fire_property_change, #register_events
Constructor Details
#initialize(form, config = {}, &block) ⇒ Label
dsl_property :display_length #please give this to ensure the we only print this much for consistency with others 2011-11-5 alias :width :display_length alias :width= :display_length=
2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 |
# File 'lib/canis/core/widgets/rwidget.rb', line 2971 def initialize form, config={}, &block @text = config.fetch(:text, "NOTFOUND") @editable = false @focusable = false # we have some processing for when a form is attached, registering a hotkey register_events :FORM_ATTACHED 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
3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3003 def bind_hotkey if @mnemonic 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? Canis::Button ) && (@label_for.respond_to? :fire) @form.bind_key(mch, "hotkey for button #{@label_for.text} ") { |_form, _butt| @label_for.fire } else $log.debug " bind_hotkey label for: #{@label_for}" @form.bind_key(mch, "hotkey for label #{text} ") { |_form, _field| @label_for.focus } end end end |
#getvalue ⇒ Object
get the value for the label
2985 2986 2987 2988 |
# File 'lib/canis/core/widgets/rwidget.rb', line 2985 def getvalue #@text_variable && @text_variable.value || @text @text end |
#label_for(field) ⇒ Object
2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 |
# File 'lib/canis/core/widgets/rwidget.rb', line 2989 def label_for field @label_for = field #$log.debug " label for: #{@label_for}" if @form bind_hotkey else # we have some processing for when a form is attached, registering a hotkey bind(:FORM_ATTACHED){ bind_hotkey } end end |
#on_enter ⇒ Object
Added 2011-10-22 to prevent some naive components from putting focus here.
3064 3065 3066 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3064 def on_enter raise "Cannot enter Label" end |
#on_leave ⇒ Object
3067 3068 3069 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3067 def on_leave raise "Cannot leave Label" end |
#repaint ⇒ Object
label’s repaint - I am removing wrapping and Array stuff and making it simple 2011-11-12
3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 |
# File 'lib/canis/core/widgets/rwidget.rb', line 3019 def repaint return unless @repaint_required raise "Label row or col nil #{@row} , #{@col}, #{@text} " if @row.nil? || @col.nil? r,c = rowcol #@bgcolor ||= $def_bg_color #@color ||= $def_fg_color _bgcolor = bgcolor() _color = color() # value often nil so putting blank, but usually some application error value = getvalue_for_paint || "" if value.is_a? Array value = value.join " " end # ensure we do not exceed if @width if value.length > @width value = value[0..@width-1] end end len = @width || value.length #acolor = get_color $datacolor # the user could have set color_pair, use that, else determine color # This implies that if he sets cp, then changing col and bg won't have an effect ! # A general routine that only changes color will not work here. acolor = @color_pair || get_color($datacolor, _color, _bgcolor) #$log.debug "label :#{@text}, #{value}, r #{r}, c #{c} col= #{@color}, #{@bgcolor} acolor #{acolor} j:#{@justify} dlL: #{@width} " str = @justify.to_sym == :right ? "%*s" : "%-*s" # added 2008-12-22 19:05 @graphic ||= @form.window # clear the area @graphic.printstring r, c, " " * len , acolor, attr() if @justify.to_sym == :center padding = (@width - 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() if @mnemonic ulindex = value.index(@mnemonic) || value.index(@mnemonic.swapcase) @graphic.mvchgat(y=r, x=c+ulindex, max=1, Ncurses::A_BOLD|Ncurses::A_UNDERLINE, acolor, nil) end @repaint_required = false end |