EasyUniversal / DocsДокументация · SDK 0.3Подписка Universal ↗
Easy Universal / Примеры и шаблоны

templates/gui-panel/gui.as

AngelScript · native runtime · локальная сборка
// Optional module: declare gui.as in package.modules. Not a built-in GUI class.
namespace easy_gui {
    class Theme {
        uint background=0x0c1016ff,panel=0x1a2028ff,text=0xdce2eaff,accent=0xff994dff,border=0x414c58ff;
        void preset(uint index){
            if(index==1){background=0xf1f3f5ff;panel=0xffffffff;text=0x20252cff;accent=0xca5e1bff;border=0xb3bcc7ff;}
            else if(index==2){background=0x141414ff;panel=0x141414ff;text=0xe5e5e5ff;accent=0xff994dff;border=0x505050ff;}
            else{background=0x0c1016ff;panel=0x1a2028ff;text=0xdce2eaff;accent=0xff994dff;border=0x414c58ff;}
        }
        void apply()const{ui::theme(background,panel,text,accent,border);}
        void load(const string &in id){
            background=load_uint(id+"-bg",background);panel=load_uint(id+"-panel",panel);
            text=load_uint(id+"-text",text);accent=load_uint(id+"-accent",accent);border=load_uint(id+"-border",border);
        }
        void save(const string &in id)const{
            if(!gui::enabled())return;
            gui::set(id+"-bg",""+background);gui::set(id+"-panel",""+panel);gui::set(id+"-text",""+text);
            gui::set(id+"-accent",""+accent);gui::set(id+"-border",""+border);
        }
    }
    // Measured rows/columns with padding, spans and per-cell alignment.
    class BoxLayout {
        float x=0,y=0,width=240,gap=8,padding=8,rowHeight=0,offset=0,placedWidth=0,placedHeight=0;
        uint count=1,column=0;
        void begin(float left,float top,float span,uint columns=1,float inset=8,float spacing=8){
            x=easy_ui::bounded(left,-90000,90000,0);y=easy_ui::bounded(top,-90000,90000,0);
            count=columns<1?1:(columns>8?8:columns);
            gap=easy_ui::bounded(spacing,0,32,8);padding=easy_ui::bounded(inset,0,32,8);
            float minimum=24*float(count)+gap*float(count-1)+2*padding;
            width=easy_ui::bounded(span,minimum,2048,minimum);
            column=0;offset=padding;rowHeight=0;
        }
        void row(){if(rowHeight>0){offset+=rowHeight+gap;rowHeight=0;column=0;}}
        vec2 place(uint span,float height,float preferred=0,uint alignment=0){
            span=span<1?1:(span>count?count:span);if(column+span>count)row();
            float cell=(width-2*padding-gap*float(count-1))/float(count),space=cell*float(span)+gap*float(span-1);
            placedWidth=preferred<=0?space:easy_ui::bounded(preferred,24,space,space);
            placedHeight=easy_ui::bounded(height,24,128,32);
            float align=alignment==1?(space-placedWidth)/2:(alignment==2?space-placedWidth:0);
            vec2 result(x+padding+float(column)*(cell+gap)+align,y+offset);
            column+=span;if(placedHeight>rowHeight)rowHeight=placedHeight;
            return result;
        }
        float content_height()const{return offset+rowHeight+padding;}
    }
    class ScrollPanel {
        float offset=0;bool active=false;
        void begin(const string &in id,float content,float x,float y,float width,float height){
            if(active)return;
            offset=ui::scroll(id,offset,content,x,y,width,height);
            render::push_clip(x,y,width,height);active=true;
        }
        void end(){if(active){render::pop_clip();active=false;}}
    }
    uint load_uint(const string &in key,uint fallback) {
        if(!gui::enabled())return fallback;
        string value=gui::get(key);if(value.length()==0||value.length()>10)return fallback;
        uint64 result=0;
        for(uint i=0;i<value.length();i++){if(value[i]<48||value[i]>57)return fallback;result=result*10+uint(value[i]-48);if(result>4294967295)return fallback;}
        return uint(result);
    }
    class Tabs {
        uint index=0;
        bool draw(const string &in id,const array<string> &in labels,float x,float y,float width) {
            uint count=labels.length();if(count==0||count>8){index=0;return false;}
            if(index>=count)index=0;
            float minimum=float(count)*24+float(count-1)*4;
            width=easy_ui::bounded(width,minimum,2048,minimum);
            float cell=(width-float(count-1)*4)/float(count);bool changed=false;
            for(uint i=0;i<count;i++)if(ui::button(id+"-"+i,(index==i?"> ":"")+labels[i],x+float(i)*(cell+4),y,cell,32)){changed=changed||index!=i;index=i;}
            return changed;
        }
    }
    class CheckboxGroup {
        array<bool> values;
        bool draw(const string &in id,const array<string> &in labels,float x,float y,float width) {
            if(labels.length()>16)return false;
            values.resize(labels.length());bool changed=false;
            for(uint i=0;i<labels.length();i++){
                bool next=ui::checkbox(id+"-"+i,labels[i],values[i],x,y+36*float(i),width,32);
                changed=changed||next!=values[i];values[i]=next;
            }
            return changed;
        }
    }
    uint hsv(float hue,float saturation,float value,uint alpha=255) {
        hue=easy_ui::bounded(hue,0,360,0);saturation=easy_ui::bounded(saturation,0,1,0);value=easy_ui::bounded(value,0,1,0);
        float sector=(hue==360?0:hue)/60,c=value*saturation,x=c*(1-math::abs(sector-2*float(uint(sector)/2)-1)),m=value-c;
        float r=0,g=0,b=0;
        if(sector<1){r=c;g=x;}else if(sector<2){r=x;g=c;}else if(sector<3){g=c;b=x;}
        else if(sector<4){g=x;b=c;}else if(sector<5){r=x;b=c;}else{r=c;b=x;}
        return (uint((r+m)*255+0.5f)<<24)|(uint((g+m)*255+0.5f)<<16)|(uint((b+m)*255+0.5f)<<8)|(alpha>255?255:alpha);
    }
    class HsvPicker {
        float hue=28,saturation=0.7f,value=1,alpha=255;
        uint color()const{return hsv(hue,saturation,value,uint(alpha));}
        void draw(const string &in id,float x,float y,float width) {
            hue=ui::slider(id+"-h","Hue",hue,0,360,1,x,y,width,48);
            saturation=ui::slider(id+"-s","Saturation",saturation,0,1,0.01f,x,y+52,width,48);
            value=ui::slider(id+"-v","Brightness",value,0,1,0.01f,x,y+104,width,48);
            alpha=ui::slider(id+"-a","Alpha",alpha,0,255,1,x,y+156,width,48);
            render::rect(x,y+210,width,20,color(),true);
        }
    }
}
Easy Universal — отдельный проект. Easy External не изменён.