Add TypesSelector, simplify default styles

This commit is contained in:
Edwin Jakobs
2020-03-26 22:54:24 +01:00
parent c1d6f698ec
commit 46d48cd07b
4 changed files with 33 additions and 59 deletions

View File

@@ -183,23 +183,15 @@ class GUI : Extension {
this.height = 175.px
}
descendant(has type "sequence-editor") {
descendant(has type listOf(
"sequence-editor",
"sliders-vector2",
"sliders-vector3",
"sliders-vector4"
)) {
this.width = 175.px
this.height = 100.px
}
descendant(has type "sliders-vector2") {
this.width = 175.px
this.height = 100.px
}
descendant(has type "sliders-vector3") {
this.width = 175.px
this.height = 100.px
}
descendant(has type "sliders-vector4") {
this.width = 175.px
this.height = 100.px
}
//</editor-fold>
}

View File

@@ -5,7 +5,6 @@ import org.openrndr.math.Vector2
import org.openrndr.math.Vector3
import org.openrndr.math.Vector4
class SlidersVector2 : SequenceEditorBase("sliders-vector2") {
var value : Vector2
get() {

View File

@@ -98,43 +98,12 @@ fun defaultStyles(
marginRight = 5.px
},
styleSheet(has type "sequence-editor") {
height = 60.px
width = 100.percent
marginTop = 5.px
marginBottom = 15.px
marginLeft = 5.px
marginRight = 5.px
color = controlTextColor
and(has state "active") {
color = controlActiveColor
}
},
styleSheet(has type "sliders-vector2") {
height = 60.px
width = 100.percent
marginTop = 5.px
marginBottom = 15.px
marginLeft = 5.px
marginRight = 5.px
color = controlTextColor
and(has state "active") {
color = controlActiveColor
}
},
styleSheet(has type "sliders-vector3") {
height = 60.px
width = 100.percent
marginTop = 5.px
marginBottom = 15.px
marginLeft = 5.px
marginRight = 5.px
color = controlTextColor
and(has state "active") {
color = controlActiveColor
}
},
styleSheet(has type "sliders-vector4") {
styleSheet(has type listOf(
"sequence-editor",
"sliders-vector2",
"sliders-vector3",
"sliders-vector4"
)) {
height = 60.px
width = 100.percent
marginTop = 5.px
@@ -156,8 +125,6 @@ fun defaultStyles(
marginRight = 5.px
},
styleSheet(has type "xy-pad") {
display = Display.BLOCK
background = Color.RGBa(ColorRGBa.GRAY)

View File

@@ -15,6 +15,7 @@ class CompoundSelector {
companion object {
val DUMMY = CompoundSelector()
}
var previous: Pair<Combinator, CompoundSelector>?
var selectors: MutableList<Selector>
@@ -84,6 +85,14 @@ class TypeSelector(val type: ElementType) : Selector() {
}
}
class TypesSelector(vararg types: ElementType) : Selector() {
private val typeSet = types.toSet()
override fun accept(element: Element): Boolean = element.type in typeSet
override fun toString(): String {
return "TypesSelector(types=$typeSet)"
}
}
class PseudoClassSelector(val c: ElementPseudoClass) : Selector() {
override fun accept(element: Element): Boolean = c in element.pseudoClasses
override fun toString(): String {
@@ -93,7 +102,7 @@ class PseudoClassSelector(val c: ElementPseudoClass) : Selector() {
}
object has {
operator fun invoke (vararg selectors:CompoundSelector) : CompoundSelector {
operator fun invoke(vararg selectors: CompoundSelector): CompoundSelector {
val active = CompoundSelector()
selectors.forEach {
active.selectors.addAll(it.selectors)
@@ -101,26 +110,33 @@ object has {
return active
}
infix fun state(q:String):CompoundSelector {
infix fun state(q: String): CompoundSelector {
val active = CompoundSelector()
active.selectors.add(PseudoClassSelector(ElementPseudoClass((q))))
return active
}
infix fun class_(q:String): CompoundSelector {
infix fun class_(q: String): CompoundSelector {
val active = CompoundSelector()
active.selectors.add(ClassSelector(ElementClass(q)))
return active
}
infix fun type(q:String):CompoundSelector {
infix fun type(q: String): CompoundSelector {
val active = CompoundSelector()
active.selectors.add(TypeSelector(ElementType(q)))
return active
}
infix fun type(qs: Iterable<String>): CompoundSelector {
val active = CompoundSelector()
val aqs = qs.map { ElementType(it) }.toList().toTypedArray()
active.selectors.add(TypesSelector(*aqs))
return active
}
}
infix fun CompoundSelector.and(other:CompoundSelector):CompoundSelector {
infix fun CompoundSelector.and(other: CompoundSelector): CompoundSelector {
val c = CompoundSelector()
c.previous = previous
c.selectors.addAll(selectors)