Changeset 24


Ignore:
Timestamp:
Jul 17, 2005 11:14:06 PM (19 years ago)
Author:
mmc
Message:

Fixed the device viewer to resize itself properly based on its
contents. The device layout takes into account the size of any
icon for a material layer, so a picture of a device can be embedded
by creating a single layer with an icon.

Fixed the Gauge to resize its icon area properly when the -spectrum
is configured later on.

Location:
trunk/gui/scripts
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/deviceEditor.tcl

    r22 r24  
    1313package require Itk
    1414
    15 option add *DeviceEditor.width 5i widgetDefault
    16 option add *DeviceEditor.height 5i widgetDefault
    1715option add *DeviceEditor.autoCleanUp yes widgetDefault
    1816
     
    4139# ----------------------------------------------------------------------
    4240itcl::body Rappture::DeviceEditor::constructor {owner args} {
    43     itk_option add hull.width hull.height
    44     pack propagate $itk_component(hull) no
    45 
    4641    itk_component add top {
    4742        frame $itk_interior.top
  • trunk/gui/scripts/deviceLayout1D.tcl

    r23 r24  
    9090        ignore -highlightthickness -highlightbackground -highlightcolor
    9191    }
    92     pack $itk_component(area) -fill both
     92    pack $itk_component(area) -expand yes -fill both
    9393    bind $itk_component(area) <Configure> \
    9494        [list $_dispatcher event -idle !redraw]
    9595
    9696    eval itk_initialize $args
     97
     98    set _sizes(header) 1
     99    set _sizes(bararea) 1
    97100}
    98101
     
    163166# ----------------------------------------------------------------------
    164167itcl::body Rappture::DeviceLayout1D::_layout {} {
    165     # first, recompute the overall height of this widget
    166     set h [expr {$_sizes(bar)+$_sizes(bar45)+2}]
     168    #
     169    # First, recompute the overall height of this widget...
     170    #
     171    # size of an ordinary material bar:
     172    set hmax [expr {$_sizes(bar)+$_sizes(bar45)+2}]
     173
     174    # add the maximum size of any embedded icons:
     175    if {$_device != ""} {
     176        foreach nn [$_device children components] {
     177            set icon [$_device get components.$nn.about.icon]
     178            if {"" != $icon} {
     179                if {[info exists _icons($icon)]} {
     180                    set imh $_icons($icon)
     181                } else {
     182                    set imh [image create photo -data $icon]
     183                    set _icons($icon) $imh
     184                }
     185
     186                set h [image height $_icons($icon)]
     187                if {$h > $hmax} {
     188                    set hmax $h
     189                }
     190            }
     191        }
     192    }
     193    set _sizes(bararea) $hmax
    167194
    168195    set fnt $itk_option(-font)
     
    171198        if {"" != $m} {
    172199            set extra [expr {1.5*[font metrics $fnt -linespace]}]
    173             set h [expr {$h+$extra}]
     200            set hmax [expr {$hmax+$extra}]
    174201            break
    175202        }
     
    181208            if {"" != [$_device get components.$nn.about.label]} {
    182209                set extra [expr {1.2*[font metrics $fnt -linespace]}]
    183                 set h [expr {$h+$extra}]
     210                set hmax [expr {$hmax+$extra}]
    184211                break
    185212            }
     
    188215
    189216    set oldh [component hull cget -height]
    190     if {$h != $oldh} {
    191         component hull configure -height $h
     217    if {$hmax != $oldh} {
     218        component hull configure -height $hmax
    192219        $_dispatcher event -idle !redraw
    193220    }
     221    set _sizes(header) [expr {$hmax - $_sizes(bararea)}]
    194222
    195223    # next, scan through the device and compute layer positions
     
    314342itcl::body Rappture::DeviceLayout1D::_drawLayer {index x0 x1} {
    315343    set c $itk_component(area)
    316     set h [expr {[winfo height $c]-1}]
    317 
    318     set y0 $h
     344    set h [expr {$_sizes(header) + $_sizes(bararea) - 1}]
     345
     346    set bsize [expr {$_sizes(bar)+$_sizes(bar45)+2}]
     347    set y0 [expr {$h - 0.5*$_sizes(bararea) + 0.5*$bsize}]
    319348    set y0p [expr {$y0-$_sizes(bar45)}]
    320349    set y1p [expr {$y0-$_sizes(bar)}]
     
    361390itcl::body Rappture::DeviceLayout1D::_drawIcon {index x0 x1 imh} {
    362391    set c $itk_component(area)
    363     set h [expr {[winfo height $c]-1}]
    364 
    365     set y0 $h
     392    set h [expr {$_sizes(header) + $_sizes(bararea) - 1}]
     393
     394    set bsize [expr {$_sizes(bar)+$_sizes(bar45)+2}]
     395    set y0 [expr {$h - 0.5*$_sizes(bararea) + 0.5*$bsize}]
    366396    set y0p [expr {$y0-$_sizes(bar45)}]
    367397    set y1p [expr {$y0-$_sizes(bar)}]
     
    374404    set y [expr {0.5*($y0+$y0p) + 0.5*($y1-$y0p)}]
    375405
    376     ##set lcolor $itk_option(-deviceoutline)
    377     ##$c create line $xx0 $y $xx1 $y -width 3
    378 
    379406    $c create image [expr {0.5*($xx0+$xx1)}] $y -anchor c -image $imh
    380407}
     
    389416itcl::body Rappture::DeviceLayout1D::_drawAnnotation {index x0 x1} {
    390417    set c $itk_component(area)
    391     set h [expr {[winfo height $c]-1}]
    392 
    393     set y0 $h
    394     set y1 [expr {$y0-$_sizes(bar)-$_sizes(bar45)}]
    395 
     418
     419    set ytop [expr {$_sizes(header)+1}]
    396420    set x0p [expr {$x0+$_sizes(bar45)}]
    397421    set x1p [expr {$x1+$_sizes(bar45)}]
     
    400424    set fnt $itk_option(-font)
    401425    set lh [font metrics $fnt -linespace]
    402     set ymid [expr {$y1-2-0.5*$lh}]
    403     set y [expr {$y1-4}]
     426    set ymid [expr {$ytop-2-0.5*$lh}]
     427    set y [expr {$ytop-4}]
    404428
    405429    #
  • trunk/gui/scripts/deviceViewer1D.tcl

    r23 r24  
    1616package require BLT
    1717
    18 option add *DeviceViewer1D.width 4i widgetDefault
    19 option add *DeviceViewer1D.height 4i widgetDefault
    2018option add *DeviceViewer1D.padding 4 widgetDefault
    2119option add *DeviceViewer1D.deviceSize 0.25i widgetDefault
     
    3432    protected method _loadDevice {}
    3533    protected method _changeTabs {}
     34    protected method _fixSize {}
    3635    protected method _fixAxes {}
    3736    protected method _align {}
     
    6059    set _owner $owner
    6160
    62     itk_option add hull.width hull.height
    6361    pack propagate $itk_component(hull) no
    6462
     
    9593        blt::graph $itk_component(inner).graph \
    9694            -highlightthickness 0 -plotpadx 0 -plotpady 0 \
    97             -width 3i -height 3i
     95            -width 4i -height 2i
    9896    } {
    9997        keep -background -foreground -cursor -font
     
    120118
    121119    eval itk_initialize $args
     120
     121    _fixSize
    122122}
    123123
     
    294294    $itk_component(graph) configure \
    295295        -rightmargin [$itk_component(layout) extents bar3D]
     296
     297    _fixSize
    296298}
    297299
     
    408410    after cancel [itcl::code $this _fixAxes]
    409411    after 100 [itcl::code $this _fixAxes]
     412}
     413
     414# ----------------------------------------------------------------------
     415# USAGE: _fixSize
     416#
     417# Used internally to fix the overall size of this widget based on
     418# the various parts inside.  Sets the requested width/height of the
     419# widget so that it is big enough to display the device and its
     420# fields.
     421# ----------------------------------------------------------------------
     422itcl::body Rappture::DeviceViewer1D::_fixSize {} {
     423    update idletasks
     424    set w [winfo reqwidth $itk_component(tabs)]
     425    set h [winfo reqheight $itk_component(tabs)]
     426    component hull configure -width $w -height $h
    410427}
    411428
  • trunk/gui/scripts/gauge.tcl

    r22 r24  
    8282itcl::body Rappture::Gauge::constructor {args} {
    8383    itk_component add icon {
    84         canvas $itk_interior.icon -borderwidth 0 -highlightthickness 0
     84        canvas $itk_interior.icon -width 1 -height 1 \
     85            -borderwidth 0 -highlightthickness 0
    8586    } {
    8687        usual
     
    542543        error "bad option \"$itk_option(-spectrum)\": should be Rappture::Spectrum object"
    543544    }
     545    _resize
    544546    _layout
    545547    _redraw
  • trunk/gui/scripts/moleculeViewer.tcl

    r22 r24  
    1515package require BLT
    1616
    17 option add *MoleculeViewer.width 4i widgetDefault
    18 option add *MoleculeViewer.height 4i widgetDefault
     17option add *MoleculeViewer.width 5i widgetDefault
     18option add *MoleculeViewer.height 5i widgetDefault
    1919option add *MoleculeViewer.backdrop black widgetDefault
    2020
  • trunk/gui/scripts/pager.tcl

    r22 r24  
    166166    set _pages [linsert $_pages $pos $params(-name)]
    167167
    168     #bind $win <Configure> \
    169     #    [itcl::code $_dispatcher event -idle !fixsize]
     168    bind $win <Configure> \
     169        [itcl::code $_dispatcher event -idle !fixsize]
    170170
    171171    # the number of pages affects the arrangment -- force an update
Note: See TracChangeset for help on using the changeset viewer.