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().
This commit is contained in:
Kartik K. Agaram 2023-10-16 22:53:26 -07:00
parent ea4a8379fe
commit 4b3f359526
6 changed files with 5 additions and 9 deletions

View File

@ -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('^[^:]*:[^:]*: ', '')

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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