Comments (2)
Thank you. That was very helpful! I get lost with regards to memory access calculations for arrays and structs in C, so deferring to your expertise alleviates this burden for me.
I amended examples/area_example.rb to utilize dashes
as per your example.
from libui.
Hi Andy
I wrote page6.c in Ruby.
Just pack the contents of arr into a binary sequence.
dashes = [
50.0, # ink
10.0, # skip
10.0, # ink
10.0 # skip
].pack('d*') # array -> string
Here is the correspondence table between types and strings.
require 'libui'
UI = LibUI
UI.init
handler = UI::FFI::AreaHandler.malloc
area = UI.new_area(handler)
brush = UI::FFI::DrawBrush.malloc.tap do |b|
b.Type = 0
b.R = 0.3
b.G = 0.6
b.B = 0.9
b.A = 1.0
end
stroke_params = UI::FFI::DrawStrokeParams.malloc.tap do |sp|
dashes = [
50.0, # ink
10.0, # skip
10.0, # ink
10.0 # skip
].pack('d*') # here!
ndash = 4
offset = -50.0
sp.Cap = UI::DrawLineCapFlat
sp.Join = UI::DrawLineJoinMiter
sp.MiterLimit = 10
sp.Dashes = dashes
sp.NumDashes = ndash
sp.DashPhase = offset
sp.Thickness = 10.0
end
handler_draw_event = Fiddle::Closure::BlockCaller.new(0, [1, 1, 1]) do |_, _, area_draw_params|
UI.draw_new_path(UI::DrawFillModeWinding).then do |path|
UI.draw_path_new_figure(path, 128.0, 25.6)
UI.draw_path_line_to(path, 230.4, 230.4)
UI.draw_path_line_to(path, 230.4 - 102.4, 230.4 + 0.0)
UI.draw_path_bezier_to(path,
51.2, 230.4,
51.2, 128.0,
128.0, 128.0)
UI.draw_path_end(path)
area_draw_params = UI::FFI::AreaDrawParams.new(area_draw_params)
UI.draw_stroke(area_draw_params.Context, path, brush.to_ptr, stroke_params)
UI.draw_free_path(path)
end
end
handler.Draw = handler_draw_event
# These callbacks are not protected from GC. It's really not very good.
handler.MouseEvent = Fiddle::Closure::BlockCaller.new(0, [0]) {}
handler.MouseCrossed = Fiddle::Closure::BlockCaller.new(0, [0]) {}
handler.DragBroken = Fiddle::Closure::BlockCaller.new(0, [0]) {}
handler.KeyEvent = Fiddle::Closure::BlockCaller.new(0, [0]) {}
box = UI.new_vertical_box
UI.box_set_padded(box, 1)
UI.box_append(box, area, 1)
main_window = UI.new_window('Basic Draw Dash', 300, 300, 1)
UI.window_set_margined(main_window, 1)
UI.window_set_child(main_window, box)
UI.window_on_closing(main_window) do
UI.control_destroy(main_window)
UI.quit
0
end
UI.control_show(main_window)
UI.main
UI.quit
from libui.
Related Issues (20)
- Small bug (I think) in examples/ directory, at the file called draw_text.rb HOT 2
- Addition of another example? Basic colour table - see Andy's example in glimmer-libui-dsl HOT 1
- Turing Pattern HOT 2
- Examples: could an example be added for LibUI.new_scrolling_area? HOT 5
- [Possible bug or strange behaviour] On 2nd run the libui window is black HOT 8
- libui-ng HOT 8
- ARM64/AARCH64 Support HOT 26
- Exe wont start (Fiddle::DLError) Windows 11 Notebook HOT 14
- Glimmer DSL for LibUI Wins Fukuoka Ruby 2022 Special Award HOT 1
- libui-ng - "beta" ffi for it, for "early testing"? HOT 6
- Warning message when running LibUI::FFI.uiInit on Mac HOT 2
- Example for Parent and Child Windows HOT 8
- [Question] Field Edit sign restriction visible in GUI? HOT 1
- libui-ng related methods: how to use it? HOT 1
- Organising on https://github.com/kojix2 ? HOT 3
- Custom toplevel methods: aiming to enhance LibUI HOT 2
- Two things about libui-ng: one is a build failure with "rake"; the other is a suggestion HOT 2
- Table Selection API HOT 12
- Question: Why choose `fiddle` rather than `ffi`? HOT 4
- Two duplicate lines, I think, at: https://github.com/kojix2/LibUI/blob/main/examples/draw_text.rb#L92 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libui.