Git Product home page Git Product logo

wings's Introduction

Wings - A simple GUI library for D based on Win32 API.

Screenshot

image

How to use:

  1. Clone or download the repo.
  2. Place the wings folder in your project folder.
  3. Import wings module in your source file. Done.
  4. NOTE: You need a manifest file to style your gui. Copy and paste the app.exe.manifest file from this repo to your exe location. And rename the file with your exe file's name. For example, if your exe file's name is program.exe, the manifest file must be program.exe.manifest.

Sample code

Below is the code that created the window in above screenshot

// Since, Wings use delegates for event handling and D is an OOP language...
// We can wrap up the entire app in a class. It's handy.
import wings;

class App {
	this() {
		this.createControls();
		this.setControlProps();		
	}

	void createControls() {
		// First of all, create the form aka window.
		frm = new Form("Wing window in D Lang", 920, 500);
		frm.createHandle();

		// If this set to true, all control handles will be
		// created right after the class ctor finished.
		frm.createChildHandles = true; 

		//Let's add a menu bar and some menu items
		mb = frm.addMenuBar("Windows", "Linux", "MacOS");
		
		// Add 3 buttons
		btn1 = new Button(frm, "Normal", 10, 10);
		btn2 = new Button(frm, "Color", btn1.right!10, 10);
		btn3 = new Button(frm, "Gradient", btn2.right!10, 10);

		cmb = new ComboBox(frm, btn3.right!10, 10, 150, 30);
		dtp = new DateTimePicker(frm, cmb.right!10, 10); 

		gb1 = new GroupBox(frm, "Compiler Options", 10, btn1.bottom!10, 200, 170);
		cb1 = new CheckBox(frm, "Profile", 15, btn1.bottom!40);
		cb2 = new CheckBox(frm, "Low Mem", 15, cb1.bottom!10);
		rb1 = new RadioButton(frm, "Console App", 15, cb2.bottom!10);
		rb2 = new RadioButton(frm, "Windowed App", 15, rb1.bottom!10);

		gb2 = new GroupBox(frm, "Project Data", 10, gb1.bottom!10, 220, 100);
		lb1 = new Label(frm, "Line Space", gb2.left!10, gb2.top!30);
		lb2 = new Label(frm, "Thread Count", gb2.left!10, lb1.bottom!10);

		// NumberPicker aka NumericUpdown in .NET
		np1 = new NumberPicker(frm, lb1.right!33, gb2.top!25);	
		np2 = new NumberPicker(frm, lb2.right!10, gb2.top!57, btnLeft: true);

		pgb = new ProgressBar(frm, 10, gb2.bottom!10, 204, 25, true);
		tb = new TextBox(frm, 10, pgb.bottom!10, pgb.width, 30);
		lbx = new ListBox(frm, gb1.right!10, btn1.bottom!15, 120, 160);

		// ListView ctor takes an array for items and another for col widths.
		lv = new ListView(frm, lbx.right!10, btn1.bottom!15, 300, 180, true,
 					 ["Windows", "Linux", "MacOS"], [80, 120, 100] );

		// Trackbar ctor takes a delegate for onValueChanged event.
		tkb1 = new TrackBar(frm, dtp.right!10, 10, 150, 40, true, true, &this.onTrackValueChanged);

		tv = new TreeView(frm, lv.right!10, lv.ypos, 200, 200, true);

		// Calendar aka MonthCalendar in .NET
		cal = new Calendar(frm, gb2.right!10, lv.bottom!15);

		// Another trackbar but this time, it's vertical.
		tkb2 = new TrackBar(frm, 500, 270, 60, 150, vertical: true, cdraw: true);

		// Add a timer with a delegate to handle the onTick event.
		tmr = frm.addTimer(800, &this.timerTickHandler);
	}

	void setControlProps() {	
		// Set some properties of our controls.
		btn1.onClick = &this.btn1OnClick;
		btn2.backColor = 0x83c5be;
		btn3.setGradientColors(0xeeef20, 0x70e000);
		cmb.addRange("Form", "Button", "Calendar", "CheckBox", "ComboBox", "DateTimePicker", "GroupBox", 4500);
		cmb.dropDownStyle = DropDownStyle.labelCombo;
		cmb.selectedIndex = 4;
		gb1.foreColor = 0xd90429; // This only works for GroupBox text.
		np1.foreColor = 0x3f37c9;
		np1.step = 0.25; 
		np2.decimalPrecision = 0;
		np2.backColor = 0xcaffbf; 
		pgb.showPercentage = true;
		tb.foreColor = 0xff0000;    
		lbx.addRange("Windows", "Linux", "MacOS", "ReactOS");	
		lv.addRow("XP", "Mountain Lion", "RedHat");
		lv.addRow("Vista", "Mavericks", "Mint");
		lv.addRow("Win7", "Mavericks", "Ubuntu");
		lv.addRow("Win8", "Catalina", "Debian");
		lv.addRow("Win10", "Big Sur", "Kali");
		lv.addContextMenu("Windows", "Linux", "MacOS");
		tv.backColor = 0xddddbb;
		auto n1 = new TreeNode("Windows");
		auto n2 = new TreeNode("Linux");
		auto n3 = new TreeNode("MacOS");
		auto n4 = new TreeNode("ReactOS");
		tv.addNodes(n1, n2, n3, n4);
		auto wn1 = new TreeNode("Win 11");
		auto wn2 = new TreeNode("Win 10");
		auto wn3 = new TreeNode("Win 8");	
		tv.addChildNodes(n1, wn1, wn2, wn3);
		auto ln1 = new TreeNode("Ubuntu");
		auto ln2 = new TreeNode("Debian");
		auto ln3 = new TreeNode("Fedora");
		tv.addChildNodes(n2, ln1, ln2, ln3);
		auto mn1 = new TreeNode("Monterey");
		auto mn2 = new TreeNode("Catalina");
		auto mn3 = new TreeNode("Mojave");
		tv.addChildNodes(n3, mn1, mn2, mn3);

		// Add menu items for our main menus.
		mb.menus["Windows"].addItems("Windows 8", "Windows 10", "Windows 11");
		mb.menus["Linux"].addItems("Ubuntu", "Debian", "Kali");
		mb.menus["MacOS"].addItems("Mavericks", "Catalina", "Big Sur");
	}

	void display() {this.frm.show();}

	// When clicked on button, combo's drop down style will change. 
	void btn1OnClick(Control s, EventArgs e) {
		this.cmb.dropDownStyle = DropDownStyle.textCombo;
	}

	// Timer tick event handler
	void timerTickHandler(Control c, EventArgs e) {writeln("Timer ticked...");}

	// ProgressBar will show the track bar values.
	void onTrackValueChanged(Control c, EventArgs e) {
		pgb.value = tkb1.value;
	}

	private:
		Form frm;
		Button btn1, btn2, btn3;
		Calendar cal;
		CheckBox cb1, cb2;
		ComboBox cmb;
		DateTimePicker dtp;
		GroupBox gb1, gb2;
		Label lb1, lb2;
		ListBox lbx;
		ListView lv;
		MenuBar mb;
		NumberPicker np1, np2;
		ProgressBar pgb;
		RadioButton rb1, rb2;
		TextBox tb;
		TrackBar tkb1, tkb2;
		TreeView tv;
		Timer tmr;	
}

void main() {
	auto app = new App();	
	app.display();
}

wings's People

Contributors

kcvinker avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

lukyguylucky

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.