about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2023-10-16 22:53:26 -0700
committerKartik K. Agaram <vc@akkartik.com>2023-10-16 22:57:46 -0700
commit4b3f3595266729a16a2a5bdb2a480576d332c14c (patch)
tree8776a614abf1d0621284c2fb4808bcf59d1f2ed8
parentea4a8379fe577207509719af41491190035fc8fa (diff)
downloadlines.love-4b3f3595266729a16a2a5bdb2a480576d332c14c.tar.gz
clearer API for drawing a button
Make it more obvious that the color passed in is just for the background.
The icon will do the rest.
r/g/b keys are more consistent with App.color().
-rw-r--r--app.lua4
-rw-r--r--button.lua2
-rw-r--r--commands.lua2
-rw-r--r--edit.lua2
-rw-r--r--source_edit.lua2
-rw-r--r--source_text.lua2
6 files changed, 5 insertions, 9 deletions
diff --git a/app.lua b/app.lua
index 5e3301f..cf89a37 100644
--- a/app.lua
+++ b/app.lua
@@ -368,10 +368,6 @@ function App.color(color)
   love.graphics.setColor(color.r, color.g, color.b, color.a)
 end
 
-function colortable(app_color)
-  return {app_color.r, app_color.g, app_color.b, app_color.a}
-end
-
 -- prepend file/line/test
 function prepend_debug_info_to_test_failure(test_name, err)
   local err_without_line_number = err:gsub('^[^:]*:[^:]*: ', '')
diff --git a/button.lua b/button.lua
index 7549169..55e4b1e 100644
--- a/button.lua
+++ b/button.lua
@@ -12,7 +12,7 @@ function button(State, name, params)
   if State.button_handlers == nil then
     State.button_handlers = {}
   end
-  love.graphics.setColor(params.color[1], params.color[2], params.color[3])
+  love.graphics.setColor(params.bg.r, params.bg.g, params.bg.b)
   love.graphics.rectangle('fill', params.x,params.y, params.w,params.h, 5,5)
   if params.icon then params.icon(params) end
   table.insert(State.button_handlers, params)
diff --git a/commands.lua b/commands.lua
index 4a0d24a..a76bae5 100644
--- a/commands.lua
+++ b/commands.lua
@@ -116,7 +116,7 @@ function add_file_to_menu(x,y, s, cursor_highlight)
   if cursor_highlight then
     color = Menu_highlight_color
   end
-  button(Editor_state, 'menu', {x=x-5, y=y-2, w=width+5*2, h=Editor_state.line_height+2*2, color=colortable(color),
+  button(Editor_state, 'menu', {x=x-5, y=y-2, w=width+5*2, h=Editor_state.line_height+2*2, bg=color,
     onpress1 = function()
       navigate_to_file(s)
     end
diff --git a/edit.lua b/edit.lua
index 7d3c26f..232d9b9 100644
--- a/edit.lua
+++ b/edit.lua
@@ -183,7 +183,7 @@ function edit.draw(State)
       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=State.left-Margin_left+4, y=y+4, w=12,h=12, bg={r=1,g=1,b=0},
           icon = icon.insert_drawing,
           onpress1 = function()
                        Drawing.before = snapshot(State, line_index-1, line_index)
diff --git a/source_edit.lua b/source_edit.lua
index 2bf0697..12c2bae 100644
--- a/source_edit.lua
+++ b/source_edit.lua
@@ -188,7 +188,7 @@ function edit.draw(State, hide_cursor, show_line_numbers)
         if show_line_numbers then
           buttonx = 4  -- HACK: position draw buttons at a fixed x on screen
         end
-        button(State, 'draw', {x=buttonx, y=y+4, w=12,h=12, color={1,1,0},
+        button(State, 'draw', {x=buttonx, y=y+4, w=12,h=12, bg={r=1,g=1,b=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 df36266..fb5123a 100644
--- a/source_text.lua
+++ b/source_text.lua
@@ -34,7 +34,7 @@ function Text.draw(State, line_index, y, startpos, hide_cursor, show_line_number
         local s,e,filename = unpack(link_offsets)
         local lo, hi = Text.clip_wikiword_with_screen_line(line, line_cache, i, s, e)
         if lo then
-          button(State, 'link', {x=State.left+lo, y=y, w=hi-lo, h=State.line_height, color={1,1,1},
+          button(State, 'link', {x=State.left+lo, y=y, w=hi-lo, h=State.line_height, bg={r=1,g=1,b=1},
             icon = icon.hyperlink_decoration,
             onpress1 = function()
                          if file_exists(filename) then