Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions colors.v
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ pub const status_dark_lilac = tea.Color{ 154, 119, 209 }
pub const status_cyan = tea.Color{ 138, 222, 237 }
pub const status_purple = tea.Color{ 130, 144, 250 }

pub fn fg_color(background_color tea.Color) tea.Color {
s_r := f32(background_color.r) / 255
s_g := f32(background_color.g) / 255
s_b := f32(background_color.b) / 255

luminance := 0.2126 * s_r + 0.7152 * s_g + 0.0722 * s_b

return if luminance > 0.5 { matte_black_fg_color } else { matte_white_fg_color }
}

9 changes: 9 additions & 0 deletions colors_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module palette

import tauraamui.bobatea as tea

fn test_fg_color_from_shades_of_bg() {
assert fg_color(tea.Color{ 10, 10, 10 }) == matte_white_fg_color
assert fg_color(tea.Color{ 200, 200, 200 }) == matte_black_fg_color
}

3 changes: 2 additions & 1 deletion editor.v
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ fn (m EditorModel) view(mut ctx tea.Context) {
}

fn (m EditorModel) render_cursor(mut ctx tea.Context) {
ctx.set_bg_color(palette.matte_white_fg_color)
default_bg_color := ctx.get_default_bg_color() or { palette.matte_black_bg_color }
ctx.set_bg_color(palette.fg_color(default_bg_color))
ctx.draw_rect(m.cursor_pos.x, m.cursor_pos.y, 1, 1)
ctx.reset_bg_color()
}
Expand Down
2 changes: 1 addition & 1 deletion editor_workspace.v
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ fn (m EditorWorkspaceModel) render_status_blocks(mut ctx tea.Context) {
ctx.push_offset(tea.Offset{ x: 2 })

file_name_label := m.active_file_name()
ctx.set_color(palette.matte_white_fg_color)
ctx.set_color(palette.fg_color(palette.status_file_name_bg_color))
ctx.set_bg_color(palette.status_file_name_bg_color)
ctx.draw_text(0, 0, file_name_label)
ctx.reset_bg_color()
Expand Down
2 changes: 1 addition & 1 deletion main.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import tauraamui.bobatea as tea
import palette

fn main() {
mut petal_model := PetalModel.new(palette.theme_bg_color)
mut petal_model := PetalModel.new(palette.theme_bg_color, palette.fg_color(palette.theme_bg_color))
mut app := tea.new_program(mut petal_model)
petal_model.app_send = app.send
app.run() or { panic('something went wrong! ${err}') }
Expand Down
8 changes: 7 additions & 1 deletion petal.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const dot = '•'
struct PetalModel {
mut:
app_send ?fn (tea.Msg)
theme_fg_color ?tea.Color
theme_bg_color ?tea.Color
first_frame bool
active_screen DebuggableModel // all screens are debuggable to help with live, well... debugging
Expand All @@ -17,9 +18,10 @@ mut:
last_resize_height int
}

fn PetalModel.new(theme_bg_color ?tea.Color) PetalModel {
fn PetalModel.new(theme_bg_color ?tea.Color, theme_fg_color ?tea.Color) PetalModel {
return PetalModel{
theme_bg_color: theme_bg_color
theme_fg_color: theme_fg_color
first_frame: true
active_screen: SplashScreenModel.new()
}
Expand Down Expand Up @@ -91,6 +93,10 @@ fn (mut m PetalModel) update(msg tea.Msg) (tea.Model, ?tea.Cmd) {

fn (mut m PetalModel) view(mut ctx tea.Context) {
if m.first_frame {
if fg_color := m.theme_fg_color {
ctx.set_default_fg_color(fg_color)
}

if bg_color := m.theme_bg_color {
ctx.set_default_bg_color(bg_color)
}
Expand Down