mirror of
https://gitlab.com/cc-ru/ocelot/ocelot-desktop.git
synced 2025-12-20 02:59:19 +01:00
Fix how LogWidget is laid out
This commit is contained in:
parent
2c77f8cba9
commit
d676a4a5bf
@ -5,23 +5,28 @@ import ocelot.desktop.color.RGBAColorNorm
|
|||||||
import ocelot.desktop.geometry.{Padding2D, Rect2D, Size2D, Vector2D}
|
import ocelot.desktop.geometry.{Padding2D, Rect2D, Size2D, Vector2D}
|
||||||
import ocelot.desktop.graphics.{Graphics, IconSource}
|
import ocelot.desktop.graphics.{Graphics, IconSource}
|
||||||
import ocelot.desktop.ui.UiHandler
|
import ocelot.desktop.ui.UiHandler
|
||||||
import ocelot.desktop.ui.event.{ClickEvent, MouseEvent}
|
|
||||||
import ocelot.desktop.ui.event.handlers.MouseHandler
|
import ocelot.desktop.ui.event.handlers.MouseHandler
|
||||||
import ocelot.desktop.ui.layout.{Layout, LinearLayout}
|
import ocelot.desktop.ui.event.{ClickEvent, MouseEvent}
|
||||||
|
import ocelot.desktop.ui.layout.{CopyLayout, Layout}
|
||||||
import ocelot.desktop.ui.widget.LogWidget.{BorderThickness, EntryMargin, EntryPadding, LogEntry}
|
import ocelot.desktop.ui.widget.LogWidget.{BorderThickness, EntryMargin, EntryPadding, LogEntry}
|
||||||
import ocelot.desktop.ui.widget.contextmenu.{ContextMenu, ContextMenuEntry}
|
import ocelot.desktop.ui.widget.contextmenu.{ContextMenu, ContextMenuEntry}
|
||||||
import ocelot.desktop.util.{DrawUtils, Orientation}
|
import ocelot.desktop.util.DrawUtils
|
||||||
|
|
||||||
import scala.annotation.tailrec
|
import scala.annotation.tailrec
|
||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
|
|
||||||
abstract class LogWidget extends Widget {
|
abstract class LogWidget extends Widget {
|
||||||
override protected val layout: Layout = new LinearLayout(this, orientation = Orientation.Vertical)
|
override protected val layout: Layout = new CopyLayout(this)
|
||||||
|
|
||||||
private object MessageListWidget extends Widget with MouseHandler { messageList =>
|
private object MessageListWidget extends Widget with MouseHandler { messageList =>
|
||||||
override protected val layout: Layout = new Layout(this)
|
override protected val layout: Layout = new Layout(this) {
|
||||||
|
override def recalculateBounds(): Unit = {
|
||||||
|
super.recalculateBounds()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private val entries = mutable.ArrayDeque.empty[Entry]
|
private val entries = mutable.ArrayDeque.empty[Entry]
|
||||||
|
private var needRelayout = false
|
||||||
|
|
||||||
val dummyEntry: Entry = new RxEntry("", nextMessageY)
|
val dummyEntry: Entry = new RxEntry("", nextMessageY)
|
||||||
|
|
||||||
@ -62,6 +67,8 @@ abstract class LogWidget extends Widget {
|
|||||||
nextMessageY - removedOffset,
|
nextMessageY - removedOffset,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
override def maximumSize: Size2D = minimumSize
|
||||||
|
|
||||||
private def nextMessageY: Float = {
|
private def nextMessageY: Float = {
|
||||||
entries.lastOption.map(_.maxY).getOrElse(0f) + EntryMargin
|
entries.lastOption.map(_.maxY).getOrElse(0f) + EntryMargin
|
||||||
}
|
}
|
||||||
@ -72,7 +79,7 @@ abstract class LogWidget extends Widget {
|
|||||||
case LogEntry.Tx(message) => new TxEntry(message, nextMessageY)
|
case LogEntry.Tx(message) => new TxEntry(message, nextMessageY)
|
||||||
})
|
})
|
||||||
|
|
||||||
parent.get.recalculateBoundsAndRelayout()
|
needRelayout = true
|
||||||
}
|
}
|
||||||
|
|
||||||
def removeFirst(count: Int): Unit = {
|
def removeFirst(count: Int): Unit = {
|
||||||
@ -82,10 +89,7 @@ abstract class LogWidget extends Widget {
|
|||||||
entries.dropInPlace(count)
|
entries.dropInPlace(count)
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is a fix for log widget not scaling down after being cleaned
|
needRelayout = true
|
||||||
// TODO: implement it nicely
|
|
||||||
size = minimumSize
|
|
||||||
parent.get.recalculateBoundsAndRelayout()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@tailrec
|
@tailrec
|
||||||
@ -106,6 +110,15 @@ abstract class LogWidget extends Widget {
|
|||||||
entries.iterator.drop(firstVisibleIdx).takeWhile(_.absoluteBounds.y <= clippedBounds.max.y)
|
entries.iterator.drop(firstVisibleIdx).takeWhile(_.absoluteBounds.y <= clippedBounds.max.y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override def update(): Unit = {
|
||||||
|
if (needRelayout) {
|
||||||
|
recalculateBoundsAndRelayout()
|
||||||
|
needRelayout = false
|
||||||
|
}
|
||||||
|
|
||||||
|
super.update()
|
||||||
|
}
|
||||||
|
|
||||||
override def draw(g: Graphics): Unit = {
|
override def draw(g: Graphics): Unit = {
|
||||||
applyRemovedOffset()
|
applyRemovedOffset()
|
||||||
for (entry <- visibleEntries) {
|
for (entry <- visibleEntries) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user