Mercurial > dwindows
comparison android/DWindows.kt @ 2656:2bdbd5e83654
Android: Save splitbar settings in dataArrayMap instead of attempting to calculate them.
This also allows the use of dw_window_s/get_data() on the splitbar handle.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 18 Sep 2021 23:57:31 +0000 |
parents | 5b63a3ed8e10 |
children | ad6fc7f1a9af |
comparison
equal
deleted
inserted
replaced
2655:5b63a3ed8e10 | 2656:2bdbd5e83654 |
---|---|
2004 { | 2004 { |
2005 var splitbar: ConstraintLayout? = null | 2005 var splitbar: ConstraintLayout? = null |
2006 | 2006 |
2007 waitOnUiThread { | 2007 waitOnUiThread { |
2008 splitbar = ConstraintLayout(this) | 2008 splitbar = ConstraintLayout(this) |
2009 | |
2010 if(splitbar != null) { | 2009 if(splitbar != null) { |
2011 val constraintSet = ConstraintSet() | 2010 val constraintSet = ConstraintSet() |
2011 val dataArrayMap = SimpleArrayMap<String, Long>() | |
2012 | |
2012 constraintSet.clone(splitbar) | 2013 constraintSet.clone(splitbar) |
2013 | 2014 |
2015 splitbar!!.tag = dataArrayMap | |
2014 splitbar!!.id = cid | 2016 splitbar!!.id = cid |
2017 | |
2018 // Add the special data to the array map | |
2019 dataArrayMap.put("_dw_type", type.toLong()) | |
2020 dataArrayMap.put("_dw_percent", 50000000L) | |
2015 | 2021 |
2016 // Place the top/left item | 2022 // Place the top/left item |
2017 if(topleft != null) { | 2023 if(topleft != null) { |
2018 if(topleft.id < 1) { | 2024 if(topleft.id < 1) { |
2019 topleft.id = View.generateViewId() | 2025 topleft.id = View.generateViewId() |
2102 | 2108 |
2103 fun splitBarGet(splitbar: ConstraintLayout): Float { | 2109 fun splitBarGet(splitbar: ConstraintLayout): Float { |
2104 var position: Float = 50.0F | 2110 var position: Float = 50.0F |
2105 | 2111 |
2106 waitOnUiThread { | 2112 waitOnUiThread { |
2107 val topleft: View? = splitbar.getChildAt(0) | 2113 val dataArrayMap: SimpleArrayMap<String, Long> = splitbar.tag as SimpleArrayMap<String, Long> |
2108 val bottomright: View? = splitbar.getChildAt(1) | 2114 var percent: Long = 50000000L |
2109 | 2115 |
2110 if(splitbar.width > 0 && splitbar.height > 0) { | 2116 if(dataArrayMap.containsKey("_dw_percent")) { |
2111 if (topleft != null) { | 2117 percent = dataArrayMap.get("_dw_percent")!! |
2112 if (splitbar.width == topleft.width) { | 2118 } |
2113 position = (topleft.height / splitbar.height) * 100.0F | 2119 |
2114 } else { | 2120 position = percent.toFloat() / 1000000.0F |
2115 position = (topleft.width / splitbar.width) * 100.0F | |
2116 } | |
2117 } else if (bottomright != null) { | |
2118 if (splitbar.width == bottomright.width) { | |
2119 position = 100.0F - ((bottomright.height / splitbar.height) * 100.0F) | |
2120 } else { | |
2121 position = 100.0F - ((bottomright.width / splitbar.width) * 100.0F) | |
2122 } | |
2123 } | |
2124 } | |
2125 } | 2121 } |
2126 return position | 2122 return position |
2127 } | 2123 } |
2128 | 2124 |
2129 fun splitBarSet(splitbar: ConstraintLayout, position: Float) { | 2125 fun splitBarSet(splitbar: ConstraintLayout, position: Float) { |
2130 waitOnUiThread { | 2126 waitOnUiThread { |
2131 val topleft: View? = splitbar.getChildAt(0) | 2127 val dataArrayMap: SimpleArrayMap<String, Long> = splitbar.tag as SimpleArrayMap<String, Long> |
2132 val bottomright: View? = splitbar.getChildAt(1) | 2128 var percent: Float = position * 1000000.0F |
2133 | 2129 |
2134 if(splitbar.width > 0 && splitbar.height > 0) { | 2130 if(percent > 0F) { |
2131 val topleft: View? = splitbar.getChildAt(0) | |
2132 val bottomright: View? = splitbar.getChildAt(1) | |
2135 val constraintSet = ConstraintSet() | 2133 val constraintSet = ConstraintSet() |
2134 var type: Long = 0L | |
2135 | |
2136 if (dataArrayMap.containsKey("_dw_type")) { | |
2137 type = dataArrayMap.get("_dw_type")!! | |
2138 } | |
2139 dataArrayMap.put("_dw_percent", percent.toLong()) | |
2140 | |
2136 constraintSet.clone(splitbar) | 2141 constraintSet.clone(splitbar) |
2137 if (topleft != null) { | 2142 if (topleft != null) { |
2138 if (splitbar.width == topleft.width) { | 2143 if (type == 1L) { |
2139 constraintSet.constrainPercentHeight(topleft.id, position / 100.0F) | 2144 constraintSet.constrainPercentHeight(topleft.id, position / 100.0F) |
2140 } else { | 2145 } else { |
2141 constraintSet.constrainPercentWidth(topleft.id, position / 100.0F) | 2146 constraintSet.constrainPercentWidth(topleft.id, position / 100.0F) |
2142 } | 2147 } |
2143 } | 2148 } |
2144 if (bottomright != null) { | 2149 if (bottomright != null) { |
2145 val altper: Float = (100.0F - position) / 100.0F | 2150 val altper: Float = (100.0F - position) / 100.0F |
2146 if (splitbar.width == bottomright.width) { | 2151 if (type == 1L) { |
2147 constraintSet.constrainPercentHeight(bottomright.id, altper) | 2152 constraintSet.constrainPercentHeight(bottomright.id, altper) |
2148 } else { | 2153 } else { |
2149 constraintSet.constrainPercentWidth(bottomright.id, altper) | 2154 constraintSet.constrainPercentWidth(bottomright.id, altper) |
2150 } | 2155 } |
2151 } | 2156 } |