Silverfrost Forums

Welcome to our forums

SET_TOOLTIP_TEXT@ + CHAR(10)

22 Feb 2021 11:48 #27150

In this example there is a %pl[full_mouse_input] region with a callback which updates the %th[at_cursor,ms_style] for the region with the current x,y coordinates at the mouse. At first glance this appears to work, but the call to SET_TOOLTIP_TEXT@ does not recognise the presence of CHAR(10), so the text in the tooltips which should be over two lines, is displayed as a single line.

module demo_mod
use clrwin
implicit none
integer, parameter :: dp=kind(1.d0), n = 10
real(dp) :: x(1:n), y(1:n)
integer :: show_coord = 1
integer(7) pl_handle
character(len=256) :: coord_string = ''
contains
  integer function gui()
  integer iw, i
    forall (i=1:n) x(i) = dble(i-1) ; forall (i=1:n) y(i) = x(i)*x(i)
    iw = winio@('%mn[Exit]&','exit')
    iw = winio@('%th[at_cursor,ms_style,delay]&', 1, 0)
    iw = winio@('%`rb[Show coordinates]&', show_coord)
    call winop@('%pl[full_mouse_input,x_array,title=Quadratic,gridlines,frame,colour=blue,width=2,symbol=10,smoothing=4]')
    iw = winio@('%nl%^?pl@&', 400, 400, n, x, y, pl_cb, coord_string)
    iw = winio@('%lc&',pl_handle)
    iw = winio@(' ')
    gui = 1
  end function gui
    
  integer function pl_cb()
  integer(7) gx,gy
  integer i
  real(kind=dp) px, py
  character(len=10) str_x, str_y
  if ( clearwin_string@('callback_reason') .eq. 'MOUSE_MOVE') then    
    if (show_coord .eq. 1) then
      gx = CLEARWIN_INFO@('GRAPHICS_MOUSE_X') ; gy = CLEARWIN_INFO@('GRAPHICS_MOUSE_Y')
      i = GET_PLOT_DATA@(gx,gy,px,py)
      if ( px .gt. minval(x) .and. px .lt. maxval(x) .and. py .gt. minval(y) .and. py .lt. maxval(y) ) then
        write(str_x,'(SPF10.3)') px ; write(str_y,'(SPF10.3)') py 
        coord_string = trim(adjustl(str_x))//char(10)//trim(adjustl(str_y))
        print*, coord_string   
        call SET_TOOLTIP_TEXT@(pl_handle,coord_string) ! ## Why does SET_TOOLTIP_TEXT@ fail to detect the char(10) in cood_string?
        ! call SET_TOOLTIP_TEXT@(pl_handle,trim(adjustl(str_x))//char(10)//trim(adjustl(str_y))) ! ## Same output as above line 
      else
        call SET_TOOLTIP_TEXT@(pl_handle,'')
      end if
    else
      call SET_TOOLTIP_TEXT@(pl_handle,'')
    end if
  end if  
  pl_cb = 2
  end function pl_cb

end module demo_mod

program main
use demo_mod
implicit none
integer i
  i = gui()
end program main 
22 Feb 2021 2:21 #27154

Ken

The initial value of coord_string must contain char(10).

I will modify the routine so that this will not be necessary in future.

22 Feb 2021 3:41 #27156

Paul, Thanks. I was completely bamboozled by that one.

Please login to reply.