Skip to content

Commit

Permalink
Manuel color support for themes
Browse files Browse the repository at this point in the history
  • Loading branch information
malisipi committed Jul 6, 2022
1 parent 850a92c commit 95937ce
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ You can find more examples in `./examples/` folder.
* Editable Label
* Switch
* Disable Status (for Buttons, Checkboxs, Selectboxs, etc.)
* Manuel Accent Color and Manuel Dark/Light Mode Support
* Custom Colors for Widgets (except Themes)
* Handle Appearance Preferences (like Background Color, Text Color)
* Improve Light Theme
Expand Down
2 changes: 1 addition & 1 deletion examples/change_object_type.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ fn change_type(event_details m.EventDetails, mut app &m.Window, app_data voidptr
}
}

mut app:=m.create(m.WindowConfig{ title:"Change Type - MUI Example", width:165, height:60})
mut app:=m.create(m.WindowConfig{ title:"Change Type - MUI Example", width:165, height:60, color:m.theme_light})
app.password(m.Widget{ id:"widget", x:"20", y:"20", onchange:change_type })
m.run(mut app)
22 changes: 22 additions & 0 deletions examples/messagebox.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import malisipi.mui as m

fn create_messagebox(event_details m.EventDetails, mut app &m.Window, app_data voidptr){
unsafe{
m.messagebox(
app.get_object_by_id("title")[0]["text"].str,
app.get_object_by_id("message")[0]["text"].str,
app.get_object_by_id("type")[0]["text"].str,
app.get_object_by_id("icon")[0]["text"].str
)
}
}

mut app:=m.create(m.WindowConfig{ title:"Messagebox - MUI Examples", width:400, height:300, color:[20,20,140] })

app.textbox(m.Widget{ id:"title", x:"5%x", y:"5%y", width:"90%x", height:"10%y", placeholder:"Title" })
app.textbox(m.Widget{ id:"message", x:"5%x", y:"20%y", width:"90%x", height:"10%y", placeholder:"Message" })
app.selectbox(m.Widget{ id:"type", x:"5%x", y:"35%y", width:"43%x", height:"10%y", list:["ok", "okcancel", "yesno", "yesnocancel"] })
app.selectbox(m.Widget{ id:"icon", x:"# 5%x", y:"35%y", width:"43%x", height:"10%y", list:["info", "warning", "error"] })
app.button(m.Widget{ id:"create", x:"5%x", y:"# 5%y", width:"90%x", height:"10%y", text:"Create", onclick:create_messagebox })

m.run(mut app)
2 changes: 1 addition & 1 deletion mui.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn create(args &WindowConfig) &Window{
mut app := &Window{
objects: []
focus: ""
color_scheme: create_gx_color_from_color_scheme()
color_scheme: if args.color!=[-1,-1,-1] { create_gx_color_from_manuel_color(args.color) } else { create_gx_color_from_color_scheme() }
gg: 0
menubar: args.menubar
x_offset: 0
Expand Down
21 changes: 19 additions & 2 deletions themes.v
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import strconv
import gx
import math

pub const (
theme_dark=[40,40,40]
theme_light=[225,225,225]
)

fn hex_to_rgb(clr string) []int {

return [ int(strconv.parse_int(clr[6..8],16,0) or {return [-1,-1,-1]}) , int(strconv.parse_int(clr[4..6],16,0) or {return [-1,-1,-1]}) , int(strconv.parse_int(clr[2..4],16,0) or {return [-1,-1,-1]}) ]
Expand Down Expand Up @@ -85,10 +90,10 @@ fn create_color_scheme() [][]int{

color_scheme:=is_light_theme()
if color_scheme { // if light theme
return create_color_scheme_from_accent_color([225,225,225])
return create_color_scheme_from_accent_color(theme_light)
}

return create_color_scheme_from_accent_color([40,40,40])
return create_color_scheme_from_accent_color(theme_dark)
}

fn create_gx_color_from_color_scheme() []gx.Color{
Expand All @@ -102,3 +107,15 @@ fn create_gx_color_from_color_scheme() []gx.Color{
}
return gx_colors
}

fn create_gx_color_from_manuel_color(the_color []int) []gx.Color{
color_scheme:=create_color_scheme_from_accent_color(the_color)
mut gx_colors:=[]gx.Color{}
for color in color_scheme {
gx_colors << gx.Color{
r:u8(math.max(math.min(color[0],255),0)),
g:u8(math.max(math.min(color[1],255),0)),
b:u8(math.max(math.min(color[2],255),0))}
}
return gx_colors
}
1 change: 1 addition & 0 deletions types.v
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub mut:
menubar []map[string]WindowData = []map[string]WindowData{}
x_offset int // 0
y_offset int //=0
color []int = [-1,-1,-1]
}

pub struct EventDetails{
Expand Down

0 comments on commit 95937ce

Please sign in to comment.