Skip to content

Commit

Permalink
604bcc3b: dngviewer & OS: better ux in combobox
Browse files Browse the repository at this point in the history
  • Loading branch information
NicSavichev committed Dec 17, 2024
1 parent 00c020d commit 0f2e51d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
20 changes: 14 additions & 6 deletions outerSpace/prog/scripts/ui/widgets/simpleComponents.nut
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from "%darg/ui_imports.nut" import *
from "%sqstd/underscore.nut" import flatten
from "style.nut" import buttonSound
from "math" import max

let dtext = @(text, style=null) {text, rendObj=ROBJ_TEXT, color = Color(180,180,180)}.__update(style ?? {})

Expand Down Expand Up @@ -38,10 +40,7 @@ function textBtn(text, onClick, style = null) {
onElemState = @(s) stateFlags.set(s)
color = stateFlags.get() & S_HOVER ? Color(255,255,255) : Color(150,250,200)
fontSize = hdpx(40)
sound = {
click = "ui/button"
hover = "ui/button_hover"
}
sound = buttonSound
}.__update(style ?? {})
}

Expand Down Expand Up @@ -150,11 +149,14 @@ function itemToOption(value){
: (t=="table" ? value.text : val)
}
}

function listItem(text, onClick, isCurrent) {
let stateFlags = Watched(0)
return @() {
rendObj = ROBJ_BOX
onClick
size = [flex(), SIZE_TO_CONTENT]
minWidth = SIZE_TO_CONTENT
behavior = Behaviors.Button
watch = stateFlags
onElemState = @(s) stateFlags.set(s)
Expand All @@ -170,6 +172,7 @@ function listItem(text, onClick, isCurrent) {
}
}


function mkCombo(opt, _group=null, _xmbNode=null) {
let watch = opt.var
let values = opt.values
Expand All @@ -178,6 +181,8 @@ function mkCombo(opt, _group=null, _xmbNode=null) {
let curVal = opt?.getValue ?? @() watch.get()
let comboOpen = Watched(false)
let close = @() comboOpen.set(false)
local width = sw(3)

function valueToOption(val) {
let {value, text} = itemToOption(val)
let cur = curVal()
Expand All @@ -187,14 +192,17 @@ function mkCombo(opt, _group=null, _xmbNode=null) {
setValue(val)
close()
}
return listItem(text, handler, isCurrent)
let res = listItem(text, handler, isCurrent)
width = max(width, calc_comp_size(res)[0])
return res
}

function list(){
function list() {
return {
flow = FLOW_VERTICAL
rendObj = ROBJ_SOLID
color = Color(30,30,30)
minWidth = width
watch
children = values.map(valueToOption)
gap = itemGap
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from "%darg/ui_imports.nut" import *
from "%sqstd/underscore.nut" import flatten
from "math" import max

let dtext = @(text, style=null) {text, rendObj=ROBJ_TEXT, color = Color(180,180,180)}.__update(style ?? {})

Expand Down Expand Up @@ -146,11 +147,14 @@ function itemToOption(value){
: (t=="table" ? value.text : val)
}
}

function listItem(text, onClick, isCurrent) {
let stateFlags = Watched(0)
return @() {
rendObj = ROBJ_BOX
onClick
size = [flex(), SIZE_TO_CONTENT]
minWidth = SIZE_TO_CONTENT
behavior = Behaviors.Button
watch = stateFlags
onElemState = @(s) stateFlags.set(s)
Expand All @@ -166,6 +170,7 @@ function listItem(text, onClick, isCurrent) {
}
}


function mkCombo(opt, _group=null, _xmbNode=null) {
let watch = opt.var
let values = opt.values
Expand All @@ -174,6 +179,8 @@ function mkCombo(opt, _group=null, _xmbNode=null) {
let curVal = opt?.getValue ?? @() watch.get()
let comboOpen = Watched(false)
let close = @() comboOpen.set(false)
local width = sw(3)

function valueToOption(val) {
let {value, text} = itemToOption(val)
let cur = curVal()
Expand All @@ -183,14 +190,17 @@ function mkCombo(opt, _group=null, _xmbNode=null) {
setValue(val)
close()
}
return listItem(text, handler, isCurrent)
let res = listItem(text, handler, isCurrent)
width = max(width, calc_comp_size(res)[0])
return res
}

function list(){
function list() {
return {
flow = FLOW_VERTICAL
rendObj = ROBJ_SOLID
color = Color(30,30,30)
minWidth = width
watch
children = values.map(valueToOption)
gap = itemGap
Expand Down

0 comments on commit 0f2e51d

Please sign in to comment.