This commit is contained in:
lxsang 2020-03-02 17:59:38 +01:00
parent 5d987f8fb6
commit ed03c72e3b
7 changed files with 152 additions and 14 deletions

View File

@ -32,6 +32,8 @@ coffees= src/core/core.coffee \
src/core/tags/LabelTag.coffee \
src/core/tags/ButtonTag.coffee \
src/core/tags/ListViewTag.coffee \
src/core/tags/SwitchTag.coffee \
src/core/tags/NSpinnerTag.coffee \
src/antos.coffee

View File

@ -72,12 +72,12 @@ class ListViewTag extends Ant.OS.GUI.BaseTag
@setopt "multiselect", false
@setopt "selectedItem", undefined
@setopt "selectedItems", []
@items = []
$(@root)
.css "display", "flex"
.css "flex-direction", "column"
multiselect: () ->
return false if @get "dropdown"
@get "multiselect"
@ -89,12 +89,11 @@ class ListViewTag extends Ant.OS.GUI.BaseTag
for item in data
el = $("<#{@get "itemtag"}>").appendTo @refs.mlist
el[0].uify @observable
console.log el
me = @
el[0]
.set "data", item
.set "oncontextmenu", (e) ->
me.icontextmenu e
me.iclick e
.set "ondbclick", (e) ->
me.idbclick e
.set "onclick", (e) ->
@ -108,15 +107,12 @@ class ListViewTag extends Ant.OS.GUI.BaseTag
return if not e.item
list = @get("selectedItems")
if @multiselect() and list.includes(e.item)
list.splice(list.indexOf(e.item))
list.splice(list.indexOf(e.item), 1)
return e.item.set "selected", false
e.item.set "selected", true
icontextmenu: (e) ->
console.log "context menu", e
idbclick: (e) ->
console.log "db click", e
@get("onlistdbclick")(e)
iselect: (e) ->
return unless e.item
if @multiselect()
@ -128,10 +124,18 @@ class ListViewTag extends Ant.OS.GUI.BaseTag
@get("selectedItem").set "selected", false if @get("selectedItem")
@set "selectedItem", e.item
@set "selectedItems", [e.item]
e.items = [e.item]
if @get "dropdown"
@refs.drlabel.set "*", e.item.get "data"
$(@refs.mlist).hide()
@get("onlistselect")(e)
@observable.trigger "listselect", { id: @aid(), evt: e }
iclose: (e) ->
console.log "close", e
return unless e.item
$(e.item).remove()
on_dropdown_changed: (v) ->
$(@refs.container).removeAttr "style"

View File

@ -0,0 +1,44 @@
class MenuEntrySimpleContentTag extends Ant.OS.GUI.BaseTag
constructor: (r, o) ->
super r, o
@setopt "data", {}
layout: () ->
[{
el: "a", children: [
{ el: "afx-switch" },
{ el: "afx-label" },
{ el: "span", class: "shortcut" }
]
}]
class MenuEntryTag extends Ant.OS.GUI.BaseTag
constructor: (r, o) ->
super r, o
@setopt "data", {}
@setopt "contentag", "afx-menu-entry"
on_data_changed: (v) ->
layout: () ->
[{
el: "li", ref: "container"
}]
class MenuTag extends Ant.OS.GUI.BaseTag
constructor: (r, o) ->
super r, o
@setopt "context", false
layout: () ->
[{
el: "ul", children: [
{ el: "li", ref: "start", class: "afx-corner-fix" },
{ el: "li", ref: "end", class: "afx-corner-fix" }
]
}]
Ant.OS.GUI.define "afx-menu", MenuTag
Ant.OS.GUI.define "afx-menu-entry", MenuEntrySimpleContentTag

View File

