59 lines
1.4 KiB
Plaintext
59 lines
1.4 KiB
Plaintext
#module "selectable"
|
|
#import "drawing_props"
|
|
#import "style"
|
|
#import "control_props"
|
|
|
|
SelectableSpec :: struct {
|
|
bounds: Rectangle
|
|
selected: bool
|
|
hovered: bool
|
|
pressed: bool
|
|
disabled: bool
|
|
face: StyleFrame
|
|
label_inset: float
|
|
}
|
|
|
|
SelectablePaint :: struct {
|
|
bounds: Rectangle
|
|
fill_color: u32
|
|
text_color: u32
|
|
label_x: float
|
|
draw_fill: bool
|
|
}
|
|
|
|
SelectableToggleResult :: struct {
|
|
selected: bool
|
|
changed: bool
|
|
}
|
|
|
|
SelectableLabelInset :: (scale: float, face: StyleFrame) -> float #export {
|
|
if scale <= 0.0 { scale = 1.0 }
|
|
inset: float = face.value.padding_x
|
|
if (face.value.fields & (u32)StylePaddingX) == (u32)0 ||
|
|
inset < 0.0 {
|
|
inset = 8.0
|
|
}
|
|
return inset * scale
|
|
}
|
|
|
|
SelectablePaintFor :: (spec: SelectableSpec) -> SelectablePaint #export {
|
|
paint: SelectablePaint
|
|
paint.bounds = spec.bounds
|
|
paint.label_x = spec.bounds.x + spec.label_inset
|
|
paint.text_color = spec.face.value.foreground
|
|
paint.draw_fill = !spec.disabled && (spec.selected || spec.hovered || spec.pressed)
|
|
paint.fill_color = spec.face.value.background
|
|
return paint
|
|
}
|
|
|
|
SelectableToggleFor :: (selected: bool, activated: bool, has_value: bool) -> SelectableToggleResult #export {
|
|
result: SelectableToggleResult
|
|
result.selected = selected
|
|
result.changed = false
|
|
if activated && has_value {
|
|
result.selected = !selected
|
|
result.changed = true
|
|
}
|
|
return result
|
|
}
|