Skip to content

Commit

Permalink
move table row highlight to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
aoterodelaroza committed Sep 3, 2024
1 parent f9a1778 commit 6e99635
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 31 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.261
1.2.262
1 change: 1 addition & 0 deletions src/gui/gui_main.f90
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ module gui_main
type(ImVec4), parameter, public :: ColorWaitBg = ImVec4(0.80, 0.80, 0.80, 0.6) ! dim the background while waiting
type(ImVec4), parameter, public :: ColorFrameBgAlt = ImVec4(0.29,0.16,0.48,0.54) ! alternate framebg
type(ImVec4), parameter, public :: ColorFieldSelected = ImVec4(0.91,1.00,0.00,0.31) ! alternate framebg
type(ImVec4), parameter, public :: ColorTableHighlightRow = ImVec4(1._c_float,0.8_c_float,0.1_c_float,0.5_c_float)

! system status (must be from lower to higher initialization level)
integer, parameter, public :: sys_empty = 0 ! not in use
Expand Down
10 changes: 5 additions & 5 deletions src/gui/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ module subroutine scene_render(s)
use interfaces_cimgui
use interfaces_opengl3
use shapes, only: sphVAO, cylVAO, textVAOos, textVBOos
use gui_main, only: fonts, fontbakesize_large, time, font_large, sys
use gui_main, only: fonts, fontbakesize_large, time, font_large, sys,&
ColorTableHighlightRow
use utils, only: ortho, project
use tools_math, only: eigsym, matinv_cfloat
use tools_io, only: string
Expand All @@ -336,8 +337,6 @@ module subroutine scene_render(s)
0.4_c_float, 1._c_float, 0.4_c_float, 0.5_c_float,&
0.4_c_float, 0.4_c_float, 1._c_float, 0.5_c_float,&
0.9_c_float, 0.7_c_float, 0.4_c_float, 0.5_c_float/),shape(rgbmsel))
real(c_float), parameter :: rgbsel(4) = &
(/1._c_float, 0.8_c_float, 0.1_c_float, 0.5_c_float/)
real(c_float), parameter :: msel_thickness = 0.1_c_float
real(c_float), parameter :: sel_thickness = 0.2_c_float
real(c_float), parameter :: sel_label_size = 1.2_c_float
Expand Down Expand Up @@ -622,7 +621,7 @@ end subroutine draw_all_mselections
!> Draw the selections
subroutine draw_all_selections()
integer :: i, j, id
real(c_float) :: x(3)
real(c_float) :: x(3), rgba(4)
logical :: ok

do i = 1, s%nsph
Expand All @@ -642,7 +641,8 @@ subroutine draw_all_selections()
if (ok) then
x = s%drawlist_sph(i)%x
if (s%animation > 0) x = x + real(displ * s%drawlist_sph(i)%xdelta,c_float)
call draw_sphere(x,s%drawlist_sph(i)%r + sel_thickness,s%atom_res,rgba=rgbsel)
rgba = (/ColorTableHighlightRow%x,ColorTableHighlightRow%y,ColorTableHighlightRow%z,ColorTableHighlightRow%w/)
call draw_sphere(x,s%drawlist_sph(i)%r + sel_thickness,s%atom_res,rgba=rgba)
radsel(j) = s%drawlist_sph(i)%r + sel_thickness
end if
end do
Expand Down
5 changes: 5 additions & 0 deletions src/gui/utils.f90
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module utils
public :: iw_text
public :: iw_button
public :: iw_tooltip
public :: iw_highlight_selectable
public :: igIsItemHovered_delayed
public :: get_time_string
public :: buffer_to_string_array
Expand Down Expand Up @@ -139,6 +140,10 @@ module subroutine iw_tooltip(str,ttshown,rgba,nowrap)
real(c_float), intent(in), optional :: rgba(4)
logical, intent(in), optional :: nowrap
end subroutine iw_tooltip
module function iw_highlight_selectable(str)
character(len=*,kind=c_char), intent(in) :: str
logical :: iw_highlight_selectable
end function iw_highlight_selectable
module function igIsItemHovered_delayed(flags,thr,already_shown)
integer(c_int), value :: flags
real(c_float), intent(in) :: thr
Expand Down
37 changes: 37 additions & 0 deletions src/gui/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,43 @@ subroutine show_tooltip()
end subroutine show_tooltip
end subroutine iw_tooltip

!> Create a selectable that highlights the current row. Return true
!> if the selectable is hovered.
module function iw_highlight_selectable(str)
use interfaces_cimgui
use gui_main, only: g, ColorTableHighlightRow
character(len=*,kind=c_char), intent(in) :: str
logical :: iw_highlight_selectable