@ -0,0 +1,45 @@
class NSpinnerTag extends Ant.OS.GUI.BaseTag
constructor: (r, o) ->
super r, o
@setopt "value", 0
@setopt "step", 1
@setopt "onchange", (e) ->
mount: () ->
me = @
$(@refs.holder).attr "type", "text"
$(@refs.incr).click (e) ->
me.set "value", (me.get("value") + me.get("step") )
e.nspin = me.get "value"
me.get("onchange")(e)
me.observable.trigger "nspin", { id: me.aid(), evt: e }
$(@refs.decr).click (e) ->
me.set "value", (me.get("value") - me.get("step") )
e.nspin = me.get "value"
me.get("onchange")(e)
me.observable.trigger "nspin", { id: me.aid(), evt: e }
on_value_changed: (v) ->
$(@refs.holder).val @get("value")
layout: () ->
[
{
el: "input", ref: "holder"
},
{
el: "ul", ref: "spinner", children: [
{ el: "li", class: "incr", ref: "incr", children: [
{ el: "i" }
] },
{ el: "li", class: "decr", ref: "decr", children: [
{ el: "i" }
] }
]
}
]
Ant.OS.GUI.define "afx-nspinner", NSpinnerTag

View File

@ -0,0 +1,30 @@
class SwitchTag extends Ant.OS.GUI.BaseTag
constructor: (r, o) ->
super r, o
@setopt "swon", false
@setopt "enable", true
@setopt "onchange", (e) ->
mount: () ->
me = @
$(@refs.switch).click (e) ->
me.onchange(e)
onchange: (e) ->
return unless @get "enable"
@setopt "swon", !@get("swon")
e.swon = @get "swon"
@get("onchange")(e)
@observable.trigger "switch", { id: @aid(), evt: e }
on_swon_changed: (v) ->
$(@refs.switch).removeClass()
$(@refs.switch).addClass "swon" if v
layout: () ->
[{
el: "span", ref: "switch"
}]
Ant.OS.GUI.define "afx-switch", SwitchTag

View File

@ -36,6 +36,9 @@ class Ant.OS.GUI.BaseTag
@set name, value
set: (opt, value) ->
if opt is "*"
@set k, v for k, v of value
else
@opts[opt] = value
@["on_#{opt}_changed"](value) if @["on_#{opt}_changed"]
@
@ -45,6 +48,7 @@ class Ant.OS.GUI.BaseTag
get: (opt) ->
return @opts if opt is "*"
@opts[opt]
uify: () ->

View File

@ -43,14 +43,16 @@ class ShowCase extends this.OS.GUI.BaseApplication
<afx-resizer data-width="5" />
<afx-vbox data-width="grow">
<afx-hbox min-height="50">
<afx-switch data-id="switch" />
<afx-button text="__(This is the label)"
data-id="bttest"
iconclass="fa fa-camera-retro fa-lg"
icon="os://packages/DummyApp/icon.png"/>
<afx-nspinner data-id="spin" value="10" step="2" />
</afx-hbox>
<afx-resizer data-height="5" />
<afx-hbox>
<afx-list-view data-id="list" multiselect="true" />
<afx-list-view data-id="list" dropdown="true" multiselect="false" />
</afx-hbox>
<afx-hbox data-height="150">
<div>box center 3</div>
@ -84,8 +86,8 @@ class ShowCase extends this.OS.GUI.BaseApplication
list[0].set "data", [
{ text: "some thing with avery long text" },
{ text: "some thing 1" },
{ text: "some thing 2" },
{ text: "some thing 1", closable: true },
{ text: "some thing 2", iconclass: "fa fa-camera-retro fa-lg" },
{ text: "some thing 3" },
{ text: "some thing 4" },
{ text: "some thing 5" }
@ -93,6 +95,13 @@ class ShowCase extends this.OS.GUI.BaseApplication
list[0].set "onlistselect", (e) ->
console.log(e.items)
sw = $ "[data-id='switch']", scheme[0]
sw[0].set "onchange", (e) ->
console.log e.swon
spin = $ "[data-id='spin']", scheme[0]
spin[0].set "onchange", (e) ->
console.log e.nspin
ShowCase.singleton = true
this.OS.register "ShowCase", ShowCase