DOF/sqr/User/UI/Widget/Scroll_Bar.nut

120 lines
3.1 KiB
Plaintext

/*
文件名:Scroll_Bar.nut
路径:User/UI/Widget/Scroll_Bar.nut
创建日期:2024-12-13 23:17
文件用途:
*/
//滚动条
class Yosin_ScrollBar extends Yosin_CommonUi {
//控制器
Controller = null;
//是否焦点
IsFocus = false;
//上按钮
UpButton = null;
//滚动按钮
ScrollButton = null;
//下按钮
DownButton = null;
//滚动条状态
ScrollBarState = true;
//回调函数
OnChange = null;
//Path
Path = "sprite/interface/lenheartwindowcommon.img";
constructor(X, Y, H, S_H) {
base.constructor(X, Y, 9, H > 26 ? H : 26);
Controller = {
CurPos = 0,
}
//上按钮
UpButton = Yosin_BaseButton(0, 0, 9, 13, Path, 16);
//点击事件回调
UpButton.OnClick = function(Button) {
}.bindenv(this);
AddUIChild(UpButton);
//滚动条
ScrollButton = Yosin_DragButton(0, 13, 9, S_H, Path, 184, false, false, true);
ScrollButton.OnChange = OnChange;
ScrollButton.SetMaxMoveValue(Height - 26);
AddUIChild(ScrollButton);
//下按钮
DownButton = Yosin_BaseButton(0, Height - 13, 9, 13, Path, 22);
//点击事件回调
DownButton.OnClick = function(Button) {
}.bindenv(this);
AddUIChild(DownButton);
}
function Proc(Dt) {
base.Proc(Dt);
if (ScrollButton) Controller.CurPos = ScrollButton.Detect_Value;
}
//设置滚动条长度
function SetScrollBarHeight(height) {
if (ScrollButton) {
RemoveUIChild(ScrollButton);
ScrollButton = null;
}
SetScrollBarState(true);
ScrollButton = Yosin_DragButton(0, 13, 9, height.tointeger(), Path, 184, false, false, true);
ScrollButton.OnChange = OnChange;
ScrollButton.SetMaxMoveValue(Height - 26);
AddUIChild(ScrollButton);
}
//设置滚动条状态
function SetScrollBarState(Flag) {
if (ScrollBarState == Flag) return;
ScrollBarState = Flag;
if (!Flag) {
UpButton.State = 3;
DownButton.State = 3;
if (ScrollButton) {
RemoveUIChild(ScrollButton);
ScrollButton = null;
}
} else {
UpButton.State = 0;
DownButton.State = 0;
}
}
//设置滚动条数值
function SetScrollBarValue(Value) {
if (ScrollButton) {
ScrollButton.SetPos(0, Value * (ScrollButton.Max_Move_Value - ScrollButton.Height + 13))
ScrollButton.DragLogic(Value);
}
}
//设置滚动
function SetScroll(Flag) {
if (ScrollButton) {
local Value = Controller.CurPos;
if (Flag) Value += 0.1;
else Value -= 0.1;
if (Value< 0) Value = 0;
if (Value > 1) Value = 1;
ScrollButton.SetPos(0, Value * (ScrollButton.Max_Move_Value - ScrollButton.Height + 13))
ScrollButton.DragLogic(Value);
}
}
function SetChangeCallBack(Func) {
OnChange = Func;
}
}