type(ImVec2) :: sz1, szero
real(c_float) :: pos
integer(c_int) :: flags
character(kind=c_char,len=:), allocatable, target :: str2
logical :: ldum

szero%x = 0
szero%y = 0
sz1%x = g%Style%ItemSpacing%x
sz1%y = g%Style%ItemSpacing%y + g%Style%CellPadding%y + g%Style%FramePadding%y
call igPushStyleVar_Vec2(ImGuiStyleVar_ItemSpacing,sz1)
call igPushStyleColor_Vec4(ImGuiCol_HeaderHovered,ColorTableHighlightRow)
pos = igGetCursorPosX()
flags = ImGuiSelectableFlags_SpanAllColumns
flags = ior(flags,ImGuiSelectableFlags_AllowItemOverlap)
str2 = trim(str) // c_null_char
call igSameLine(0._c_float,0._c_float)
ldum = igSelectable_Bool(c_loc(str2),.false._c_bool,flags,szero)
call igSetCursorPosX(pos)
iw_highlight_selectable = .false.
if (igIsItemHovered(ImGuiHoveredFlags_None)) then
iw_highlight_selectable = &
igIsMouseHoveringRect(g%LastItemData%NavRect%min,g%LastItemData%NavRect%max,.false._c_bool)
end if
call igPopStyleColor(1_c_int)
call igPopStyleVar(1_c_int)

end function iw_highlight_selectable

! Returns true if the last item has been hovered for at least thr
! seconds. If already_shown (the tooltip has already been displayed),
! do not use the delay.
Expand Down
33 changes: 8 additions & 25 deletions src/gui/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -3217,7 +3217,7 @@ function atom_selection_widget(c,r) result(changed)
use gui_main, only: g
use scenes, only: draw_style_atom, draw_style_molecule
use utils, only: iw_text, iw_combo_simple, iw_tooltip, iw_calcheight, iw_checkbox,&
iw_clamp_color3, iw_calcwidth, iw_button, iw_coloredit3
iw_clamp_color3, iw_calcwidth, iw_button, iw_coloredit3, iw_highlight_selectable
use crystalmod, only: crystal
use global, only: iunit_ang, dunit0
use tools_io, only: string, ioj_right
Expand Down Expand Up @@ -3252,8 +3252,6 @@ function atom_selection_widget(c,r) result(changed)
integer, parameter :: im_radius = 4
integer, parameter :: im_rest = 5

type(ImVec4), parameter :: rgbsel = ImVec4(1._c_float,0.8_c_float,0.1_c_float,0.5_c_float)

logical, save :: ttshown = .false. ! tooltip flag

szero%x = 0
Expand Down Expand Up @@ -3370,29 +3368,14 @@ function atom_selection_widget(c,r) result(changed)
call igAlignTextToFramePadding()
call iw_text(string(i))

! the selectable
sz1%x = g%Style%ItemSpacing%x
sz1%y = g%Style%ItemSpacing%y + g%Style%CellPadding%y + g%Style%FramePadding%y
call igPushStyleVar_Vec2(ImGuiStyleVar_ItemSpacing,sz1)
call igPushStyleColor_Vec4(ImGuiCol_HeaderHovered,rgbsel)
pos = igGetCursorPosX()
flags = ImGuiSelectableFlags_SpanAllColumns
flags = ior(flags,ImGuiSelectableFlags_AllowItemOverlap)
str2 = "##selectableatomtable" // suffix // c_null_char
call igSameLine(0._c_float,0._c_float)
ldum = igSelectable_Bool(c_loc(str2),.false._c_bool,flags,szero)
call igSetCursorPosX(pos)
if (igIsItemHovered(ImGuiHoveredFlags_None)) then
if (igIsMouseHoveringRect(g%LastItemData%NavRect%min,g%LastItemData%NavRect%max,.false._c_bool)) then
win(win(r%idwin)%idparent)%sc%nselection = 1
win(win(r%idwin)%idparent)%sc%selection_type = r%atom_style%type
win(win(r%idwin)%idparent)%sc%selection(1) = i
win(win(r%idwin)%idparent)%forcerender = .true.
oksel = .true.
end if
! the highlight selectable
if (iw_highlight_selectable("##selectableatomtable" // suffix)) then
win(win(r%idwin)%idparent)%sc%nselection = 1
win(win(r%idwin)%idparent)%sc%selection_type = r%atom_style%type
win(win(r%idwin)%idparent)%sc%selection(1) = i
win(win(r%idwin)%idparent)%forcerender = .true.
oksel = .true.
end if
call igPopStyleColor(1_c_int)
call igPopStyleVar(1_c_int)
end if

! name
Expand Down

0 comments on commit 6e99635

Please sign in to comment.