-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from spbu-coding-2023/refactor/menu
Delete useful code with `by` operator
- Loading branch information
Showing
10 changed files
with
70 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,15 @@ | ||
package viewModel | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import viewModel.canvas.CanvasViewModel | ||
|
||
class MenuViewModel( | ||
val canvasViewModel: CanvasViewModel | ||
) { | ||
var isNodeCreating | ||
get() = canvasViewModel.isNodeCreatingMode | ||
set(value) { | ||
canvasViewModel.isNodeCreatingMode = value | ||
} | ||
|
||
fun onNodeCreatingChange() { | ||
isNodeCreating = !isNodeCreating | ||
} | ||
|
||
var isClustering | ||
get() = canvasViewModel.isClustering | ||
set(value) { | ||
canvasViewModel.isClustering = value | ||
} | ||
|
||
fun onClusteringChange() { | ||
isClustering = !isClustering | ||
} | ||
|
||
var isRanked | ||
get() = canvasViewModel.isRanked | ||
set(value) { | ||
canvasViewModel.isRanked = value | ||
} | ||
|
||
fun onRankedChange() { | ||
isRanked = !isRanked | ||
} | ||
|
||
val _isAlgorithmMenuOpen = mutableStateOf(false) | ||
var isAlgorithmMenuOpen | ||
get() = _isAlgorithmMenuOpen.value | ||
set(value) { | ||
_isAlgorithmMenuOpen.value = value | ||
} | ||
|
||
fun onAlgorithmMenuOpenChange() { | ||
isAlgorithmMenuOpen = !isAlgorithmMenuOpen | ||
} | ||
var isNodeCreating by canvasViewModel::isNodeCreatingMode | ||
var isClustering by canvasViewModel::isClustering | ||
var isRanked by canvasViewModel::isRanked | ||
var isAlgorithmMenuOpen by mutableStateOf(false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
package viewModel.canvas | ||
|
||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.ui.graphics.Color | ||
import viewModel.graph.EdgeViewModel | ||
|
||
class EdgeCanvasViewModel( | ||
val first: VertexCanvasViewModel, | ||
val second: VertexCanvasViewModel, | ||
val color: Color, | ||
strokeWidth: Float, | ||
zoom: Float, | ||
val showOrientation: MutableState<Boolean> | ||
val edgeViewModel: EdgeViewModel, | ||
private val canvasViewModel: CanvasViewModel, | ||
) { | ||
var strokeWidth = strokeWidth * (zoom) | ||
var showOrientation by canvasViewModel::isOrientated | ||
|
||
fun updateEdge(zoom: Float) { | ||
strokeWidth = 8f * zoom | ||
} | ||
val strokeWidth | ||
get() = edgeViewModel.strokeWidth * canvasViewModel.zoom | ||
} |
68 changes: 15 additions & 53 deletions
68
src/main/kotlin/viewModel/canvas/VertexCanvasViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,31 @@ | ||
package viewModel.canvas | ||
|
||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.ui.geometry.Offset | ||
import viewModel.graph.VertexViewModel | ||
|
||
class VertexCanvasViewModel( | ||
val vertexViewModel: VertexViewModel, | ||
private val zoom: MutableState<Float>, | ||
private val center: MutableState<Offset>, | ||
private val canvasSize: MutableState<Offset> | ||
private val vertexViewModel: VertexViewModel, | ||
private val canvasViewModel: CanvasViewModel, | ||
) { | ||
private val _offset = mutableStateOf( | ||
calculateOffset() | ||
) | ||
var offset | ||
get() = _offset.value | ||
set(value) { | ||
_offset.value = value | ||
} | ||
|
||
private val _radius = mutableStateOf(calculateRadius()) | ||
var radius | ||
get() = _radius.value | ||
set(value) { | ||
_radius.value = value | ||
} | ||
|
||
var color | ||
get() = vertexViewModel.color | ||
set(value) { | ||
vertexViewModel.color = value | ||
} | ||
val color by vertexViewModel::color | ||
val label by vertexViewModel::label | ||
|
||
private val _strokeWidth = mutableStateOf(calculateStrokeWidth()) | ||
var strokeWidth | ||
get() = _strokeWidth.value | ||
set(value) { | ||
_strokeWidth.value = value | ||
} | ||
val strokeWidth | ||
get() = 8f * canvasViewModel.zoom | ||
val radius | ||
get() = vertexViewModel.radius * canvasViewModel.zoom | ||
val offset | ||
get() = calculateOffset() | ||
|
||
private val _textSize = mutableStateOf(calculateTextSize()) | ||
var textSize | ||
get() = _textSize.value | ||
set(value) { | ||
_textSize.value = value | ||
} | ||
val textSize | ||
get() = vertexViewModel.radius * 0.6f * canvasViewModel.zoom | ||
|
||
fun onDrag(it: Offset): Unit { | ||
vertexViewModel.onDrag(it * (1f / zoom.value)) | ||
} | ||
|
||
fun updateVertex() { | ||
offset = calculateOffset() | ||
radius = calculateRadius() | ||
strokeWidth = calculateStrokeWidth() | ||
textSize = calculateTextSize() | ||
vertexViewModel.onDrag(it * (1f / canvasViewModel.zoom)) | ||
} | ||
|
||
private fun calculateOffset() = Offset( | ||
(canvasSize.value.x / 2) + ((vertexViewModel.x - center.value.x) * zoom.value), | ||
(canvasSize.value.y / 2) + ((vertexViewModel.y - center.value.y) * zoom.value) | ||
(canvasViewModel.canvasSize.x / 2) + ((vertexViewModel.x - canvasViewModel.center.x) * canvasViewModel.zoom), | ||
(canvasViewModel.canvasSize.y / 2) + ((vertexViewModel.y - canvasViewModel.center.y) * canvasViewModel.zoom) | ||
) | ||
|
||
private fun calculateRadius() = vertexViewModel.radius * zoom.value | ||
private fun calculateStrokeWidth() = 8f * zoom.value | ||
private fun calculateTextSize() = vertexViewModel.radius * 0.6f * zoom.value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.