sliders for font size and color settings

akkartik
Nov 21, 2023, 10:20 AM
JV27LDDKKY57IEBWGBFPSHEARMOEGLBYGBJD27PDPTNWWYXA4T6AC

Dependencies

  • [2] 4GX6NAY4 some very basic animations for switching panes
  • [3] RK2ASPN7 add lots of buttons to the toolbar
  • [4] FPSPT5TM show current pane number
  • [5] V2G455IR clean up a debug print
  • [6] 5RUFNRJO start of the visual skeleton
  • [7] I52S4E5F running `print` now appends to output editor
  • [8] PRE6XPRN responsively increase/decrease font height
  • [9] 4QFVRJ5U get rid of pane transition animations
  • [10] WR2WMEPE implement 'Run' button
  • [*] R5QXEHUI somebody stop me
  • [*] VUF2SX7B implement carousel buttons for inserting/switching current pane
  • [*] ZM7NOBRM new fork: carousel shell
  • [*] VAVXKWZV aggregate global state inside a 'pane' object
  • [*] UEG224LH debug animations

Change contents

  • file addition: 0095-Selected_slider (----------)
    [12.2]
    Selected_slider = nil
  • file addition: 0093-on_area (----------)
    [12.2]
    on_area = function(s, x,y)
    if x < s.x then return end
    if x > s.x+s.w then return end
    if y < s.y then return end
    if y > s.y+s.h then return end
    return true
    end
  • file addition: 0092-Settings_menu_area (----------)
    [12.2]
    Settings_menu_area = {}
  • file addition: 0091-Foreground_color (----------)
    [12.2]
    Foreground_color = {r=0, g=0, b=0}
  • file addition: 0090-Background_color (----------)
    [12.2]
    Background_color = {r=1, g=1, b=1}
  • file addition: 0089-Settings_background_sliders (----------)
    [12.2]
    Settings_background_sliders = {}
  • file addition: 0088-Settings_foreground_sliders (----------)
    [12.2]
    Settings_foreground_sliders = {}
  • file addition: 0087-on_slider (----------)
    [12.2]
    on_slider = function(slider, x,y)
    if x < slider.x0 or x > slider.x1 then return end
    if y < slider.y0-slider.h/2 or y > slider.y0+slider.h/2 then return end
    return true
    end
  • file addition: 0086-mouse_on_any_slider (----------)
    [12.2]
    mouse_on_any_slider = function(x,y, mouse_button)
    local result = false
    if on_slider(Settings_font_slider, x,y) then
    Selected_slider = Settings_font_slider.name
    result = true
    end
    for color,slider in pairs(Settings_foreground_sliders) do
    if on_slider(slider, x,y) then
    Selected_slider = slider.name
    result = true
    end
    end
    for color,slider in pairs(Settings_background_sliders) do
    if on_slider(slider, x,y) then
    Selected_slider = slider.name
    result = true
    end
    end
    return result
    end
  • file addition: 0085-slider_value (----------)
    [12.2]
    slider_value = function(slider, x)
    local s = slider
    if x < s.x0 then x = s.x0 end
    if x > s.x1 then x = s.x1 end
    s.x = x
    s.value = s.lo + (s.x-s.x0)*(s.hi-s.lo)/(s.x1-s.x0)
    return s.value
    end
  • file addition: 0084-update_any_sliders (----------)
    [12.2]
    update_any_sliders = function(x,y)
    if Selected_slider == Settings_font_slider.name then
    update_font_settings(slider_value(Settings_font_slider, x))
    return true
    end
    for color,slider in pairs(Settings_foreground_sliders) do
    if Selected_slider == slider.name then
    Foreground_color[color] = slider_value(slider, x)
    return true
    end
    end
    for color,slider in pairs(Settings_background_sliders) do
    if Selected_slider == slider.name then
    Background_color[color] = slider_value(slider, x)
    return true
    end
    end
    end
  • file addition: 0083-Settings_font_slider (----------)
    [12.2]
    Settings_font_slider = {
    name='font',
    -- left extreme
    x0=nil, y0=nil,
    -- right extreme
    x1=nil,
    -- slider itself
    x=nil, -- y=y0
    w=nil, h=nil,
    lo=20, hi=40,
    }
  • file addition: 0082-draw_slider (----------)
    [12.2]
    -- draw a slider widget starting at x,y, extending right w pixels
    -- position 'value' on the slider
    -- the leftmost point on the slider will have value 'lo', and the rightmost will have 'hi'. In between the value will be linearly interpolated.
    draw_slider = function(s)
    love.graphics.line(s.x0, s.y0, s.x1, s.y0)
    s.x = s.x0 + (s.x1-s.x0)*(s.value-s.lo)/(s.hi-s.lo)
    love.graphics.rectangle('fill', s.x-s.h/2, s.y0-s.h/2, s.w,s.h)
    end
  • file addition: 0081-draw_settings_menu (----------)
    [12.2]
    draw_settings_menu = function()
    App.color(Menu_background)
    local w,h = 200, love.graphics.getFont():getHeight()*8
    local x,y = Safe_width-30-w, Menu_bottom
    Settings_menu_area = {x=x, y=y, w=w, h=h}
    love.graphics.rectangle('fill', x,y, w,h)
    App.color(Normal_color)
    -- font size slider
    love.graphics.print('font size', x+10,y+10)
    y = y+10+Line_height
    local sx = x+App.width('bg')+50 -- align all sliders
    Settings_font_slider = {
    name='font',
    -- x limits
    x0=sx+20, x1=Safe_width-30,
    -- central y
    y0=y+10,
    -- slider knob dimensions
    w=10, h=10,
    -- extremes
    lo=20, hi=40, -- font sizes
    value=Current_pane.editor_state.font_height
    }
    draw_slider(Settings_font_slider)
    y = y+10
    -- colors
    love.graphics.print('colors', x+10,y+10)
    y = y+10+Line_height
    -- colors/foreground
    love.graphics.print('fg', x+20, y)
    App.color(Foreground_color)
    love.graphics.rectangle('fill', sx-20,y+5, 20,20)
    Settings_foreground_sliders = {
    r = {
    name='fg/r',
    x0 = sx+20, x1=Safe_width-30,
    y0 = y,
    w=10, h=10,
    lo = 0, hi=1,
    value = Foreground_color.r
    },
    g = {
    name='fg/g',
    x0 = sx+20, x1=Safe_width-30,
    y0 = y+15,
    w=10, h=10,
    lo = 0, hi=1,
    value = Foreground_color.g
    },
    b = {
    name='fg/b',
    x0 = sx+20, x1=Safe_width-30,
    y0 = y+30,
    w=10, h=10,
    lo = 0, hi=1,
    value = Foreground_color.b
    },
    }
    App.color(Normal_color)
    draw_slider(Settings_foreground_sliders.r)
    draw_slider(Settings_foreground_sliders.g)
    draw_slider(Settings_foreground_sliders.b)
    y = y+10+Line_height+10
    -- colors/background
    love.graphics.print('bg', x+20, y)
    App.color(Background_color)
    love.graphics.rectangle('fill', sx-20,y+5, 20,20)
    App.color(Normal_color)
    Settings_background_sliders = {
    r = {
    name='bg/r',
    x0 = sx+20, x1=Safe_width-30,
    y0 = y,
    w=10, h=10,
    lo = 0, hi=1,
    value = Background_color.r
    },
    g = {
    name='bg/g',
    x0 = sx+20, x1=Safe_width-30,
    y0 = y+15,
    w=10, h=10,
    lo = 0, hi=1,
    value = Background_color.g
    },
    b = {
    name='bg/b',
    x0 = sx+20, x1=Safe_width-30,
    y0 = y+30,
    w=10, h=10,
    lo = 0, hi=1,
    value = Background_color.b
    },
    }
    App.color(Normal_color)
    draw_slider(Settings_background_sliders.r)
    draw_slider(Settings_background_sliders.g)
    draw_slider(Settings_background_sliders.b)
    end
  • file addition: 0080-Show_settings (----------)
    [12.2]
    Show_settings =false
  • file addition: 0079-White (----------)
    [12.2]
    White = {r=1, g=1, b=1}
  • replacement in 0072-settings_button at line 9
    [3.1684][3.1684:1705]()
    print('settings')
    [3.1684]
    [3.1705]
    Show_settings = not Show_settings
  • replacement in 0051-run_button at line 15
    [2.550][4.591:634](),[4.591][4.591:634](),[2.661][4.634:667](),[4.634][4.634:667]()
    love.graphics.setBackgroundColor(1,1,1)
    love.graphics.setColor(0,0,0)
    [4.591]
    [4.667]
    -- love.graphics.setBackgroundColor(Background_color.r, Background_color.g, Background_color.b)
  • edit in 0021-draw_menu at line 4
    [4.825][4.221:246]()
    App.color(Normal_color)
  • edit in 0021-draw_menu at line 5
    [4.269]
    [3.7721]
    App.color(White)
  • edit in 0021-draw_menu at line 7
    [3.7781]
    [3.7781]
    App.color(Normal_color)
  • edit in 0021-draw_menu at line 32
    [13.2238]
    [4.1096]
    if Show_settings then
    draw_settings_menu()
    end
  • edit in 0017-on.mouse_release at line 2
    [14.2259]
    [15.2424]
    Selected_slider = nil
  • edit in 0016-on.mouse_press at line 3
    [15.3206]
    [4.1739]
    return
    end
    if mouse_on_any_slider(x,y, mouse_button) then
  • edit in 0016-on.mouse_press at line 8
    [4.1753]
    [15.3207]
    if not on_area(Settings_menu_area, x,y) then
    Show_settings = false
    end
  • replacement in 0012-on.draw at line 6
    [3.8266][3.8266:8372]()
    edit.draw(Current_pane.editor_state, --[[fg]] nil, --[[hide_cursor]] nil, --[[show_line_numbers]] true)
    [3.8266]
    [3.8372]
    edit.draw(Current_pane.editor_state, --[[fg]] Foreground_color, --[[hide_cursor]] nil, --[[show_line_numbers]] true)
  • replacement in 0012-on.draw at line 9
    [3.8439][3.8439:8523]()
    edit.draw(Current_pane.output_editor_state, Normal_color, --[[hide cursor]] true)
    [3.8439]
    [3.8523]
    edit.draw(Current_pane.output_editor_state, Foreground_color, --[[hide cursor]] true)
  • edit in 0004-on.update at line 3
    [16.1760]
    [15.4658]
    if App.mouse_down(1) then
    update_any_sliders(App.mouse_x(), App.mouse_y())
    end