Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Rowdy.Setup(...);
- import "core";
- import "string";
- import "event";
- import "class";
- package "ui";
- local base, metatable, methods = nil, nil, { };
- -- private members
- local function OnLeftDown(self)
- local protected = self[UI.Button];
- protected.textColor = { protected.text:GetFontColor() };
- protected.text:SetFontColor(.2, .5, .3, 1);
- protected.borderColor = { self:GetBorderColor() };
- self:SetBorderColor(.2, .5, .3, 1);
- end
- local function OnLeftUpOutside(self)
- local protected = self[UI.Button];
- if (not protected.textColor or not protected.borderColor) then
- return;
- end
- protected.text:SetFontColor(unpack(protected.textColor));
- self:SetBorderColor(unpack(protected.borderColor));
- end
- local function OnLeftUp(self)
- OnLeftUpOutside(self);
- self.Event.Click(self);
- end
- local function UpdateSize(self)
- local protected = self[UI.Button];
- local textFrame = protected.text;
- self:SetWidth(textFrame:GetWidth() + 20);
- self:SetHeight(textFrame:GetHeight() + 10);
- end
- -- public members
- methods.SetText = function(self, text)
- local protected = self[UI.Button];
- local textFrame = protected.text;
- textFrame:SetText(text);
- if (protected.autosize) then
- UpdateSize(self);
- end
- end
- methods.SetAutoSize = function(self, value)
- self[UI.Button].autosize = value;
- if (value) then
- UpdateSize(self);
- end
- end
- methods.GetAutoSize = function(self, value)
- return self[UI.Button].autosize;
- end
- -- constructor
- UI.Button = function(parent)
- assert(isInstanceOf(parent, UI.Context) or isInstanceOf(parent, UI.FrameBase),
- "UI.Button requires 'parent' (UI.Context) parameter");
- local name = parent:GetName() .. "Button";
- local self = UI.FramedFrame(name, parent);
- self:SetWidth(20);
- self:SetHeight(20);
- local text = UI.Text(name .. "Text", self);
- text:SetPoint("CENTER", self, "CENTER", -0.5, -1);
- text:SetAutoSize(true);
- self.Event.LeftDown = OnLeftDown;
- self.Event.LeftUp = OnLeftUp;
- self.Event.LeftUpoutside = OnLeftUpOutside;
- self[UI.Button] = {
- text = text,
- };
- self.Event:add("Click");
- base, metatable = class(base, metatable, methods, self, UI.Button);
- self:SetAutoSize(true);
- return self;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement