aboutsummaryrefslogtreecommitdiff
path: root/render.f90
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2020-04-28 20:55:15 -0400
committerJeffrey Armstrong <jeff@approximatrix.com>2020-04-28 20:55:15 -0400
commitdfd21b695107fc01941e3218b60d360ee38fb150 (patch)
tree21c6097a544870972d21f69eea57e8ada5f7555f /render.f90
parenteb8d9bc74a0624dbc98ffb75268a3ba57bd43b40 (diff)
downloadLR-87-dfd21b695107fc01941e3218b60d360ee38fb150.zip
LR-87-dfd21b695107fc01941e3218b60d360ee38fb150.tar.gz
Links are now rendered in the dumb renderer. Preparation sub now available before every layout is performed.
Diffstat (limited to 'render.f90')
-rw-r--r--render.f9064
1 files changed, 64 insertions, 0 deletions
diff --git a/render.f90 b/render.f90
index 2913507..6d19729 100644
--- a/render.f90
+++ b/render.f90
@@ -11,6 +11,7 @@ implicit none
procedure::render_proportional
procedure(initialize), deferred::initialize
+ procedure(prepare_for_layout), deferred::prepare_for_layout
procedure(calculate_width), deferred::text_width
procedure(calculate_height), deferred::text_height
@@ -21,6 +22,11 @@ implicit none
procedure(calculate_height), deferred::preformatted_height
procedure(calculate_visibility), deferred::is_preformatted_visible
procedure(draw_text), deferred::draw_preformatted
+
+ procedure(calculate_width), deferred::link_width
+ procedure(calculate_height), deferred::link_height
+ procedure(calculate_visibility), deferred::is_link_visible
+ procedure(draw_link), deferred::draw_link
end type renderer
@@ -32,6 +38,13 @@ implicit none
end interface
abstract interface
+ subroutine prepare_for_layout(self)
+ import::renderer
+ class(renderer)::self
+ end subroutine prepare_for_layout
+ end interface
+
+ abstract interface
function calculate_width(self, text)
import::renderer
class(renderer)::self
@@ -65,6 +78,14 @@ implicit none
logical::calculate_visibility
end function calculate_visibility
end interface
+
+ abstract interface
+ subroutine draw_link(self, text, url)
+ import::renderer
+ class(renderer)::self
+ character(*), intent(in)::text, url
+ end subroutine draw_link
+ end interface
contains
@@ -170,4 +191,47 @@ contains
r%y = r%y + r%preformatted_height(text)
end subroutine render_preformatted
+
+ subroutine render_link(r, text)
+ implicit none
+
+ class(renderer)::r
+ character(*)::text
+ integer::i_whitespace, d_length
+
+ character(len=:), allocatable::url, display
+
+ ! Find the url first - just allocate the same
+ ! size as the text, good enough...
+ allocate(character(len=len_trim(text)) :: url)
+ url = adjustl(text)
+
+ ! The display text occurs after the first whitespace
+ ! in url now
+ i_whitespace = index(trim(url)," ")
+ if(index(trim(url), CHAR(9)) > 0) then
+ if(i_whitespace == 0 .OR. index(trim(url), CHAR(9)) < i_whitespace) then
+ i_whitespace = index(trim(url), CHAR(9))
+ end if
+ end if
+
+ if(i_whitespace == 0) then
+ allocate(character(len=len_trim(url)) :: display)
+ display = url
+ else
+ d_length = len_trim(url) - i_whitespace + 1
+ allocate(character(len=d_length) :: display)
+ display = adjustl(url(i_whitespace:len_trim(url)))
+ end if
+
+ if(r%is_link_visible(display)) then
+ call r%draw_link(display, url)
+ end if
+ r%y = r%y + r%link_height(display)
+
+ deallocate(url)
+ deallocate(display)
+
+ end subroutine render_link
+
end module render