Skip to content

Commit

Permalink
add: base of Layout-system
Browse files Browse the repository at this point in the history
  • Loading branch information
TamasSzekeres committed Jan 28, 2018
1 parent 00944c5 commit 045a38b
Show file tree
Hide file tree
Showing 14 changed files with 496 additions and 150 deletions.
19 changes: 19 additions & 0 deletions examples/layout/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{cr,yml}]
indent_style = space
indent_size = 2

[Makefile]
indent_style = tab
indent_size = 4
13 changes: 13 additions & 0 deletions examples/layout/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/bin/
/doc/
/libs/
/lib/
/.crystal/
/.shards/

# Executable
layout

# Libraries don't need dependency lock
# Dependencies will be locked in application that uses them
/shard.lock
1 change: 1 addition & 0 deletions examples/layout/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: crystal
21 changes: 21 additions & 0 deletions examples/layout/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 TamasSzekeres

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
15 changes: 15 additions & 0 deletions examples/layout/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
all:
crystal build src/layout.cr --link-flags -L/usr/X11R6/lib/

clean:
rm layout

clear-deps:
rm -rf .shards
rm -rf lib
rm shard.lock

install:
crystal deps

reinstall: clear-deps install
19 changes: 19 additions & 0 deletions examples/layout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ltk-cr/examples/layout

Simple example application with using layout.

## Usage

Resize the window to view layout working.

## Contributing

1. Fork it ( https://github.com/TamasSzekeres/ltk-cr/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request

## Contributors

- [TamasSzekeres](https://github.com/TamasSzekeres) Tamás Szekeres - creator, maintainer
24 changes: 24 additions & 0 deletions examples/layout/shard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: layout
version: 0.1.0

authors:
- Tamás Szekeres <szektam2@gmail.com>

description: Simple example Window with using layout.

dependencies:
x11:
path: ../../../x11-cr/.
cairo:
path: ../../../cairo-cr/.

ltk:
path: ../../.

targets:
button:
main: src/layout.cr

crystal: 0.24.1

license: MIT
43 changes: 43 additions & 0 deletions examples/layout/src/layout.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require "ltk"

module Layout
include Ltk

class Example
# Handling of clicking on the close_button.
def close_button_click
puts "close_button clicked!"
Application.close
end

def main
# Creating The Main Window.
main_win = MainWindow.new
main_win.title = "Ltk-Win"
main_win.geometry = Rect.new 10, 10, 400, 300
main_win.margins = Margins.new 20, 20, 20, 20

# Creating a PushButton on the Main Window.
one_button = PushButton.new "One", main_win
one_button.object_name = "one_button"
one_button.geometry = Rect.new 20, 20, 150, 23
one_button.on_click = ->close_button_click

two_button = PushButton.new "Two", main_win
two_button.object_name = "two_button"
two_button.geometry = Rect.new 20, 60, 150, 23
two_button.on_click = ->close_button_click

layout = HorizontalLayout.new nil
layout.add_widget one_button
layout.add_widget two_button

main_win.layout = layout

# Runs the application.
Application.run ARGV
end
end

Example.new.main
end
4 changes: 3 additions & 1 deletion src/ltk/base/margins.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Ltk
struct Margins
ZERO = Margins.new 0, 0, 0, 0

property left : Int32
property top : Int32
property right : Int32
Expand Down Expand Up @@ -62,4 +64,4 @@ module Ltk
(@right / divisor).round.to_i, (@bottom / divisor).round.to_i)
end
end
end
end
Loading

0 comments on commit 045a38b

Please sign in to comment.