about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-09-14 22:27:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-09-14 22:27:38 -0700
commit1fd30c0462faf598d5ef7b2911379bc19a649253 (patch)
tree4c275e5efc0e99efddef0e3b556b2535bc534d99
parent706296388809984b20b32edf3fa8f576c85508c5 (diff)
downloadtext.love-1fd30c0462faf598d5ef7b2911379bc19a649253.tar.gz
always show line numbers in source editor
The drawing buttons are now absolutely positioned, which is a horrible
hack. But for just the source editor it seems good enough. The
alternative is to modify magic constants in all the tests :/
-rw-r--r--source.lua5
-rw-r--r--source_edit.lua3
-rw-r--r--source_text.lua2
3 files changed, 7 insertions, 3 deletions
diff --git a/source.lua b/source.lua
index d9e44b6..4a8bb48 100644
--- a/source.lua
+++ b/source.lua
@@ -1,6 +1,7 @@
 source = {}
 
 Editor_state = {}
+Line_number_width = 3  -- in ems
 
 -- called both in tests and real run
 function source.initialize_globals()
@@ -125,7 +126,7 @@ function source.load_settings()
   if Show_log_browser_side then
     right = App.screen.width/2 - Margin_right
   end
-  Editor_state = edit.initialize_state(Margin_top, Margin_left, right, settings.font_height, math.floor(settings.font_height*1.3))
+  Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), right, settings.font_height, math.floor(settings.font_height*1.3))
   Editor_state.filename = settings.filename
   Editor_state.filename = basename(Editor_state.filename)  -- migrate settings that used full paths; we now support only relative paths within the app
   if settings.cursors then
@@ -153,7 +154,7 @@ function source.initialize_default_settings()
   local font_height = 20
   love.graphics.setFont(love.graphics.newFont(font_height))
   source.initialize_window_geometry()
-  Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right)
+  Editor_state = edit.initialize_state(Margin_top, Margin_left + Line_number_width*App.width('m'), App.screen.width-Margin_right)
   Editor_state.filename = 'run.lua'
   Editor_state.font_height = font_height
   Editor_state.line_height = math.floor(font_height*1.3)
diff --git a/source_edit.lua b/source_edit.lua
index 96bfb12..78c7f4d 100644
--- a/source_edit.lua
+++ b/source_edit.lua
@@ -7,6 +7,7 @@ Current_stroke_color = {r=0.7, g=0.7, b=0.7}  -- in process of being drawn
 Current_name_background_color = {r=1, g=0, b=0, a=0.1}  -- name currently being edited
 Focus_stroke_color = {r=1, g=0, b=0}  -- what mouse is hovering over
 Highlight_color = {r=0.7, g=0.7, b=0.9}  -- selected text
+Line_number_color = {r=0.6, g=0.6, b=0.6}
 Icon_color = {r=0.7, g=0.7, b=0.7}  -- color of current mode icon in drawings
 Help_color = {r=0, g=0.5, b=0}
 Help_background_color = {r=0, g=0.5, b=0, a=0.1}
@@ -168,7 +169,7 @@ function edit.draw(State, hide_cursor)
       end
       if line.data == '' then
         -- button to insert new drawing
-        button(State, 'draw', {x=State.left-Margin_left+4, y=y+4, w=12,h=12, color={1,1,0},
+        button(State, 'draw', {x=4, y=y+4, w=12,h=12, color={1,1,0},
           icon = icon.insert_drawing,
           onpress1 = function()
                        Drawing.before = snapshot(State, line_index-1, line_index)
diff --git a/source_text.lua b/source_text.lua
index 5bc8942..68b560e 100644
--- a/source_text.lua
+++ b/source_text.lua
@@ -12,6 +12,8 @@ function Text.draw(State, line_index, y, startpos, hide_cursor)
   local final_screen_line_starting_pos = startpos  -- track value to return
   Text.populate_screen_line_starting_pos(State, line_index)
   Text.populate_link_offsets(State, line_index)
+  App.color(Line_number_color)
+  love.graphics.print(line_index, State.left-Line_number_width*App.width('m')+10,y)
   initialize_color()
   assert(#line_cache.screen_line_starting_pos >= 1)
   for i=1,#line_cache.screen_line_starting_pos do