diff --git a/sqr/User/UI/Widget/Drag_Button.nut b/sqr/User/UI/Widget/Drag_Button.nut index bdb5c2b..4934f04 100644 --- a/sqr/User/UI/Widget/Drag_Button.nut +++ b/sqr/User/UI/Widget/Drag_Button.nut @@ -15,6 +15,9 @@ class Yosin_DragButton extends Yosin_CommonUi { //按钮 Button = null; + //变动位置回调函数 + OnChange = null; + //鼠标相对位置 M_Xpos = null; M_Ypos = null; @@ -26,6 +29,8 @@ class Yosin_DragButton extends Yosin_CommonUi { Max_Move_Value = 0; //移动值 Move_Value = 0; + //侦测值 + Detect_Value = 0; constructor(X, Y, W, H, Path, Idx, Direction = true, UnavailableFlag = true) { this.Path = Path; @@ -41,6 +46,7 @@ class Yosin_DragButton extends Yosin_CommonUi { x = X, y = Y } + } //override @@ -67,16 +73,28 @@ class Yosin_DragButton extends Yosin_CommonUi { //左键拖动 if (Direction) { Move_Value = B_X + (MousePos_X - M_Xpos); - if (Move_Value >= (0 + BasePos.x) && Move_Value<(Max_Move_Value - Width + BasePos.x)) X = Move_Value; + if (!(Move_Value >= (0 + BasePos.x) && Move_Value <= (Max_Move_Value - Width + BasePos.x))) { + X = Move_Value; + DragLogic((Move_Value - Localtion_X).tofloat() / (Max_Move_Value - Width + BasePos.x - Localtion_X).tofloat()); + } } else { Move_Value = B_Y + (MousePos_Y - M_Ypos); - if (Move_Value >= (0 + BasePos.y) && Move_Value<(Max_Move_Value - Height + BasePos.y)) Y = (Move_Value); + if (Move_Value >= (0 + BasePos.y) && Move_Value <= (Max_Move_Value - Height + BasePos.y)) { + Y = (Move_Value); + DragLogic((Move_Value - Localtion_Y).tofloat() / (Max_Move_Value - Height + BasePos.y - Localtion_Y).tofloat()); + } } SyncPos(X, Y); } } + //拖动逻辑 + function DragLogic(Value) { + Detect_Value = Value; + if (OnChange) OnChange(Value); + } + //鼠标左键弹起回调 function OnMouseLbUp(MousePos_X, MousePos_Y) { base.OnMouseLbUp(MousePos_X, MousePos_Y); diff --git a/sqr/User/UI/Widget/Scroll_Bar.nut b/sqr/User/UI/Widget/Scroll_Bar.nut index cd39151..690f073 100644 --- a/sqr/User/UI/Widget/Scroll_Bar.nut +++ b/sqr/User/UI/Widget/Scroll_Bar.nut @@ -4,7 +4,7 @@ 创建日期:2024-12-13 23:17 文件用途: */ -//基础按钮 +//滚动条 class Yosin_ScrollBar extends Yosin_CommonUi { //控制器 Controller = null; @@ -19,6 +19,9 @@ class Yosin_ScrollBar extends Yosin_CommonUi { //下按钮 DownButton = null; + //回调函数 + OnChange = null; + //Path Path = "sprite/interface/lenheartwindowcommon.img"; @@ -54,6 +57,11 @@ class Yosin_ScrollBar extends Yosin_CommonUi { function Proc(Dt) { base.Proc(Dt); + Controller.CurPos = ScrollButton.Detect_Value; + } + + function SetChangeCallBack(Func) { + ScrollButton.OnChange = Func; } } \ No newline at end of file