Skip to content

Commit

Permalink
Support complicated widget drawing in frame
Browse files Browse the repository at this point in the history
  • Loading branch information
malisipi committed Feb 3, 2023
1 parent 0f0da8d commit b5a21dc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
8 changes: 7 additions & 1 deletion examples/scrollable_widgets.v
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ app.scrollbar(id:"textarea_scrollbar", x:180, y:20, width: 20, height:200, verti
app.table(id:"table", table:user_list, x:300, y:20, width:380, height:100, row_height:40)
app.scrollbar(id:"table_scrollbar", x:680, y:20, width: 20, height:100, vertical:true, connected_widget:app.get_object_by_id("table")[0])

app.frame(id:"frame", x:20, y:320, width:480, height:230, view_area:[800,600])
app.frame(id:"frame", x:20, y:320, width:480, height:230, view_area:[1250,1250])
app.scrollbar(id:"frame_scrollbar_v", x:500, y:320, width: 20, height:250, vertical:true, connected_widget:app.get_object_by_id("frame")[0])
app.scrollbar(id:"frame_scrollbar_h", x:20, y:550, width: 480, height:20, connected_widget:app.get_object_by_id("frame")[0])

app.list(id:"list", table:user_list, x:20, y:20, width:380, height:100, row_height:40, frame:"frame")
app.scrollbar(id:"list_scrollbar", x:400, y:20, width: 20, height:100, vertical:true, connected_widget:app.get_object_by_id("list")[0], frame:"frame")

app.checkbox(id:"checkbox", x:500, y:300, width:20, text:"Check me!" frame:"frame")
app.switch(id:"switch", x:500, y:330, width:40, text:"Switch me!" frame:"frame")
app.selectbox(id:"selectbox", x:500, y:360, list:["English","Turkish","Spanish"], text:"Language", frame:"frame")
app.slider(id:"slider", x:500, y:390, frame:"frame")
app.radio(id:"radio", x:500, y:420, height:20, list:["Cat","Dog","Bird"], frame:"frame")

app.run()
10 changes: 5 additions & 5 deletions mui.v
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,21 @@ fn frame_fn(app &Window) {
}"password"{
draw_password(app, object)
}"checkbox"{
$if !dont_clip ? { app.gg.scissor_rect(object["x"].num, object["y"].num, object["w"].num + 200, object["h"].num) }
$if !dont_clip ? { if object["in"].str=="" { app.gg.scissor_rect(object["x"].num, object["y"].num, object["w"].num + 200, object["h"].num) } }
draw_checkbox(app, object)
}"switch"{
$if !dont_clip ? { app.gg.scissor_rect(object["x"].num, object["y"].num, object["w"].num + 200, object["h"].num) }
$if !dont_clip ? { if object["in"].str=="" { app.gg.scissor_rect(object["x"].num, object["y"].num, object["w"].num + 200, object["h"].num) } }
draw_switch(app, object)
}"selectbox"{
$if !dont_clip ? { app.gg.scissor_rect(object["x"].num, object["y"].num, object["w"].num, object["h"].num+800) }
$if !dont_clip ? { if object["in"].str=="" { app.gg.scissor_rect(object["x"].num, object["y"].num, object["w"].num, object["h"].num+800) } }
draw_selectbox(app, object)
}"slider"{
$if !dont_clip ? { app.gg.scissor_rect(object["x"].num, object["y"].num, object["w"].num + 200, object["h"].num + 200) }
$if !dont_clip ? { if object["in"].str=="" { app.gg.scissor_rect(object["x"].num, object["y"].num, object["w"].num + 200, object["h"].num + 200) } }
draw_slider(app, object)
}"link"{
draw_link(app, object)
}"radio"{
$if !dont_clip ? { app.gg.scissor_rect(object["x"].num-1, object["y"].num-1, object["w"].num + 200, object["h"].num+2) }
$if !dont_clip ? { if object["in"].str=="" { app.gg.scissor_rect(object["x"].num-1, object["y"].num-1, object["w"].num + 200, object["h"].num+2) } }
draw_radio(app, object)
}"group"{
draw_group(app, object)
Expand Down
9 changes: 5 additions & 4 deletions radio.v
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn add_radio(mut app &Window, list []string, group_id string, x IntOrString,
for which_item,item in list {
app.objects << {
"type": WindowData{str:"radio"},
"id": WindowData{str:group_id+"_"+which_item.str()}
"id": WindowData{str:group_id+"_"+which_item.str()},
"text": WindowData{str:item},
"x": WindowData{num:0},
"y": WindowData{num:0},
Expand All @@ -36,9 +36,10 @@ pub fn add_radio(mut app &Window, list []string, group_id string, x IntOrString,
"y_raw":WindowData{str: match y{ int{ (y+((match wh{int{wh}string{0}}+5)*which_item)).str() } string{ print("Anchors couldn't be used in Y of radio buttons.\n") "0" } } },
"w_raw":WindowData{str: match wh{ int{ wh.str() } string{ print("Anchors couldn't be used in size of radio buttons.\n") "0" } } },
"h_raw":WindowData{str: match wh{ int{ wh.str() } string{ print("Anchors couldn't be used in size of radio buttons.\n") "0" } } },
"c": WindowData{bol:selected==which_item}
"hi": WindowData{bol:hi}
"tSize":WindowData{num:tSize}
"c": WindowData{bol:selected==which_item},
"hi": WindowData{bol:hi},
"tSize":WindowData{num:tSize},
"in": WindowData{str:frame},
}
}
}
Expand Down
21 changes: 12 additions & 9 deletions selectbox.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ import gx
pub fn add_selectbox(mut app &Window, text string, list []string, selected int, id string, x IntOrString, y IntOrString, w IntOrString, h IntOrString, hi bool, bg gx.Color, bfg gx.Color, fg gx.Color, fnchg OnEvent, frame string, zindex int){
app.objects << {
"type": WindowData{str:"selectbox"},
"id": WindowData{str:id}
"id": WindowData{str:id},
"in": WindowData{str:frame},
"z_ind":WindowData{num:zindex},
"text": WindowData{str:if text==""{ list[selected] } else { text }},
"x": WindowData{num:0},
"y": WindowData{num:0},
"w": WindowData{num:0},
"h": WindowData{num:0},
"x_raw":WindowData{str: match x{ int{ x.str() } string{ x } } },
"y_raw":WindowData{str: match y{ int{ y.str() } string{ y } } },
"w_raw":WindowData{str: match w{ int{ w.str() } string{ w } } },
"h_raw":WindowData{str: match h{ int{ h.str() } string{ h } } },
"x_raw":WindowData{str: match x{ int{ x.str() } string{ x } } },
"y_raw":WindowData{str: match y{ int{ y.str() } string{ y } } },
"w_raw":WindowData{str: match w{ int{ w.str() } string{ w } } },
"h_raw":WindowData{str: match h{ int{ h.str() } string{ h } } },
"bg": WindowData{clr:bg},
"bfg": WindowData{clr:bfg},
"fg": WindowData{clr:fg}
"list": WindowData{str:list.join("\0")}
"s": WindowData{num:if text==""{ selected } else { -1 }}
"hi": WindowData{bol:hi}
"fg": WindowData{clr:fg},
"list": WindowData{str:list.join("\0")},
"s": WindowData{num:if text==""{ selected } else { -1 }},
"hi": WindowData{bol:hi},
"fnchg":WindowData{fun:fnchg}
}
}
Expand All @@ -48,6 +48,9 @@ fn draw_selectbox(app &Window, object map[string]WindowData){
})

if app.focus==object["id"].str {
$if !dont_clip ? {
app.gg.scissor_rect(object["x"].num,object["y"].num+object["h"].num,object["w"].num,object["h"].num*object["list"].str.split("\0").len)
}
for which_item, item in object["list"].str.split("\0"){
app.gg.draw_rect_filled(object["x"].num, object["y"].num+object["h"].num*(which_item+1), object["w"].num, object["h"].num, object["bg"].clr)
app.gg.draw_rect_filled(object["x"].num+2, object["y"].num+2+object["h"].num*(which_item+1), object["w"].num-4, object["h"].num-4, object["bfg"].clr)
Expand Down

0 comments on commit b5a21dc

Please sign in to comment.